Skip to content

Commit c165699

Browse files
authored
HBASE-23625 Reduced number of Checkstyle violations in hbase-common
Signed-off-by: stack <stack@apache.org>
1 parent 8f292a8 commit c165699

10 files changed

Lines changed: 130 additions & 198 deletions

File tree

hbase-common/src/main/java/org/apache/hadoop/hbase/CellScanner.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
1918
package org.apache.hadoop.hbase;
2019

2120
import java.io.IOException;
@@ -56,7 +55,7 @@ public interface CellScanner {
5655
/**
5756
* Advance the scanner 1 cell.
5857
* @return true if the next cell is found and {@link #current()} will return a valid Cell
59-
* @throws IOException
58+
* @throws IOException if advancing the scanner fails
6059
*/
6160
boolean advance() throws IOException;
6261
}

hbase-common/src/main/java/org/apache/hadoop/hbase/IndividualBytesFieldCell.java

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
1918
package org.apache.hadoop.hbase;
2019

2120
import org.apache.commons.lang3.ArrayUtils;
@@ -25,12 +24,14 @@
2524

2625
@InterfaceAudience.Private
2726
public class IndividualBytesFieldCell implements ExtendedCell, Cloneable {
28-
29-
private static final long FIXED_OVERHEAD = ClassSize.align( // do alignment(padding gap)
30-
ClassSize.OBJECT // object header
31-
+ KeyValue.TIMESTAMP_TYPE_SIZE // timestamp and type
32-
+ Bytes.SIZEOF_LONG // sequence id
33-
+ 5 * ClassSize.REFERENCE); // references to all byte arrays: row, family, qualifier, value, tags
27+
// do alignment(padding gap)
28+
private static final long FIXED_OVERHEAD = ClassSize.align(ClassSize.OBJECT // object header
29+
// timestamp and type
30+
+ KeyValue.TIMESTAMP_TYPE_SIZE
31+
// sequence id
32+
+ Bytes.SIZEOF_LONG
33+
// references to all byte arrays: row, family, qualifier, value, tags
34+
+ 5 * ClassSize.REFERENCE);
3435

3536
// The following fields are backed by individual byte arrays
3637
private final byte[] row;
@@ -54,13 +55,13 @@ public class IndividualBytesFieldCell implements ExtendedCell, Cloneable {
5455
private final byte type; // A byte, rather than org.apache.hadoop.hbase.KeyValue.Type
5556
private long seqId;
5657

57-
public IndividualBytesFieldCell(byte[] row, byte[] family, byte[] qualifier,
58-
long timestamp, KeyValue.Type type, byte[] value) {
58+
public IndividualBytesFieldCell(byte[] row, byte[] family, byte[] qualifier, long timestamp,
59+
KeyValue.Type type, byte[] value) {
5960
this(row, family, qualifier, timestamp, type, 0L /* sequence id */, value, null /* tags */);
6061
}
6162

62-
public IndividualBytesFieldCell(byte[] row, byte[] family, byte[] qualifier,
63-
long timestamp, KeyValue.Type type, long seqId, byte[] value, byte[] tags) {
63+
public IndividualBytesFieldCell(byte[] row, byte[] family, byte[] qualifier, long timestamp,
64+
KeyValue.Type type, long seqId, byte[] value, byte[] tags) {
6465
this(row, 0, ArrayUtils.getLength(row),
6566
family, 0, ArrayUtils.getLength(family),
6667
qualifier, 0, ArrayUtils.getLength(qualifier),
@@ -69,13 +70,10 @@ public IndividualBytesFieldCell(byte[] row, byte[] family, byte[] qualifier,
6970
tags, 0, ArrayUtils.getLength(tags));
7071
}
7172

72-
public IndividualBytesFieldCell(byte[] row, int rOffset, int rLength,
73-
byte[] family, int fOffset, int fLength,
74-
byte[] qualifier, int qOffset, int qLength,
75-
long timestamp, KeyValue.Type type, long seqId,
76-
byte[] value, int vOffset, int vLength,
77-
byte[] tags, int tagsOffset, int tagsLength) {
78-
73+
public IndividualBytesFieldCell(byte[] row, int rOffset, int rLength, byte[] family, int fOffset,
74+
int fLength, byte[] qualifier, int qOffset, int qLength, long timestamp, KeyValue.Type type,
75+
long seqId, byte[] value, int vOffset, int vLength, byte[] tags, int tagsOffset,
76+
int tagsLength) {
7977
// Check row, family, qualifier and value
8078
KeyValue.checkParameters(row, rLength, // row and row length
8179
family, fLength, // family and family length
@@ -119,10 +117,12 @@ public IndividualBytesFieldCell(byte[] row, int rOffset, int rLength,
119117

120118
private void checkArrayBounds(byte[] bytes, int offset, int length) {
121119
if (offset < 0 || length < 0) {
122-
throw new IllegalArgumentException("Negative number! offset=" + offset + "and length=" + length);
120+
throw new IllegalArgumentException("Negative number! offset=" + offset + "and length="
121+
+ length);
123122
}
124123
if (bytes == null && (offset != 0 || length != 0)) {
125-
throw new IllegalArgumentException("Null bytes array but offset=" + offset + "and length=" + length);
124+
throw new IllegalArgumentException("Null bytes array but offset=" + offset + "and length="
125+
+ length);
126126
}
127127
if (bytes != null && bytes.length < offset + length) {
128128
throw new IllegalArgumentException("Out of bounds! bytes.length=" + bytes.length
@@ -131,7 +131,7 @@ private void checkArrayBounds(byte[] bytes, int offset, int length) {
131131
}
132132

133133
private long heapOverhead() {
134-
return FIXED_OVERHEAD
134+
return FIXED_OVERHEAD
135135
+ ClassSize.ARRAY // row , can not be null
136136
+ ((family == null) ? 0 : ClassSize.ARRAY) // family , can be null
137137
+ ((qualifier == null) ? 0 : ClassSize.ARRAY) // qualifier, can be null
@@ -152,13 +152,14 @@ public byte[] getRowArray() {
152152

153153
@Override
154154
public int getRowOffset() {
155-
return rOffset;
156-
}
155+
return rOffset;
156+
}
157157

158158
@Override
159159
public short getRowLength() {
160-
// If row is null or rLength is invalid, the constructor will reject it, by {@link KeyValue#checkParameters()},
161-
// so it is safe to call rLength and make the type conversion.
160+
// If row is null or rLength is invalid, the constructor will reject it, by
161+
// {@link KeyValue#checkParameters()}, so it is safe to call rLength and make the type
162+
// conversion.
162163
return (short)(rLength);
163164
}
164165

@@ -255,7 +256,8 @@ public int getTagsLength() {
255256
*/
256257
@Override
257258
public long heapSize() {
258-
// Size of array headers are already included into overhead, so do not need to include it for each byte array
259+
// Size of array headers are already included into overhead, so do not need to include it for
260+
// each byte array
259261
return heapOverhead() // overhead, with array headers included
260262
+ ClassSize.align(getRowLength()) // row
261263
+ ClassSize.align(getFamilyLength()) // family

hbase-common/src/main/java/org/apache/hadoop/hbase/util/AbstractByteRange.java

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
@InterfaceAudience.Private
6060
@InterfaceStability.Evolving
6161
public abstract class AbstractByteRange implements ByteRange {
62-
6362
public static final int UNSET_HASH_VALUE = -1;
6463

6564
// Note to maintainers: Do not make these final, as the intention is to
@@ -95,18 +94,17 @@ public byte[] getBytes() {
9594
return bytes;
9695
}
9796

98-
@Override
99-
public abstract ByteRange unset();
100-
10197
@Override
10298
public ByteRange set(int capacity) {
10399
return set(new byte[capacity]);
104100
}
105101

106102
@Override
107103
public ByteRange set(byte[] bytes) {
108-
if (null == bytes)
104+
if (null == bytes) {
109105
return unset();
106+
}
107+
110108
clearHashCache();
111109
this.bytes = bytes;
112110
this.offset = 0;
@@ -116,8 +114,10 @@ public ByteRange set(byte[] bytes) {
116114

117115
@Override
118116
public ByteRange set(byte[] bytes, int offset, int length) {
119-
if (null == bytes)
117+
if (null == bytes) {
120118
return unset();
119+
}
120+
121121
clearHashCache();
122122
this.bytes = bytes;
123123
this.offset = offset;
@@ -172,15 +172,19 @@ public byte get(int index) {
172172

173173
@Override
174174
public ByteRange get(int index, byte[] dst) {
175-
if (0 == dst.length)
175+
if (0 == dst.length) {
176176
return this;
177+
}
178+
177179
return get(index, dst, 0, dst.length);
178180
}
179181

180182
@Override
181183
public ByteRange get(int index, byte[] dst, int offset, int length) {
182-
if (0 == length)
184+
if (0 == length) {
183185
return this;
186+
}
187+
184188
System.arraycopy(this.bytes, this.offset + index, dst, offset, length);
185189
return this;
186190
}
@@ -243,27 +247,6 @@ public static int getVLongSize(long val) {
243247
return rPos + 1;
244248
}
245249

246-
@Override
247-
public abstract ByteRange put(int index, byte val);
248-
249-
@Override
250-
public abstract ByteRange put(int index, byte[] val);
251-
252-
@Override
253-
public abstract ByteRange put(int index, byte[] val, int offset, int length);
254-
255-
@Override
256-
public abstract ByteRange putInt(int index, int val);
257-
258-
@Override
259-
public abstract ByteRange putLong(int index, long val);
260-
261-
@Override
262-
public abstract ByteRange putShort(int index, short val);
263-
264-
@Override
265-
public abstract int putVLong(int index, long val);
266-
267250
//
268251
// methods for duplicating the current instance
269252
//

hbase-common/src/main/java/org/apache/hadoop/hbase/util/AbstractPositionedByteRange.java

Lines changed: 7 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@
1717
*/
1818
package org.apache.hadoop.hbase.util;
1919

20-
2120
import org.apache.yetus.audience.InterfaceAudience;
2221
import org.apache.yetus.audience.InterfaceStability;
2322

24-
import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting;
25-
2623
/**
2724
* Extends the basic {@link SimpleByteRange} implementation with position
2825
* support. {@code position} is considered transient, not fundamental to the
@@ -48,9 +45,6 @@ public abstract class AbstractPositionedByteRange extends AbstractByteRange impl
4845

4946
protected int limit = 0;
5047

51-
@Override
52-
public abstract PositionedByteRange unset();
53-
5448
@Override
5549
public PositionedByteRange set(int capacity) {
5650
this.position = 0;
@@ -134,77 +128,24 @@ public byte get() {
134128

135129
@Override
136130
public PositionedByteRange get(byte[] dst) {
137-
if (0 == dst.length)
131+
if (0 == dst.length) {
138132
return this;
139-
return this.get(dst, 0, dst.length); // be clear we're calling self, not
140-
// super
133+
}
134+
135+
return this.get(dst, 0, dst.length); // be clear we're calling self, not super
141136
}
142137

143138
@Override
144139
public PositionedByteRange get(byte[] dst, int offset, int length) {
145-
if (0 == length)
140+
if (0 == length) {
146141
return this;
142+
}
143+
147144
super.get(this.position, dst, offset, length);
148145
this.position += length;
149146
return this;
150147
}
151148

152-
@Override
153-
public abstract PositionedByteRange put(byte val);
154-
155-
@Override
156-
public abstract PositionedByteRange put(byte[] val);
157-
158-
@Override
159-
public abstract PositionedByteRange put(byte[] val, int offset, int length);
160-
161-
@Override
162-
public abstract PositionedByteRange putInt(int index, int val);
163-
164-
@Override
165-
public abstract PositionedByteRange putLong(int index, long val);
166-
167-
@Override
168-
public abstract PositionedByteRange putShort(int index, short val);
169-
170-
@Override
171-
public abstract PositionedByteRange putInt(int val);
172-
173-
@Override
174-
public abstract PositionedByteRange putLong(long val);
175-
176-
@Override
177-
public abstract PositionedByteRange putShort(short val);
178-
179-
@Override
180-
public abstract int putVLong(int index, long val);
181-
182-
@Override
183-
public abstract int putVLong(long val);
184-
/**
185-
* Similar to {@link java.nio.ByteBuffer#flip()}. Sets length to position, position to
186-
* offset.
187-
*/
188-
@VisibleForTesting
189-
PositionedByteRange flip() {
190-
clearHashCache();
191-
length = position;
192-
position = offset;
193-
return this;
194-
}
195-
196-
/**
197-
* Similar to {@link java.nio.ByteBuffer#clear()}. Sets position to 0, length to
198-
* capacity.
199-
*/
200-
@VisibleForTesting
201-
PositionedByteRange clear() {
202-
clearHashCache();
203-
position = 0;
204-
length = bytes.length - offset;
205-
return this;
206-
}
207-
208149
// java boilerplate
209150

210151
@Override
@@ -247,24 +188,6 @@ public long getVLong() {
247188
return p;
248189
}
249190

250-
@Override
251-
public abstract PositionedByteRange put(int index, byte val);
252-
253-
@Override
254-
public abstract PositionedByteRange put(int index, byte[] val);
255-
256-
@Override
257-
public abstract PositionedByteRange put(int index, byte[] val, int offset, int length);
258-
259-
@Override
260-
public abstract PositionedByteRange deepCopy();
261-
262-
@Override
263-
public abstract PositionedByteRange shallowCopy();
264-
265-
@Override
266-
public abstract PositionedByteRange shallowCopySubRange(int innerOffset, int copyLength);
267-
268191
@Override
269192
public PositionedByteRange setLimit(int limit) {
270193
this.limit = limit;

hbase-common/src/main/java/org/apache/hadoop/hbase/util/AtomicUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
* Utilities related to atomic operations.
2626
*/
2727
@InterfaceAudience.Private
28-
public class AtomicUtils {
28+
public final class AtomicUtils {
29+
private AtomicUtils() {
30+
}
31+
2932
/**
3033
* Updates a AtomicLong which is supposed to maintain the minimum values. This method is not
3134
* synchronized but is thread-safe.
@@ -59,5 +62,4 @@ public static void updateMax(AtomicLong max, long value) {
5962
}
6063
}
6164
}
62-
6365
}

0 commit comments

Comments
 (0)