Skip to content

Commit a140786

Browse files
HorizonNetJenkins
authored andcommitted
HBASE-23622 Reduced the number of Checkstyle violations in hbase-common
Signed-off-by: stack <[email protected]> Signed-off-by: Viraj Jasani <[email protected]> (cherry picked from commit 19d5d4b) Change-Id: Iaa41158379238d08da43bc224c22a8bd5cb24e55
1 parent 8ab63bf commit a140786

10 files changed

Lines changed: 89 additions & 81 deletions

File tree

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
import java.util.Comparator;
2121

2222
import org.apache.hadoop.hbase.util.ByteBufferUtils;
23-
import org.apache.hbase.thirdparty.com.google.common.primitives.Longs;
2423
import org.apache.yetus.audience.InterfaceAudience;
2524
import org.slf4j.Logger;
2625
import org.slf4j.LoggerFactory;
2726

27+
import org.apache.hbase.thirdparty.com.google.common.primitives.Longs;
2828

2929
/**
3030
* A comparator for case where {@link ByteBufferKeyValue} is prevalent type (BBKV
@@ -71,7 +71,6 @@ public BBKVComparator(Comparator fallback) {
7171

7272
@Override
7373
public int compare(Object l, Object r) {
74-
// LOG.info("ltype={} rtype={}", l, r);
7574
if ((l instanceof ByteBufferKeyValue) && (r instanceof ByteBufferKeyValue)) {
7675
return compare((ByteBufferKeyValue)l, (ByteBufferKeyValue)r, false);
7776
}
@@ -81,7 +80,7 @@ public int compare(Object l, Object r) {
8180

8281
// TODO: Come back here. We get a few percentage points extra of throughput if this is a
8382
// private method.
84-
static final int compare(ByteBufferKeyValue left, ByteBufferKeyValue right,
83+
static int compare(ByteBufferKeyValue left, ByteBufferKeyValue right,
8584
boolean ignoreSequenceid) {
8685
// NOTE: Same method is in CellComparatorImpl, also private, not shared, intentionally. Not
8786
// sharing gets us a few percent more throughput in compares. If changes here or there, make

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static CellComparator getInstance() {
5454
/**
5555
* Compare cells.
5656
* @param ignoreSequenceid True if we are to compare the key portion only and ignore
57-
* the sequenceid. Set to false to compare key and consider sequenceid.
57+
* the sequenceid. Set to false to compare key and consider sequenceid.
5858
* @return 0 if equal, -1 if a &lt; b, and +1 if a &gt; b.
5959
*/
6060
int compare(Cell leftCell, Cell rightCell, boolean ignoreSequenceid);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,19 @@
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.util.Comparator;
2221

2322
import org.apache.hadoop.hbase.KeyValue.Type;
2423
import org.apache.hadoop.hbase.util.ByteBufferUtils;
2524
import org.apache.hadoop.hbase.util.Bytes;
26-
import org.apache.hbase.thirdparty.com.google.common.primitives.Longs;
2725
import org.apache.yetus.audience.InterfaceAudience;
2826
import org.apache.yetus.audience.InterfaceStability;
2927
import org.slf4j.Logger;
3028
import org.slf4j.LoggerFactory;
3129

32-
30+
import org.apache.hbase.thirdparty.com.google.common.primitives.Longs;
3331

3432
/**
3533
* Compare two HBase cells. Do not use this method comparing <code>-ROOT-</code> or
@@ -52,11 +50,13 @@
5250
@InterfaceStability.Evolving
5351
public class CellComparatorImpl implements CellComparator {
5452
static final Logger LOG = LoggerFactory.getLogger(CellComparatorImpl.class);
53+
5554
/**
5655
* Comparator for plain key/values; i.e. non-catalog table key/values. Works on Key portion
5756
* of KeyValue only.
5857
*/
5958
public static final CellComparatorImpl COMPARATOR = new CellComparatorImpl();
59+
6060
/**
6161
* A {@link CellComparatorImpl} for <code>hbase:meta</code> catalog table
6262
* {@link KeyValue}s.
@@ -342,7 +342,7 @@ private static int compareRows(byte[] left, int loffset, int llength, byte[] rig
342342
return -1;
343343
} else if (rightDelimiter < 0 && leftDelimiter >= 0) {
344344
return 1;
345-
} else if (leftDelimiter < 0 && rightDelimiter < 0) {
345+
} else if (leftDelimiter < 0) {
346346
return 0;
347347
}
348348
}
@@ -365,7 +365,7 @@ private static int compareRows(byte[] left, int loffset, int llength, byte[] rig
365365
return -1;
366366
} else if (rightDelimiter < 0 && leftDelimiter >= 0) {
367367
return 1;
368-
} else if (leftDelimiter < 0 && rightDelimiter < 0) {
368+
} else if (leftDelimiter < 0) {
369369
return 0;
370370
}
371371
}

hbase-common/src/main/java/org/apache/hadoop/hbase/net/Address.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* We cannot have Guava classes in our API hence this Type.
3232
*/
3333
@InterfaceAudience.Public
34-
public class Address implements Comparable<Address> {
34+
public final class Address implements Comparable<Address> {
3535
private HostAndPort hostAndPort;
3636

3737
private Address(HostAndPort hostAndPort) {
@@ -62,7 +62,7 @@ public String toString() {
6262
/**
6363
* If hostname is a.b.c and the port is 123, return a:123 instead of a.b.c:123.
6464
* @return if host looks like it is resolved -- not an IP -- then strip the domain portion
65-
* otherwise returns same as {@link #toString()}}
65+
* otherwise returns same as {@link #toString()}}
6666
*/
6767
public String toStringWithoutDomain() {
6868
String hostname = getHostname();
@@ -100,7 +100,10 @@ public int hashCode() {
100100
@Override
101101
public int compareTo(Address that) {
102102
int compare = this.getHostname().compareTo(that.getHostname());
103-
if (compare != 0) return compare;
103+
if (compare != 0) {
104+
return compare;
105+
}
106+
104107
return this.getPort() - that.getPort();
105108
}
106109
}

hbase-common/src/main/java/org/apache/hadoop/hbase/trace/SpanReceiverHost.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class SpanReceiverHost {
4040
private Configuration conf;
4141
private boolean closed = false;
4242

43-
private static enum SingletonHolder {
43+
private enum SingletonHolder {
4444
INSTANCE;
4545
final transient Object lock = new Object();
4646
transient SpanReceiverHost host = null;
@@ -78,7 +78,6 @@ public static Configuration getConfiguration(){
7878
/**
7979
* Reads the names of classes specified in the {@code hbase.trace.spanreceiver.classes} property
8080
* and instantiates and registers them with the Tracer.
81-
*
8281
*/
8382
public void loadSpanReceivers() {
8483
String[] receiverNames = conf.getStrings(SPAN_RECEIVERS_CONF_KEY);
@@ -93,7 +92,7 @@ public void loadSpanReceivers() {
9392
SpanReceiver receiver = builder.className(className).build();
9493
if (receiver != null) {
9594
receivers.add(receiver);
96-
LOG.info("SpanReceiver " + className + " was loaded successfully.");
95+
LOG.info("SpanReceiver {} was loaded successfully.", className);
9796
}
9897
}
9998
for (SpanReceiver rcvr : receivers) {
@@ -105,7 +104,10 @@ public void loadSpanReceivers() {
105104
* Calls close() on all SpanReceivers created by this SpanReceiverHost.
106105
*/
107106
public synchronized void closeReceivers() {
108-
if (closed) return;
107+
if (closed) {
108+
return;
109+
}
110+
109111
closed = true;
110112
for (SpanReceiver rcvr : receivers) {
111113
try {

hbase-common/src/main/java/org/apache/hadoop/hbase/trace/TraceUtil.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private TraceUtil() {
3838
}
3939

4040
public static void initTracer(Configuration c) {
41-
if(c != null) {
41+
if (c != null) {
4242
conf = new HBaseHTraceConfiguration(c);
4343
}
4444

@@ -62,7 +62,9 @@ public static TraceScope createTrace(String description) {
6262
* @return TraceScope or null when not tracing
6363
*/
6464
public static TraceScope createTrace(String description, Span span) {
65-
if(span == null) return createTrace(description);
65+
if (span == null) {
66+
return createTrace(description);
67+
}
6668

6769
return (tracer == null) ? null : tracer.newScope(description, span.getSpanId());
6870
}

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

Lines changed: 7 additions & 5 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.util;
2019

2120
import java.io.IOException;
@@ -31,12 +30,16 @@
3130
* Utility methods for working with {@link ByteRange}.
3231
*/
3332
@InterfaceAudience.Public
34-
public class ByteRangeUtils {
33+
public final class ByteRangeUtils {
34+
private ByteRangeUtils() {
35+
}
3536

3637
public static int numEqualPrefixBytes(ByteRange left, ByteRange right, int rightInnerOffset) {
3738
int maxCompares = Math.min(left.getLength(), right.getLength() - rightInnerOffset);
38-
final byte[] lbytes = left.getBytes(), rbytes = right.getBytes();
39-
final int loffset = left.getOffset(), roffset = right.getOffset();
39+
final byte[] lbytes = left.getBytes();
40+
final byte[] rbytes = right.getBytes();
41+
final int loffset = left.getOffset();
42+
final int roffset = right.getOffset();
4043
for (int i = 0; i < maxCompares; ++i) {
4144
if (lbytes[loffset + i] != rbytes[roffset + rightInnerOffset + i]) {
4245
return i;
@@ -76,5 +79,4 @@ public static void write(OutputStream os, ByteRange byteRange, int byteRangeInne
7679
os.write(byteRange.getBytes(), byteRange.getOffset() + byteRangeInnerOffset,
7780
byteRange.getLength() - byteRangeInnerOffset);
7881
}
79-
8082
}

0 commit comments

Comments
 (0)