Skip to content

Commit

Permalink
HBASE-23622 Reduced the number of Checkstyle violations in hbase-common
Browse files Browse the repository at this point in the history
Signed-off-by: stack <[email protected]>
Signed-off-by: Viraj Jasani <[email protected]>
  • Loading branch information
HorizonNet authored Dec 28, 2019
1 parent 703ee60 commit 2ca1e46
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
import java.util.Comparator;

import org.apache.hadoop.hbase.util.ByteBufferUtils;
import org.apache.hbase.thirdparty.com.google.common.primitives.Longs;
import org.apache.yetus.audience.InterfaceAudience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

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

@Override
public int compare(Object l, Object r) {
// LOG.info("ltype={} rtype={}", l, r);
if ((l instanceof ByteBufferKeyValue) && (r instanceof ByteBufferKeyValue)) {
return compare((ByteBufferKeyValue)l, (ByteBufferKeyValue)r, false);
}
Expand All @@ -81,7 +80,7 @@ public int compare(Object l, Object r) {

// TODO: Come back here. We get a few percentage points extra of throughput if this is a
// private method.
static final int compare(ByteBufferKeyValue left, ByteBufferKeyValue right,
static int compare(ByteBufferKeyValue left, ByteBufferKeyValue right,
boolean ignoreSequenceid) {
// NOTE: Same method is in CellComparatorImpl, also private, not shared, intentionally. Not
// sharing gets us a few percent more throughput in compares. If changes here or there, make
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static CellComparator getInstance() {
/**
* Compare cells.
* @param ignoreSequenceid True if we are to compare the key portion only and ignore
* the sequenceid. Set to false to compare key and consider sequenceid.
* the sequenceid. Set to false to compare key and consider sequenceid.
* @return 0 if equal, -1 if a &lt; b, and +1 if a &gt; b.
*/
int compare(Cell leftCell, Cell rightCell, boolean ignoreSequenceid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hadoop.hbase;

import java.util.Comparator;

import org.apache.hadoop.hbase.KeyValue.Type;
import org.apache.hadoop.hbase.util.ByteBufferUtils;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hbase.thirdparty.com.google.common.primitives.Longs;
import org.apache.yetus.audience.InterfaceAudience;
import org.apache.yetus.audience.InterfaceStability;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


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

/**
* Compare two HBase cells. Do not use this method comparing <code>-ROOT-</code> or
Expand All @@ -52,11 +50,13 @@
@InterfaceStability.Evolving
public class CellComparatorImpl implements CellComparator {
static final Logger LOG = LoggerFactory.getLogger(CellComparatorImpl.class);

/**
* Comparator for plain key/values; i.e. non-catalog table key/values. Works on Key portion
* of KeyValue only.
*/
public static final CellComparatorImpl COMPARATOR = new CellComparatorImpl();

/**
* A {@link CellComparatorImpl} for <code>hbase:meta</code> catalog table
* {@link KeyValue}s.
Expand Down Expand Up @@ -342,7 +342,7 @@ private static int compareRows(byte[] left, int loffset, int llength, byte[] rig
return -1;
} else if (rightDelimiter < 0 && leftDelimiter >= 0) {
return 1;
} else if (leftDelimiter < 0 && rightDelimiter < 0) {
} else if (leftDelimiter < 0) {
return 0;
}
}
Expand All @@ -365,7 +365,7 @@ private static int compareRows(byte[] left, int loffset, int llength, byte[] rig
return -1;
} else if (rightDelimiter < 0 && leftDelimiter >= 0) {
return 1;
} else if (leftDelimiter < 0 && rightDelimiter < 0) {
} else if (leftDelimiter < 0) {
return 0;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* We cannot have Guava classes in our API hence this Type.
*/
@InterfaceAudience.Public
public class Address implements Comparable<Address> {
public final class Address implements Comparable<Address> {
private HostAndPort hostAndPort;

private Address(HostAndPort hostAndPort) {
Expand Down Expand Up @@ -62,7 +62,7 @@ public String toString() {
/**
* If hostname is a.b.c and the port is 123, return a:123 instead of a.b.c:123.
* @return if host looks like it is resolved -- not an IP -- then strip the domain portion
* otherwise returns same as {@link #toString()}}
* otherwise returns same as {@link #toString()}}
*/
public String toStringWithoutDomain() {
String hostname = getHostname();
Expand Down Expand Up @@ -100,7 +100,10 @@ public int hashCode() {
@Override
public int compareTo(Address that) {
int compare = this.getHostname().compareTo(that.getHostname());
if (compare != 0) return compare;
if (compare != 0) {
return compare;
}

return this.getPort() - that.getPort();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class SpanReceiverHost {
private Configuration conf;
private boolean closed = false;

private static enum SingletonHolder {
private enum SingletonHolder {
INSTANCE;
final transient Object lock = new Object();
transient SpanReceiverHost host = null;
Expand Down Expand Up @@ -78,7 +78,6 @@ public static Configuration getConfiguration(){
/**
* Reads the names of classes specified in the {@code hbase.trace.spanreceiver.classes} property
* and instantiates and registers them with the Tracer.
*
*/
public void loadSpanReceivers() {
String[] receiverNames = conf.getStrings(SPAN_RECEIVERS_CONF_KEY);
Expand All @@ -93,7 +92,7 @@ public void loadSpanReceivers() {
SpanReceiver receiver = builder.className(className).build();
if (receiver != null) {
receivers.add(receiver);
LOG.info("SpanReceiver " + className + " was loaded successfully.");
LOG.info("SpanReceiver {} was loaded successfully.", className);
}
}
for (SpanReceiver rcvr : receivers) {
Expand All @@ -105,7 +104,10 @@ public void loadSpanReceivers() {
* Calls close() on all SpanReceivers created by this SpanReceiverHost.
*/
public synchronized void closeReceivers() {
if (closed) return;
if (closed) {
return;
}

closed = true;
for (SpanReceiver rcvr : receivers) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private TraceUtil() {
}

public static void initTracer(Configuration c) {
if(c != null) {
if (c != null) {
conf = new HBaseHTraceConfiguration(c);
}

Expand All @@ -62,7 +62,9 @@ public static TraceScope createTrace(String description) {
* @return TraceScope or null when not tracing
*/
public static TraceScope createTrace(String description, Span span) {
if(span == null) return createTrace(description);
if (span == null) {
return createTrace(description);
}

return (tracer == null) ? null : tracer.newScope(description, span.getSpanId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hadoop.hbase.util;

import java.io.IOException;
Expand All @@ -31,12 +30,16 @@
* Utility methods for working with {@link ByteRange}.
*/
@InterfaceAudience.Public
public class ByteRangeUtils {
public final class ByteRangeUtils {
private ByteRangeUtils() {
}

public static int numEqualPrefixBytes(ByteRange left, ByteRange right, int rightInnerOffset) {
int maxCompares = Math.min(left.getLength(), right.getLength() - rightInnerOffset);
final byte[] lbytes = left.getBytes(), rbytes = right.getBytes();
final int loffset = left.getOffset(), roffset = right.getOffset();
final byte[] lbytes = left.getBytes();
final byte[] rbytes = right.getBytes();
final int loffset = left.getOffset();
final int roffset = right.getOffset();
for (int i = 0; i < maxCompares; ++i) {
if (lbytes[loffset + i] != rbytes[roffset + rightInnerOffset + i]) {
return i;
Expand Down Expand Up @@ -76,5 +79,4 @@ public static void write(OutputStream os, ByteRange byteRange, int byteRangeInne
os.write(byteRange.getBytes(), byteRange.getOffset() + byteRangeInnerOffset,
byteRange.getLength() - byteRangeInnerOffset);
}

}
Loading

0 comments on commit 2ca1e46

Please sign in to comment.