aboutsummaryrefslogtreecommitdiffstats
path: root/predicate-search-core/src/main/java/com/yahoo/document/predicate/RangePartition.java
diff options
context:
space:
mode:
Diffstat (limited to 'predicate-search-core/src/main/java/com/yahoo/document/predicate/RangePartition.java')
-rw-r--r--predicate-search-core/src/main/java/com/yahoo/document/predicate/RangePartition.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/predicate-search-core/src/main/java/com/yahoo/document/predicate/RangePartition.java b/predicate-search-core/src/main/java/com/yahoo/document/predicate/RangePartition.java
new file mode 100644
index 00000000000..33cdd23c45c
--- /dev/null
+++ b/predicate-search-core/src/main/java/com/yahoo/document/predicate/RangePartition.java
@@ -0,0 +1,67 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.document.predicate;
+
+/**
+ * @author <a href="mailto:magnarn@yahoo-inc.com">Magnar Nedland</a>
+ */
+public class RangePartition extends PredicateValue {
+
+ private String label;
+
+ public RangePartition(String label) {
+ this.label = label;
+ }
+
+ public RangePartition(String key, long fromInclusive, long toInclusive, boolean isNeg) {
+ this(makeLabel(key, fromInclusive, toInclusive, isNeg));
+ }
+
+ private static String makeLabel(String key, long fromInclusive, long toInclusive, boolean isNeg) {
+ if (isNeg) {
+ // special case for toInclusive==long_min: It will print its own hyphen.
+ return key + "=" + (toInclusive==0x8000000000000000L? "" : "-") + toInclusive + "-" + fromInclusive;
+ } else {
+ // special case for toInclusive==long_min: It will print its own hyphen.
+ return key + "=" + fromInclusive + (toInclusive==0x8000000000000000L? "" : "-") + toInclusive;
+ }
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ @Override
+ public RangePartition clone() throws CloneNotSupportedException {
+ return (RangePartition)super.clone();
+ }
+
+ @Override
+ public int hashCode() {
+ return label.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof RangePartition)) {
+ return false;
+ }
+ return label.equals(((RangePartition)obj).getLabel());
+ }
+
+ @Override
+ protected void appendTo(StringBuilder out) {
+ int i = label.lastIndexOf('=');
+ appendQuotedTo(label.substring(0, i), out);
+ if (out.charAt(out.length() - 1) == '\'') {
+ out.deleteCharAt(out.length() - 1);
+ out.append(label.substring(i));
+ out.append('\'');
+ } else {
+ out.append(label.substring(i));
+ }
+ }
+
+}