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
34 @InterfaceAudience.Public
35 @InterfaceStability.Stable
36 public class BinaryPrefixComparator extends ByteArrayComparable {
37
38
39
40
41
42 public BinaryPrefixComparator(byte[] value) {
43 super(value);
44 }
45
46 @Override
47 public int compareTo(byte [] value, int offset, int length) {
48 return Bytes.compareTo(this.value, 0, this.value.length, value, offset,
49 this.value.length <= length ? this.value.length : length);
50 }
51
52
53
54
55 @Override
56 public byte [] toByteArray() {
57 ComparatorProtos.BinaryPrefixComparator.Builder builder =
58 ComparatorProtos.BinaryPrefixComparator.newBuilder();
59 builder.setComparable(super.convert());
60 return builder.build().toByteArray();
61 }
62
63
64
65
66
67
68
69 public static BinaryPrefixComparator parseFrom(final byte [] pbBytes)
70 throws DeserializationException {
71 ComparatorProtos.BinaryPrefixComparator proto;
72 try {
73 proto = ComparatorProtos.BinaryPrefixComparator.parseFrom(pbBytes);
74 } catch (InvalidProtocolBufferException e) {
75 throw new DeserializationException(e);
76 }
77 return new BinaryPrefixComparator(proto.getComparable().getValue().toByteArray());
78 }
79
80
81
82
83
84
85 @Override
86 boolean areSerializedFieldsEqual(ByteArrayComparable other) {
87 if (other == this) return true;
88 if (!(other instanceof BinaryPrefixComparator)) return false;
89
90 return super.areSerializedFieldsEqual(other);
91 }
92 }