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 import org.apache.hadoop.hbase.exceptions.DeserializationException;
23 import org.apache.hadoop.hbase.protobuf.generated.ComparatorProtos;
24 import org.apache.hadoop.hbase.util.Bytes;
25
26
27
28
29
30 public class LongComparator extends ByteArrayComparable {
31 private Long longValue;
32
33 public LongComparator(long value) {
34 super(Bytes.toBytes(value));
35 this.longValue = value;
36 }
37
38 @Override
39 public int compareTo(byte[] value, int offset, int length) {
40 Long that = Bytes.toLong(value, offset, length);
41 return this.longValue.compareTo(that);
42 }
43
44
45
46
47 public byte [] toByteArray() {
48 ComparatorProtos.LongComparator.Builder builder =
49 ComparatorProtos.LongComparator.newBuilder();
50 builder.setComparable(super.convert());
51 return builder.build().toByteArray();
52 }
53
54
55
56
57
58
59
60 public static LongComparator parseFrom(final byte [] pbBytes)
61 throws DeserializationException {
62 ComparatorProtos.LongComparator proto;
63 try {
64 proto = ComparatorProtos.LongComparator.parseFrom(pbBytes);
65 } catch (InvalidProtocolBufferException e) {
66 throw new DeserializationException(e);
67 }
68 return new LongComparator(Bytes.toLong(proto.getComparable().getValue().toByteArray()));
69 }
70
71
72
73
74
75
76 boolean areSerializedFieldsEqual(LongComparator other) {
77 if (other == this) return true;
78 if (!(other instanceof LongComparator)) return false;
79
80 return super.areSerializedFieldsEqual(other);
81 }
82 }