diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /predicate-search/src/main/java/com/yahoo/search/predicate/Config.java |
Publish
Diffstat (limited to 'predicate-search/src/main/java/com/yahoo/search/predicate/Config.java')
-rw-r--r-- | predicate-search/src/main/java/com/yahoo/search/predicate/Config.java | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/predicate-search/src/main/java/com/yahoo/search/predicate/Config.java b/predicate-search/src/main/java/com/yahoo/search/predicate/Config.java new file mode 100644 index 00000000000..23569baab73 --- /dev/null +++ b/predicate-search/src/main/java/com/yahoo/search/predicate/Config.java @@ -0,0 +1,75 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.search.predicate; + +import com.google.common.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); + } + + } +} |