From 159e61bbe5ba51cb0f365b338a49f90ad067dc57 Mon Sep 17 00:00:00 2001 From: Lee Rhodes Date: Thu, 31 Aug 2023 10:44:41 -0700 Subject: [PATCH 1/3] This fixes the remaining spotBugs issues. And adds the missing ItemsSketch to the CrossCheckQuantilesTest. --- README.md | 6 ++ .../org/apache/datasketches/common/Util.java | 2 +- .../datasketches/kll/KllItemsSketch.java | 2 +- .../kll/KllItemsSketchSortedView.java | 5 +- .../quantiles/ItemsSketchSortedView.java | 7 ++- .../apache/datasketches/common/TestUtil.java | 8 +-- .../kll/KllCrossLanguageTest.java | 2 +- .../kll/KllItemsSketchSortedViewString.java | 37 +++++++++++ .../datasketches/kll/KllItemsSketchTest.java | 2 +- .../ItemsSketchSortedViewString.java | 36 +++++++++++ .../QuantilesSketchCrossLanguageTest.java | 4 +- .../CrossCheckQuantilesTest.java | 61 ++++++++++++------- tools/FindBugsExcludeFilter.xml | 20 ++++++ 13 files changed, 155 insertions(+), 37 deletions(-) create mode 100644 src/test/java/org/apache/datasketches/kll/KllItemsSketchSortedViewString.java create mode 100644 src/test/java/org/apache/datasketches/quantiles/ItemsSketchSortedViewString.java diff --git a/README.md b/README.md index 7616288be..8da5faac3 100644 --- a/README.md +++ b/README.md @@ -150,3 +150,9 @@ In Eclipse, open the project *Properties / Java Build Path / Module Dependencies **NOTE:** If you execute *Maven/Update Project...* from Eclipse with the option *Update project configuration from pom.xml* checked, all of the above will be erased, and you will have to redo it. +## Known Issues + +#### SpotBugs + +* Make sure you configure SpotBugs with the /tools/FindBugsExcludeFilter.xml file. Otherwise, you will get a lot of false positive or low risk issues that we have examined and exliminated with this exclusion file. + diff --git a/src/main/java/org/apache/datasketches/common/Util.java b/src/main/java/org/apache/datasketches/common/Util.java index 758ee7caa..18e051261 100644 --- a/src/main/java/org/apache/datasketches/common/Util.java +++ b/src/main/java/org/apache/datasketches/common/Util.java @@ -767,7 +767,7 @@ public static int numDigits(int n) { * @return the given number to a string prepended with spaces */ public static String intToFixedLengthString(final int number, final int length) { - final String num = Integer.valueOf(number).toString(); + final String num = Integer.toString(number); return characterPad(num, length, ' ', false); } diff --git a/src/main/java/org/apache/datasketches/kll/KllItemsSketch.java b/src/main/java/org/apache/datasketches/kll/KllItemsSketch.java index 79fc0e3d2..3497fcd1f 100644 --- a/src/main/java/org/apache/datasketches/kll/KllItemsSketch.java +++ b/src/main/java/org/apache/datasketches/kll/KllItemsSketch.java @@ -240,7 +240,7 @@ public double[] getRanks(final T[] quantiles, final QuantileSearchCriteria searc } @Override - public KllItemsSketchSortedView getSortedView() { + public final KllItemsSketchSortedView getSortedView() { if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); } refreshSortedView(); return kllItemsSV; diff --git a/src/main/java/org/apache/datasketches/kll/KllItemsSketchSortedView.java b/src/main/java/org/apache/datasketches/kll/KllItemsSketchSortedView.java index 4f5b53304..1b04a4d3e 100644 --- a/src/main/java/org/apache/datasketches/kll/KllItemsSketchSortedView.java +++ b/src/main/java/org/apache/datasketches/kll/KllItemsSketchSortedView.java @@ -58,9 +58,8 @@ public class KllItemsSketchSortedView implements GenericSortedView { * @param totalN the total number of items presented to the sketch. * @param minItem used to extract the type of T * @param comparator the Comparator for type T - * */ - public KllItemsSketchSortedView( + KllItemsSketchSortedView( final T[] quantiles, final long[] cumWeights, final long totalN, @@ -77,7 +76,7 @@ public KllItemsSketchSortedView( * Constructs this Sorted View given the sketch * @param sk the given KllItemsSketch. */ - public KllItemsSketchSortedView(final KllItemsSketch sk) { + KllItemsSketchSortedView(final KllItemsSketch sk) { this.totalN = sk.getN(); this.minItem = sk.getMinItem(); final Object[] srcQuantiles = sk.getTotalItemsArray(); diff --git a/src/main/java/org/apache/datasketches/quantiles/ItemsSketchSortedView.java b/src/main/java/org/apache/datasketches/quantiles/ItemsSketchSortedView.java index 70fdd312b..4d6d30317 100644 --- a/src/main/java/org/apache/datasketches/quantiles/ItemsSketchSortedView.java +++ b/src/main/java/org/apache/datasketches/quantiles/ItemsSketchSortedView.java @@ -41,7 +41,7 @@ * @author Kevin Lang * @author Alexander Saydakov */ -public final class ItemsSketchSortedView implements GenericSortedView { +public class ItemsSketchSortedView implements GenericSortedView { private final T[] quantiles; private final long[] cumWeights; //comes in as individual weights, converted to cumulative natural weights private final long totalN; @@ -54,7 +54,10 @@ public final class ItemsSketchSortedView implements GenericSortedView { * @param totalN the total number of items presented to the sketch. * @param comparator comparator for type T */ - ItemsSketchSortedView(final T[] quantiles, final long[] cumWeights, final long totalN, + ItemsSketchSortedView( + final T[] quantiles, + final long[] cumWeights, + final long totalN, final Comparator comparator) { this.quantiles = quantiles; this.cumWeights = cumWeights; diff --git a/src/test/java/org/apache/datasketches/common/TestUtil.java b/src/test/java/org/apache/datasketches/common/TestUtil.java index f1beb85c1..5a5fdacb2 100644 --- a/src/test/java/org/apache/datasketches/common/TestUtil.java +++ b/src/test/java/org/apache/datasketches/common/TestUtil.java @@ -29,7 +29,7 @@ */ public final class TestUtil { - private static String userDir = System.getProperty("user.dir"); + private static final String userDir = System.getProperty("user.dir"); /** * TestNG group constants @@ -41,17 +41,17 @@ public final class TestUtil { /** * The full target Path for Java serialized sketches to be tested by other languages. */ - public static Path javaPath = createPath("target/java_generated_files"); + public static final Path javaPath = createPath("target/java_generated_files"); /** * The full target Path for C++ serialized sketches to be tested by Java. */ - public static Path cppPath = createPath("target/cpp_generated_files"); + public static final Path cppPath = createPath("target/cpp_generated_files"); /** * The full target Path for historical C++ serialized sketches to be tested by Java. */ - public static Path cppHistPath = createPath("src/test/resources"); + public static final Path cppHistPath = createPath("src/test/resources"); private static Path createPath(final String projectLocalDir) { try { diff --git a/src/test/java/org/apache/datasketches/kll/KllCrossLanguageTest.java b/src/test/java/org/apache/datasketches/kll/KllCrossLanguageTest.java index 9e116cf2d..ff50bd3f6 100644 --- a/src/test/java/org/apache/datasketches/kll/KllCrossLanguageTest.java +++ b/src/test/java/org/apache/datasketches/kll/KllCrossLanguageTest.java @@ -161,7 +161,7 @@ public int compare(final String s1, final String s2) { try { final int i1 = Integer.parseInt(s1); final int i2 = Integer.parseInt(s2); - return Integer.valueOf(i1).compareTo(i2); + return Integer.compare(i1, i2); } catch (NumberFormatException e) { throw new RuntimeException(e); } diff --git a/src/test/java/org/apache/datasketches/kll/KllItemsSketchSortedViewString.java b/src/test/java/org/apache/datasketches/kll/KllItemsSketchSortedViewString.java new file mode 100644 index 000000000..5eb513aa8 --- /dev/null +++ b/src/test/java/org/apache/datasketches/kll/KllItemsSketchSortedViewString.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.datasketches.kll; + +import java.util.Comparator; + +/** + * For testing only + */ +public class KllItemsSketchSortedViewString extends KllItemsSketchSortedView { + + public KllItemsSketchSortedViewString( + final String[] quantiles, + final long[] cumWeights, + final long totalN, + final String minItem, + final Comparator comparator) { + super(quantiles, cumWeights, totalN, minItem, comparator); + } +} diff --git a/src/test/java/org/apache/datasketches/kll/KllItemsSketchTest.java b/src/test/java/org/apache/datasketches/kll/KllItemsSketchTest.java index 0913f46d2..fddd5fbee 100644 --- a/src/test/java/org/apache/datasketches/kll/KllItemsSketchTest.java +++ b/src/test/java/org/apache/datasketches/kll/KllItemsSketchTest.java @@ -50,7 +50,7 @@ public class KllItemsSketchTest { private static final double PMF_EPS_FOR_K_128 = 0.025; // PMF rank error (epsilon) for k=128 private static final double PMF_EPS_FOR_K_256 = 0.013; // PMF rank error (epsilon) for k=256 private static final double NUMERIC_NOISE_TOLERANCE = 1E-6; - public ArrayOfStringsSerDe serDe = new ArrayOfStringsSerDe(); + private ArrayOfStringsSerDe serDe = new ArrayOfStringsSerDe(); @Test public void empty() { diff --git a/src/test/java/org/apache/datasketches/quantiles/ItemsSketchSortedViewString.java b/src/test/java/org/apache/datasketches/quantiles/ItemsSketchSortedViewString.java new file mode 100644 index 000000000..6a4934f97 --- /dev/null +++ b/src/test/java/org/apache/datasketches/quantiles/ItemsSketchSortedViewString.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.datasketches.quantiles; + +import java.util.Comparator; + +/** + * For testing only + */ +public class ItemsSketchSortedViewString extends ItemsSketchSortedView { + + public ItemsSketchSortedViewString( + final String[] quantiles, + final long[] cumWeights, + final long totalN, + final Comparator comparator) { + super(quantiles, cumWeights, totalN, comparator); + } +} diff --git a/src/test/java/org/apache/datasketches/quantiles/QuantilesSketchCrossLanguageTest.java b/src/test/java/org/apache/datasketches/quantiles/QuantilesSketchCrossLanguageTest.java index 4a6451a4c..c2c1238f9 100644 --- a/src/test/java/org/apache/datasketches/quantiles/QuantilesSketchCrossLanguageTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/QuantilesSketchCrossLanguageTest.java @@ -68,7 +68,7 @@ public int compare(final String s1, final String s2) { try { final int i1 = Integer.parseInt(s1); final int i2 = Integer.parseInt(s2); - return Integer.valueOf(i1).compareTo(i2); + return Integer.compare(i1,i2); } catch (NumberFormatException e) { throw new RuntimeException(e); } @@ -117,7 +117,7 @@ public int compare(final String s1, final String s2) { try { final int i1 = Integer.parseInt(s1); final int i2 = Integer.parseInt(s2); - return Integer.valueOf(i1).compareTo(i2); + return Integer.compare(i1, i2); } catch (NumberFormatException e) { throw new RuntimeException(e); } diff --git a/src/test/java/org/apache/datasketches/quantilescommon/CrossCheckQuantilesTest.java b/src/test/java/org/apache/datasketches/quantilescommon/CrossCheckQuantilesTest.java index e1bb5416d..eb9a0a59f 100644 --- a/src/test/java/org/apache/datasketches/quantilescommon/CrossCheckQuantilesTest.java +++ b/src/test/java/org/apache/datasketches/quantilescommon/CrossCheckQuantilesTest.java @@ -19,14 +19,20 @@ package org.apache.datasketches.quantilescommon; -import static org.apache.datasketches.common.Util.*; +import static org.apache.datasketches.common.Util.intToFixedLengthString; +import static org.apache.datasketches.common.Util.LS; +import static org.apache.datasketches.quantilescommon.LinearRanksAndQuantiles.getTrueDoubleQuantile; +import static org.apache.datasketches.quantilescommon.LinearRanksAndQuantiles.getTrueDoubleRank; +import static org.apache.datasketches.quantilescommon.LinearRanksAndQuantiles.getTrueFloatQuantile; +import static org.apache.datasketches.quantilescommon.LinearRanksAndQuantiles.getTrueFloatRank; +import static org.apache.datasketches.quantilescommon.LinearRanksAndQuantiles.getTrueItemQuantile; +import static org.apache.datasketches.quantilescommon.LinearRanksAndQuantiles.getTrueItemRank; +import static org.apache.datasketches.quantilescommon.QuantileSearchCriteria.EXCLUSIVE; +import static org.apache.datasketches.quantilescommon.QuantileSearchCriteria.INCLUSIVE; import static org.apache.datasketches.quantilescommon.ReflectUtilityTest.CLASSIC_DOUBLES_SV_CTOR; import static org.apache.datasketches.quantilescommon.ReflectUtilityTest.KLL_DOUBLES_SV_CTOR; import static org.apache.datasketches.quantilescommon.ReflectUtilityTest.KLL_FLOATS_SV_CTOR; import static org.apache.datasketches.quantilescommon.ReflectUtilityTest.REQ_SV_CTOR; -import static org.apache.datasketches.quantilescommon.LinearRanksAndQuantiles.*; -import static org.apache.datasketches.quantilescommon.QuantileSearchCriteria.EXCLUSIVE; -import static org.apache.datasketches.quantilescommon.QuantileSearchCriteria.INCLUSIVE; import static org.testng.Assert.assertEquals; import java.util.Comparator; @@ -38,10 +44,12 @@ import org.apache.datasketches.kll.KllFloatsSketch; import org.apache.datasketches.kll.KllFloatsSketchSortedView; import org.apache.datasketches.kll.KllItemsSketch; -import org.apache.datasketches.kll.KllItemsSketchSortedView; +import org.apache.datasketches.kll.KllItemsSketchSortedViewString; import org.apache.datasketches.quantiles.DoublesSketch; -import org.apache.datasketches.quantiles.UpdateDoublesSketch; import org.apache.datasketches.quantiles.DoublesSketchSortedView; +import org.apache.datasketches.quantiles.ItemsSketch; +import org.apache.datasketches.quantiles.ItemsSketchSortedViewString; +import org.apache.datasketches.quantiles.UpdateDoublesSketch; import org.apache.datasketches.req.ReqSketch; import org.apache.datasketches.req.ReqSketchSortedView; import org.testng.annotations.Test; @@ -128,12 +136,14 @@ public class CrossCheckQuantilesTest { KllDoublesSketch kllDoublesSk = null; UpdateDoublesSketch classicDoublesSk = null; KllItemsSketch kllItemsSk = null; + ItemsSketch itemsSk = null; ReqSketchSortedView reqFloatsSV = null; KllFloatsSketchSortedView kllFloatsSV = null; KllDoublesSketchSortedView kllDoublesSV = null; DoublesSketchSortedView classicDoublesSV = null; - KllItemsSketchSortedView kllItemsSV = null; + KllItemsSketchSortedViewString kllItemsSV = null; + ItemsSketchSortedViewString itemsSV = null; public CrossCheckQuantilesTest() {} @@ -157,8 +167,9 @@ public void runTests() throws Exception { private void checkGetRank(int set, QuantileSearchCriteria crit) { double trueRank; double testRank; + + println(LS + "FLOATS getRank Test SV vs Sk"); float maxFloatvalue = getMaxFloatValue(set); - println(""); for (float v = 5f; v <= maxFloatvalue + 5f; v += 5f) { trueRank = getTrueFloatRank(svCumWeights[set], svFValues[set],v, crit); testRank = reqFloatsSV.getRank(v, crit); @@ -173,7 +184,7 @@ private void checkGetRank(int set, QuantileSearchCriteria crit) { println("Floats set: " + set + ", value: " + v + ", rank: " + trueRank + ", crit: " + crit.toString()); } - println(""); + println(LS + "DOUBLES getRank Test SV vs Sk"); double maxDoubleValue = getMaxDoubleValue(set); for (double v = 5; v <= maxDoubleValue + 5; v += 5) { trueRank = getTrueDoubleRank(svCumWeights[set], svDValues[set],v, crit); @@ -191,7 +202,7 @@ private void checkGetRank(int set, QuantileSearchCriteria crit) { println("Doubles set: " + set + ", value: " + v + ", rank: " + trueRank + ", crit: " + crit.toString()); } - println(""); + println(LS + "ITEMS getRank Test SV vs Sk"); int maxItemValue; try { maxItemValue = Integer.parseInt(getMaxItemValue(set)); } catch (NumberFormatException e) { throw new SketchesArgumentException(e.toString()); } @@ -204,9 +215,13 @@ private void checkGetRank(int set, QuantileSearchCriteria crit) { testRank = kllItemsSk.getRank(s, crit); assertEquals(testRank, trueRank); + testRank = itemsSV.getRank(s, crit); + assertEquals(testRank, trueRank); + testRank = itemsSk.getRank(s, crit); + assertEquals(testRank, trueRank); + println("Items set: " + set + ", value: " + s + ", rank: " + trueRank + ", crit: " + crit.toString()); } - } private void checkGetQuantile(int set, QuantileSearchCriteria crit) { @@ -214,13 +229,13 @@ private void checkGetQuantile(int set, QuantileSearchCriteria crit) { double dTwoN = twoN; float trueFQ; float testFQ; - println(""); + + println(LS + "FLOATS getQuantile Test SV vs Sk"); for (int i = 0; i <= twoN; i++) { double normRank = i / dTwoN; trueFQ = getTrueFloatQuantile(svCumWeights[set], svFValues[set], normRank, crit); testFQ = reqFloatsSV.getQuantile(normRank, crit); - assertEquals(testFQ, trueFQ); testFQ = reqFloatsSk.getQuantile(normRank, crit); assertEquals(testFQ, trueFQ); @@ -233,7 +248,7 @@ private void checkGetQuantile(int set, QuantileSearchCriteria crit) { println("Floats set: " + set + ", rank: " + normRank + ", Q: " + trueFQ + ", crit: " + crit.toString()); } - println(""); + println(LS + "DOUBLES getQuantile Test SV vs Sk"); double trueDQ; double testDQ; for (int i = 0; i <= twoN; i++) { @@ -253,7 +268,7 @@ private void checkGetQuantile(int set, QuantileSearchCriteria crit) { println("Doubles set: " + set + ", rank: " + normRank + ", Q: " + trueDQ + ", crit: " + crit.toString()); } - println(""); + println(LS + "ITEMS getQuantile Test SV vs Sk"); String trueIQ; String testIQ; for (int i = 0; i <= twoN; i++) { @@ -265,6 +280,11 @@ private void checkGetQuantile(int set, QuantileSearchCriteria crit) { testIQ = kllItemsSk.getQuantile(normRank, crit); assertEquals(testIQ, trueIQ); + testIQ = itemsSV.getQuantile(normRank, crit); + assertEquals(testIQ, trueIQ); + testIQ = itemsSk.getQuantile(normRank, crit); + assertEquals(testIQ, trueIQ); + println("Items set: " + set + ", rank: " + normRank + ", Q: " + trueIQ + ", crit: " + crit.toString()); } @@ -293,6 +313,7 @@ private void buildSketches(int set) { kllDoublesSk = KllDoublesSketch.newHeapInstance(k); classicDoublesSk = DoublesSketch.builder().setK(k).build(); kllItemsSk = KllItemsSketch.newHeapInstance(k, Comparator.naturalOrder(), serDe); + itemsSk = ItemsSketch.getInstance(String.class, k, Comparator.naturalOrder()); int count = skFStreamValues[set].length; for (int i = 0; i < count; i++) { @@ -301,6 +322,7 @@ private void buildSketches(int set) { kllDoublesSk.update(skDStreamValues[set][i]); classicDoublesSk.update(skDStreamValues[set][i]); kllItemsSk.update(skIStreamValues[set][i]); + itemsSk.update(skIStreamValues[set][i]); } } @@ -311,7 +333,8 @@ private void buildSVs(int set) throws Exception { kllFloatsSV = getRawKllFloatsSV(svFValues[set], svCumWeights[set], totalN[set]); kllDoublesSV = getRawKllDoublesSV(svDValues[set], svCumWeights[set], totalN[set]); classicDoublesSV = getRawClassicDoublesSV(svDValues[set], svCumWeights[set], totalN[set]); - kllItemsSV = getRawKllItemsSV(svIValues[set], svCumWeights[set], totalN[set], minItem, comparator); + kllItemsSV = new KllItemsSketchSortedViewString(svIValues[set], svCumWeights[set], totalN[set], minItem, comparator); + itemsSV = new ItemsSketchSortedViewString(svIValues[set], svCumWeights[set], totalN[set], comparator); } private final ReqSketchSortedView getRawReqSV( @@ -334,12 +357,6 @@ private final DoublesSketchSortedView getRawClassicDoublesSV( return (DoublesSketchSortedView) CLASSIC_DOUBLES_SV_CTOR.newInstance(values, cumWeights, totalN); } - private final KllItemsSketchSortedView getRawKllItemsSV( - final String[] values, final long[] cumWeights, final long totalN, final String minItem, - final Comparator comparator) throws Exception { - return new KllItemsSketchSortedView(values, cumWeights, totalN, minItem, comparator); - } - /********BUILD DATA SETS**********/ private void buildDataSets() { diff --git a/tools/FindBugsExcludeFilter.xml b/tools/FindBugsExcludeFilter.xml index 32e2abc1d..c212a9034 100644 --- a/tools/FindBugsExcludeFilter.xml +++ b/tools/FindBugsExcludeFilter.xml @@ -44,4 +44,24 @@ under the License. + + + + + + + + + + + + + + + + + + + + From 8d2d1b84215cfcacd65b3a2626b0e5e7981c29f8 Mon Sep 17 00:00:00 2001 From: Lee Rhodes Date: Thu, 31 Aug 2023 11:17:37 -0700 Subject: [PATCH 2/3] Removed one exclusion as unnecessary in FindBugsExcludeFilter.xml Documented in the code where the SpotBugs finds issues that we still suppress. (only 3 places.) --- .../java/org/apache/datasketches/kll/KllItemsSketch.java | 2 +- .../quantilescommon/GenericSortedViewIterator.java | 4 ++-- src/test/java/org/apache/datasketches/req/ReqDebugImpl.java | 2 +- tools/FindBugsExcludeFilter.xml | 6 +----- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/apache/datasketches/kll/KllItemsSketch.java b/src/main/java/org/apache/datasketches/kll/KllItemsSketch.java index 3497fcd1f..4c0bb3888 100644 --- a/src/main/java/org/apache/datasketches/kll/KllItemsSketch.java +++ b/src/main/java/org/apache/datasketches/kll/KllItemsSketch.java @@ -243,7 +243,7 @@ public double[] getRanks(final T[] quantiles, final QuantileSearchCriteria searc public final KllItemsSketchSortedView getSortedView() { if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); } refreshSortedView(); - return kllItemsSV; + return kllItemsSV; //SpotBugs EI_EXPOSE_REP, Suppressed by FindBugsExcludeFilter } @Override diff --git a/src/main/java/org/apache/datasketches/quantilescommon/GenericSortedViewIterator.java b/src/main/java/org/apache/datasketches/quantilescommon/GenericSortedViewIterator.java index e2a805633..69b454a92 100644 --- a/src/main/java/org/apache/datasketches/quantilescommon/GenericSortedViewIterator.java +++ b/src/main/java/org/apache/datasketches/quantilescommon/GenericSortedViewIterator.java @@ -35,8 +35,8 @@ public class GenericSortedViewIterator implements SortedViewIterator { private int index; public GenericSortedViewIterator(final T[] quantiles, final long[] cumWeights) { - this.quantiles = quantiles; - this.cumWeights = cumWeights; + this.quantiles = quantiles; //SpotBugs EI_EXPOSE_REP2 suppressed by FindBugsExcludeFilter + this.cumWeights = cumWeights; //SpotBugs EI_EXPOSE_REP2 suppressed by FindBugsExcludeFilter this.totalN = (cumWeights.length > 0) ? cumWeights[cumWeights.length - 1] : 0; index = -1; } diff --git a/src/test/java/org/apache/datasketches/req/ReqDebugImpl.java b/src/test/java/org/apache/datasketches/req/ReqDebugImpl.java index 522718df6..1c9a28b07 100644 --- a/src/test/java/org/apache/datasketches/req/ReqDebugImpl.java +++ b/src/test/java/org/apache/datasketches/req/ReqDebugImpl.java @@ -53,7 +53,7 @@ public ReqDebugImpl(final int debugLevel, final String fmt) { @Override public void emitStart(final ReqSketch sk) { if (debugLevel == 0) { return; } - this.sk = sk; + this.sk = sk; //SpotBugs EI_EXPOSE_REP2 suppressed by FindBugsExcludeFilter println("START"); } diff --git a/tools/FindBugsExcludeFilter.xml b/tools/FindBugsExcludeFilter.xml index c212a9034..2a318b8f0 100644 --- a/tools/FindBugsExcludeFilter.xml +++ b/tools/FindBugsExcludeFilter.xml @@ -55,13 +55,9 @@ under the License. - - - - - + From 8484dade6ce77779c61e31cd43e62de18714c815 Mon Sep 17 00:00:00 2001 From: Lee Rhodes Date: Thu, 31 Aug 2023 12:36:05 -0700 Subject: [PATCH 3/3] Was able to remove 2 exclusions from FindBugsExcludeFilter.xml --- .../org/apache/datasketches/kll/KllItemsSketch.java | 11 +++++++---- .../apache/datasketches/quantiles/ItemsSketch.java | 10 +++++++--- .../req/{ReqDebugImpl.java => ReqDebugImplTest.java} | 4 ++-- .../apache/datasketches/req/ReqSketchBuilderTest.java | 2 +- .../org/apache/datasketches/req/ReqSketchTest.java | 2 +- tools/FindBugsExcludeFilter.xml | 11 ----------- 6 files changed, 18 insertions(+), 22 deletions(-) rename src/test/java/org/apache/datasketches/req/{ReqDebugImpl.java => ReqDebugImplTest.java} (98%) diff --git a/src/main/java/org/apache/datasketches/kll/KllItemsSketch.java b/src/main/java/org/apache/datasketches/kll/KllItemsSketch.java index 4c0bb3888..97bbc519f 100644 --- a/src/main/java/org/apache/datasketches/kll/KllItemsSketch.java +++ b/src/main/java/org/apache/datasketches/kll/KllItemsSketch.java @@ -242,8 +242,8 @@ public double[] getRanks(final T[] quantiles, final QuantileSearchCriteria searc @Override public final KllItemsSketchSortedView getSortedView() { if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); } - refreshSortedView(); - return kllItemsSV; //SpotBugs EI_EXPOSE_REP, Suppressed by FindBugsExcludeFilter + return refreshSortedView(); + //return kllItemsSV; //SpotBugs EI_EXPOSE_REP, Suppressed by FindBugsExcludeFilter } @Override @@ -301,8 +301,11 @@ MemoryRequestServer getMemoryRequestServer() { @Override abstract int getMinMaxSizeBytes(); - private final void refreshSortedView() { - kllItemsSV = (kllItemsSV == null) ? new KllItemsSketchSortedView(this) : kllItemsSV; + private final KllItemsSketchSortedView refreshSortedView() { + final KllItemsSketchSortedView sv = (kllItemsSV == null) + ? kllItemsSV = new KllItemsSketchSortedView(this) + : kllItemsSV; + return sv; } abstract T[] getRetainedItemsArray(); diff --git a/src/main/java/org/apache/datasketches/quantiles/ItemsSketch.java b/src/main/java/org/apache/datasketches/quantiles/ItemsSketch.java index aa9aea721..caa73c6ec 100644 --- a/src/main/java/org/apache/datasketches/quantiles/ItemsSketch.java +++ b/src/main/java/org/apache/datasketches/quantiles/ItemsSketch.java @@ -581,7 +581,8 @@ public void putMemory(final WritableMemory dstMem, final ArrayOfItemsSerDe se @Override public GenericSortedView getSortedView() { - return new ItemsSketchSortedView(this); + if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); } + return refreshSortedView(); } @Override @@ -605,8 +606,11 @@ public void update(final T item) { // Restricted - private final void refreshSortedView() { - classicQisSV = (classicQisSV == null) ? new ItemsSketchSortedView(this) : classicQisSV; + private final ItemsSketchSortedView refreshSortedView() { + final ItemsSketchSortedView sv = (classicQisSV == null) + ? classicQisSV = new ItemsSketchSortedView(this) + : classicQisSV; + return sv; } /** diff --git a/src/test/java/org/apache/datasketches/req/ReqDebugImpl.java b/src/test/java/org/apache/datasketches/req/ReqDebugImplTest.java similarity index 98% rename from src/test/java/org/apache/datasketches/req/ReqDebugImpl.java rename to src/test/java/org/apache/datasketches/req/ReqDebugImplTest.java index 1c9a28b07..5e757ce0f 100644 --- a/src/test/java/org/apache/datasketches/req/ReqDebugImpl.java +++ b/src/test/java/org/apache/datasketches/req/ReqDebugImplTest.java @@ -33,7 +33,7 @@ * * @author Lee Rhodes */ -public class ReqDebugImpl implements ReqDebug { +public class ReqDebugImplTest implements ReqDebug { private static final String LS = System.getProperty("line.separator"); private static final String TAB = "\t"; private ReqSketch sk; @@ -45,7 +45,7 @@ public class ReqDebugImpl implements ReqDebug { * @param debugLevel sets the debug level of detail * @param fmt string format to use when printing values */ - public ReqDebugImpl(final int debugLevel, final String fmt) { + public ReqDebugImplTest(final int debugLevel, final String fmt) { this.debugLevel = debugLevel; this.fmt = fmt; } diff --git a/src/test/java/org/apache/datasketches/req/ReqSketchBuilderTest.java b/src/test/java/org/apache/datasketches/req/ReqSketchBuilderTest.java index ca0893cbb..8e33b03e2 100644 --- a/src/test/java/org/apache/datasketches/req/ReqSketchBuilderTest.java +++ b/src/test/java/org/apache/datasketches/req/ReqSketchBuilderTest.java @@ -32,7 +32,7 @@ public class ReqSketchBuilderTest { @Test public void checkBldr() { final ReqSketchBuilder bldr = new ReqSketchBuilder(); - final ReqDebugImpl rdi = new ReqDebugImpl(2, "%4.0f"); + final ReqDebugImplTest rdi = new ReqDebugImplTest(2, "%4.0f"); bldr.setK(50).setHighRankAccuracy(true).setReqDebug(rdi); assertEquals(bldr.getK(), 50); assertEquals(bldr.getHighRankAccuracy(), true); diff --git a/src/test/java/org/apache/datasketches/req/ReqSketchTest.java b/src/test/java/org/apache/datasketches/req/ReqSketchTest.java index e76bf207a..4db9112a8 100644 --- a/src/test/java/org/apache/datasketches/req/ReqSketchTest.java +++ b/src/test/java/org/apache/datasketches/req/ReqSketchTest.java @@ -80,7 +80,7 @@ public void bigTestImpl(final int k, final int min, final int max, final boolean public ReqSketch loadSketch(final int k, final int min, final int max, final boolean up, final boolean hra, final int skDebug) { final ReqSketchBuilder bldr = ReqSketch.builder(); - bldr.setReqDebug(new ReqDebugImpl(skDebug, "%5.0f")); + bldr.setReqDebug(new ReqDebugImplTest(skDebug, "%5.0f")); bldr.setK(k); bldr.setHighRankAccuracy(hra); final ReqSketch sk = bldr.build(); diff --git a/tools/FindBugsExcludeFilter.xml b/tools/FindBugsExcludeFilter.xml index 2a318b8f0..6ce8f010c 100644 --- a/tools/FindBugsExcludeFilter.xml +++ b/tools/FindBugsExcludeFilter.xml @@ -44,17 +44,6 @@ under the License. - - - - - - - - - - -