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.classification.InterfaceAudience;
24 import org.apache.hadoop.classification.InterfaceStability;
25 import org.apache.hadoop.hbase.exceptions.DeserializationException;
26 import org.apache.hadoop.hbase.protobuf.generated.ClientProtos;
27 import org.apache.hadoop.hbase.protobuf.generated.ComparatorProtos;
28
29
30
31
32
33 @InterfaceAudience.Public
34 @InterfaceStability.Stable
35 public class NullComparator extends ByteArrayComparable {
36
37 public NullComparator() {
38 super(new byte[0]);
39 }
40
41 @Override
42 public int compareTo(byte[] value) {
43 return value != null ? 1 : 0;
44 }
45
46 @Override
47 public boolean equals(Object obj) {
48 return obj == null;
49 }
50
51 @Override
52 public int hashCode() {
53 return 0;
54 }
55
56 @Override
57 public int compareTo(byte[] value, int offset, int length) {
58 throw new UnsupportedOperationException();
59 }
60
61
62
63
64 public byte [] toByteArray() {
65 ComparatorProtos.NullComparator.Builder builder =
66 ComparatorProtos.NullComparator.newBuilder();
67 return builder.build().toByteArray();
68 }
69
70
71
72
73
74
75
76 public static NullComparator parseFrom(final byte [] pbBytes)
77 throws DeserializationException {
78 try {
79 @SuppressWarnings("unused")
80 ComparatorProtos.NullComparator proto = ComparatorProtos.NullComparator.parseFrom(pbBytes);
81 } catch (InvalidProtocolBufferException e) {
82 throw new DeserializationException(e);
83 }
84 return new NullComparator();
85 }
86
87
88
89
90
91
92 boolean areSerializedFieldsEqual(ByteArrayComparable other) {
93 if (other == this) return true;
94 if (!(other instanceof NullComparator)) return false;
95
96 return super.areSerializedFieldsEqual(other);
97 }
98 }