blob: 0ee3c256bf0b8f808387db80bb59dd91fc799a2a (
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
78
79
80
81
82
83
84
85
86
|
// Copyright 2017 Yahoo Holdings. 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 RangeEdgePartition extends RangePartition {
private final long value;
private final int lowerBound;
private final int upperBound;
public RangeEdgePartition(String label, long value, int lower, int upper) {
super(label);
this.value = value;
this.lowerBound = lower;
this.upperBound = upper;
}
public long getValue() {
return value;
}
public int getLowerBound() {
return lowerBound;
}
public int getUpperBound() {
return upperBound;
}
@Override
public RangeEdgePartition clone() throws CloneNotSupportedException {
return (RangeEdgePartition)super.clone();
}
@Override
public int hashCode() {
return super.hashCode() + new Long(value).hashCode() +
new Integer(lowerBound).hashCode() + new Integer(upperBound).hashCode();
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof RangeEdgePartition)) {
return false;
}
RangeEdgePartition other = (RangeEdgePartition)obj;
return super.equals(other) &&
value == other.value &&
lowerBound == other.lowerBound &&
upperBound == other.upperBound;
}
@Override
protected void appendTo(StringBuilder out) {
super.appendTo(out);
out.append("+[");
if (lowerBound > 0)
out.append(lowerBound);
out.append("..");
if (upperBound >= 0)
out.append(upperBound);
out.append(']');
}
public long encodeBounds() {
if (lowerBound > 0) {
if (upperBound >= 0) {
return lowerBound << 16 | (upperBound + 1);
} else {
return lowerBound | 0x80000000L;
}
} else {
if (upperBound >= 0) {
return (upperBound + 1) | 0x40000000;
} else {
return 0x80000000L; // >0
}
}
}
}
|