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