You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by le...@apache.org on 2021/09/27 03:59:55 UTC

[datasketches-java] 01/01: Fix Checkstyle and SpotBugs warnings.

This is an automated email from the ASF dual-hosted git repository.

leerho pushed a commit to branch FixCheckstyleAndSpotBugs
in repository https://gitbox.apache.org/repos/asf/datasketches-java.git

commit 69c269c5229c235e599e8305ca861d8c779b00a6
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Sun Sep 26 20:59:41 2021 -0700

    Fix Checkstyle and SpotBugs warnings.
    
    Update Checkstyle config to make it compatible with newest version.
    
    Update SpotBugs exclusions where frequent false positives are a problem.
---
 .../java/org/apache/datasketches/hash/MurmurHash3.java  |  6 +++---
 .../java/org/apache/datasketches/hll/BaseHllSketch.java | 10 +++++-----
 .../org/apache/datasketches/kll/KllFloatsSketch.java    | 10 ++++++----
 .../java/org/apache/datasketches/kll/KllHelper.java     | 17 ++++++++---------
 .../datasketches/quantiles/KolmogorovSmirnov.java       |  2 +-
 .../java/org/apache/datasketches/quantiles/Util.java    |  4 ++--
 src/main/java/org/apache/datasketches/tuple/Util.java   |  3 ++-
 .../java/org/apache/datasketches/BinarySearchTest.java  |  1 +
 tools/FindBugsExcludeFilter.xml                         |  5 +++++
 tools/SketchesCheckstyle.xml                            |  4 ++--
 10 files changed, 35 insertions(+), 27 deletions(-)

diff --git a/src/main/java/org/apache/datasketches/hash/MurmurHash3.java b/src/main/java/org/apache/datasketches/hash/MurmurHash3.java
index 1060e40..1e5c3ca 100644
--- a/src/main/java/org/apache/datasketches/hash/MurmurHash3.java
+++ b/src/main/java/org/apache/datasketches/hash/MurmurHash3.java
@@ -321,7 +321,7 @@ public final class MurmurHash3 implements Serializable {
     final int pos = buf.position();
     final int rem = buf.remaining();
     checkPositive(rem);
-    Memory mem = Memory.wrap(buf, ByteOrder.LITTLE_ENDIAN).region(pos, rem);
+    final Memory mem = Memory.wrap(buf, ByteOrder.LITTLE_ENDIAN).region(pos, rem);
     return hash(mem, seed);
   }
 
@@ -343,7 +343,7 @@ public final class MurmurHash3 implements Serializable {
     final long lengthBytes = mem.getCapacity();
     checkPositive(lengthBytes);
 
-    Memory memLE = mem.getTypeByteOrder() == ByteOrder.LITTLE_ENDIAN
+    final Memory memLE = mem.getTypeByteOrder() == ByteOrder.LITTLE_ENDIAN
         ? mem : mem.region(0, lengthBytes, ByteOrder.LITTLE_ENDIAN);
 
     final HashState hashState = new HashState(seed, seed);
@@ -548,7 +548,7 @@ public final class MurmurHash3 implements Serializable {
     return out;
   }
 
-  private static void checkPositive(long size) {
+  private static void checkPositive(final long size) {
     if (size <= 0) {
       throw new SketchesArgumentException("Array size must not be negative or zero: " + size);
     }
diff --git a/src/main/java/org/apache/datasketches/hll/BaseHllSketch.java b/src/main/java/org/apache/datasketches/hll/BaseHllSketch.java
index 4d63b27..324bf9f 100644
--- a/src/main/java/org/apache/datasketches/hll/BaseHllSketch.java
+++ b/src/main/java/org/apache/datasketches/hll/BaseHllSketch.java
@@ -25,10 +25,10 @@ import static org.apache.datasketches.hash.MurmurHash3.hash;
 import static org.apache.datasketches.hll.HllUtil.KEY_BITS_26;
 import static org.apache.datasketches.hll.HllUtil.KEY_MASK_26;
 
-import org.apache.datasketches.memory.Memory;
-
 import java.nio.ByteBuffer;
 
+import org.apache.datasketches.memory.Memory;
+
 /**
  * Although this class is package-private, it provides a single place to define and document
  * the common public API for both HllSketch and Union.
@@ -334,10 +334,10 @@ abstract class BaseHllSketch {
    * Bytes are read from the current position of the buffer until its limit.
    * If the byte buffer is null or has no bytes remaining, no update attempt is made and the method returns.
    *
-   * This method will not modify the position, mark, limit, or byte order of the buffer.
+   * <p>This method will not modify the position, mark, limit, or byte order of the buffer.</p>
    *
-   * Little-endian order is preferred, but not required. This method may perform better if the provided byte
-   * buffer is in little-endian order.
+   * <p>Little-endian order is preferred, but not required. This method may perform better if the provided byte
+   * buffer is in little-endian order.</p>
    *
    * @param data The given byte buffer.
    */
diff --git a/src/main/java/org/apache/datasketches/kll/KllFloatsSketch.java b/src/main/java/org/apache/datasketches/kll/KllFloatsSketch.java
index 6249c12..32390d9 100644
--- a/src/main/java/org/apache/datasketches/kll/KllFloatsSketch.java
+++ b/src/main/java/org/apache/datasketches/kll/KllFloatsSketch.java
@@ -29,6 +29,7 @@ import static java.lang.Math.pow;
 import static java.lang.Math.round;
 
 import java.util.Arrays;
+import java.util.Random;
 
 import org.apache.datasketches.ByteArrayUtil;
 import org.apache.datasketches.Family;
@@ -249,7 +250,8 @@ public class KllFloatsSketch {
   private float minValue_;
   private float maxValue_;
   private final boolean compatible; //compatible with quantiles sketch
-
+  private static final Random random = new Random();
+  
   /**
    * Heap constructor with the default <em>k = 200</em>, which has a rank error of about 1.65%.
    */
@@ -1030,9 +1032,9 @@ public class KllFloatsSketch {
       Arrays.sort(items_, adjBeg, adjBeg + adjPop);
     }
     if (popAbove == 0) {
-      KllHelper.randomlyHalveUp(items_, adjBeg, adjPop);
+      KllHelper.randomlyHalveUp(items_, adjBeg, adjPop, random);
     } else {
-      KllHelper.randomlyHalveDown(items_, adjBeg, adjPop);
+      KllHelper.randomlyHalveDown(items_, adjBeg, adjPop, random);
       KllHelper.mergeSortedArrays(items_, adjBeg, halfAdjPop, items_, rawLim, popAbove,
           items_, adjBeg + halfAdjPop);
     }
@@ -1123,7 +1125,7 @@ public class KllFloatsSketch {
 
     // notice that workbuf is being used as both the input and output here
     final int[] result = KllHelper.generalCompress(k_, m_, provisionalNumLevels, workbuf,
-        worklevels, workbuf, outlevels, isLevelZeroSorted_);
+        worklevels, workbuf, outlevels, isLevelZeroSorted_, random);
     final int finalNumLevels = result[0];
     final int finalCapacity = result[1];
     final int finalPop = result[2];
diff --git a/src/main/java/org/apache/datasketches/kll/KllHelper.java b/src/main/java/org/apache/datasketches/kll/KllHelper.java
index dcfe928..8f322c4 100644
--- a/src/main/java/org/apache/datasketches/kll/KllHelper.java
+++ b/src/main/java/org/apache/datasketches/kll/KllHelper.java
@@ -31,8 +31,6 @@ import java.util.Random;
  */
 class KllHelper {
 
-  private static final Random random = new Random();
-
   static boolean isEven(final int value) {
     return (value & 1) == 0;
   }
@@ -101,8 +99,8 @@ class KllHelper {
   /**
    * Computes the actual capacity of a given level given its depth index.
    * If the depth of levels exceeds 30, this uses a folding technique to accurately compute the
-   * actual leval capacity upto a depth of 60. Without folding, the internal calculations would
-   * excceed the capacity of a long.
+   * actual level capacity up to a depth of 60. Without folding, the internal calculations would
+   * exceed the capacity of a long.
    * @param k the configured k of the sketch
    * @param depth the zero-based index of the level being computed.
    * @return the actual capacity of a given level given its depth index.
@@ -218,7 +216,8 @@ class KllHelper {
       final int[] inLevels,
       final float[] outBuf,
       final int[] outLevels,
-      final boolean isLevelZeroSorted) {
+      final boolean isLevelZeroSorted,
+      final Random random) {
     assert numLevelsIn > 0; // things are too weird if zero levels are allowed
     int numLevels = numLevelsIn;
     int currentItemCount = inLevels[numLevels] - inLevels[0]; // decreases with each compaction
@@ -269,9 +268,9 @@ class KllHelper {
         }
 
         if (popAbove == 0) { // Level above is empty, so halve up
-          randomlyHalveUp(inBuf, adjBeg, adjPop);
+          randomlyHalveUp(inBuf, adjBeg, adjPop, random);
         } else { // Level above is nonempty, so halve down, then merge up
-          randomlyHalveDown(inBuf, adjBeg, adjPop);
+          randomlyHalveDown(inBuf, adjBeg, adjPop, random);
           mergeSortedArrays(inBuf, adjBeg, halfAdjPop, inBuf, rawLim, popAbove, inBuf, adjBeg + halfAdjPop);
         }
 
@@ -301,7 +300,7 @@ class KllHelper {
     return new int[] {numLevels, targetItemCount, currentItemCount};
   }
 
-  static void randomlyHalveDown(final float[] buf, final int start, final int length) {
+  static void randomlyHalveDown(final float[] buf, final int start, final int length, final Random random) {
     assert isEven(length);
     final int half_length = length / 2;
     final int offset = random.nextInt(2);
@@ -313,7 +312,7 @@ class KllHelper {
     }
   }
 
-  static void randomlyHalveUp(final float[] buf, final int start, final int length) {
+  static void randomlyHalveUp(final float[] buf, final int start, final int length, final Random random) {
     assert isEven(length);
     final int half_length = length / 2;
     final int offset = random.nextInt(2);
diff --git a/src/main/java/org/apache/datasketches/quantiles/KolmogorovSmirnov.java b/src/main/java/org/apache/datasketches/quantiles/KolmogorovSmirnov.java
index c639cbe..2217fb5 100644
--- a/src/main/java/org/apache/datasketches/quantiles/KolmogorovSmirnov.java
+++ b/src/main/java/org/apache/datasketches/quantiles/KolmogorovSmirnov.java
@@ -58,7 +58,7 @@ final class KolmogorovSmirnov {
       } else if (qSamplesArr[j] < pSamplesArr[i]) {
         j++;
       } else {
-    	i++;
+        i++;
         j++;
       }
     }
diff --git a/src/main/java/org/apache/datasketches/quantiles/Util.java b/src/main/java/org/apache/datasketches/quantiles/Util.java
index 328e3f1..03a70b4 100644
--- a/src/main/java/org/apache/datasketches/quantiles/Util.java
+++ b/src/main/java/org/apache/datasketches/quantiles/Util.java
@@ -94,7 +94,7 @@ final class Util {
   public static double computeKSThreshold(final DoublesSketch sketch1,
                                            final DoublesSketch sketch2,
                                            final double tgtPvalue) {
-	  return KolmogorovSmirnov.computeKSThreshold(sketch1, sketch2, tgtPvalue);
+    return KolmogorovSmirnov.computeKSThreshold(sketch1, sketch2, tgtPvalue);
   }
 
   /**
@@ -111,7 +111,7 @@ final class Util {
   @Deprecated
   public static boolean kolmogorovSmirnovTest(final DoublesSketch sketch1,
       final DoublesSketch sketch2, final double tgtPvalue) {
-	  return KolmogorovSmirnov.kolmogorovSmirnovTest(sketch1, sketch2, tgtPvalue);
+    return KolmogorovSmirnov.kolmogorovSmirnovTest(sketch1, sketch2, tgtPvalue);
   }
 
   /**
diff --git a/src/main/java/org/apache/datasketches/tuple/Util.java b/src/main/java/org/apache/datasketches/tuple/Util.java
index 46f2027..587da94 100644
--- a/src/main/java/org/apache/datasketches/tuple/Util.java
+++ b/src/main/java/org/apache/datasketches/tuple/Util.java
@@ -24,7 +24,8 @@ import static org.apache.datasketches.Util.MIN_LG_ARR_LONGS;
 import static org.apache.datasketches.Util.ceilingPowerOf2;
 import static org.apache.datasketches.Util.startingSubMultiple;
 import static org.apache.datasketches.hash.MurmurHash3.hash;
-import static org.apache.datasketches.memory.XxHash.*;
+import static org.apache.datasketches.memory.XxHash.hashCharArr;
+import static org.apache.datasketches.memory.XxHash.hashString;
 
 import org.apache.datasketches.SketchesArgumentException;
 
diff --git a/src/test/java/org/apache/datasketches/BinarySearchTest.java b/src/test/java/org/apache/datasketches/BinarySearchTest.java
index b1bac81..8395de3 100644
--- a/src/test/java/org/apache/datasketches/BinarySearchTest.java
+++ b/src/test/java/org/apache/datasketches/BinarySearchTest.java
@@ -37,6 +37,7 @@ import org.testng.annotations.Test;
 public class BinarySearchTest {
   static Random rand = new Random(1);
   private static final String LS = System.getProperty("line.separator");
+
   private static int randDelta() { return rand.nextDouble() < 0.4 ? 0 : 1; }
 
   private static float[] buildRandFloatArr(final int len) {
diff --git a/tools/FindBugsExcludeFilter.xml b/tools/FindBugsExcludeFilter.xml
index c0498e1..2c669f0 100644
--- a/tools/FindBugsExcludeFilter.xml
+++ b/tools/FindBugsExcludeFilter.xml
@@ -75,6 +75,11 @@ under the License.
     <Bug pattern="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD" />
     <Class name="org.apache.datasketches.theta.UpdateSketchBuilder" />
   </Match>
+
+  <Match> <!-- Too many False Positives -->
+    <Bug pattern="DMI_RANDOM_USED_ONLY_ONCE" />
+    
+  </Match>  
   
 </FindBugsFilter>
 
diff --git a/tools/SketchesCheckstyle.xml b/tools/SketchesCheckstyle.xml
index 5fe40e5..a2218c2 100644
--- a/tools/SketchesCheckstyle.xml
+++ b/tools/SketchesCheckstyle.xml
@@ -200,7 +200,7 @@ under the License.
     </module>
     
     <module name="JavadocMethod">
-      <property name="scope" value="public"/>
+      <property name="accessModifiers" value="public"/>
       <property name="allowMissingParamTags" value="false"/> <!-- default -->
       <property name="allowMissingReturnTag" value="false"/> <!-- default -->
       <property name="allowedAnnotations" value="Override, Test"/>
@@ -240,7 +240,7 @@ under the License.
     </module>
     
     <module name="CommentsIndentation">
-      <property name="severity" value="warning"/>
+      <property name="severity" value="ignore"/>
       <!-- <metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/> -->
     </module>
     

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org