1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.filter;
20
21 import com.google.protobuf.InvalidProtocolBufferException;
22
23 import org.apache.hadoop.hbase.classification.InterfaceAudience;
24 import org.apache.hadoop.hbase.classification.InterfaceStability;
25 import org.apache.hadoop.hbase.exceptions.DeserializationException;
26 import org.apache.hadoop.hbase.protobuf.generated.ComparatorProtos;
27 import org.apache.hadoop.hbase.util.Bytes;
28
29
30
31
32 @InterfaceAudience.Public
33 @InterfaceStability.Stable
34 public class LongComparator extends ByteArrayComparable {
35 private Long longValue;
36
37 public LongComparator(long value) {
38 super(Bytes.toBytes(value));
39 this.longValue = value;
40 }
41
42 @Override
43 public int compareTo(byte[] value, int offset, int length) {
44 Long that = Bytes.toLong(value, offset, length);
45 return this.longValue.compareTo(that);
46 }
47
48
49
50
51 public byte [] toByteArray() {
52 ComparatorProtos.LongComparator.Builder builder =
53 ComparatorProtos.LongComparator.newBuilder();
54 builder.setComparable(super.convert());
55 return builder.build().toByteArray();
56 }
57
58
59
60
61
62
63
64 public static LongComparator parseFrom(final byte [] pbBytes)
65 throws DeserializationException {
66 ComparatorProtos.LongComparator proto;
67 try {
68 proto = ComparatorProtos.LongComparator.parseFrom(pbBytes);
69 } catch (InvalidProtocolBufferException e) {
70 throw new DeserializationException(e);
71 }
72 return new LongComparator(Bytes.toLong(proto.getComparable().getValue().toByteArray()));
73 }
74
75
76
77
78
79
80 boolean areSerializedFieldsEqual(LongComparator other) {
81 if (other == this) return true;
82 if (!(other instanceof LongComparator)) return false;
83
84 return super.areSerializedFieldsEqual(other);
85 }
86 }