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 2019/11/30 23:48:36 UTC
[incubator-datasketches-java] 01/02: Mostly code cleanup
This is an automated email from the ASF dual-hosted git repository.
leerho pushed a commit to branch Cleanup
in repository https://gitbox.apache.org/repos/asf/incubator-datasketches-java.git
commit 71133e1f5828a570783dc1aa7cbca071118cd856
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Mon Nov 25 16:57:27 2019 -0800
Mostly code cleanup
---
.../apache/datasketches/hllmap/package-info.java | 2 +-
.../java/org/apache/datasketches/package-info.java | 2 +-
.../apache/datasketches/BinomialBoundsNTest.java | 78 +++----
.../BoundsOnBinomialProportionsTest.java | 100 ++++----
.../BoundsOnRatiosInThetaSketchedSetsTest.java | 53 +++--
.../org/apache/datasketches/ByteArrayUtilTest.java | 80 +++----
.../java/org/apache/datasketches/FamilyTest.java | 26 +--
.../apache/datasketches/HashOperationsTest.java | 53 +++--
.../org/apache/datasketches/QuickSelectTest.java | 258 ++++++++++-----------
.../apache/datasketches/SketchesExceptionTest.java | 4 +-
.../java/org/apache/datasketches/UtilTest.java | 72 +++---
.../org/apache/datasketches/cpc/BitMatrix.java | 10 +-
.../datasketches/cpc/CompressedStateTest.java | 25 +-
.../cpc/CompressionCharacterization.java | 90 +++----
tools/SketchesCheckstyle.xml | 14 +-
15 files changed, 441 insertions(+), 426 deletions(-)
diff --git a/src/main/java/org/apache/datasketches/hllmap/package-info.java b/src/main/java/org/apache/datasketches/hllmap/package-info.java
index 0ba1bb8..373a9f2 100644
--- a/src/main/java/org/apache/datasketches/hllmap/package-info.java
+++ b/src/main/java/org/apache/datasketches/hllmap/package-info.java
@@ -18,7 +18,7 @@
*/
/**
- * <p>The hllmap package contains a space efficient HLL mapping sketch of keys to approximate unique
+ * The hllmap package contains a space efficient HLL mapping sketch of keys to approximate unique
* count of identifiers. For example, counting the number of unique users (identifiers) per IP
* address.
*
diff --git a/src/main/java/org/apache/datasketches/package-info.java b/src/main/java/org/apache/datasketches/package-info.java
index ffe2f13..b5ed8c8 100644
--- a/src/main/java/org/apache/datasketches/package-info.java
+++ b/src/main/java/org/apache/datasketches/package-info.java
@@ -18,7 +18,7 @@
*/
/**
- * <p>This package is the parent package for all sketch algorithms.
+ * This package is the parent package for all sketch algorithms.
* Classes at this level are used by more than one sub-package.
*
* @author Lee Rhodes
diff --git a/src/test/java/org/apache/datasketches/BinomialBoundsNTest.java b/src/test/java/org/apache/datasketches/BinomialBoundsNTest.java
index 578c39e..2b6a486 100644
--- a/src/test/java/org/apache/datasketches/BinomialBoundsNTest.java
+++ b/src/test/java/org/apache/datasketches/BinomialBoundsNTest.java
@@ -34,7 +34,7 @@ import org.testng.annotations.Test;
@SuppressWarnings("javadoc")
public class BinomialBoundsNTest {
- public static double[] runTestAux (long max_numSamplesI, int ci, double min_p) {
+ public static double[] runTestAux(final long max_numSamplesI, final int ci, final double min_p) {
long numSamplesI = 0;
double p, lb, ub;
double sum1 = 0.0;
@@ -47,31 +47,31 @@ public class BinomialBoundsNTest {
p = 1.0;
while (p >= min_p) {
- lb = BinomialBoundsN.getLowerBound (numSamplesI, p, ci, false);
- ub = BinomialBoundsN.getUpperBound (numSamplesI, p, ci, false);
+ lb = BinomialBoundsN.getLowerBound(numSamplesI, p, ci, false);
+ ub = BinomialBoundsN.getUpperBound(numSamplesI, p, ci, false);
// if (numSamplesI == 300 && p > 0.365 && p < 0.367) { ub += 0.01; } // artificial discrepancy
// the logarithm helps discrepancies to not be swamped out of the total
- sum1 += Math.log (lb + 1.0);
- sum2 += Math.log (ub + 1.0);
+ sum1 += Math.log(lb + 1.0);
+ sum2 += Math.log(ub + 1.0);
count += 2;
if (p < 1.0) {
- lb = BinomialBoundsN.getLowerBound (numSamplesI, 1.0 - p, ci, false);
- ub = BinomialBoundsN.getUpperBound (numSamplesI, 1.0 - p, ci, false);
- sum3 += Math.log (lb + 1.0);
- sum4 += Math.log (ub + 1.0);
+ lb = BinomialBoundsN.getLowerBound(numSamplesI, 1.0 - p, ci, false);
+ ub = BinomialBoundsN.getUpperBound(numSamplesI, 1.0 - p, ci, false);
+ sum3 += Math.log(lb + 1.0);
+ sum4 += Math.log(ub + 1.0);
count += 2;
}
p *= 0.99;
}
- numSamplesI = Math.max (numSamplesI+1, (1001*numSamplesI)/1000);
+ numSamplesI = Math.max(numSamplesI + 1, (1001 * numSamplesI) / 1000);
}
println(String.format("{%.15e, %.15e, %.15e, %.15e, %d}", sum1, sum2, sum3, sum4, count));
- double[] arrOut = {sum1, sum2, sum3, sum4, count};
+ final double[] arrOut = {sum1, sum2, sum3, sum4, count};
return arrOut;
}
@@ -81,24 +81,24 @@ public class BinomialBoundsNTest {
public static void checkBounds() {
int i = 0;
for (int ci = 1; ci <= 3; ci++, i++) {
- double[] arr = runTestAux (20, ci, 1e-3);
- for (int j=0; j<5; j++) {
- assertTrue(((arr[j] / std[i][j]) -1.0) < TOL);
+ final double[] arr = runTestAux(20, ci, 1e-3);
+ for (int j = 0; j < 5; j++) {
+ assertTrue(((arr[j] / std[i][j]) - 1.0) < TOL);
}
}
for (int ci = 1; ci <= 3; ci++, i++) {
- double[] arr = runTestAux (200, ci, 1e-5);
- for (int j=0; j<5; j++) {
- assertTrue(((arr[j] / std[i][j]) -1.0) < TOL);
+ final double[] arr = runTestAux(200, ci, 1e-5);
+ for (int j = 0; j < 5; j++) {
+ assertTrue(((arr[j] / std[i][j]) - 1.0) < TOL);
}
}
//comment last one out for a shorter test
-// for (int ci = 1; ci <= 3; ci++, i++) {
-// double[] arr = runTestAux (2000, ci, 1e-7);
-// for (int j=0; j<5; j++) {
-// assertTrue((arr[j] / std[i][j] -1.0) < TOL);
-// }
-// }
+ // for (int ci = 1; ci <= 3; ci++, i++) {
+ // final double[] arr = runTestAux(2000, ci, 1e-7);
+ // for (int j = 0; j < 5; j++) {
+ // assertTrue(((arr[j] / std[i][j]) - 1.0) < TOL);
+ // }
+ //}
}
// With all 3 enabled the test should produce in groups of 3 */
@@ -126,19 +126,19 @@ public class BinomialBoundsNTest {
checkArgs(10L, 1.0, 0);
checkArgs(10L, 1.0, 4);
fail("Expected SketchesArgumentException");
- } catch (SketchesArgumentException e) {
+ } catch (final SketchesArgumentException e) {
//pass
}
}
@Test
public static void checkComputeApproxBino_LB_UB() {
- long n = 100;
- double theta = (2.0 - 1e-5)/2.0;
+ final long n = 100;
+ final double theta = (2.0 - 1e-5) / 2.0;
double result = getLowerBound(n, theta, 1, false);
assertEquals(result, n, 0.0);
result = getUpperBound(n, theta, 1, false);
- assertEquals(result, n+1, 0.0);
+ assertEquals(result, n + 1, 0.0);
result = getLowerBound(n, theta, 1, true);
assertEquals(result, 0.0, 0.0);
result = getUpperBound(n, theta, 1, true);
@@ -153,28 +153,28 @@ public class BinomialBoundsNTest {
@Test
public static void boundsExample() {
println("BinomialBoundsN Example:");
- int k = 500;
- double theta = 0.001;
- int stdDev = 2;
- double ub = BinomialBoundsN.getUpperBound(k, theta, stdDev, false);
- double est = k/theta;
- double lb = BinomialBoundsN.getLowerBound(k, theta, stdDev, false);
- println("K="+k+", Theta="+theta+", SD="+stdDev);
- println("UB: "+ub);
- println("Est: "+est);
- println("LB: "+lb);
+ final int k = 500;
+ final double theta = 0.001;
+ final int stdDev = 2;
+ final double ub = BinomialBoundsN.getUpperBound(k, theta, stdDev, false);
+ final double est = k / theta;
+ final double lb = BinomialBoundsN.getLowerBound(k, theta, stdDev, false);
+ println("K=" + k + ", Theta=" + theta + ", SD=" + stdDev);
+ println("UB: " + ub);
+ println("Est: " + est);
+ println("LB: " + lb);
println("");
}
@Test
public void printlnTest() {
- println("PRINTING: "+this.getClass().getName());
+ println("PRINTING: " + this.getClass().getName());
}
/**
* @param s value to print
*/
- static void println(String s) {
+ static void println(final String s) {
//System.out.println(s); //disable here
}
diff --git a/src/test/java/org/apache/datasketches/BoundsOnBinomialProportionsTest.java b/src/test/java/org/apache/datasketches/BoundsOnBinomialProportionsTest.java
index bdab44e..8529ad3 100644
--- a/src/test/java/org/apache/datasketches/BoundsOnBinomialProportionsTest.java
+++ b/src/test/java/org/apache/datasketches/BoundsOnBinomialProportionsTest.java
@@ -37,51 +37,53 @@ import org.testng.annotations.Test;
public class BoundsOnBinomialProportionsTest {
@Test
- public static void tinyLBTest () {
- // these answers were computed using a different programming language and therefore might not match exactly.
- double [] answers = {0.0, 0.004592032688529923, 0.04725537386564205,
- 0.1396230607626959, 0.2735831034867167, 0.4692424353373485};
- double kappa = 2.0;
- assertTrue (0.0 == approximateLowerBoundOnP (0, 0, kappa));
- long n = 5;
+ public static void tinyLBTest() {
+ //these answers were computed using a different programming language and therefore might not
+ // match exactly.
+ final double[] answers = {0.0, 0.004592032688529923, 0.04725537386564205,
+ 0.1396230607626959, 0.2735831034867167, 0.4692424353373485};
+ final double kappa = 2.0;
+ assertTrue( 0.0 == approximateLowerBoundOnP(0, 0, kappa) );
+ final long n = 5;
for (long k = 0; k <= n; k++) {
- double lb = approximateLowerBoundOnP (n, k, kappa);
- double est = estimateUnknownP (n, k);
- assertTrue (lb <= est);
- assertTrue (Math.abs (lb - answers[(int) k]) < 1e-14);
+ final double lb = approximateLowerBoundOnP(n, k, kappa);
+ final double est = estimateUnknownP(n, k);
+ assertTrue(lb <= est);
+ assertTrue(Math.abs(lb - answers[(int) k]) < 1e-14);
// System.out.printf ("LB\t%d\t%d\t%.1f\t%.16g%n", n, k, kappa, lb);
}
}
@Test
- public static void tinyUBTest () {
- // these answers were computed using a different programming language and therefore might not match exactly.
- double [] answers = {0.5307575646626514, 0.7264168965132833, 0.860376939237304,
- 0.952744626134358, 0.9954079673114701, 1.0};
- double kappa = 2.0;
- assertTrue (1.0 == approximateUpperBoundOnP (0, 0, kappa));
- long n = 5;
+ public static void tinyUBTest() {
+ //these answers were computed using a different programming language and therefore might not
+ // match exactly.
+ final double[] answers = {0.5307575646626514, 0.7264168965132833, 0.860376939237304,
+ 0.952744626134358, 0.9954079673114701, 1.0};
+ final double kappa = 2.0;
+ assertTrue(1.0 == approximateUpperBoundOnP(0, 0, kappa));
+ final long n = 5;
for (long k = 0; k <= n; k++) {
- double ub = approximateUpperBoundOnP (n, k, kappa);
- double est = estimateUnknownP (n, k);
- assertTrue (ub >= est);
- assertTrue (Math.abs (ub - answers[(int) k]) < 1e-14);
+ final double ub = approximateUpperBoundOnP(n, k, kappa);
+ final double est = estimateUnknownP(n, k);
+ assertTrue(ub >= est);
+ assertTrue(Math.abs(ub - answers[(int) k]) < 1e-14);
// System.out.printf ("UB\t%d\t%d\t%.1f\t%.16g%n", n, k, kappa, ub);
}
}
// This is for Kevin's use only, and will not be one of the unit tests.
- public static void lotsOfSpewage (long maxN) {
+ public static void lotsOfSpewage(final long maxN) {
for (long n = 0; n <= maxN; n++) {
for (long k = 0; k <= n; k++) {
for (double kappa = 0.5; kappa < 5.0; kappa += 0.5) {
- double lb = approximateLowerBoundOnP (n, k, kappa);
- double ub = approximateUpperBoundOnP (n, k, kappa);
- double est = estimateUnknownP (n, k);
- assertTrue (lb <= est);
- assertTrue (ub >= est);
- String slb = String.format("LB\t%d\t%d\t%.1f\t%.16g%n", n, k, kappa, lb);
- String sub = String.format("UB\t%d\t%d\t%.1f\t%.16g%n", n, k, kappa, ub);
+ final double lb = approximateLowerBoundOnP(n, k, kappa);
+ final double ub = approximateUpperBoundOnP(n, k, kappa);
+ final double est = estimateUnknownP(n, k);
+ assertTrue(lb <= est);
+ assertTrue(ub >= est);
+ final String slb = String.format("LB\t%d\t%d\t%.1f\t%.16g%n", n, k, kappa, lb);
+ final String sub = String.format("UB\t%d\t%d\t%.1f\t%.16g%n", n, k, kappa, ub);
println(slb);
println(sub);
}
@@ -90,29 +92,29 @@ public class BoundsOnBinomialProportionsTest {
}
// This is for Kevin's use only, and will not be one of the unit tests.
- public static void printSomeNormalCDF () {
- double [] someX = {-10.0, -4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 10.0};
+ public static void printSomeNormalCDF() {
+ final double[] someX = {-10.0, -4.0, -3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, 4.0, 10.0};
for (int i = 0; i < 11; i++) {
- String s = String.format("normalCDF(%.1f) = %.12f%n", someX[i], normalCDF(someX[i]));
+ final String s = String.format("normalCDF(%.1f) = %.12f%n", someX[i], normalCDF(someX[i]));
println(s);
}
}
// This is for Kevin's use only, and will not be one of the unit tests.
-// public static void main (String[] args) {
-// tinyLBTest ();
-// tinyUBTest ();
-// assertTrue (args.length == 1);
-// long maxN = Long.parseLong(args[0]);
-// lotsOfSpewage (maxN);
-// }
+ // public static void main (String[] args) {
+ // tinyLBTest ();
+ // tinyUBTest ();
+ // assertTrue (args.length == 1);
+ // long maxN = Long.parseLong(args[0]);
+ // lotsOfSpewage (maxN);
+ // }
@Test
public static void checkNumStdDevZero() {
- double lb = BoundsOnBinomialProportions.approximateLowerBoundOnP( 1000, 100, 0.0);
- double ub = BoundsOnBinomialProportions.approximateUpperBoundOnP( 1000, 100, 0.0);
- println("LB: "+lb);
- println("UB: "+ub);
+ final double lb = BoundsOnBinomialProportions.approximateLowerBoundOnP( 1000, 100, 0.0);
+ final double ub = BoundsOnBinomialProportions.approximateUpperBoundOnP( 1000, 100, 0.0);
+ println("LB: " + lb);
+ println("UB: " + ub);
}
@Test
@@ -121,21 +123,21 @@ public class BoundsOnBinomialProportionsTest {
estimateUnknownP(-1, 50);
fail("Should have thrown SketchesArgumentException.");
}
- catch (SketchesArgumentException e) {
+ catch (final SketchesArgumentException e) {
//expected
}
try {
estimateUnknownP(500, -50);
fail("Should have thrown SketchesArgumentException.");
}
- catch (SketchesArgumentException e) {
+ catch (final SketchesArgumentException e) {
//expected
}
try {
estimateUnknownP(500, 5000);
fail("Should have thrown SketchesArgumentException.");
}
- catch (SketchesArgumentException e) {
+ catch (final SketchesArgumentException e) {
//expected
}
assertEquals(estimateUnknownP(0, 0), 0.5, 0.0);
@@ -149,13 +151,13 @@ public class BoundsOnBinomialProportionsTest {
@Test
public void printlnTest() {
- println("PRINTING: "+this.getClass().getName());
+ println("PRINTING: " + this.getClass().getName());
}
/**
* @param s value to print
*/
- static void println(String s) {
+ static void println(final String s) {
//System.out.println(s); //disable here
}
diff --git a/src/test/java/org/apache/datasketches/BoundsOnRatiosInThetaSketchedSetsTest.java b/src/test/java/org/apache/datasketches/BoundsOnRatiosInThetaSketchedSetsTest.java
index 2a0cffc..d1610b0 100644
--- a/src/test/java/org/apache/datasketches/BoundsOnRatiosInThetaSketchedSetsTest.java
+++ b/src/test/java/org/apache/datasketches/BoundsOnRatiosInThetaSketchedSetsTest.java
@@ -22,28 +22,27 @@ package org.apache.datasketches;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
-import org.testng.annotations.Test;
-
import org.apache.datasketches.theta.CompactSketch;
import org.apache.datasketches.theta.Intersection;
import org.apache.datasketches.theta.Sketches;
import org.apache.datasketches.theta.UpdateSketch;
+import org.testng.annotations.Test;
@SuppressWarnings("javadoc")
public class BoundsOnRatiosInThetaSketchedSetsTest {
@Test
public void checkNormalReturns() {
- UpdateSketch skA = Sketches.updateSketchBuilder().build(); //4K
- UpdateSketch skC = Sketches.updateSketchBuilder().build();
- int uA = 10000;
- int uC = 100000;
- for (int i=0; i<uA; i++) { skA.update(i); }
- for (int i=0; i<uC; i++) { skC.update(i+(uA/2)); }
- Intersection inter = Sketches.setOperationBuilder().buildIntersection();
+ final UpdateSketch skA = Sketches.updateSketchBuilder().build(); //4K
+ final UpdateSketch skC = Sketches.updateSketchBuilder().build();
+ final int uA = 10000;
+ final int uC = 100000;
+ for (int i = 0; i < uA; i++) { skA.update(i); }
+ for (int i = 0; i < uC; i++) { skC.update(i + (uA / 2)); }
+ final Intersection inter = Sketches.setOperationBuilder().buildIntersection();
inter.update(skA);
inter.update(skC);
- CompactSketch skB = inter.getResult();
+ final CompactSketch skB = inter.getResult();
double est = BoundsOnRatiosInThetaSketchedSets.getEstimateOfBoverA(skA, skB);
double lb = BoundsOnRatiosInThetaSketchedSets.getLowerBoundForBoverA(skA, skB);
@@ -51,45 +50,45 @@ public class BoundsOnRatiosInThetaSketchedSetsTest {
assertTrue(ub > est);
assertTrue(est > lb);
assertEquals(est, 0.5, .03);
- println("ub : "+ ub);
- println("est: "+est);
- println("lb : "+lb);
+ println("ub : " + ub);
+ println("est: " + est);
+ println("lb : " + lb);
skA.reset(); //skA is now empty
est = BoundsOnRatiosInThetaSketchedSets.getEstimateOfBoverA(skA, skB);
lb = BoundsOnRatiosInThetaSketchedSets.getLowerBoundForBoverA(skA, skB);
ub = BoundsOnRatiosInThetaSketchedSets.getUpperBoundForBoverA(skA, skB);
- println("ub : "+ ub);
- println("est: "+est);
- println("lb : "+lb);
+ println("ub : " + ub);
+ println("est: " + est);
+ println("lb : " + lb);
skC.reset(); //Now both are empty
est = BoundsOnRatiosInThetaSketchedSets.getEstimateOfBoverA(skA, skC);
lb = BoundsOnRatiosInThetaSketchedSets.getLowerBoundForBoverA(skA, skC);
ub = BoundsOnRatiosInThetaSketchedSets.getUpperBoundForBoverA(skA, skC);
- println("ub : "+ ub);
- println("est: "+est);
- println("lb : "+lb);
+ println("ub : " + ub);
+ println("est: " + est);
+ println("lb : " + lb);
}
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkAbnormalReturns() {
- UpdateSketch skA = Sketches.updateSketchBuilder().build(); //4K
- UpdateSketch skC = Sketches.updateSketchBuilder().build();
- int uA = 100000;
- int uC = 10000;
- for (int i=0; i<uA; i++) { skA.update(i); }
- for (int i=0; i<uC; i++) { skC.update(i+(uA/2)); }
+ final UpdateSketch skA = Sketches.updateSketchBuilder().build(); //4K
+ final UpdateSketch skC = Sketches.updateSketchBuilder().build();
+ final int uA = 100000;
+ final int uC = 10000;
+ for (int i = 0; i < uA; i++) { skA.update(i); }
+ for (int i = 0; i < uC; i++) { skC.update(i + (uA / 2)); }
BoundsOnRatiosInThetaSketchedSets.getEstimateOfBoverA(skA, skC);
}
@Test
public void printlnTest() {
- println("PRINTING: "+this.getClass().getName());
+ println("PRINTING: " + this.getClass().getName());
}
/**
* @param s value to print
*/
- static void println(String s) {
+ static void println(final String s) {
//System.out.println(s); //disable here
}
}
diff --git a/src/test/java/org/apache/datasketches/ByteArrayUtilTest.java b/src/test/java/org/apache/datasketches/ByteArrayUtilTest.java
index b69ae0a..a372e67 100644
--- a/src/test/java/org/apache/datasketches/ByteArrayUtilTest.java
+++ b/src/test/java/org/apache/datasketches/ByteArrayUtilTest.java
@@ -51,10 +51,10 @@ public class ByteArrayUtilTest {
@Test
public void checkGetPutShortLE() {
- byte[] arr = { 79, -93, 124, 117 };
- short out1 = getShortLE(arr, 0);
- short out2 = getShortLE(arr, 2);
- byte[] arr2 = new byte[4];
+ final byte[] arr = { 79, -93, 124, 117 };
+ final short out1 = getShortLE(arr, 0);
+ final short out2 = getShortLE(arr, 2);
+ final byte[] arr2 = new byte[4];
putShortLE(arr2, 0, out1);
putShortLE(arr2, 2, out2);
assertEquals(arr2, arr);
@@ -62,10 +62,10 @@ public class ByteArrayUtilTest {
@Test
public void checkGetPutShortBE() {
- byte[] arr = { 79, -93, 124, 117 };
- short out1 = getShortBE(arr, 0);
- short out2 = getShortBE(arr, 2);
- byte[] arr2 = new byte[4];
+ final byte[] arr = { 79, -93, 124, 117 };
+ final short out1 = getShortBE(arr, 0);
+ final short out2 = getShortBE(arr, 2);
+ final byte[] arr2 = new byte[4];
putShortBE(arr2, 0, out1);
putShortBE(arr2, 2, out2);
assertEquals(arr2, arr);
@@ -73,10 +73,10 @@ public class ByteArrayUtilTest {
@Test
public void checkGetPutIntLE() {
- byte[] arr = { 79, -93, 124, 117, -73, -100, -114, 77 };
- int out1 = getIntLE(arr, 0);
- int out2 = getIntLE(arr, 4);
- byte[] arr2 = new byte[8];
+ final byte[] arr = { 79, -93, 124, 117, -73, -100, -114, 77 };
+ final int out1 = getIntLE(arr, 0);
+ final int out2 = getIntLE(arr, 4);
+ final byte[] arr2 = new byte[8];
putIntLE(arr2, 0, out1);
putIntLE(arr2, 4, out2);
assertEquals(arr2, arr);
@@ -84,10 +84,10 @@ public class ByteArrayUtilTest {
@Test
public void checkGetPutIntBE() {
- byte[] arr = { 79, -93, 124, 117, -73, -100, -114, 77 };
- int out1 = getIntBE(arr, 0);
- int out2 = getIntBE(arr, 4);
- byte[] arr2 = new byte[8];
+ final byte[] arr = { 79, -93, 124, 117, -73, -100, -114, 77 };
+ final int out1 = getIntBE(arr, 0);
+ final int out2 = getIntBE(arr, 4);
+ final byte[] arr2 = new byte[8];
putIntBE(arr2, 0, out1);
putIntBE(arr2, 4, out2);
assertEquals(arr2, arr);
@@ -96,10 +96,10 @@ public class ByteArrayUtilTest {
@Test
public void checkGetPutLongLE() {
- byte[] arr = { 79, -93, 124, 117, -73, -100, -114, 77, 5, -95, -15, 41, -89, -124, -26, -87 };
- long out1 = getLongLE(arr, 0);
- long out2 = getLongLE(arr, 8);
- byte[] arr2 = new byte[16];
+ final byte[] arr = { 79, -93, 124, 117, -73, -100, -114, 77, 5, -95, -15, 41, -89, -124, -26, -87 };
+ final long out1 = getLongLE(arr, 0);
+ final long out2 = getLongLE(arr, 8);
+ final byte[] arr2 = new byte[16];
putLongLE(arr2, 0, out1);
putLongLE(arr2, 8, out2);
assertEquals(arr2, arr);
@@ -107,10 +107,10 @@ public class ByteArrayUtilTest {
@Test
public void checkGetPutLongBE() {
- byte[] arr = { 79, -93, 124, 117, -73, -100, -114, 77, 5, -95, -15, 41, -89, -124, -26, -87 };
- long out1 = getLongBE(arr, 0);
- long out2 = getLongBE(arr, 8);
- byte[] arr2 = new byte[16];
+ final byte[] arr = { 79, -93, 124, 117, -73, -100, -114, 77, 5, -95, -15, 41, -89, -124, -26, -87 };
+ final long out1 = getLongBE(arr, 0);
+ final long out2 = getLongBE(arr, 8);
+ final byte[] arr2 = new byte[16];
putLongBE(arr2, 0, out1);
putLongBE(arr2, 8, out2);
assertEquals(arr2, arr);
@@ -118,10 +118,10 @@ public class ByteArrayUtilTest {
@Test
public void checkGetPutFloatLE() {
- byte[] arr = { -37, 15, 73, 64, 84, -8, 45, 64 }; //PI, E
- float out1 = getFloatLE(arr, 0);
- float out2 = getFloatLE(arr, 4);
- byte[] arr2 = new byte[8];
+ final byte[] arr = { -37, 15, 73, 64, 84, -8, 45, 64 }; //PI, E
+ final float out1 = getFloatLE(arr, 0);
+ final float out2 = getFloatLE(arr, 4);
+ final byte[] arr2 = new byte[8];
putFloatLE(arr2, 0, out1);
putFloatLE(arr2, 4, out2);
assertEquals(arr2, arr);
@@ -131,10 +131,10 @@ public class ByteArrayUtilTest {
@Test
public void checkGetPutFloatBE() {
- byte[] arr = { -37, 15, 73, 64, 84, -8, 45, 64 }; //PI, E
- float out1 = getFloatBE(arr, 0);
- float out2 = getFloatBE(arr, 4);
- byte[] arr2 = new byte[8];
+ final byte[] arr = { -37, 15, 73, 64, 84, -8, 45, 64 }; //PI, E
+ final float out1 = getFloatBE(arr, 0);
+ final float out2 = getFloatBE(arr, 4);
+ final byte[] arr2 = new byte[8];
putFloatBE(arr2, 0, out1);
putFloatBE(arr2, 4, out2);
assertEquals(arr2, arr);
@@ -142,10 +142,10 @@ public class ByteArrayUtilTest {
@Test
public void checkGetPutDoubleLE() {
- byte[] arr = { 24, 45, 68, 84, -5, 33, 9, 64, 105, 87, 20, -117, 10, -65, 5, 64 }; //PI, E
- double out1 = getDoubleLE(arr, 0);
- double out2 = getDoubleLE(arr, 8);
- byte[] arr2 = new byte[16];
+ final byte[] arr = { 24, 45, 68, 84, -5, 33, 9, 64, 105, 87, 20, -117, 10, -65, 5, 64 }; //PI, E
+ final double out1 = getDoubleLE(arr, 0);
+ final double out2 = getDoubleLE(arr, 8);
+ final byte[] arr2 = new byte[16];
putDoubleLE(arr2, 0, out1);
putDoubleLE(arr2, 8, out2);
assertEquals(arr2, arr);
@@ -155,10 +155,10 @@ public class ByteArrayUtilTest {
@Test
public void checkGetPutDoubleBE() {
- byte[] arr = { 24, 45, 68, 84, -5, 33, 9, 64, 105, 87, 20, -117, 10, -65, 5, 64 }; //PI, E
- double out1 = getDoubleBE(arr, 0);
- double out2 = getDoubleBE(arr, 8);
- byte[] arr2 = new byte[16];
+ final byte[] arr = { 24, 45, 68, 84, -5, 33, 9, 64, 105, 87, 20, -117, 10, -65, 5, 64 }; //PI, E
+ final double out1 = getDoubleBE(arr, 0);
+ final double out2 = getDoubleBE(arr, 8);
+ final byte[] arr2 = new byte[16];
putDoubleBE(arr2, 0, out1);
putDoubleBE(arr2, 8, out2);
assertEquals(arr2, arr);
diff --git a/src/test/java/org/apache/datasketches/FamilyTest.java b/src/test/java/org/apache/datasketches/FamilyTest.java
index cd996ab..38eb68e 100644
--- a/src/test/java/org/apache/datasketches/FamilyTest.java
+++ b/src/test/java/org/apache/datasketches/FamilyTest.java
@@ -34,18 +34,18 @@ public class FamilyTest {
@Test
public void checkFamilyEnum() {
- Family[] families = Family.values();
- int numFam = families.length;
+ final Family[] families = Family.values();
+ final int numFam = families.length;
- for (int i=0; i<numFam; i++) {
- Family f = families[i];
- int fid = f.getID();
+ for (int i = 0; i < numFam; i++) {
+ final Family f = families[i];
+ final int fid = f.getID();
f.checkFamilyID(fid);
- Family f2 = idToFamily(fid);
+ final Family f2 = idToFamily(fid);
assertTrue(f.equals(f2));
assertEquals(f.getFamilyName(), f2.getFamilyName());
- int id2 = f2.getID();
+ final int id2 = f2.getID();
assertEquals(fid, id2);
}
checkStringToFamily("Alpha");
@@ -57,8 +57,8 @@ public class FamilyTest {
checkStringToFamily("Quantiles");
}
- private static void checkStringToFamily(String inStr) {
- String fName = stringToFamily(inStr).toString();
+ private static void checkStringToFamily(final String inStr) {
+ final String fName = stringToFamily(inStr).toString();
assertEquals(fName, inStr.toUpperCase());
}
@@ -69,20 +69,20 @@ public class FamilyTest {
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkBadFamilyID() {
- Family famAlpha = Family.ALPHA;
- Family famQS = Family.QUICKSELECT;
+ final Family famAlpha = Family.ALPHA;
+ final Family famQS = Family.QUICKSELECT;
famAlpha.checkFamilyID(famQS.getID());
}
@Test
public void printlnTest() {
- println("PRINTING: "+this.getClass().getName());
+ println("PRINTING: " + this.getClass().getName());
}
/**
* @param s value to print
*/
- static void println(String s) {
+ static void println(final String s) {
//System.out.println(s); //disable here
}
diff --git a/src/test/java/org/apache/datasketches/HashOperationsTest.java b/src/test/java/org/apache/datasketches/HashOperationsTest.java
index 81d91ba..00c34fa 100644
--- a/src/test/java/org/apache/datasketches/HashOperationsTest.java
+++ b/src/test/java/org/apache/datasketches/HashOperationsTest.java
@@ -34,9 +34,8 @@ import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
-import org.testng.annotations.Test;
-
import org.apache.datasketches.memory.WritableMemory;
+import org.testng.annotations.Test;
@SuppressWarnings("javadoc")
public class HashOperationsTest {
@@ -65,13 +64,13 @@ public class HashOperationsTest {
@Test
public void checkHashArrayInsert() {
- long[] hTable = new long[16];
- long[] hashIn = new long[1];
- for (int i=0; i<8; i++) {
+ final long[] hTable = new long[16];
+ final long[] hashIn = new long[1];
+ for (int i = 0; i < 8; i++) {
hashIn[0] = i;
- long h = hash(hashIn, 0)[0] >>> 1;
+ final long h = hash(hashIn, 0)[0] >>> 1;
hashInsertOnly(hTable, 4, h);
- int count = hashArrayInsert(hTable, hTable, 4, Long.MAX_VALUE);
+ final int count = hashArrayInsert(hTable, hTable, 4, Long.MAX_VALUE);
assertEquals(count, 0);
}
@@ -79,52 +78,52 @@ public class HashOperationsTest {
@Test
public void testContinueCondtion() {
- long thetaLong = Long.MAX_VALUE/2;
+ final long thetaLong = Long.MAX_VALUE / 2;
assertTrue(continueCondition(thetaLong, 0));
assertTrue(continueCondition(thetaLong, thetaLong));
- assertTrue(continueCondition(thetaLong, thetaLong +1));
- assertFalse(continueCondition(thetaLong, thetaLong -1));
+ assertTrue(continueCondition(thetaLong, thetaLong + 1));
+ assertFalse(continueCondition(thetaLong, thetaLong - 1));
}
@Test
public void testHashInsertOnlyNoStride() {
- long[] table = new long[32];
- int index = hashInsertOnly(table, 5, 1);
+ final long[] table = new long[32];
+ final int index = hashInsertOnly(table, 5, 1);
assertEquals(index, 1);
assertEquals(table[1], 1L);
}
@Test
public void testHashInsertOnlyWithStride() {
- long[] table = new long[32];
+ final long[] table = new long[32];
table[1] = 1;
- int index = hashInsertOnly(table, 5, 1);
+ final int index = hashInsertOnly(table, 5, 1);
assertEquals(index, 2);
assertEquals(table[2], 1L);
}
@Test
public void testHashInsertOnlyMemoryNoStride() {
- long[] table = new long[32];
- WritableMemory mem = WritableMemory.wrap(table);
- int index = fastHashInsertOnly(mem, 5, 1, 0);
+ final long[] table = new long[32];
+ final WritableMemory mem = WritableMemory.wrap(table);
+ final int index = fastHashInsertOnly(mem, 5, 1, 0);
assertEquals(index, 1);
assertEquals(table[1], 1L);
}
@Test
public void testHashInsertOnlyMemoryWithStride() {
- long[] table = new long[32];
+ final long[] table = new long[32];
table[1] = 1;
- WritableMemory mem = WritableMemory.wrap(table);
- int index = fastHashInsertOnly(mem, 5, 1, 0);
+ final WritableMemory mem = WritableMemory.wrap(table);
+ final int index = fastHashInsertOnly(mem, 5, 1, 0);
assertEquals(index, 2);
assertEquals(table[2], 1L);
}
@Test
public void checkFullHeapTableCatchesInfiniteLoop() {
- long[] table = new long[32];
+ final long[] table = new long[32];
for (int i = 1; i <= 32; ++i) {
hashInsertOnly(table, 5, i);
}
@@ -150,8 +149,8 @@ public class HashOperationsTest {
@Test
public void checkFullDirectTableCatchesInfiniteLoop() {
- long[] table = new long[32];
- WritableMemory mem = WritableMemory.wrap(table);
+ final long[] table = new long[32];
+ final WritableMemory mem = WritableMemory.wrap(table);
for (int i = 1; i <= 32; ++i) {
fastHashInsertOnly(mem, 5, i, 0);
}
@@ -177,8 +176,8 @@ public class HashOperationsTest {
@Test
public void checkFullFastDirectTableCatchesInfiniteLoop() {
- long[] table = new long[32];
- WritableMemory wmem = WritableMemory.wrap(table);
+ final long[] table = new long[32];
+ final WritableMemory wmem = WritableMemory.wrap(table);
for (int i = 1; i <= 32; ++i) {
fastHashInsertOnly(wmem, 5, i, 0);
@@ -203,13 +202,13 @@ public class HashOperationsTest {
@Test
public void printlnTest() {
- println("PRINTING: "+this.getClass().getName());
+ println("PRINTING: " + this.getClass().getName());
}
/**
* @param s value to print
*/
- static void println(String s) {
+ static void println(final String s) {
//System.out.println(s); //disable here
}
diff --git a/src/test/java/org/apache/datasketches/QuickSelectTest.java b/src/test/java/org/apache/datasketches/QuickSelectTest.java
index ca9766e..4414c26 100644
--- a/src/test/java/org/apache/datasketches/QuickSelectTest.java
+++ b/src/test/java/org/apache/datasketches/QuickSelectTest.java
@@ -19,10 +19,10 @@
package org.apache.datasketches;
+import static java.lang.String.format;
import static org.apache.datasketches.QuickSelect.select;
import static org.apache.datasketches.QuickSelect.selectExcludingZeros;
import static org.apache.datasketches.QuickSelect.selectIncludingZeros;
-import static java.lang.String.format;
import java.util.Random;
@@ -41,16 +41,16 @@ public class QuickSelectTest {
@Test
public void checkQuickSelect0Based() {
- int len = 64;
- long[] arr = new long[len];
+ final int len = 64;
+ final long[] arr = new long[len];
for (int i = 0; i < len; i++ ) {
arr[i] = i;
}
for (int pivot = 0; pivot < 64; pivot++ ) {
- long trueVal = pivot;
+ final long trueVal = pivot;
for (int i = 0; i < 1000; i++ ) {
shuffle(arr);
- long retVal = select(arr, 0, len - 1, pivot);
+ final long retVal = select(arr, 0, len - 1, pivot);
Assert.assertEquals(retVal, trueVal);
}
}
@@ -58,45 +58,45 @@ public class QuickSelectTest {
@Test
public void checkQuickSelect1BasedExcludingZeros() {
- int len = 64;
- int nonZeros = (7 * len) / 8;
- long[] arr = new long[len];
+ final int len = 64;
+ final int nonZeros = (7 * len) / 8;
+ final long[] arr = new long[len];
for (int i = 0; i < nonZeros; i++ ) {
arr[i] = i + 1;
}
- int pivot = len / 2;
- long trueVal = arr[pivot - 1];
+ final int pivot = len / 2;
+ final long trueVal = arr[pivot - 1];
shuffle(arr);
- long retVal = selectExcludingZeros(arr, nonZeros, pivot);
+ final long retVal = selectExcludingZeros(arr, nonZeros, pivot);
Assert.assertEquals(retVal, trueVal);
}
@Test
public void checkQuickSelect1BasedExcludingZeros2() {
- int len = 64;
- int nonZeros = 16;
- long[] arr = new long[len];
+ final int len = 64;
+ final int nonZeros = 16;
+ final long[] arr = new long[len];
for (int i = 0; i < nonZeros; i++ ) {
arr[i] = i + 1;
}
shuffle(arr);
- int pivot = len / 2;
- long retVal = selectExcludingZeros(arr, nonZeros, pivot);
+ final int pivot = len / 2;
+ final long retVal = selectExcludingZeros(arr, nonZeros, pivot);
Assert.assertEquals(retVal, 0);
}
@Test
public void checkQuickSelect1BasedIncludingZeros() {
- int len = 64;
- int zeros = len / 8;
- long[] arr = new long[len];
+ final int len = 64;
+ final int zeros = len / 8;
+ final long[] arr = new long[len];
for (int i = zeros; i < len; i++ ) {
arr[i] = i + 1;
}
- int pivot = len / 2;
- long trueVal = arr[pivot - 1];
+ final int pivot = len / 2;
+ final long trueVal = arr[pivot - 1];
shuffle(arr);
- long retVal = selectIncludingZeros(arr, pivot);
+ final long retVal = selectIncludingZeros(arr, pivot);
Assert.assertEquals(retVal, trueVal);
}
@@ -104,16 +104,16 @@ public class QuickSelectTest {
@Test
public void checkQuickSelectDbl0Based() {
- int len = 64;
- double[] arr = new double[len];
+ final int len = 64;
+ final double[] arr = new double[len];
for (int i = 0; i < len; i++ ) {
arr[i] = i;
}
for (int pivot = 0; pivot < 64; pivot++ ) {
- double trueVal = pivot;
+ final double trueVal = pivot;
for (int i = 0; i < 1000; i++ ) {
shuffle(arr);
- double retVal = select(arr, 0, len - 1, pivot);
+ final double retVal = select(arr, 0, len - 1, pivot);
Assert.assertEquals(retVal, trueVal, 0.0);
}
}
@@ -121,45 +121,45 @@ public class QuickSelectTest {
@Test
public void checkQuickSelectDbl1BasedExcludingZeros() {
- int len = 64;
- int nonZeros = (7 * len) / 8;
- double[] arr = new double[len];
+ final int len = 64;
+ final int nonZeros = (7 * len) / 8;
+ final double[] arr = new double[len];
for (int i = 0; i < nonZeros; i++ ) {
arr[i] = i + 1;
}
- int pivot = len / 2;
- double trueVal = arr[pivot - 1];
+ final int pivot = len / 2;
+ final double trueVal = arr[pivot - 1];
shuffle(arr);
- double retVal = selectExcludingZeros(arr, nonZeros, pivot);
+ final double retVal = selectExcludingZeros(arr, nonZeros, pivot);
Assert.assertEquals(retVal, trueVal, 0.0);
}
@Test
public void checkQuickSelectDbl1BasedExcludingZeros2() {
- int len = 64;
- int nonZeros = 16;
- double[] arr = new double[len];
+ final int len = 64;
+ final int nonZeros = 16;
+ final double[] arr = new double[len];
for (int i = 0; i < nonZeros; i++ ) {
arr[i] = i + 1;
}
shuffle(arr);
- int pivot = len / 2;
- double retVal = selectExcludingZeros(arr, nonZeros, pivot);
+ final int pivot = len / 2;
+ final double retVal = selectExcludingZeros(arr, nonZeros, pivot);
Assert.assertEquals(retVal, 0, 0.0);
}
@Test
public void checkQuickSelectDbl1BasedIncludingZeros() {
- int len = 64;
- int zeros = len / 8;
- double[] arr = new double[len];
+ final int len = 64;
+ final int zeros = len / 8;
+ final double[] arr = new double[len];
for (int i = zeros; i < len; i++ ) {
arr[i] = i + 1;
}
- int pivot = len / 2;
- double trueVal = arr[pivot -1];
+ final int pivot = len / 2;
+ final double trueVal = arr[pivot - 1];
shuffle(arr);
- double retVal = selectIncludingZeros(arr, pivot);
+ final double retVal = selectIncludingZeros(arr, pivot);
Assert.assertEquals(retVal, trueVal, 0.0);
}
@@ -168,11 +168,11 @@ public class QuickSelectTest {
* Rearrange the elements of an array in random order.
* @param a long array
*/
- public static void shuffle(long[] a) {
- int N = a.length;
+ public static void shuffle(final long[] a) {
+ final int N = a.length;
for (int i = 0; i < N; i++ ) {
- int r = i + uniform(N - i); // between i and N-1
- long temp = a[i];
+ final int r = i + uniform(N - i); // between i and N-1
+ final long temp = a[i];
a[i] = a[r];
a[r] = temp;
}
@@ -182,11 +182,11 @@ public class QuickSelectTest {
* Rearrange the elements of an array in random order.
* @param a double array
*/
- public static void shuffle(double[] a) {
- int N = a.length;
+ public static void shuffle(final double[] a) {
+ final int N = a.length;
for (int i = 0; i < N; i++ ) {
- int r = i + uniform(N - i); // between i and N-1
- double temp = a[i];
+ final int r = i + uniform(N - i); // between i and N-1
+ final double temp = a[i];
a[i] = a[r];
a[r] = temp;
}
@@ -199,16 +199,16 @@ public class QuickSelectTest {
* @param n the upper exclusive bound
* @return random integer
*/
- public static int uniform(int n) {
+ public static int uniform(final int n) {
if (n <= 0) {
throw new SketchesArgumentException("n must be positive");
}
return random.nextInt(n);
}
- private static String printArr(long[] arr) {
- StringBuilder sb = new StringBuilder();
- int len = arr.length;
+ private static String printArr(final long[] arr) {
+ final StringBuilder sb = new StringBuilder();
+ final int len = arr.length;
sb.append(" Base0").append(" Base1").append(" Value").append(LS);
for (int i = 0; i < len; i++ ) {
sb
@@ -218,9 +218,9 @@ public class QuickSelectTest {
return sb.toString();
}
- private static String printArr(double[] arr) {
- StringBuilder sb = new StringBuilder();
- int len = arr.length;
+ private static String printArr(final double[] arr) {
+ final StringBuilder sb = new StringBuilder();
+ final int len = arr.length;
sb.append(" Base0").append(" Base1").append(" Value").append(LS);
for (int i = 0; i < len; i++ ) {
sb
@@ -232,10 +232,10 @@ public class QuickSelectTest {
//For console testing
static void test1() {
- int len = 16;
- int nonZeros = (3 * len) / 4;
- int zeros = len - nonZeros;
- long[] arr = new long[len];
+ final int len = 16;
+ final int nonZeros = (3 * len) / 4;
+ final int zeros = len - nonZeros;
+ final long[] arr = new long[len];
for (int i = 0; i < nonZeros; i++ ) {
arr[i] = i + 1;
}
@@ -244,26 +244,26 @@ public class QuickSelectTest {
shuffle(arr);
println("Randomized Ordering:");
println(printArr(arr));
- int pivot = len / 2;
+ final int pivot = len / 2;
println("select(...):");
println("ArrSize : " + len);
println("NonZeros: " + nonZeros);
println("Zeros : " + zeros);
println("Choose pivot at 1/2 array size, pivot: " + pivot);
- long ret = select(arr, 0, len - 1, pivot);
+ final long ret = select(arr, 0, len - 1, pivot);
println("Return value of 0-based pivot including zeros:");
println("select(arr, 0, " + (len - 1) + ", " + pivot + ") => " + ret);
println("0-based index of pivot = pivot = " + (pivot));
- println("Result Array:"+LS);
+ println("Result Array:" + LS);
println(printArr(arr));
}
//For console testing
static void test2() {
- int len = 16;
- int nonZeros = (3 * len) / 4;
- int zeros = len - nonZeros;
- long[] arr = new long[len];
+ final int len = 16;
+ final int nonZeros = (3 * len) / 4;
+ final int zeros = len - nonZeros;
+ final long[] arr = new long[len];
for (int i = 0; i < nonZeros; i++ ) {
arr[i] = i + 1;
}
@@ -272,26 +272,26 @@ public class QuickSelectTest {
shuffle(arr);
println("Randomized Ordering:");
println(printArr(arr));
- int pivot = len / 2; //= 8
+ final int pivot = len / 2; //= 8
println("selectDiscountingZeros(...):");
println("ArrSize : " + len);
println("NonZeros: " + nonZeros);
println("Zeros : " + zeros);
println("Choose pivot at 1/2 array size, pivot= " + pivot);
- long ret = selectExcludingZeros(arr, nonZeros, pivot);
+ final long ret = selectExcludingZeros(arr, nonZeros, pivot);
println("Return value of 1-based pivot discounting zeros:");
println("selectDiscountingZeros(arr, " + nonZeros + ", " + pivot + ") => " + ret);
println("0-based index of pivot= pivot+zeros-1 = " + ((pivot + zeros) - 1));
- println("Result Array:"+LS);
+ println("Result Array:" + LS);
println(printArr(arr));
}
//For console testing
static void test3() {
- int len = 16;
- int nonZeros = (3 * len) / 4;
- int zeros = len - nonZeros;
- long[] arr = new long[len];
+ final int len = 16;
+ final int nonZeros = (3 * len) / 4;
+ final int zeros = len - nonZeros;
+ final long[] arr = new long[len];
for (int i = 0; i < nonZeros; i++ ) {
arr[i] = i + 1;
}
@@ -300,25 +300,25 @@ public class QuickSelectTest {
shuffle(arr);
println("Randomized Ordering:");
println(printArr(arr));
- int pivot = len / 2; //= 8
+ final int pivot = len / 2; //= 8
println("selectIncludingZeros(...):");
println("ArrSize : " + len);
println("NonZeros: " + nonZeros);
println("Zeros : " + zeros);
println("Choose pivot at 1/2 array size, pivot= " + pivot);
- long ret = selectIncludingZeros(arr, pivot);
+ final long ret = selectIncludingZeros(arr, pivot);
println("Return value of 1-based pivot including zeros:");
println("selectIncludingZeros(arr, " + pivot + ") => " + ret);
println("0-based index of pivot= pivot-1 = " + (pivot - 1));
- println("Result Array:"+LS);
+ println("Result Array:" + LS);
println(printArr(arr));
}
static void testDbl1() {
- int len = 16;
- int nonZeros = (3 * len) / 4;
- int zeros = len - nonZeros;
- double[] arr = new double[len];
+ final int len = 16;
+ final int nonZeros = (3 * len) / 4;
+ final int zeros = len - nonZeros;
+ final double[] arr = new double[len];
for (int i = 0; i < nonZeros; i++ ) {
arr[i] = i + 1;
}
@@ -327,26 +327,26 @@ public class QuickSelectTest {
shuffle(arr);
println("Randomized Ordering:");
println(printArr(arr));
- int pivot = len / 2;
+ final int pivot = len / 2;
println("select(...):");
println("ArrSize : " + len);
println("NonZeros: " + nonZeros);
println("Zeros : " + zeros);
println("Choose pivot at 1/2 array size, pivot: " + pivot);
- double ret = select(arr, 0, len - 1, pivot);
+ final double ret = select(arr, 0, len - 1, pivot);
println("Return value of 0-based pivot including zeros:");
println("select(arr, 0, " + (len - 1) + ", " + pivot + ") => " + ret);
println("0-based index of pivot = pivot = " + (pivot));
- println("Result Array:"+LS);
+ println("Result Array:" + LS);
println(printArr(arr));
}
//For console testing
static void testDbl2() {
- int len = 16;
- int nonZeros = (3 * len) / 4;
- int zeros = len - nonZeros;
- double[] arr = new double[len];
+ final int len = 16;
+ final int nonZeros = (3 * len) / 4;
+ final int zeros = len - nonZeros;
+ final double[] arr = new double[len];
for (int i = 0; i < nonZeros; i++ ) {
arr[i] = i + 1;
}
@@ -355,26 +355,26 @@ public class QuickSelectTest {
shuffle(arr);
println("Randomized Ordering:");
println(printArr(arr));
- int pivot = len / 2; //= 8
+ final int pivot = len / 2; //= 8
println("selectDiscountingZeros(...):");
println("ArrSize : " + len);
println("NonZeros: " + nonZeros);
println("Zeros : " + zeros);
println("Choose pivot at 1/2 array size, pivot= " + pivot);
- double ret = selectExcludingZeros(arr, nonZeros, pivot);
+ final double ret = selectExcludingZeros(arr, nonZeros, pivot);
println("Return value of 1-based pivot discounting zeros:");
println("selectDiscountingZeros(arr, " + nonZeros + ", " + pivot + ") => " + ret);
println("0-based index of pivot= pivot+zeros-1 = " + ((pivot + zeros) - 1));
- println("Result Array:"+LS);
+ println("Result Array:" + LS);
println(printArr(arr));
}
//For console testing
static void testDbl3() {
- int len = 16;
- int nonZeros = (3 * len) / 4;
- int zeros = len - nonZeros;
- double[] arr = new double[len];
+ final int len = 16;
+ final int nonZeros = (3 * len) / 4;
+ final int zeros = len - nonZeros;
+ final double[] arr = new double[len];
for (int i = 0; i < nonZeros; i++ ) {
arr[i] = i + 1;
}
@@ -383,63 +383,63 @@ public class QuickSelectTest {
shuffle(arr);
println("Randomized Ordering:");
println(printArr(arr));
- int pivot = len / 2; //= 8
+ final int pivot = len / 2; //= 8
println("selectIncludingZeros(...):");
println("ArrSize : " + len);
println("NonZeros: " + nonZeros);
println("Zeros : " + zeros);
println("Choose pivot at 1/2 array size, pivot= " + pivot);
- double ret = selectIncludingZeros(arr, pivot);
+ final double ret = selectIncludingZeros(arr, pivot);
println("Return value of 1-based pivot including zeros:");
println("selectIncludingZeros(arr, " + pivot + ") => " + ret);
println("0-based index of pivot= pivot-1 = " + (pivot - 1));
- println("Result Array:"+LS);
+ println("Result Array:" + LS);
println(printArr(arr));
}
-// public static void main(String[] args) {
-// println(LS+"==LONGS 1=========="+LS);
-// test1();
-// println(LS+"==LONGS 2=========="+LS);
-// test2();
-// println(LS+"==LONGS 3=========="+LS);
-// test3();
-// println(LS+"==DOUBLES 1========"+LS);
-// testDbl1();
-// println(LS+"==DOUBLES 2========"+LS);
-// testDbl2();
-// println(LS+"==DOUBLES 3========"+LS);
-// testDbl3();
-//
-//
-// QuickSelectTest qst = new QuickSelectTest();
-// qst.checkQuickSelect0Based();
-// qst.checkQuickSelect1BasedExcludingZeros();
-// qst.checkQuickSelect1BasedExcludingZeros2();
-// qst.checkQuickSelect1BasedIncludingZeros();
-// qst.checkQuickSelectDbl0Based();
-// qst.checkQuickSelectDbl1BasedExcludingZeros();
-// qst.checkQuickSelectDbl1BasedExcludingZeros2();
-// qst.checkQuickSelectDbl1BasedIncludingZeros();
-//
-// }
+ // public static void main(String[] args) {
+ // println(LS+"==LONGS 1=========="+LS);
+ // test1();
+ // println(LS+"==LONGS 2=========="+LS);
+ // test2();
+ // println(LS+"==LONGS 3=========="+LS);
+ // test3();
+ // println(LS+"==DOUBLES 1========"+LS);
+ // testDbl1();
+ // println(LS+"==DOUBLES 2========"+LS);
+ // testDbl2();
+ // println(LS+"==DOUBLES 3========"+LS);
+ // testDbl3();
+ //
+ //
+ // QuickSelectTest qst = new QuickSelectTest();
+ // qst.checkQuickSelect0Based();
+ // qst.checkQuickSelect1BasedExcludingZeros();
+ // qst.checkQuickSelect1BasedExcludingZeros2();
+ // qst.checkQuickSelect1BasedIncludingZeros();
+ // qst.checkQuickSelectDbl0Based();
+ // qst.checkQuickSelectDbl1BasedExcludingZeros();
+ // qst.checkQuickSelectDbl1BasedExcludingZeros2();
+ // qst.checkQuickSelectDbl1BasedIncludingZeros();
+ //
+ // }
@Test
public void printlnTest() {
- println("PRINTING: "+this.getClass().getName());
+ println("PRINTING: " + this.getClass().getName());
}
/**
* @param s value to print
*/
- static void println(String s) {
+ static void println(final String s) {
//System.out.println(s); //disable here
}
/**
* @param d value to print
*/
- static void println(double d) {
+ static void println(final double d) {
//System.out.println(d); //disable here
}
diff --git a/src/test/java/org/apache/datasketches/SketchesExceptionTest.java b/src/test/java/org/apache/datasketches/SketchesExceptionTest.java
index ca852c9..acd95af 100644
--- a/src/test/java/org/apache/datasketches/SketchesExceptionTest.java
+++ b/src/test/java/org/apache/datasketches/SketchesExceptionTest.java
@@ -43,10 +43,10 @@ public class SketchesExceptionTest {
public void checkSketchesExceptionWithThrowable() {
try {
throw new SketchesException("First Exception.");
- } catch (SketchesException se) {
+ } catch (final SketchesException se) {
try {
throw new SketchesException("Second Exception. ", se);
- } catch (SketchesException se2) {
+ } catch (final SketchesException se2) {
//success
}
}
diff --git a/src/test/java/org/apache/datasketches/UtilTest.java b/src/test/java/org/apache/datasketches/UtilTest.java
index 4072f84..c4fea7c 100644
--- a/src/test/java/org/apache/datasketches/UtilTest.java
+++ b/src/test/java/org/apache/datasketches/UtilTest.java
@@ -85,7 +85,7 @@ public class UtilTest {
checkIfPowerOf2(7, "Test 7");
Assert.fail("Expected SketchesArgumentException");
}
- catch (SketchesArgumentException e) {
+ catch (final SketchesArgumentException e) {
//pass
}
}
@@ -159,10 +159,10 @@ public class UtilTest {
@Test
public void checkIsLessThanUnsigned() {
- long n1 = 1;
- long n2 = 3;
- long n3 = -3;
- long n4 = -1;
+ final long n1 = 1;
+ final long n2 = 3;
+ final long n3 = -3;
+ final long n4 = -1;
Assert.assertTrue(isLessThanUnsigned(n1, n2));
Assert.assertTrue(isLessThanUnsigned(n2, n3));
Assert.assertTrue(isLessThanUnsigned(n3, n4));
@@ -173,16 +173,16 @@ public class UtilTest {
@Test
public void checkZeroPad() {
- long v = 123456789;
- String vHex = Long.toHexString(v);
- String out = zeroPad(vHex, 16);
+ final long v = 123456789;
+ final String vHex = Long.toHexString(v);
+ final String out = zeroPad(vHex, 16);
println("Pad 16, prepend 0: " + out);
}
@Test
public void checkCharacterPad() {
- String s = "Pad 30, postpend z:";
- String out = characterPad(s, 30, 'z', true);
+ final String s = "Pad 30, postpend z:";
+ final String out = characterPad(s, 30, 'z', true);
println(out);
}
@@ -203,10 +203,10 @@ public class UtilTest {
@Test
public void checkEvenlyLgSpaced() {
- int lgStart = 0;
- int lgEnd = 4;
- int ppo = 1;
- int points = (ppo * (lgEnd - lgStart)) +1;
+ final int lgStart = 0;
+ final int lgEnd = 4;
+ final int ppo = 1;
+ final int points = (ppo * (lgEnd - lgStart)) + 1;
int[] pts = evenlyLgSpaced(lgStart, lgEnd, points);
Assert.assertEquals(pts[0], 1);
Assert.assertEquals(pts[1], 2);
@@ -229,32 +229,32 @@ public class UtilTest {
@Test
public void checkBytesToInt() {
- byte[] arr = new byte[] {4, 3, 2, 1};
- int result = 4 + (3 << 8) + (2 << 16) + (1 << 24);
+ final byte[] arr = new byte[] {4, 3, 2, 1};
+ final int result = 4 + (3 << 8) + (2 << 16) + (1 << 24);
Assert.assertEquals(bytesToInt(arr), result);
- byte[] arr2 = intToBytes(result, new byte[4]);
+ final byte[] arr2 = intToBytes(result, new byte[4]);
Assert.assertEquals(arr, arr2);
}
@Test
public void checkBytesToLong() {
- byte[] arr = new byte[] {8, 7, 6, 5, 4, 3, 2, 1};
- long result = 8L + (7L << 8) + (6L << 16) + (5L << 24)
+ final byte[] arr = new byte[] {8, 7, 6, 5, 4, 3, 2, 1};
+ final long result = 8L + (7L << 8) + (6L << 16) + (5L << 24)
+ (4L << 32) + (3L << 40) + (2L << 48) + (1L << 56);
Assert.assertEquals(bytesToLong(arr), result);
}
@Test
public void checkBytesToString() {
- long lng = 0XF8F7F6F504030201L;
+ final long lng = 0XF8F7F6F504030201L;
//println(Long.toHexString(lng));
byte[] bytes = new byte[8];
bytes = Util.longToBytes(lng, bytes);
- String sep = ".";
- String unsignLE = bytesToString(bytes, false, true, sep);
- String signedLE = bytesToString(bytes, true, true, sep);
- String unsignBE = bytesToString(bytes, false, false, sep);
- String signedBE = bytesToString(bytes, true, false, sep);
+ final String sep = ".";
+ final String unsignLE = bytesToString(bytes, false, true, sep);
+ final String signedLE = bytesToString(bytes, true, true, sep);
+ final String unsignBE = bytesToString(bytes, false, false, sep);
+ final String signedBE = bytesToString(bytes, true, false, sep);
Assert.assertEquals(unsignLE, "1.2.3.4.245.246.247.248");
Assert.assertEquals(signedLE, "1.2.3.4.-11.-10.-9.-8");
Assert.assertEquals(unsignBE, "248.247.246.245.4.3.2.1");
@@ -263,17 +263,17 @@ public class UtilTest {
@Test
public void checkNsecToString() {
- long nS = 1000000000L + 1000000L + 1000L + 1L;
- String result = nanoSecToString(nS);
- String expected = "1.001_001_001";
+ final long nS = 1000000000L + 1000000L + 1000L + 1L;
+ final String result = nanoSecToString(nS);
+ final String expected = "1.001_001_001";
Assert.assertEquals(result, expected);
}
@Test
public void checkMsecToString() {
- long nS = (60L * 60L * 1000L) + (60L * 1000L) + 1000L + 1L;
- String result = milliSecToString(nS);
- String expected = "1:01:01.001";
+ final long nS = (60L * 60L * 1000L) + (60L * 1000L) + 1000L + 1L;
+ final String result = milliSecToString(nS);
+ final String expected = "1:01:01.001";
Assert.assertEquals(result, expected);
}
@@ -302,9 +302,9 @@ public class UtilTest {
@Test
public void checkPwr2LawExamples() {
- int maxP = 32;
- int minP = 1;
- int ppo = 4;
+ final int maxP = 32;
+ final int minP = 1;
+ final int ppo = 4;
for (int p = minP; p <= maxP; p = pwr2LawNext(ppo, p)) {
print(p + " ");
@@ -324,7 +324,7 @@ public class UtilTest {
try {
simpleIntLog2(0);
fail();
- } catch (SketchesArgumentException e) {}
+ } catch (final SketchesArgumentException e) { }
}
//Resources
@@ -357,7 +357,7 @@ public class UtilTest {
@Test
public void printlnTest() {
- println("PRINTING: "+this.getClass().getName());
+ println("PRINTING: " + this.getClass().getName());
}
static void println(final Object o) {
diff --git a/src/test/java/org/apache/datasketches/cpc/BitMatrix.java b/src/test/java/org/apache/datasketches/cpc/BitMatrix.java
index eca0685..9b5c50b 100644
--- a/src/test/java/org/apache/datasketches/cpc/BitMatrix.java
+++ b/src/test/java/org/apache/datasketches/cpc/BitMatrix.java
@@ -36,11 +36,11 @@ class BitMatrix {
private long[] bitMatrix;
private boolean numCouponsInvalid; //only used if we allowed merges
- BitMatrix(int lgK) {
+ BitMatrix(final int lgK) {
this(lgK, DEFAULT_UPDATE_SEED);
}
- BitMatrix(int lgK, long seed) {
+ BitMatrix(final int lgK, final long seed) {
this.lgK = lgK;
this.seed = seed;
bitMatrix = new long[1 << lgK];
@@ -82,7 +82,7 @@ class BitMatrix {
if (col > 63) { col = 63; } // clip so that 0 <= col <= 63
final long kMask = (1L << lgK) - 1L;
int row = (int) (hash0 & kMask);
- int rowCol = (row << 6) | col;
+ final int rowCol = (row << 6) | col;
// Avoid the hash table's "empty" value which is (2^26 -1, 63) (all ones) by changing it
// to the pair (2^26 - 2, 63), which effectively merges the two cells.
@@ -90,8 +90,8 @@ class BitMatrix {
// It can't happen at all if lgK (or maxLgK) < 26.
if (rowCol == -1) { row ^= 1; } //set the LSB of row to 0
- long oldPattern = bitMatrix[row];
- long newPattern = oldPattern | (1L << col);
+ final long oldPattern = bitMatrix[row];
+ final long newPattern = oldPattern | (1L << col);
if (newPattern != oldPattern) {
numCoupons++;
bitMatrix[row] = newPattern;
diff --git a/src/test/java/org/apache/datasketches/cpc/CompressedStateTest.java b/src/test/java/org/apache/datasketches/cpc/CompressedStateTest.java
index 6b4cb2b..a2fd4d5 100644
--- a/src/test/java/org/apache/datasketches/cpc/CompressedStateTest.java
+++ b/src/test/java/org/apache/datasketches/cpc/CompressedStateTest.java
@@ -24,10 +24,9 @@ import static org.testng.Assert.fail;
import java.io.PrintStream;
-import org.testng.annotations.Test;
-
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
+import org.testng.annotations.Test;
/**
* @author Lee Rhodes
@@ -40,7 +39,7 @@ public class CompressedStateTest {
@SuppressWarnings("unused")
- private void updateStateUnion(CpcSketch sk) {
+ private void updateStateUnion(final CpcSketch sk) {
Format skFmt = sk.getFormat();
CompressedState state = CompressedState.compress(sk);
Flavor f = state.getFlavor();
@@ -52,9 +51,9 @@ public class CompressedStateTest {
printf("%8d %8d %10s %35s\n", vIn, c, f.toString(), fmt.toString());
CompressedState state2 = CompressedState.importFromMemory(wmem);
- CpcUnion union = new CpcUnion(lgK);
+ final CpcUnion union = new CpcUnion(lgK);
union.update(sk);
- CpcSketch sk2 = union.getResult();
+ final CpcSketch sk2 = union.getResult();
skFmt = sk2.getFormat();
state = CompressedState.compress(sk2);
f = state.getFlavor();
@@ -70,8 +69,8 @@ public class CompressedStateTest {
@Test
public void checkLoadMemory() {
printf("%8s %8s %10s %35s\n", "vIn", "c", "Flavor", "Format");
- CpcSketch sk = new CpcSketch(lgK);
- int k = 1 << lgK;
+ final CpcSketch sk = new CpcSketch(lgK);
+ final int k = 1 << lgK;
//EMPTY_MERGED
updateStateUnion(sk);
@@ -96,7 +95,7 @@ public class CompressedStateTest {
@Test
public void checkToString() {
- CpcSketch sketch = new CpcSketch(10);
+ final CpcSketch sketch = new CpcSketch(10);
CompressedState state = CompressedState.compress(sketch);
println(state.toString());
sketch.update(0);
@@ -109,27 +108,27 @@ public class CompressedStateTest {
@Test
public void checkIsCompressed() {
- CpcSketch sk = new CpcSketch(10);
- byte[] byteArr = sk.toByteArray();
+ final CpcSketch sk = new CpcSketch(10);
+ final byte[] byteArr = sk.toByteArray();
byteArr[5] &= (byte) -3;
try {
CompressedState.importFromMemory(Memory.wrap(byteArr));
fail();
- } catch (AssertionError e) {}
+ } catch (final AssertionError e) { }
}
/**
* @param format the string to print
* @param args the arguments
*/
- private static void printf(String format, Object... args) {
+ private static void printf(final String format, final Object... args) {
//ps.printf(format, args);
}
/**
* @param s the string to print
*/
- private static void println(String s) {
+ private static void println(final String s) {
//ps.println(s); //disable here
}
diff --git a/src/test/java/org/apache/datasketches/cpc/CompressionCharacterization.java b/src/test/java/org/apache/datasketches/cpc/CompressionCharacterization.java
index 967a1c0..10c8f63 100644
--- a/src/test/java/org/apache/datasketches/cpc/CompressionCharacterization.java
+++ b/src/test/java/org/apache/datasketches/cpc/CompressionCharacterization.java
@@ -63,8 +63,16 @@ public class CompressionCharacterization {
private CpcSketch[] unCompressedSketches;
- public CompressionCharacterization(int lgMinK, int lgMaxK, int lgMinT, int lgMaxT, int lgMulK,
- int uPPO, int incLgK, PrintStream pS, PrintWriter pW) {
+ public CompressionCharacterization(
+ final int lgMinK,
+ final int lgMaxK,
+ final int lgMinT,
+ final int lgMaxT,
+ final int lgMulK,
+ final int uPPO,
+ final int incLgK,
+ final PrintStream pS,
+ final PrintWriter pW) {
this.lgMinK = lgMinK;
this.lgMaxK = lgMaxK;
this.lgMinT = lgMinT;
@@ -88,27 +96,27 @@ public class CompressionCharacterization {
}
}
- private void doRangeOfNAtLgK(int lgK) {
+ private void doRangeOfNAtLgK(final int lgK) {
long n = 1;
- int lgMaxN = lgK + lgMulK;
- long maxN = 1L << lgMaxN;
- double slope = -(double)(lgMaxT - lgMinT) / lgMaxN;
+ final int lgMaxN = lgK + lgMulK;
+ final long maxN = 1L << lgMaxN;
+ final double slope = -(double)(lgMaxT - lgMinT) / lgMaxN;
while (n <= maxN) {
- double lgT = (slope * log2(n)) + lgMaxT;
- int totTrials = Math.max(ceilingPowerOf2((int) Math.pow(2.0, lgT)), (1 << lgMinT));
+ final double lgT = (slope * log2(n)) + lgMaxT;
+ final int totTrials = Math.max(ceilingPowerOf2((int) Math.pow(2.0, lgT)), (1 << lgMinT));
doTrialsAtLgKAtN(lgK, n, totTrials);
n = Math.round(pwrLawNextDouble(uPPO, n, true, 2.0));
}
}
- private void doTrialsAtLgKAtN(int lgK, long n, int totalTrials) {
- int k = 1 << lgK;
- int minNK = (int) ((k < n) ? k : n);
- double nOverK = (double) n / k;
- int lgTotTrials = Integer.numberOfTrailingZeros(totalTrials);
- int lgWaves = Math.max(lgTotTrials - 10, 0);
- int trialsPerWave = 1 << (lgTotTrials - lgWaves);
+ private void doTrialsAtLgKAtN(final int lgK, final long n, final int totalTrials) {
+ final int k = 1 << lgK;
+ final int minNK = (int) ((k < n) ? k : n);
+ final double nOverK = (double) n / k;
+ final int lgTotTrials = Integer.numberOfTrailingZeros(totalTrials);
+ final int lgWaves = Math.max(lgTotTrials - 10, 0);
+ final int trialsPerWave = 1 << (lgTotTrials - lgWaves);
//printf("%d %d %d %d\n", totalTrials, lgTotTrials, 1 << lgWaves, trialsPerWave);
streamSketches = new CpcSketch[trialsPerWave];
compressedStates1 = new CompressedState[trialsPerWave];
@@ -128,14 +136,14 @@ public class CompressionCharacterization {
long sumUnc_nS = 0;
long sumEqu_nS = 0;
long nanoStart, nanoEnd;
- long start = System.currentTimeMillis();
+ final long start = System.currentTimeMillis();
//Wave Loop
for (int w = 0; w < (1 << lgWaves); w++) {
//Construct array with sketches loop
nanoStart = System.nanoTime();
for (int trial = 0; trial < trialsPerWave; trial++) {
- CpcSketch sketch = new CpcSketch(lgK);
+ final CpcSketch sketch = new CpcSketch(lgK);
streamSketches[trial] = sketch;
}
nanoEnd = System.nanoTime();
@@ -144,7 +152,7 @@ public class CompressionCharacterization {
//Sketch Update loop
for (int trial = 0; trial < trialsPerWave; trial++) {
- CpcSketch sketch = streamSketches[trial];
+ final CpcSketch sketch = streamSketches[trial];
for (long i = 0; i < n; i++) { //increment loop
sketch.update(vIn += iGoldenU64);
}
@@ -155,8 +163,8 @@ public class CompressionCharacterization {
//Compress loop
for (int trial = 0; trial < trialsPerWave; trial++) {
- CpcSketch sketch = streamSketches[trial];
- CompressedState state = CompressedState.compress(sketch);
+ final CpcSketch sketch = streamSketches[trial];
+ final CompressedState state = CompressedState.compress(sketch);
compressedStates1[trial] = state;
totalC += sketch.numCoupons;
totalW += state.csvLengthInts + state.cwLengthInts;
@@ -167,9 +175,9 @@ public class CompressionCharacterization {
//State to Memory loop
for (int trial = 0; trial < trialsPerWave; trial++) {
- CompressedState state = compressedStates1[trial];
- long cap = state.getRequiredSerializedBytes();
- WritableMemory wmem = WritableMemory.allocate((int) cap);
+ final CompressedState state = compressedStates1[trial];
+ final long cap = state.getRequiredSerializedBytes();
+ final WritableMemory wmem = WritableMemory.allocate((int) cap);
state.exportToMemory(wmem);
memoryArr[trial] = wmem;
}
@@ -180,8 +188,8 @@ public class CompressionCharacterization {
//Memory to State loop
for (int trial = 0; trial < trialsPerWave; trial++) {
- Memory mem = memoryArr[trial];
- CompressedState state = importFromMemory(mem);
+ final Memory mem = memoryArr[trial];
+ final CompressedState state = importFromMemory(mem);
compressedStates2[trial] = state;
}
@@ -191,7 +199,7 @@ public class CompressionCharacterization {
//Uncompress loop
for (int trial = 0; trial < trialsPerWave; trial++) {
- CompressedState state = compressedStates2[trial];
+ final CompressedState state = compressedStates2[trial];
CpcSketch uncSk = null;
uncSk = CpcSketch.uncompress(state, DEFAULT_UPDATE_SEED);
unCompressedSketches[trial] = uncSk;
@@ -212,11 +220,11 @@ public class CompressionCharacterization {
} // end wave loop
- double total_S = (System.currentTimeMillis() - start) / 1E3;
- double avgC = (1.0 * totalC) / totalTrials;
- double avgCoK = avgC / k;
- double avgWords = (1.0 * totalW) / totalTrials;
- double avgBytes = (4.0 * totalW) / totalTrials;
+ final double total_S = (System.currentTimeMillis() - start) / 1E3;
+ final double avgC = (1.0 * totalC) / totalTrials;
+ final double avgCoK = avgC / k;
+ final double avgWords = (1.0 * totalW) / totalTrials;
+ final double avgBytes = (4.0 * totalW) / totalTrials;
final double avgCtor_nS = Math.round((double) sumCtor_nS / totalTrials);
@@ -242,10 +250,10 @@ public class CompressionCharacterization {
final double avgEqu_nSperMinNK = avgEqu_nS / minNK;
- int len = unCompressedSketches.length;
- Flavor finFlavor = unCompressedSketches[len - 1].getFlavor();
- String offStr = Integer.toString(unCompressedSketches[len - 1].windowOffset);
- String flavorOff = finFlavor.toString() + String.format("%2s", offStr);
+ final int len = unCompressedSketches.length;
+ final Flavor finFlavor = unCompressedSketches[len - 1].getFlavor();
+ final String offStr = Integer.toString(unCompressedSketches[len - 1].windowOffset);
+ final String flavorOff = finFlavor.toString() + String.format("%2s", offStr);
printf(dfmt,
lgK,
totalTrials,
@@ -273,13 +281,13 @@ public class CompressionCharacterization {
total_S);
}
- private void printf(String format, Object ... args) {
+ private void printf(final String format, final Object ... args) {
if (ps != null) { ps.printf(format, args); }
if (pw != null) { pw.printf(format, args); }
}
private void assembleFormats() {
- String[][] assy = {
+ final String[][] assy = {
{"lgK", "%3s", "%3d"},
{"Trials", "%9s", "%9d"},
{"n", "%12s", "%12d"},
@@ -305,13 +313,13 @@ public class CompressionCharacterization {
{"AvgEqu_nSperMinNK", "%18s", "%18.4g"},
{"Total_S", "%8s", "%8.3f"}
};
- int cols = assy.length;
+ final int cols = assy.length;
hStrArr = new String[cols];
- StringBuilder headerFmt = new StringBuilder();
- StringBuilder dataFmt = new StringBuilder();
+ final StringBuilder headerFmt = new StringBuilder();
+ final StringBuilder dataFmt = new StringBuilder();
headerFmt.append("\nCompression Characterization\n");
for (int i = 0; i < cols; i++) {
- hStrArr[i] =assy[i][0];
+ hStrArr[i] = assy[i][0];
headerFmt.append(assy[i][1]);
headerFmt.append((i < (cols - 1)) ? "\t" : "\n");
dataFmt.append(assy[i][2]);
diff --git a/tools/SketchesCheckstyle.xml b/tools/SketchesCheckstyle.xml
index b7659fd..bd5e06b 100644
--- a/tools/SketchesCheckstyle.xml
+++ b/tools/SketchesCheckstyle.xml
@@ -36,7 +36,7 @@ under the License.
<module name = "Checker">
<property name="charset" value="UTF-8"/>
<property name="severity" value="warning"/>
- <property name="fileExtensions" value="java, properties, xml"/>
+ <property name="fileExtensions" value="java"/>
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
@@ -56,6 +56,14 @@ under the License.
<!-- <metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/> -->
</module>
+ <module name="SuppressWithPlainTextCommentFilter">
+ <property name="offCommentFormat" value="//CHECKSTYLE.OFF\: ([\w\|]+)"/>
+ <property name="onCommentFormat" value="//CHECKSTYLE.ON\: ([\w\|]+)"/>
+ <property name="checkFormat" value="$1"/>
+ </module>
+
+ <!-- ******************************************************** -->
+
<module name="TreeWalker">
<!-- Annotations -->
@@ -176,8 +184,8 @@ under the License.
<!-- Enable suppression using comments: //CHECKSTYLE.OFF: "RULE" and //CHECKSTYLE.ON: "RULE"
You must specify the specific rule, as in: //CHECKSTYLE.OFF: LineLength -->
<module name="SuppressionCommentFilter">
- <property name="offCommentFormat" value="CHECKSTYLE.OFF\: ([\w\|]+)"/>
- <property name="onCommentFormat" value="CHECKSTYLE.ON\: ([\w\|]+)"/>
+ <property name="offCommentFormat" value="//CHECKSTYLE.OFF\: ([\w\|]+)"/>
+ <property name="onCommentFormat" value="//CHECKSTYLE.ON\: ([\w\|]+)"/>
<property name="checkFormat" value="$1"/>
</module>
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org