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 @Override
52 public byte [] toByteArray() {
53 ComparatorProtos.LongComparator.Builder builder =
54 ComparatorProtos.LongComparator.newBuilder();
55 builder.setComparable(super.convert());
56 return builder.build().toByteArray();
57 }
58
59
60
61
62
63
64
65 public static LongComparator parseFrom(final byte [] pbBytes)
66 throws DeserializationException {
67 ComparatorProtos.LongComparator proto;
68 try {
69 proto = ComparatorProtos.LongComparator.parseFrom(pbBytes);
70 } catch (InvalidProtocolBufferException e) {
71 throw new DeserializationException(e);
72 }
73 return new LongComparator(Bytes.toLong(proto.getComparable().getValue().toByteArray()));
74 }
75
76
77
78
79
80
81 boolean areSerializedFieldsEqual(LongComparator other) {
82 if (other == this) return true;
83 if (!(other instanceof LongComparator)) return false;
84
85 return super.areSerializedFieldsEqual(other);
86 }
87 }