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 org.apache.hadoop.hbase.classification.InterfaceAudience;
23 import org.apache.hadoop.hbase.classification.InterfaceStability;
24 import org.apache.hadoop.hbase.exceptions.DeserializationException;
25 import org.apache.hadoop.hbase.protobuf.generated.ComparatorProtos;
26
27 import com.google.protobuf.InvalidProtocolBufferException;
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 @edu.umd.cs.findbugs.annotations.SuppressWarnings (value="EQ_UNUSUAL", justification="")
48 public boolean equals(Object obj) {
49 return obj == null;
50 }
51
52 @Override
53 public int hashCode() {
54 return 0;
55 }
56
57 @Override
58 public int compareTo(byte[] value, int offset, int length) {
59 return compareTo(value);
60 }
61
62
63
64
65 public byte [] toByteArray() {
66 ComparatorProtos.NullComparator.Builder builder =
67 ComparatorProtos.NullComparator.newBuilder();
68 return builder.build().toByteArray();
69 }
70
71
72
73
74
75
76
77 public static NullComparator parseFrom(final byte [] pbBytes)
78 throws DeserializationException {
79 try {
80
81 ComparatorProtos.NullComparator.parseFrom(pbBytes);
82 } catch (InvalidProtocolBufferException e) {
83 throw new DeserializationException(e);
84 }
85 return new NullComparator();
86 }
87
88
89
90
91
92
93 boolean areSerializedFieldsEqual(ByteArrayComparable other) {
94 if (other == this) return true;
95 if (!(other instanceof NullComparator)) return false;
96
97 return super.areSerializedFieldsEqual(other);
98 }
99 }