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: Sean Busbey <[email protected]>
  • Loading branch information
HorizonNet authored Jan 19, 2020
1 parent 64b9d2f commit 99a59cf
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@
<suppress checks="." files=".*/generated/.*\.java"/>
<suppress checks="." files=".*/generated-jamon/.*\.java"/>
<suppress checks="MagicNumberCheck" files=".*Test\.java"/>
<!-- Will not have a private constructor, because it is InterfaceAudience.Public -->
<suppress checks="HideUtilityClassConstructor" files="org.apache.hadoop.hbase.util.ByteRangeUtils"/>
</suppressions>
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public int compare(Cell a, Cell b) {
* @param a
* @param b
* @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.
*/
public static int compare(final Cell a, final Cell b, boolean ignoreSequenceid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* An immutable type to hold a hostname and port combo, like an Endpoint
* or java.net.InetSocketAddress (but without danger of our calling
* resolve -- we do NOT want a resolve happening every time we want
* to hold a hostname and port combo). This class is also <<Comparable>>.
* to hold a hostname and port combo). This class is also {@link Comparable}
* <p>In implementation this class is a facade over Guava's {@link HostAndPort}.
* We cannot have Guava classes in our API hence this Type.
*/
Expand Down Expand Up @@ -83,7 +83,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 @@ -43,7 +43,7 @@ public class SpanReceiverHost {
private boolean closed = false;

@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="SE_BAD_FIELD")
private static enum SingletonHolder {
private enum SingletonHolder {
INSTANCE;
final Object lock = new Object();
SpanReceiverHost host = null; // FindBugs: SE_BAD_FIELD
Expand All @@ -64,14 +64,13 @@ public static SpanReceiverHost getInstance(Configuration conf) {
}

SpanReceiverHost(Configuration conf) {
receivers = new HashSet<SpanReceiver>();
receivers = new HashSet<>();
this.conf = conf;
}

/**
* 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 @@ -98,7 +97,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 @@ -15,9 +15,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hadoop.hbase.util;

import com.google.common.collect.Lists;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
Expand All @@ -26,19 +27,18 @@
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.hbase.classification.InterfaceStability;

import com.google.common.collect.Lists;

/**
* Utility methods for working with {@link ByteRange}.
*/
@InterfaceAudience.Public
@InterfaceStability.Evolving
public class 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 All @@ -49,7 +49,7 @@ public static int numEqualPrefixBytes(ByteRange left, ByteRange right, int right

public static ArrayList<byte[]> copyToNewArrays(Collection<ByteRange> ranges) {
if (ranges == null) {
return new ArrayList<byte[]>(0);
return new ArrayList<>(0);
}
ArrayList<byte[]> arrays = Lists.newArrayListWithCapacity(ranges.size());
for (ByteRange range : ranges) {
Expand All @@ -60,7 +60,7 @@ public static ArrayList<byte[]> copyToNewArrays(Collection<ByteRange> ranges) {

public static ArrayList<ByteRange> fromArrays(Collection<byte[]> arrays) {
if (arrays == null) {
return new ArrayList<ByteRange>(0);
return new ArrayList<>(0);
}
ArrayList<ByteRange> ranges = Lists.newArrayListWithCapacity(arrays.size());
for (byte[] array : arrays) {
Expand All @@ -78,5 +78,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 99a59cf

Please sign in to comment.