aboutsummaryrefslogtreecommitdiffstats
path: root/predicate-search/src/main/java/com/yahoo/search/predicate/Config.java
blob: 6b731b6221d4aba972a0f6ff197d178967b130ac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.predicate;

import com.yahoo.api.annotations.Beta;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

/**
 * Configuration for a {@link PredicateIndexBuilder}/{@link PredicateIndex} instance.
 *
 * @author bjorncs
 */
@Beta
public class Config {

    public final int arity;
    public final long lowerBound;
    public final long upperBound;
    public final boolean useConjunctionAlgorithm;

    private Config(int arity, long lowerBound, long upperBound, boolean useConjunctionAlgorithm) {
        this.arity = arity;
        this.lowerBound = lowerBound;
        this.upperBound = upperBound;
        this.useConjunctionAlgorithm = useConjunctionAlgorithm;
    }

    public void writeToOutputStream(DataOutputStream out) throws IOException {
        out.writeInt(arity);
        out.writeLong(lowerBound);
        out.writeLong(upperBound);
        out.writeBoolean(useConjunctionAlgorithm);
    }

    public static Config fromInputStream(DataInputStream in) throws IOException {
        int arity = in.readInt();
        long lowerBound = in.readLong();
        long upperBound = in.readLong();
        boolean useConjunctionAlgorithm = in.readBoolean();
        return new Config(arity, lowerBound, upperBound, useConjunctionAlgorithm);
    }

    public static class Builder {
        private int arity = 8;
        private long lowerBound = Long.MIN_VALUE;
        private long upperBound = Long.MAX_VALUE;
        private boolean useConjunctionAlgorithm = false;

        public Builder setArity(int arity) {
            this.arity = arity;
            return this;
        }

        public Builder setLowerBound(long lowerBound) {
            this.lowerBound = lowerBound;
            return this;
        }

        public Builder setUpperBound(long upperBound) {
            this.upperBound = upperBound;
            return this;
        }

        public Builder setUseConjunctionAlgorithm(boolean enabled) {
            this.useConjunctionAlgorithm = enabled;
            return this;
        }

        public Config build() {
            return new Config(arity, lowerBound, upperBound, useConjunctionAlgorithm);
        }

    }

}