From c182f65613c8e21100a1b272940e08b23320d158 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Wed, 13 Sep 2023 18:10:39 -0400 Subject: [PATCH] Better lambdas Use final Initialize Map when instantiating Use diamonds Use varargs --- .../bloomfilter/ArrayCountingBloomFilter.java | 6 +- .../collections4/bloomfilter/BloomFilter.java | 12 +-- .../bloomfilter/CellProducer.java | 12 +-- .../bloomfilter/CountingBloomFilter.java | 12 +-- .../bloomfilter/IndexProducer.java | 4 +- .../collections4/bloomfilter/IndexUtils.java | 2 +- .../apache/commons/collections4/BulkTest.java | 2 +- .../collections4/CollectionUtilsTest.java | 3 +- .../commons/collections4/ListUtilsTest.java | 2 +- .../commons/collections4/MapUtilsTest.java | 2 +- .../commons/collections4/SetUtilsTest.java | 2 +- .../collections4/bag/PredicatedBagTest.java | 2 +- .../bag/PredicatedSortedBagTest.java | 2 +- .../AbstractBitMapProducerTest.java | 6 +- .../bloomfilter/AbstractBloomFilterTest.java | 28 +++---- .../bloomfilter/AbstractCellProducerTest.java | 6 +- .../AbstractCountingBloomFilterTest.java | 36 ++++----- .../AbstractIndexProducerTest.java | 2 +- .../collections4/bloomfilter/BitMapTest.java | 2 +- .../DefaultBitMapProducerTest.java | 13 ++- .../bloomfilter/DefaultBloomFilterTest.java | 16 ++-- .../bloomfilter/DefaultIndexProducerTest.java | 8 +- .../bloomfilter/IndexProducerTest.java | 4 +- .../bloomfilter/SetOperationsTest.java | 80 +++++++++---------- .../bloomfilter/SimpleBloomFilterTest.java | 6 +- .../bloomfilter/TestingHashers.java | 10 +-- .../collection/CompositeCollectionTest.java | 2 + .../collection/PredicatedCollectionTest.java | 2 +- .../collections4/list/PredicatedListTest.java | 2 +- .../collections4/map/PredicatedMapTest.java | 2 +- .../map/PredicatedSortedMapTest.java | 2 +- .../multiset/PredicatedMultiSetTest.java | 2 +- .../queue/PredicatedQueueTest.java | 2 +- .../collections4/set/PredicatedSetTest.java | 2 +- 34 files changed, 145 insertions(+), 151 deletions(-) diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/ArrayCountingBloomFilter.java b/src/main/java/org/apache/commons/collections4/bloomfilter/ArrayCountingBloomFilter.java index 5fa0296f84..b06f2c4d4c 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/ArrayCountingBloomFilter.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/ArrayCountingBloomFilter.java @@ -272,10 +272,10 @@ public int[] asIndexArray() { } @Override - public int getMaxInsert(CellProducer cellProducer) { - int[] max = {Integer.MAX_VALUE}; + public int getMaxInsert(final CellProducer cellProducer) { + final int[] max = {Integer.MAX_VALUE}; cellProducer.forEachCell( (x, y) -> { - int count = cells[x] / y; + final int count = cells[x] / y; if (count < max[0]) { max[0] = count; } diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilter.java b/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilter.java index e4783bf3e1..fbfbb91c49 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilter.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilter.java @@ -231,14 +231,14 @@ default boolean isFull() { * @see Shape */ default int estimateN() { - double d = getShape().estimateN(cardinality()); + final double d = getShape().estimateN(cardinality()); if (Double.isInfinite(d)) { return Integer.MAX_VALUE; } if (Double.isNaN(d)) { throw new IllegalArgumentException("Cardinality too large: " + cardinality()); } - long l = Math.round(d); + final long l = Math.round(d); return l > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) l; } @@ -283,8 +283,8 @@ default int estimateUnion(final BloomFilter other) { */ default int estimateIntersection(final BloomFilter other) { Objects.requireNonNull(other, "other"); - double eThis = getShape().estimateN(cardinality()); - double eOther = getShape().estimateN(other.cardinality()); + final double eThis = getShape().estimateN(cardinality()); + final double eOther = getShape().estimateN(other.cardinality()); if (Double.isInfinite(eThis) && Double.isInfinite(eOther)) { // if both are infinite the union is infinite and we return Integer.MAX_VALUE return Integer.MAX_VALUE; @@ -296,9 +296,9 @@ default int estimateIntersection(final BloomFilter other) { } else if (Double.isInfinite(eOther)) { estimate = Math.round(eThis); } else { - BloomFilter union = this.copy(); + final BloomFilter union = this.copy(); union.merge(other); - double eUnion = getShape().estimateN(union.cardinality()); + final double eUnion = getShape().estimateN(union.cardinality()); if (Double.isInfinite(eUnion)) { throw new IllegalArgumentException("The estimated N for the union of the filters is infinite"); } diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/CellProducer.java b/src/main/java/org/apache/commons/collections4/bloomfilter/CellProducer.java index 6949a13c64..ecb984e2ce 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/CellProducer.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/CellProducer.java @@ -95,8 +95,8 @@ static CellProducer from(final IndexProducer producer) { private void populate() { if (counterCells.isEmpty()) { producer.forEachIndex( idx -> { - CounterCell cell = new CounterCell(idx, 1); - CounterCell counter = counterCells.get(cell); + final CounterCell cell = new CounterCell(idx, 1); + final CounterCell counter = counterCells.get(cell); if (counter == null) { counterCells.put(cell, cell); } else { @@ -114,9 +114,9 @@ public int[] asIndexArray() { } @Override - public boolean forEachCell(CellConsumer consumer) { + public boolean forEachCell(final CellConsumer consumer) { populate(); - for (CounterCell cell : counterCells.values()) { + for (final CounterCell cell : counterCells.values()) { if (!consumer.test(cell.idx, cell.count)) { return false; } @@ -131,13 +131,13 @@ final class CounterCell implements Comparable { final int idx; int count; - CounterCell(int idx, int count) { + CounterCell(final int idx, final int count) { this.idx = idx; this.count = count; } @Override - public int compareTo(CounterCell other) { + public int compareTo(final CounterCell other) { return Integer.compare(idx, other.idx); } } diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilter.java b/src/main/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilter.java index 7c9310f406..a0ee54653a 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilter.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilter.java @@ -91,7 +91,7 @@ public interface CountingBloomFilter extends BloomFilter, CellProducer { * @param bloomFilter the Bloom filter the check for. * @return the maximum number of times the Bloom filter could have been inserted. */ - default int getMaxInsert(BloomFilter bloomFilter) { + default int getMaxInsert(final BloomFilter bloomFilter) { return getMaxInsert((BitMapProducer) bloomFilter); } @@ -104,7 +104,7 @@ default int getMaxInsert(BloomFilter bloomFilter) { * @return the maximum number of times the IndexProducer could have been inserted. * @see #getMaxInsert(CellProducer) */ - default int getMaxInsert(IndexProducer idxProducer) { + default int getMaxInsert(final IndexProducer idxProducer) { return getMaxInsert(CellProducer.from(idxProducer.uniqueIndices()) ); } @@ -121,7 +121,7 @@ default int getMaxInsert(IndexProducer idxProducer) { * @param hasher the Hasher to provide the indices. * @return the maximum number of times the hasher could have been inserted. */ - default int getMaxInsert(Hasher hasher) { + default int getMaxInsert(final Hasher hasher) { return getMaxInsert(hasher.indices(getShape())); } @@ -131,12 +131,12 @@ default int getMaxInsert(Hasher hasher) { * @param bitMapProducer the BitMapProducer to provide the indices. * @return the maximum number of times the BitMapProducer could have been inserted. */ - default int getMaxInsert(BitMapProducer bitMapProducer) { + default int getMaxInsert(final BitMapProducer bitMapProducer) { if (!contains(bitMapProducer)) { return 0; } - long[] bitMaps = bitMapProducer.asBitMapArray(); - int[] max = { Integer.MAX_VALUE }; + final long[] bitMaps = bitMapProducer.asBitMapArray(); + final int[] max = { Integer.MAX_VALUE }; forEachCell((x, y) -> { if ((bitMaps[BitMap.getLongIndex(x)] & BitMap.getLongBit(x)) != 0) { max[0] = max[0] <= y ? max[0] : y; diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/IndexProducer.java b/src/main/java/org/apache/commons/collections4/bloomfilter/IndexProducer.java index 0269d34eac..dd73a423d1 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/IndexProducer.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/IndexProducer.java @@ -131,7 +131,7 @@ int[] toArray() { return size == data.length ? data : Arrays.copyOf(data, size); } } - Indices indices = new Indices(); + final Indices indices = new Indices(); forEachIndex(indices::add); return indices.toArray(); } @@ -158,7 +158,7 @@ default IndexProducer uniqueIndices() { return new IndexProducer() { @Override - public boolean forEachIndex(IntPredicate predicate) { + public boolean forEachIndex(final IntPredicate predicate) { for (int idx = bitSet.nextSetBit(0); idx >= 0; idx = bitSet.nextSetBit(idx + 1)) { if (!predicate.test(idx)) { return false; diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/IndexUtils.java b/src/main/java/org/apache/commons/collections4/bloomfilter/IndexUtils.java index 96bfefec02..5cbf677852 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/IndexUtils.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/IndexUtils.java @@ -38,7 +38,7 @@ private IndexUtils() {} * @param index the index to add at. * @return the array or a newly allocated copy of the array. */ - static int[] ensureCapacityForAdd(int[] array, int index) { + static int[] ensureCapacityForAdd(final int[] array, final int index) { if (index >= array.length) { return Arrays.copyOf(array, (int) Math.min(IndexUtils.MAX_ARRAY_SIZE, Math.max(array.length * 2L, index + 1))); } diff --git a/src/test/java/org/apache/commons/collections4/BulkTest.java b/src/test/java/org/apache/commons/collections4/BulkTest.java index c1b2be256e..d341584439 100644 --- a/src/test/java/org/apache/commons/collections4/BulkTest.java +++ b/src/test/java/org/apache/commons/collections4/BulkTest.java @@ -155,7 +155,7 @@ public class BulkTest implements Cloneable { /** * the name of the simple test method */ - private String name; + private final String name; /** * Constructs a new {@code BulkTest} instance that will run the diff --git a/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java b/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java index 03d4fbe9dd..f1e6a2f8e9 100644 --- a/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java @@ -689,8 +689,7 @@ public void get() { assertEquals(2, CollectionUtils.get((Object) collectionA.iterator(), 2)); final Map map = CollectionUtils.getCardinalityMap(collectionA); // Test assumes a defined iteration order so convert to a LinkedHashMap - final Map linkedMap = new LinkedHashMap<>(); - linkedMap.putAll(map); + final Map linkedMap = new LinkedHashMap<>(map); assertEquals(linkedMap.entrySet().iterator().next(), CollectionUtils.get((Object) linkedMap, 0)); } diff --git a/src/test/java/org/apache/commons/collections4/ListUtilsTest.java b/src/test/java/org/apache/commons/collections4/ListUtilsTest.java index 00d5f58219..328a1a0873 100644 --- a/src/test/java/org/apache/commons/collections4/ListUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/ListUtilsTest.java @@ -344,7 +344,7 @@ public void testPartition() { @Test public void testPredicatedList() { - final Predicate predicate = o -> o instanceof String; + final Predicate predicate = String.class::isInstance; final List list = ListUtils.predicatedList(new ArrayList<>(), predicate); assertTrue(list instanceof PredicatedList, "returned object should be a PredicatedList"); assertAll( diff --git a/src/test/java/org/apache/commons/collections4/MapUtilsTest.java b/src/test/java/org/apache/commons/collections4/MapUtilsTest.java index b81539a38d..2f8083aed5 100644 --- a/src/test/java/org/apache/commons/collections4/MapUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/MapUtilsTest.java @@ -62,7 +62,7 @@ public class MapUtilsTest { private static final String TWO = "Two"; public Predicate getPredicate() { - return o -> o instanceof String; + return String.class::isInstance; } @Test diff --git a/src/test/java/org/apache/commons/collections4/SetUtilsTest.java b/src/test/java/org/apache/commons/collections4/SetUtilsTest.java index 322615d649..47d6b3b9db 100644 --- a/src/test/java/org/apache/commons/collections4/SetUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/SetUtilsTest.java @@ -208,7 +208,7 @@ public void testNewIdentityHashSet() { @Test public void testpredicatedSet() { - final Predicate predicate = o -> o instanceof String; + final Predicate predicate = String.class::isInstance; final Set set = SetUtils.predicatedSet(new HashSet<>(), predicate); assertTrue(set instanceof PredicatedSet, "returned object should be a PredicatedSet"); assertAll( diff --git a/src/test/java/org/apache/commons/collections4/bag/PredicatedBagTest.java b/src/test/java/org/apache/commons/collections4/bag/PredicatedBagTest.java index 6379f464f2..eed7904b8e 100644 --- a/src/test/java/org/apache/commons/collections4/bag/PredicatedBagTest.java +++ b/src/test/java/org/apache/commons/collections4/bag/PredicatedBagTest.java @@ -41,7 +41,7 @@ public PredicatedBagTest() { } protected Predicate stringPredicate() { - return o -> o instanceof String; + return String.class::isInstance; } protected Predicate truePredicate = TruePredicate.truePredicate(); diff --git a/src/test/java/org/apache/commons/collections4/bag/PredicatedSortedBagTest.java b/src/test/java/org/apache/commons/collections4/bag/PredicatedSortedBagTest.java index 5d3b7cb566..d15e84c610 100644 --- a/src/test/java/org/apache/commons/collections4/bag/PredicatedSortedBagTest.java +++ b/src/test/java/org/apache/commons/collections4/bag/PredicatedSortedBagTest.java @@ -42,7 +42,7 @@ public PredicatedSortedBagTest() { } protected Predicate stringPredicate() { - return o -> o instanceof String; + return String.class::isInstance; } protected Predicate truePredicate = TruePredicate.truePredicate(); diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBitMapProducerTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBitMapProducerTest.java index ec3832b754..8ae739c7d0 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBitMapProducerTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBitMapProducerTest.java @@ -106,14 +106,12 @@ public final void testForEachBitMapPair() { // test where the created producer does not process all records because the predicate function // returns false before the processing is completed. - int[] limit = new int[1]; + final int[] limit = new int[1]; final LongBiPredicate shortFunc = (x, y) -> { limit[0]++; return limit[0] < 2; }; - final BitMapProducer shortProducer = l -> { - return true; - }; + final BitMapProducer shortProducer = l -> true; assertFalse(createProducer().forEachBitMapPair(shortProducer, shortFunc)); } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilterTest.java index e4a9082771..3d332146d5 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilterTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilterTest.java @@ -119,7 +119,7 @@ public void testMergeWithHasher() { @Test public void testMergeWithBitMapProducer() { - int bitMapCount = BitMap.numberOfBitMaps(getTestShape().getNumberOfBits()); + final int bitMapCount = BitMap.numberOfBitMaps(getTestShape().getNumberOfBits()); for (int i = 0; i < 5; i++) { final long[] values = new long[bitMapCount]; for (final int idx : DefaultIndexProducerTest.generateIntArray(getTestShape().getNumberOfHashFunctions(), getTestShape().getNumberOfBits())) { @@ -134,7 +134,7 @@ public void testMergeWithBitMapProducer() { assertTrue(lst.isEmpty()); } // values too large - long[] values = new long[bitMapCount]; + final long[] values = new long[bitMapCount]; Arrays.fill(values, Long.MAX_VALUE); final BitMapProducer badProducer = BitMapProducer.fromBitMapArray(values); final BloomFilter bf = createEmptyFilter(getTestShape()); @@ -162,11 +162,11 @@ public void testMergeWithIndexProducer() { // value to large final BloomFilter f1 = createEmptyFilter(getTestShape()); assertThrows(IllegalArgumentException.class, - () -> f1.merge(IndexProducer.fromIndexArray(new int[] {getTestShape().getNumberOfBits()}))); + () -> f1.merge(IndexProducer.fromIndexArray(getTestShape().getNumberOfBits()))); // negative value final BloomFilter f2 = createEmptyFilter(getTestShape()); assertThrows(IllegalArgumentException.class, - () -> f2.merge(IndexProducer.fromIndexArray(new int[] {-1}))); + () -> f2.merge(IndexProducer.fromIndexArray(-1))); } @Test @@ -218,12 +218,12 @@ public void testClear() { @Test public final void testNegativeIntersection() { - IndexProducer p1 = IndexProducer.fromIndexArray(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 20, 26, 28, 30, 32, 34, 35, 36, 37, 39, 40, 41, 42, 43, 45, 46, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71); - IndexProducer p2 = IndexProducer.fromIndexArray(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); + final IndexProducer p1 = IndexProducer.fromIndexArray(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 20, 26, 28, 30, 32, 34, 35, 36, 37, 39, 40, 41, 42, 43, 45, 46, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71); + final IndexProducer p2 = IndexProducer.fromIndexArray(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); - BloomFilter filter1 = createEmptyFilter(Shape.fromKM(17, 72)); + final BloomFilter filter1 = createEmptyFilter(Shape.fromKM(17, 72)); filter1.merge(p1); - BloomFilter filter2 = createEmptyFilter(Shape.fromKM(17, 72)); + final BloomFilter filter2 = createEmptyFilter(Shape.fromKM(17, 72)); filter2.merge(p2); assertEquals(0, filter1.estimateIntersection(filter2)); } @@ -249,9 +249,9 @@ public final void testEstimateIntersection() { assertEquals(0, bf.estimateIntersection(bf4)); assertEquals(0, bf4.estimateIntersection(bf)); - int midPoint = getTestShape().getNumberOfBits() / 2; - BloomFilter bf5 = TestingHashers.populateRange(createEmptyFilter(getTestShape()), 0, midPoint); - BloomFilter bf6 = TestingHashers.populateRange(createEmptyFilter(getTestShape()), midPoint+1, getTestShape().getNumberOfBits()-1); + final int midPoint = getTestShape().getNumberOfBits() / 2; + final BloomFilter bf5 = TestingHashers.populateRange(createEmptyFilter(getTestShape()), 0, midPoint); + final BloomFilter bf6 = TestingHashers.populateRange(createEmptyFilter(getTestShape()), midPoint+1, getTestShape().getNumberOfBits()-1); assertThrows(IllegalArgumentException.class, () -> bf5.estimateIntersection(bf6)); // infinite with infinite @@ -371,8 +371,8 @@ public final void testMerge() { assertThrows(IllegalArgumentException.class, () -> bf1.merge(new BadHasher(-1))); // test error when bloom filter returns values out of range - Shape s = Shape.fromKM(getTestShape().getNumberOfHashFunctions(), getTestShape().getNumberOfBits() * 3); - Hasher h = new IncrementingHasher(getTestShape().getNumberOfBits() * 2, 1); + final Shape s = Shape.fromKM(getTestShape().getNumberOfHashFunctions(), getTestShape().getNumberOfBits() * 3); + final Hasher h = new IncrementingHasher(getTestShape().getNumberOfBits() * 2, 1); final BloomFilter bf5 = new SimpleBloomFilter(s); bf5.merge(h); assertThrows(IllegalArgumentException.class, () -> bf1.merge(bf5)); @@ -441,7 +441,7 @@ public static class BadHasher implements Hasher { IndexProducer producer; public BadHasher(final int value) { - this.producer = IndexProducer.fromIndexArray(new int[] {value}); + this.producer = IndexProducer.fromIndexArray(value); } @Override diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractCellProducerTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractCellProducerTest.java index 6591d14e44..68dcbb6b1f 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractCellProducerTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractCellProducerTest.java @@ -106,10 +106,10 @@ public final void testIndexConsistency() { @Test public void testForEachCellValues() { - int[] expectedIdx = getExpectedIndices(); - int[] expectedValue = getExpectedValues(); + final int[] expectedIdx = getExpectedIndices(); + final int[] expectedValue = getExpectedValues(); assertEquals(expectedIdx.length, expectedValue.length, "expected index length and value length do not match"); - int[] idx = {0}; + final int[] idx = {0}; createProducer().forEachCell((i, j) -> { assertEquals(expectedIdx[idx[0]], i, "bad index at " + idx[0]); assertEquals(expectedValue[idx[0]], j, "bad value at " + idx[0]); diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractCountingBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractCountingBloomFilterTest.java index 6d489d8d13..6bc6b1bdd6 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractCountingBloomFilterTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractCountingBloomFilterTest.java @@ -39,7 +39,7 @@ public abstract class AbstractCountingBloomFilterTest { for (int i = 1; i < 18; i++) { if (!consumer.test(i, maxValue)) { @@ -194,7 +194,7 @@ public final void testSubtract() { assertCounts(bf3, new int[] {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}); assertThrows(IllegalArgumentException.class, () -> bf3.remove( new BadHasher(-1))); - assertThrows(IllegalArgumentException.class, () -> bf3.remove( new BadHasher(getTestShape().getNumberOfBits())));; + assertThrows(IllegalArgumentException.class, () -> bf3.remove( new BadHasher(getTestShape().getNumberOfBits()))); } /** @@ -266,7 +266,7 @@ public final void testRemove() { final BitMapProducer bmp2 = BitMapProducer.fromIndexProducer(ip2, getTestShape().getNumberOfBits()); assertThrows(IllegalArgumentException.class, () -> bf7.remove(bmp2)); assertThrows(IllegalArgumentException.class, () -> bf7.remove( new BadHasher(-1))); - assertThrows(IllegalArgumentException.class, () -> bf7.remove( new BadHasher(getTestShape().getNumberOfBits())));; + assertThrows(IllegalArgumentException.class, () -> bf7.remove( new BadHasher(getTestShape().getNumberOfBits()))); } @Test @@ -299,12 +299,12 @@ public void testExcludesDuplicates() { assertTrue(bf1.forEachCell((x, y) -> false), "Hasher in removes results in value not equal to 0"); } - private void verifyMaxInsert(CountingBloomFilter bf, int from1, int from11) { - BloomFilter bfFrom0 = new DefaultBloomFilterTest.SparseDefaultBloomFilter(getTestShape()); + private void verifyMaxInsert(final CountingBloomFilter bf, final int from1, final int from11) { + final BloomFilter bfFrom0 = new DefaultBloomFilterTest.SparseDefaultBloomFilter(getTestShape()); bfFrom0.merge(new IncrementingHasher(0, 1)); - BloomFilter bfFrom1 = new DefaultBloomFilterTest.SparseDefaultBloomFilter(getTestShape()); + final BloomFilter bfFrom1 = new DefaultBloomFilterTest.SparseDefaultBloomFilter(getTestShape()); bfFrom1.merge(TestingHashers.FROM1); - BloomFilter bfFrom11 = new DefaultBloomFilterTest.SparseDefaultBloomFilter(getTestShape()); + final BloomFilter bfFrom11 = new DefaultBloomFilterTest.SparseDefaultBloomFilter(getTestShape()); bfFrom11.merge(TestingHashers.FROM11); assertEquals(0, bf.getMaxInsert(new IncrementingHasher(0, 1))); @@ -325,7 +325,7 @@ private void verifyMaxInsert(CountingBloomFilter bf, int from1, int from11) { @Test public void testGetMaxInsert() { - CountingBloomFilter bf = createEmptyFilter(getTestShape()); + final CountingBloomFilter bf = createEmptyFilter(getTestShape()); verifyMaxInsert(bf, 0, 0); bf.merge(TestingHashers.FROM1); verifyMaxInsert(bf, 1, 0); @@ -343,7 +343,7 @@ public void testGetMaxInsert() { assertEquals(0, bf.getMaxInsert(new IncrementingHasher(5, 1))); } - private void assertCell3(CountingBloomFilter bf, int value) { + private void assertCell3(final CountingBloomFilter bf, final int value) { bf.forEachCell((k, v) -> { if (k == 3) { assertEquals(value, v, "Mismatch at position 3"); @@ -356,11 +356,11 @@ private void assertCell3(CountingBloomFilter bf, int value) { @Test public void mergeIncrementsAllCellsTest() { - CountingBloomFilter f1 = createEmptyFilter(Shape.fromKM(1, 10)); - CountingBloomFilter f2 = f1.copy(); - CountingBloomFilter f3 = f1.copy(); + final CountingBloomFilter f1 = createEmptyFilter(Shape.fromKM(1, 10)); + final CountingBloomFilter f2 = f1.copy(); + final CountingBloomFilter f3 = f1.copy(); // index producer produces 3 two times. - IndexProducer ip = p -> { + final IndexProducer ip = p -> { p.test(3); p.test(3); return true; @@ -376,16 +376,16 @@ public void mergeIncrementsAllCellsTest() { @Test public void removeDecrementsAllCellsTest() { - CountingBloomFilter f1 = createEmptyFilter(Shape.fromKM(1, 10)); - CellProducer cp = p -> { + final CountingBloomFilter f1 = createEmptyFilter(Shape.fromKM(1, 10)); + final CellProducer cp = p -> { p.test(3, 3); return true; }; f1.add(cp); - CountingBloomFilter f2 = f1.copy(); - CountingBloomFilter f3 = f1.copy(); + final CountingBloomFilter f2 = f1.copy(); + final CountingBloomFilter f3 = f1.copy(); // index producer produces 3 two times. - IndexProducer ip = p -> { + final IndexProducer ip = p -> { p.test(3); p.test(3); return true; diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractIndexProducerTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractIndexProducerTest.java index 868982d2a6..faa66ead7b 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractIndexProducerTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractIndexProducerTest.java @@ -249,7 +249,7 @@ public void testForEachIndexEarlyExit() { @Test public void testUniqueReturnsSelf() { - IndexProducer expected = createProducer().uniqueIndices(); + final IndexProducer expected = createProducer().uniqueIndices(); assertSame(expected, expected.uniqueIndices()); } } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapTest.java index 00d5df451d..5c58ca345a 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapTest.java @@ -128,7 +128,7 @@ public void testModEdgeCases() { * @param dividend the dividend * @param divisor the divisor */ - private void assertMod(long dividend, int divisor) { + private void assertMod(final long dividend, final int divisor) { assertTrue(divisor > 0 && divisor <= Integer.MAX_VALUE, "Incorrect usage. Divisor must be strictly positive."); assertEquals((int) Long.remainderUnsigned(dividend, divisor), BitMap.mod(dividend, divisor), diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBitMapProducerTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBitMapProducerTest.java index d0bee54c7f..cc8cfdf748 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBitMapProducerTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBitMapProducerTest.java @@ -91,16 +91,13 @@ public void testFromBitMapArray() { @Test public void testAsBitMapArrayLargeArray() { final long[] expected = generateLongArray(32); - BitMapProducer producer = new BitMapProducer() { - @Override - public boolean forEachBitMap(LongPredicate predicate) { - for (long l : expected) { - if (!predicate.test(l)) { - return false; - } + final BitMapProducer producer = predicate -> { + for (final long l : expected) { + if (!predicate.test(l)) { + return false; } - return true; } + return true; }; final long[] ary = producer.asBitMapArray(); assertArrayEquals(expected, ary); diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBloomFilterTest.java index 302bee7ad3..e716c42b56 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBloomFilterTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBloomFilterTest.java @@ -71,15 +71,15 @@ public void testHasherBasedMergeWithDifferingSparseness() { @Test public void testEstimateNWithBrokenCardinality() { // build a filter - BloomFilter filter1 = TestingHashers.populateEntireFilter(new BrokenCardinality(getTestShape())); + final BloomFilter filter1 = TestingHashers.populateEntireFilter(new BrokenCardinality(getTestShape())); assertThrows(IllegalArgumentException.class, () -> filter1.estimateN()); } @Test public void testEstimateLargeN() { - Shape s = Shape.fromKM(1, Integer.MAX_VALUE); + final Shape s = Shape.fromKM(1, Integer.MAX_VALUE); // create a very large filter with Integer.MAX_VALUE-1 bits set. - BloomFilter bf1 = new SimpleBloomFilter(s); + final BloomFilter bf1 = new SimpleBloomFilter(s); bf1.merge((BitMapProducer) predicate -> { int limit = Integer.MAX_VALUE - 1; while (limit > 64) { @@ -100,9 +100,9 @@ public void testEstimateLargeN() { @Test public void testIntersectionLimit() { - Shape s = Shape.fromKM(1, Integer.MAX_VALUE); + final Shape s = Shape.fromKM(1, Integer.MAX_VALUE); // create a very large filter with Integer.MAX_VALUE-1 bit set. - BloomFilter bf1 = new SimpleBloomFilter(s); + final BloomFilter bf1 = new SimpleBloomFilter(s); bf1.merge((BitMapProducer) predicate -> { int limit = Integer.MAX_VALUE - 1; while (limit > 64) { @@ -122,9 +122,9 @@ public void testIntersectionLimit() { @Test public void testSparseNonSparseMerging() { - BloomFilter bf1 = new SparseDefaultBloomFilter(getTestShape()); + final BloomFilter bf1 = new SparseDefaultBloomFilter(getTestShape()); bf1.merge(TestingHashers.FROM1); - BloomFilter bf2 = new NonSparseDefaultBloomFilter(getTestShape()); + final BloomFilter bf2 = new NonSparseDefaultBloomFilter(getTestShape()); bf2.merge(TestingHashers.FROM11); BloomFilter result = bf1.copy(); @@ -255,7 +255,7 @@ public AbstractDefaultBloomFilter copy() { static class BrokenCardinality extends NonSparseDefaultBloomFilter { - BrokenCardinality(Shape shape) { + BrokenCardinality(final Shape shape) { super(shape); } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultIndexProducerTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultIndexProducerTest.java index 73a3a58dc9..382321355f 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultIndexProducerTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultIndexProducerTest.java @@ -124,9 +124,9 @@ public void testFromIndexArray() { @ParameterizedTest @ValueSource(ints = {32, 33}) - public void testEntries(int size) { - int[] values = IntStream.range(0, size).toArray(); - IndexProducer producer = predicate -> { + public void testEntries(final int size) { + final int[] values = IntStream.range(0, size).toArray(); + final IndexProducer producer = predicate -> { Objects.requireNonNull(predicate); for (final int i : values) { if (!predicate.test(i)) { @@ -135,7 +135,7 @@ public void testEntries(int size) { } return true; }; - int[] other = producer.asIndexArray(); + final int[] other = producer.asIndexArray(); assertArrayEquals(values, other); } } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerTest.java index 655dfeed9d..9cf4bcc37f 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerTest.java @@ -74,8 +74,8 @@ public boolean forEachBitMap(final LongPredicate consumer) { @ParameterizedTest @ValueSource(ints = {32, 33}) - void testAsIndexArray(int n) { - IndexProducer ip = i -> { + void testAsIndexArray(final int n) { + final IndexProducer ip = i -> { for (int j = 0; j < n; j++) { // Always test index zero i.test(0); diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/SetOperationsTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/SetOperationsTest.java index 792917bc1d..94acad15de 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/SetOperationsTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/SetOperationsTest.java @@ -208,16 +208,16 @@ public final void testJaccardSimilarity() { @Test public final void testOrCardinality() { final Shape shape = Shape.fromKM(3, 128); - BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63, 64})); - BloomFilter filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69})); + BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63, 64)); + BloomFilter filter2 = createFilter(shape, IndexProducer.fromIndexArray(5, 64, 69)); assertSymmetricOperation(5, SetOperations::orCardinality, filter1, filter2); - filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63})); - filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69})); + filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63)); + filter2 = createFilter(shape, IndexProducer.fromIndexArray(5, 64, 69)); assertSymmetricOperation(5, SetOperations::orCardinality, filter1, filter2); - filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 63})); - filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69})); + filter1 = createFilter(shape, IndexProducer.fromIndexArray(5, 63)); + filter2 = createFilter(shape, IndexProducer.fromIndexArray(5, 64, 69)); assertSymmetricOperation(4, SetOperations::orCardinality, filter1, filter2); } @@ -225,32 +225,32 @@ public final void testOrCardinality() { public final void testOrCardinalityWithDifferentLengthFilters() { final Shape shape = Shape.fromKM(3, 128); final Shape shape2 = Shape.fromKM(3, 192); - BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63, 64})); - BloomFilter filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169})); + BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63, 64)); + BloomFilter filter2 = createFilter(shape2, IndexProducer.fromIndexArray(5, 64, 169)); assertSymmetricOperation(5, SetOperations::orCardinality, filter1, filter2); - filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63})); - filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169})); + filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63)); + filter2 = createFilter(shape2, IndexProducer.fromIndexArray(5, 64, 169)); assertSymmetricOperation(5, SetOperations::orCardinality, filter1, filter2); - filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 63})); - filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169})); + filter1 = createFilter(shape, IndexProducer.fromIndexArray(5, 63)); + filter2 = createFilter(shape2, IndexProducer.fromIndexArray(5, 64, 169)); assertSymmetricOperation(4, SetOperations::orCardinality, filter1, filter2); } @Test public final void testAndCardinality() { final Shape shape = Shape.fromKM(3, 128); - BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63, 64})); - BloomFilter filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69})); + BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63, 64)); + BloomFilter filter2 = createFilter(shape, IndexProducer.fromIndexArray(5, 64, 69)); assertSymmetricOperation(1, SetOperations::andCardinality, filter1, filter2); - filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63})); - filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69})); + filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63)); + filter2 = createFilter(shape, IndexProducer.fromIndexArray(5, 64, 69)); assertSymmetricOperation(0, SetOperations::andCardinality, filter1, filter2); - filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 63})); - filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69})); + filter1 = createFilter(shape, IndexProducer.fromIndexArray(5, 63)); + filter2 = createFilter(shape, IndexProducer.fromIndexArray(5, 64, 69)); assertSymmetricOperation(1, SetOperations::andCardinality, filter1, filter2); } @@ -258,37 +258,37 @@ public final void testAndCardinality() { public final void testAndCardinalityWithDifferentLengthFilters() { final Shape shape = Shape.fromKM(3, 128); final Shape shape2 = Shape.fromKM(3, 192); - BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63, 64})); - BloomFilter filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169})); + BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63, 64)); + BloomFilter filter2 = createFilter(shape2, IndexProducer.fromIndexArray(5, 64, 169)); assertSymmetricOperation(1, SetOperations::andCardinality, filter1, filter2); - filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63})); - filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169})); + filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63)); + filter2 = createFilter(shape2, IndexProducer.fromIndexArray(5, 64, 169)); assertSymmetricOperation(0, SetOperations::andCardinality, filter1, filter2); - filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 63})); - filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169})); + filter1 = createFilter(shape, IndexProducer.fromIndexArray(5, 63)); + filter2 = createFilter(shape2, IndexProducer.fromIndexArray(5, 64, 169)); assertSymmetricOperation(1, SetOperations::andCardinality, filter1, filter2); } @Test public final void testXorCardinality() { final Shape shape = Shape.fromKM(3, 128); - BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63, 64})); - BloomFilter filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69})); + BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63, 64)); + BloomFilter filter2 = createFilter(shape, IndexProducer.fromIndexArray(5, 64, 69)); assertSymmetricOperation(4, SetOperations::xorCardinality, filter1, filter2); - filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63})); - filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69})); + filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63)); + filter2 = createFilter(shape, IndexProducer.fromIndexArray(5, 64, 69)); assertSymmetricOperation(5, SetOperations::xorCardinality, filter1, filter2); - filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 63})); - filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69})); + filter1 = createFilter(shape, IndexProducer.fromIndexArray(5, 63)); + filter2 = createFilter(shape, IndexProducer.fromIndexArray(5, 64, 69)); assertSymmetricOperation(3, SetOperations::xorCardinality, filter1, filter2); final Shape bigShape = Shape.fromKM(3, 192); - filter1 = createFilter(bigShape, IndexProducer.fromIndexArray(new int[] {1, 63, 185})); - filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 63, 69})); + filter1 = createFilter(bigShape, IndexProducer.fromIndexArray(1, 63, 185)); + filter2 = createFilter(shape, IndexProducer.fromIndexArray(5, 63, 69)); assertSymmetricOperation(4, SetOperations::xorCardinality, filter1, filter2); } @@ -297,23 +297,23 @@ public final void testXorCardinalityWithDifferentLengthFilters() { final Shape shape = Shape.fromKM(3, 128); final Shape shape2 = Shape.fromKM(3, 192); - BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63, 64})); - BloomFilter filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169})); + BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63, 64)); + BloomFilter filter2 = createFilter(shape2, IndexProducer.fromIndexArray(5, 64, 169)); assertSymmetricOperation(4, SetOperations::xorCardinality, filter1, filter2); - filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63})); - filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169})); + filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63)); + filter2 = createFilter(shape2, IndexProducer.fromIndexArray(5, 64, 169)); assertSymmetricOperation(5, SetOperations::xorCardinality, filter1, filter2); - filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 63})); - filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169})); + filter1 = createFilter(shape, IndexProducer.fromIndexArray(5, 63)); + filter2 = createFilter(shape2, IndexProducer.fromIndexArray(5, 64, 169)); assertSymmetricOperation(3, SetOperations::xorCardinality, filter1, filter2); } @Test public final void testCommutativityOnMismatchedSizes() { - final BitMapProducer p1 = BitMapProducer.fromBitMapArray(new long[] {0x3L, 0x5L}); - final BitMapProducer p2 = BitMapProducer.fromBitMapArray(new long[] {0x1L}); + final BitMapProducer p1 = BitMapProducer.fromBitMapArray(0x3L, 0x5L); + final BitMapProducer p2 = BitMapProducer.fromBitMapArray(0x1L); assertEquals(SetOperations.orCardinality(p1, p2), SetOperations.orCardinality(p2, p1)); assertEquals(SetOperations.xorCardinality(p1, p2), SetOperations.xorCardinality(p2, p1)); diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/SimpleBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/SimpleBloomFilterTest.java index f58828afcf..1552e9c763 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/SimpleBloomFilterTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/SimpleBloomFilterTest.java @@ -32,12 +32,10 @@ protected SimpleBloomFilter createEmptyFilter(final Shape shape) { @Test public void testMergeShortBitMapProducer() { - SimpleBloomFilter filter = createEmptyFilter(getTestShape()); + final SimpleBloomFilter filter = createEmptyFilter(getTestShape()); // create a producer that returns too few values // shape expects 2 longs we are sending 1. - BitMapProducer producer = p -> { - return p.test(2L); - }; + final BitMapProducer producer = p -> p.test(2L); assertTrue(filter.merge(producer)); assertEquals(1, filter.cardinality()); } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/TestingHashers.java b/src/test/java/org/apache/commons/collections4/bloomfilter/TestingHashers.java index 84b17f554c..c97d59c1fa 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/TestingHashers.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/TestingHashers.java @@ -42,8 +42,8 @@ private TestingHashers() {} * @param hashers The hashers to merge * @return {@code filter} for chaining */ - public static T mergeHashers(T filter, Hasher...hashers) { - for (Hasher h : hashers) { + public static T mergeHashers(final T filter, final Hasher...hashers) { + for (final Hasher h : hashers) { filter.merge(h); } return filter; @@ -55,7 +55,7 @@ public static T mergeHashers(T filter, Hasher...hashers) * @param filter The Bloom filter to populate * @return {@code filter} for chaining */ - public static T populateFromHashersFrom1AndFrom11(T filter) { + public static T populateFromHashersFrom1AndFrom11(final T filter) { return mergeHashers(filter, FROM1, FROM11); } @@ -65,7 +65,7 @@ public static T populateFromHashersFrom1AndFrom11(T filt * @param filter the Bloom filter to populate * @return {@code filter} for chaining */ - public static T populateEntireFilter(T filter) { + public static T populateEntireFilter(final T filter) { return populateRange(filter, 0, filter.getShape().getNumberOfBits() - 1); } @@ -77,7 +77,7 @@ public static T populateEntireFilter(T filter) { * @param end the last bit to enable. * @return {@code filter} for chaining */ - public static T populateRange(T filter, int start, int end) { + public static T populateRange(final T filter, final int start, final int end) { filter.merge((IndexProducer) p -> { for (int i = start; i <= end; i++) { if (!p.test(i)) { diff --git a/src/test/java/org/apache/commons/collections4/collection/CompositeCollectionTest.java b/src/test/java/org/apache/commons/collections4/collection/CompositeCollectionTest.java index 9bc394ca21..05d0830a28 100644 --- a/src/test/java/org/apache/commons/collections4/collection/CompositeCollectionTest.java +++ b/src/test/java/org/apache/commons/collections4/collection/CompositeCollectionTest.java @@ -112,6 +112,8 @@ protected void setUpMutatorTest() { setUpTest(); c.setMutator(new CompositeCollection.CollectionMutator() { + private static final long serialVersionUID = 1L; + @Override public boolean add(final CompositeCollection composite, final List> collections, final E obj) { for (final Collection coll : collections) { diff --git a/src/test/java/org/apache/commons/collections4/collection/PredicatedCollectionTest.java b/src/test/java/org/apache/commons/collections4/collection/PredicatedCollectionTest.java index b259237be5..d42d12ea9e 100644 --- a/src/test/java/org/apache/commons/collections4/collection/PredicatedCollectionTest.java +++ b/src/test/java/org/apache/commons/collections4/collection/PredicatedCollectionTest.java @@ -75,7 +75,7 @@ public Collection makeConfirmedFullCollection() { } protected Predicate testPredicate = - o -> o instanceof String; + String.class::isInstance; public Collection makeTestCollection() { return decorateCollection(new ArrayList<>(), testPredicate); diff --git a/src/test/java/org/apache/commons/collections4/list/PredicatedListTest.java b/src/test/java/org/apache/commons/collections4/list/PredicatedListTest.java index cc80cd366b..80880d077f 100644 --- a/src/test/java/org/apache/commons/collections4/list/PredicatedListTest.java +++ b/src/test/java/org/apache/commons/collections4/list/PredicatedListTest.java @@ -59,7 +59,7 @@ public E[] getFullElements() { } protected Predicate testPredicate = - o -> o instanceof String; + String.class::isInstance; public List makeTestList() { return decorateList(new ArrayList<>(), testPredicate); diff --git a/src/test/java/org/apache/commons/collections4/map/PredicatedMapTest.java b/src/test/java/org/apache/commons/collections4/map/PredicatedMapTest.java index 1b9968b859..3ceed1f2aa 100644 --- a/src/test/java/org/apache/commons/collections4/map/PredicatedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/PredicatedMapTest.java @@ -40,7 +40,7 @@ public class PredicatedMapTest extends AbstractIterableMapTest { protected static final Predicate truePredicate = TruePredicate.truePredicate(); - protected static final Predicate testPredicate = o -> o instanceof String; + protected static final Predicate testPredicate = String.class::isInstance; public PredicatedMapTest() { super(PredicatedMapTest.class.getSimpleName()); diff --git a/src/test/java/org/apache/commons/collections4/map/PredicatedSortedMapTest.java b/src/test/java/org/apache/commons/collections4/map/PredicatedSortedMapTest.java index 51e7d50c1a..dfb6c95432 100644 --- a/src/test/java/org/apache/commons/collections4/map/PredicatedSortedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/PredicatedSortedMapTest.java @@ -52,7 +52,7 @@ public int compare(final K arg0, final K arg1) { protected static final Predicate truePredicate = TruePredicate.truePredicate(); - protected static final Predicate testPredicate = o -> o instanceof String; + protected static final Predicate testPredicate = String.class::isInstance; protected final Comparator reverseStringComparator = new ReverseStringComparator(); diff --git a/src/test/java/org/apache/commons/collections4/multiset/PredicatedMultiSetTest.java b/src/test/java/org/apache/commons/collections4/multiset/PredicatedMultiSetTest.java index 3f4a5bcac7..b12ef5315b 100644 --- a/src/test/java/org/apache/commons/collections4/multiset/PredicatedMultiSetTest.java +++ b/src/test/java/org/apache/commons/collections4/multiset/PredicatedMultiSetTest.java @@ -41,7 +41,7 @@ public PredicatedMultiSetTest() { } protected Predicate stringPredicate() { - return o -> o instanceof String; + return String.class::isInstance; } protected Predicate truePredicate = TruePredicate.truePredicate(); diff --git a/src/test/java/org/apache/commons/collections4/queue/PredicatedQueueTest.java b/src/test/java/org/apache/commons/collections4/queue/PredicatedQueueTest.java index 46ee5413b2..c5f7eda0b8 100644 --- a/src/test/java/org/apache/commons/collections4/queue/PredicatedQueueTest.java +++ b/src/test/java/org/apache/commons/collections4/queue/PredicatedQueueTest.java @@ -70,7 +70,7 @@ public Collection makeConfirmedFullCollection() { return list; } - protected Predicate testPredicate = o -> o instanceof String; + protected Predicate testPredicate = String.class::isInstance; public Queue makeTestQueue() { return decorateCollection(new LinkedList<>(), testPredicate); diff --git a/src/test/java/org/apache/commons/collections4/set/PredicatedSetTest.java b/src/test/java/org/apache/commons/collections4/set/PredicatedSetTest.java index afba189e22..8c572d79e6 100644 --- a/src/test/java/org/apache/commons/collections4/set/PredicatedSetTest.java +++ b/src/test/java/org/apache/commons/collections4/set/PredicatedSetTest.java @@ -57,7 +57,7 @@ public E[] getFullElements() { } protected Predicate testPredicate = - o -> o instanceof String; + String.class::isInstance; protected PredicatedSet makeTestSet() { return decorateSet(new HashSet<>(), testPredicate);