1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.util;
19
20 import org.apache.hadoop.hbase.classification.InterfaceAudience;
21 import org.apache.hadoop.hbase.classification.InterfaceStability;
22
23
24
25
26 @InterfaceAudience.Public
27 @InterfaceStability.Evolving
28 public class SimpleByteRange extends AbstractByteRange {
29 public SimpleByteRange() {
30 }
31
32 public SimpleByteRange(int capacity) {
33 this(new byte[capacity]);
34 }
35
36
37
38
39
40 public SimpleByteRange(byte[] bytes) {
41 set(bytes);
42 }
43
44
45
46
47
48
49
50
51 public SimpleByteRange(byte[] bytes, int offset, int length) {
52 set(bytes, offset, length);
53 }
54
55
56
57
58
59 @Override
60 public ByteRange unset() {
61 throw new ReadOnlyByteRangeException();
62 }
63
64 @Override
65 public ByteRange set(int capacity) {
66 if (super.bytes != null) {
67 throw new ReadOnlyByteRangeException();
68 }
69 return super.set(capacity);
70 }
71
72 @Override
73 public ByteRange set(byte[] bytes) {
74 if (super.bytes != null) {
75 throw new ReadOnlyByteRangeException();
76 }
77 return super.set(bytes);
78 }
79
80 @Override
81 public ByteRange set(byte[] bytes, int offset, int length) {
82 if (super.bytes != null) {
83 throw new ReadOnlyByteRangeException();
84 }
85 return super.set(bytes, offset, length);
86 }
87
88
89
90
91 @Override
92 public ByteRange put(int index, byte val) {
93 throw new ReadOnlyByteRangeException();
94 }
95
96 @Override
97 public ByteRange put(int index, byte[] val) {
98 throw new ReadOnlyByteRangeException();
99 }
100
101 @Override
102 public ByteRange put(int index, byte[] val, int offset, int length) {
103 throw new ReadOnlyByteRangeException();
104 }
105
106
107
108
109
110 @Override
111 public ByteRange shallowCopy() {
112 SimpleByteRange clone = new SimpleByteRange(bytes, offset, length);
113 if (isHashCached()) {
114 clone.hash = hash;
115 }
116 return clone;
117 }
118
119 @Override
120 public ByteRange shallowCopySubRange(int innerOffset, int copyLength) {
121 SimpleByteRange clone = new SimpleByteRange(bytes, offset + innerOffset,
122 copyLength);
123 if (isHashCached()) {
124 clone.hash = hash;
125 }
126 return clone;
127 }
128
129 @Override
130 public boolean equals(Object thatObject) {
131 if (thatObject == null){
132 return false;
133 }
134 if (this == thatObject) {
135 return true;
136 }
137 if (hashCode() != thatObject.hashCode()) {
138 return false;
139 }
140 if (!(thatObject instanceof SimpleByteRange)) {
141 return false;
142 }
143 SimpleByteRange that = (SimpleByteRange) thatObject;
144 return Bytes.equals(bytes, offset, length, that.bytes, that.offset, that.length);
145 }
146
147 @Override
148 public ByteRange deepCopy() {
149 SimpleByteRange clone = new SimpleByteRange(deepCopyToNewArray());
150 if (isHashCached()) {
151 clone.hash = hash;
152 }
153 return clone;
154 }
155
156 @Override
157 public ByteRange putInt(int index, int val) {
158 throw new ReadOnlyByteRangeException();
159 }
160
161 @Override
162 public ByteRange putLong(int index, long val) {
163 throw new ReadOnlyByteRangeException();
164 }
165
166 @Override
167 public ByteRange putShort(int index, short val) {
168 throw new ReadOnlyByteRangeException();
169 }
170
171 @Override
172 public int putVLong(int index, long val) {
173 throw new ReadOnlyByteRangeException();
174 }
175 }