From 3071aea62de6caa0416e873b3930d08f3c703cc7 Mon Sep 17 00:00:00 2001 From: Alex Herbert Date: Sat, 5 Nov 2022 22:06:15 +0000 Subject: [PATCH] Bloom filter code clean-up Correct whitespace issues. Javadoc additions and corrections. --- .../bloomfilter/BitCountProducer.java | 6 +- .../collections4/bloomfilter/BitMap.java | 4 +- .../bloomfilter/BitMapProducer.java | 10 +-- .../collections4/bloomfilter/BloomFilter.java | 6 +- .../bloomfilter/CountingBloomFilter.java | 10 +-- .../bloomfilter/CountingLongPredicate.java | 2 +- .../bloomfilter/EnhancedDoubleHasher.java | 4 +- .../collections4/bloomfilter/Hasher.java | 2 +- .../bloomfilter/HasherCollection.java | 4 +- .../collections4/bloomfilter/IndexFilter.java | 2 +- .../bloomfilter/IndexProducer.java | 6 +- .../bloomfilter/SetOperations.java | 2 +- .../collections4/bloomfilter/Shape.java | 2 +- .../bloomfilter/SimpleBloomFilter.java | 2 +- .../bloomfilter/package-info.java | 2 +- .../bloomfilter/AbstractBloomFilterTest.java | 18 ++-- .../AbstractCountingBloomFilterTest.java | 18 ++-- .../bloomfilter/AbstractHasherTest.java | 11 ++- .../AbstractIndexProducerTest.java | 8 +- ...romAbsoluteUniqueHasherCollectionTest.java | 3 +- ...ducerFromArrayCountingBloomFilterTest.java | 4 +- ...CountProducerFromHasherCollectionTest.java | 4 +- .../BitCountProducerFromHasherTest.java | 4 +- ...ountProducerFromSimpleBloomFilterTest.java | 2 +- ...ountProducerFromSparseBloomFilterTest.java | 2 +- ...roducerFromUniqueHasherCollectionTest.java | 4 +- .../BitCountProducerFromUniqueHasherTest.java | 2 +- .../BitMapProducerFromLongArrayTest.java | 2 +- .../DefaultBitCountProducerTest.java | 4 +- .../DefaultBitMapProducerTest.java | 8 +- .../bloomfilter/DefaultBloomFilterTest.java | 10 +-- .../bloomfilter/EnhancedDoubleHasherTest.java | 6 +- .../bloomfilter/HasherCollectionTest.java | 4 +- .../bloomfilter/IndexFilterTest.java | 8 +- .../IndexProducerFromBitmapProducerTest.java | 6 +- .../bloomfilter/IndexProducerTest.java | 4 +- .../bloomfilter/SetOperationsTest.java | 84 +++++++++---------- .../bloomfilter/SimpleBloomFilterTest.java | 1 - .../bloomfilter/SparseBloomFilterTest.java | 6 +- 39 files changed, 149 insertions(+), 138 deletions(-) diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/BitCountProducer.java b/src/main/java/org/apache/commons/collections4/bloomfilter/BitCountProducer.java index e32313c7c..f7a6c8833 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/BitCountProducer.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/BitCountProducer.java @@ -52,7 +52,7 @@ public interface BitCountProducer extends IndexProducer { /** * Performs the given action for each {@code } pair where the count is non-zero. - * Any exceptions thrown by the action are relayed to the caller. The consumer is applied to each + * Any exceptions thrown by the action are relayed to the caller. The consumer is applied to each * index-count pair, if the consumer returns {@code false} the execution is stopped, {@code false} * is returned, and no further pairs are processed. * @@ -74,7 +74,7 @@ public interface BitCountProducer extends IndexProducer { } /** - * Creates a BitCountProducer from an IndexProducer. The resulting + * Creates a BitCountProducer from an IndexProducer. The resulting * producer will return every index from the IndexProducer with a count of 1. * *

Note that the BitCountProducer does not remove duplicates. Any use of the @@ -119,7 +119,7 @@ public interface BitCountProducer extends IndexProducer { * * @param index the bit index. * @param count the count at the specified bit index. - * @return {@code true} if processing should continue, {@code false} it processing should stop. + * @return {@code true} if processing should continue, {@code false} if processing should stop. */ boolean test(int index, int count); } diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/BitMap.java b/src/main/java/org/apache/commons/collections4/bloomfilter/BitMap.java index f6f744ef7..d6e1c11ee 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/BitMap.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/BitMap.java @@ -19,8 +19,8 @@ package org.apache.commons.collections4.bloomfilter; /** * Contains functions to convert {@code int} indices into Bloom filter bit positions and visa versa. * - *

The functions view an array of longs as a collection of bit maps each containing 64 bits. The bits are arranged - * in memory as a little-endian long value. This matches the requirements of the BitMapProducer interface.

+ *

The functions view an array of longs as a collection of bit maps each containing 64 bits. The bits are arranged + * in memory as a little-endian long value. This matches the requirements of the BitMapProducer interface.

* * @since 4.5 */ diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/BitMapProducer.java b/src/main/java/org/apache/commons/collections4/bloomfilter/BitMapProducer.java index 542447e60..768bb108b 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/BitMapProducer.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/BitMapProducer.java @@ -39,7 +39,7 @@ import java.util.function.LongPredicate; public interface BitMapProducer { /** - * Each bit map is passed to the predicate in order. The predicate is applied to each + * Each bit map is passed to the predicate in order. The predicate is applied to each * bit map value, if the predicate returns {@code false} the execution is stopped, {@code false} * is returned, and no further bit maps are processed. * @@ -54,11 +54,11 @@ public interface BitMapProducer { boolean forEachBitMap(LongPredicate predicate); /** - * Applies the {@code func} to each bit map pair in order. Will apply all of the bit maps from the other - * BitMapProducer to this producer. If this producer does not have as many bit maps it will provide 0 (zero) + * Applies the {@code func} to each bit map pair in order. Will apply all of the bit maps from the other + * BitMapProducer to this producer. If this producer does not have as many bit maps it will provide 0 (zero) * for all excess calls to the LongBiPredicate. *

- * The default implementation of this method uses {@code asBitMapArray()} It is recommended that implementations + * The default implementation of this method uses {@code asBitMapArray()}. It is recommended that implementations * of BitMapProducer that have local arrays reimplement this method.

* * @param other The other BitMapProducer that provides the y values in the (x,y) pair. @@ -73,7 +73,7 @@ public interface BitMapProducer { /** * Return a copy of the BitMapProducer data as a bit map array. *

- * The default implementation of this method is slow. It is recommended + * The default implementation of this method is slow. It is recommended * that implementing classes reimplement this method. *

* @return An array of bit map data. 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 f939538b0..8174df2a3 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilter.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilter.java @@ -32,8 +32,8 @@ public interface BloomFilter extends IndexProducer, BitMapProducer { /** * The sparse characteristic used to determine the best method for matching. *

For `sparse` implementations - * the {@code forEachIndex(IntConsumer consumer)} method is more efficient. For non `sparse` implementations - * the {@code forEachBitMap(LongConsumer consumer)} is more efficient. Implementers should determine if it is easier + * the {@code forEachIndex(IntConsumer consumer)} method is more efficient. For non `sparse` implementations + * the {@code forEachBitMap(LongConsumer consumer)} is more efficient. Implementers should determine if it is easier * for the implementation to produce indexes of bit map blocks.

*/ int SPARSE = 0x1; @@ -136,7 +136,7 @@ public interface BloomFilter extends IndexProducer, BitMapProducer { * @return true if the merge was successful */ default boolean merge(BloomFilter other) { - return (characteristics() & SPARSE) != 0 ? merge((IndexProducer) other ) : merge((BitMapProducer) other); + return (characteristics() & SPARSE) != 0 ? merge((IndexProducer) other) : merge((BitMapProducer) other); } /** 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 1d6f65cf5..314ac1701 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilter.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilter.java @@ -82,7 +82,7 @@ public interface CountingBloomFilter extends BloomFilter, BitCountProducer { /** * Merges the specified Bloom filter into this Bloom filter. * - *

Specifically: all counts for the indexes identified by the {@code other} filter will be incremented by 1,

+ *

Specifically: all counts for the indexes identified by the {@code other} filter will be incremented by 1.

* *

Note: If the other filter is a counting Bloom filter the index counts are ignored and it is treated as an * IndexProducer.

@@ -102,7 +102,7 @@ public interface CountingBloomFilter extends BloomFilter, BitCountProducer { /** * Merges the specified Hasher into this Bloom filter. * - *

Specifically: all counts for the unique indexes identified by the {@code hasher} will be incremented by 1,

+ *

Specifically: all counts for the unique indexes identified by the {@code hasher} will be incremented by 1.

* *

This method will return {@code true} if the filter is valid after the operation.

* @@ -119,7 +119,7 @@ public interface CountingBloomFilter extends BloomFilter, BitCountProducer { /** * Merges the specified index producer into this Bloom filter. * - *

Specifically: all counts for the indexes identified by the {@code indexProducer} will be incremented by 1,

+ *

Specifically: all counts for the indexes identified by the {@code indexProducer} will be incremented by 1.

* *

This method will return {@code true} if the filter is valid after the operation.

* @@ -143,7 +143,7 @@ public interface CountingBloomFilter extends BloomFilter, BitCountProducer { /** * Merges the specified BitMap producer into this Bloom filter. * - *

Specifically: all counts for the indexes identified by the {@code bitMapProducer} will be incremented by 1,

+ *

Specifically: all counts for the indexes identified by the {@code bitMapProducer} will be incremented by 1.

* *

This method will return {@code true} if the filter is valid after the operation.

* @@ -160,7 +160,7 @@ public interface CountingBloomFilter extends BloomFilter, BitCountProducer { /** * Removes the specified Bloom filter from this Bloom filter. * - *

Specifically: all counts for the indexes identified by the {@code other} filter will be decremented by 1,

+ *

Specifically: all counts for the indexes identified by the {@code other} filter will be decremented by 1.

* *

Note: If the other filter is a counting Bloom filter the index counts are ignored and it is treated as an * IndexProducer.

diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/CountingLongPredicate.java b/src/main/java/org/apache/commons/collections4/bloomfilter/CountingLongPredicate.java index 2611ae444..6acb3900d 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/CountingLongPredicate.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/CountingLongPredicate.java @@ -32,7 +32,7 @@ class CountingLongPredicate implements LongPredicate { /** * Constructs an instance that will compare the elements in @{code ary} with the elements returned by @{code func}. - * function is called as @{code func.test( idxValue, otherValue )}. if there are more @{code otherValue} values than + * function is called as @{code func.test( idxValue, otherValue )}. If there are more @{code otherValue} values than * @{code idxValues} then @{code func} is called as @{code func.test( 0, otherValue )}. * @param ary The array of long values to compare. * @param func The function to apply to the pairs of long values. diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/EnhancedDoubleHasher.java b/src/main/java/org/apache/commons/collections4/bloomfilter/EnhancedDoubleHasher.java index 347a951a3..a559b6902 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/EnhancedDoubleHasher.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/EnhancedDoubleHasher.java @@ -68,7 +68,7 @@ public class EnhancedDoubleHasher implements Hasher { int shift = Long.SIZE; final int end = offset + Math.min(len, Long.BYTES); for (int i = offset; i < end; i++) { - shift -= Byte.SIZE; + shift -= Byte.SIZE; val |= ((long) (byteArray[i] & 0xFF) << shift); } return val; @@ -104,7 +104,7 @@ public class EnhancedDoubleHasher implements Hasher { } /** - * Constructs the EnhancedDoubleHasher from 2 longs. The long values will be interpreted as unsigned values. + * Constructs the EnhancedDoubleHasher from 2 longs. The long values will be interpreted as unsigned values. * @param initial The initial value for the hasher. * @param increment The value to increment the hash by on each iteration. */ diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/Hasher.java b/src/main/java/org/apache/commons/collections4/bloomfilter/Hasher.java index 573532e12..0277535bb 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/Hasher.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/Hasher.java @@ -49,7 +49,7 @@ public interface Hasher { * Creates an IndexProducer of unique indices for this hasher based on the Shape. * *

This is like the `indices(Shape)` method except that it adds the guarantee that no - * duplicate values will be returned. The indices produced are equivalent to those returned + * duplicate values will be returned. The indices produced are equivalent to those returned * from by a Bloom filter created from this hasher.

* * @param shape the shape of the desired Bloom filter. diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/HasherCollection.java b/src/main/java/org/apache/commons/collections4/bloomfilter/HasherCollection.java index 56652ecbf..481cdc84e 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/HasherCollection.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/HasherCollection.java @@ -25,7 +25,7 @@ import java.util.Objects; import java.util.function.IntPredicate; /** - * A collection of Hashers. Useful when the generation of a Bloom filter depends upon + * A collection of Hashers. Useful when the generation of a Bloom filter depends upon * multiple items. *

* Hashers for each item are added to the HasherCollection and then @@ -95,7 +95,7 @@ public class HasherCollection implements Hasher { * hashers. * *

This method may return duplicates if the collection of unique values from each of the contained - * hashers contain duplicates. This is equivalent to creating Bloom filters for each contained hasher + * hashers contain duplicates. This is equivalent to creating Bloom filters for each contained hasher * and returning an IndexProducer with the concatenated output indices from each filter.

* *

A BitCountProducer generated from this IndexProducer is equivalent to a BitCountProducer from a diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/IndexFilter.java b/src/main/java/org/apache/commons/collections4/bloomfilter/IndexFilter.java index 82e110345..65e960a17 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/IndexFilter.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/IndexFilter.java @@ -77,7 +77,7 @@ public final class IndexFilter { /** * An IndexTracker implementation that uses an array of integers to track whether or not a - * number has been seen. Suitable for Shapes that have few hash functions. + * number has been seen. Suitable for Shapes that have few hash functions. * @since 4.5 */ static class ArrayTracker implements IntPredicate { 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 11cb3dd8d..880d4d9d4 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/IndexProducer.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/IndexProducer.java @@ -24,7 +24,7 @@ import java.util.function.LongPredicate; /** * An object that produces indices of a Bloom filter. *

- * The default implementation of {@code asIndexArray} is slow. Implementers should reimplement the + * The default implementation of {@code asIndexArray} is slow. Implementers should reimplement the * method where possible.

* * @since 4.5 @@ -33,7 +33,7 @@ import java.util.function.LongPredicate; public interface IndexProducer { /** - * Each index is passed to the predicate. The predicate is applied to each + * Each index is passed to the predicate. The predicate is applied to each * index value, if the predicate returns {@code false} the execution is stopped, {@code false} * is returned, and no further indices are processed. * @@ -112,7 +112,7 @@ public interface IndexProducer { *

Indices ordering and uniqueness is not guaranteed.

* *

- * The default implementation of this method is slow. It is recommended + * The default implementation of this method is slow. It is recommended * that implementing classes reimplement this method. *

* diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/SetOperations.java b/src/main/java/org/apache/commons/collections4/bloomfilter/SetOperations.java index fa2855971..56df5b79b 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/SetOperations.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/SetOperations.java @@ -44,7 +44,7 @@ public final class SetOperations { } /** - * Calculates the cardinality of a BitMapProducer. By necessity this method will visit each bit map + * Calculates the cardinality of a BitMapProducer. By necessity this method will visit each bit map * created by the producer. * @param producer the Producer to calculate the cardinality for. * @return the cardinality of the bit maps produced by the producer. diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/Shape.java b/src/main/java/org/apache/commons/collections4/bloomfilter/Shape.java index 2632fedac..a3256fe1a 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/Shape.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/Shape.java @@ -149,7 +149,7 @@ public final class Shape { /** * Determines if a cardinality is sparse based on the shape. - *

This method assumes that bit maps are 64bits and indexes are 32bits. If the memory + *

This method assumes that bit maps are 64bits and indexes are 32bits. If the memory * necessary to store the cardinality as indexes is less than the estimated memory for bit maps, * the cardinality is determined to be {@code sparse}.

* @param cardinality the cardinality to check. diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/SimpleBloomFilter.java b/src/main/java/org/apache/commons/collections4/bloomfilter/SimpleBloomFilter.java index df5ee707b..0607a83b2 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/SimpleBloomFilter.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/SimpleBloomFilter.java @@ -29,7 +29,7 @@ import java.util.function.LongPredicate; public final class SimpleBloomFilter implements BloomFilter { /** - * The array of bit map longs that defines this Bloom filter. Will be null if the filter is empty. + * The array of bit map longs that defines this Bloom filter. Will be null if the filter is empty. */ private final long[] bitMap; diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/package-info.java b/src/main/java/org/apache/commons/collections4/bloomfilter/package-info.java index 36d6ce916..a8d18c8c2 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/package-info.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/package-info.java @@ -35,7 +35,7 @@ *

BloomFilter

* *

The Bloom filter architecture here is designed for speed of execution, so some methods like {@code merge}, {@code remove}, - * {@code add}, and {@code subtract} may throw exceptions. Once an exception is thrown the state of the Bloom filter is unknown. + * {@code add}, and {@code subtract} may throw exceptions. Once an exception is thrown the state of the Bloom filter is unknown. * The choice to use not use atomic transactions was made to achieve maximum performance under correct usage.

* *

In addition the architecture is designed so that the implementation of the storage of bits is abstracted. 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 cc196a00a..976ed1673 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilterTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilterTest.java @@ -127,7 +127,7 @@ public abstract class AbstractBloomFilterTest { Hasher hasher = new ArrayHasher(expected); f.merge(hasher); // create sorted unique array of expected values - assertArrayEquals(DefaultIndexProducerTest.unique(expected), f.asIndexArray( )); + assertArrayEquals(DefaultIndexProducerTest.unique(expected), f.asIndexArray()); } } @@ -135,7 +135,7 @@ public abstract class AbstractBloomFilterTest { public void testMergeWithBitMapProducer() { for (int i = 0; i < 5; i++) { long[] values = new long[2]; - for (int idx : DefaultIndexProducerTest.generateIntArray(getTestShape().getNumberOfHashFunctions(), getTestShape().getNumberOfBits())) { + for (int idx : DefaultIndexProducerTest.generateIntArray(getTestShape().getNumberOfHashFunctions(), getTestShape().getNumberOfBits())) { BitMap.set(values, idx); } BloomFilter f = createFilter(getTestShape(), BitMapProducer.fromBitMapArray(values)); @@ -175,11 +175,11 @@ public abstract class AbstractBloomFilterTest { // value to large final BloomFilter f1 = createEmptyFilter(getTestShape()); assertThrows(IllegalArgumentException.class, - () -> f1.merge(IndexProducer.fromIndexArray(new int[] { getTestShape().getNumberOfBits() }))); + () -> f1.merge(IndexProducer.fromIndexArray(new int[] {getTestShape().getNumberOfBits()}))); // negative value final BloomFilter f2 = createEmptyFilter(getTestShape()); assertThrows(IllegalArgumentException.class, - () -> f2.merge(IndexProducer.fromIndexArray(new int[] { -1 }))); + () -> f2.merge(IndexProducer.fromIndexArray(new int[] {-1}))); } @Test @@ -391,13 +391,13 @@ public abstract class AbstractBloomFilterTest { public void testIndexProducerMerge() { Shape shape = Shape.fromKM(5, 10); - assertIndexProducerMerge(shape, new int[] { 0, 2, 4, 6, 8 }, new int[] { 0, 2, 4, 6, 8 }); + assertIndexProducerMerge(shape, new int[] {0, 2, 4, 6, 8}, new int[] {0, 2, 4, 6, 8}); // test duplicate values - assertIndexProducerMerge(shape, new int[] { 0, 2, 4, 2, 8 }, new int[] { 0, 2, 4, 8 }); + assertIndexProducerMerge(shape, new int[] {0, 2, 4, 2, 8}, new int[] {0, 2, 4, 8}); // test negative values - assertFailedIndexProducerConstructor(shape, new int[] { 0, 2, 4, -2, 8 }); + assertFailedIndexProducerConstructor(shape, new int[] {0, 2, 4, -2, 8}); // test index too large - assertFailedIndexProducerConstructor(shape, new int[] { 0, 2, 4, 12, 8 }); + assertFailedIndexProducerConstructor(shape, new int[] {0, 2, 4, 12, 8}); // test no indices assertIndexProducerMerge(shape, new int[0], new int[0]); } @@ -427,7 +427,7 @@ public abstract class AbstractBloomFilterTest { IndexProducer producer; BadHasher(int value) { - this.producer = IndexProducer.fromIndexArray(new int[] { value }); + this.producer = IndexProducer.fromIndexArray(new int[] {value}); } @Override 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 48fbd92f4..7fda48a45 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractCountingBloomFilterTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractCountingBloomFilterTest.java @@ -31,11 +31,11 @@ import org.junit.jupiter.api.Test; */ public abstract class AbstractCountingBloomFilterTest extends AbstractBloomFilterTest { - protected int[] from1Counts = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 }; - protected int[] from11Counts = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 0 }; - protected int[] bigHashCounts = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 0 }; + protected int[] from1Counts = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}; + protected int[] from11Counts = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0}; + protected int[] bigHashCounts = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 0}; protected final BitCountProducer maximumValueProducer = new BitCountProducer() { @@ -191,7 +191,7 @@ public abstract class AbstractCountingBloomFilterTest bf6.remove(ip2)); + assertThrows(IllegalArgumentException.class, () -> bf6.remove(ip2)); final CountingBloomFilter bf7 = createFilter(getTestShape(), from1); final BitMapProducer bmp2 = BitMapProducer.fromIndexProducer(ip2, getTestShape().getNumberOfBits()); - assertThrows( IllegalArgumentException.class, () -> bf7.remove(bmp2)); + assertThrows(IllegalArgumentException.class, () -> bf7.remove(bmp2)); } @Test diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractHasherTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractHasherTest.java index 9b3d4a577..b2f30037a 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractHasherTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractHasherTest.java @@ -29,7 +29,7 @@ public abstract class AbstractHasherTest extends AbstractIndexProducerTest { protected abstract Hasher createEmptyHasher(); /** - * A method to get the number of items in a hasher. Mostly applies to + * A method to get the number of items in a hasher. Mostly applies to * Collections of hashers. * @param hasher the hasher to check. * @return the number of hashers in the hasher @@ -59,9 +59,14 @@ public abstract class AbstractHasherTest extends AbstractIndexProducerTest { } @ParameterizedTest - @CsvSource({ "17, 72", "3, 14", "5, 67868", "75, 10"}) + @CsvSource({ + "17, 72", + "3, 14", + "5, 67868", + "75, 10" + }) public void testHashing(int k, int m) { - int[] count = { 0 }; + int[] count = {0}; Hasher hasher = createHasher(); hasher.indices(Shape.fromKM(k, m)).forEachIndex(i -> { assertTrue(i >= 0 && i < m, () -> "Out of range: " + i + ", m=" + m); 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 5a4b4498b..0cee07101 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractIndexProducerTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractIndexProducerTest.java @@ -33,9 +33,9 @@ public abstract class AbstractIndexProducerTest { private static final IntPredicate TRUE_PREDICATE = i -> true; private static final IntPredicate FALSE_PREDICATE = i -> false; - /** Flag to indicate the {@link IndexProducer#forEachIndex(IntPredicate)} is ordered. */ + /** Flag to indicate the indices are ordered, e.g. from {@link IndexProducer#forEachIndex(IntPredicate)}. */ protected static final int ORDERED = 0x1; - /** Flag to indicate the {@link IndexProducer#forEachIndex(IntPredicate)} is distinct. */ + /** Flag to indicate the indices are distinct, e.g. from {@link IndexProducer#forEachIndex(IntPredicate)}. */ protected static final int DISTINCT = 0x2; /** @@ -84,6 +84,8 @@ public abstract class AbstractIndexProducerTest { /** * Gets the behaviour of the {@link IndexProducer#asIndexArray()} method. * @return the behaviour. + * @see #ORDERED + * @see #DISTINCT */ protected abstract int getAsIndexArrayBehaviour(); @@ -91,6 +93,8 @@ public abstract class AbstractIndexProducerTest { * Gets the behaviour of the {@link IndexProducer#forEachIndex(IntPredicate)} method. * By default returns the value of {@code getAsIndexArrayBehaviour()} method. * @return the behaviour. + * @see #ORDERED + * @see #DISTINCT */ protected int getForEachIndexBehaviour() { return getAsIndexArrayBehaviour(); diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromAbsoluteUniqueHasherCollectionTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromAbsoluteUniqueHasherCollectionTest.java index a61c80aef..47a6299df 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromAbsoluteUniqueHasherCollectionTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromAbsoluteUniqueHasherCollectionTest.java @@ -16,7 +16,6 @@ */ package org.apache.commons.collections4.bloomfilter; - public class BitCountProducerFromAbsoluteUniqueHasherCollectionTest extends AbstractBitCountProducerTest { @Override @@ -39,6 +38,6 @@ public class BitCountProducerFromAbsoluteUniqueHasherCollectionTest extends Abst @Override protected int[] getExpectedIndices() { - return new int[]{1, 2, 3, 4, 5, 7, 9}; + return new int[] {1, 2, 3, 4, 5, 7, 9}; } } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromArrayCountingBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromArrayCountingBloomFilterTest.java index 340e8146c..5add47c24 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromArrayCountingBloomFilterTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromArrayCountingBloomFilterTest.java @@ -41,13 +41,13 @@ public class BitCountProducerFromArrayCountingBloomFilterTest extends AbstractBi @Override protected int[][] getExpectedBitCount() { - return new int[][]{{0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 2}, {6, 2}, {7, 2}, + return new int[][] {{0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 2}, {6, 2}, {7, 2}, {8, 2}, {9, 2}, {10, 2}, {11, 2}, {12, 2}, {13, 2}, {14, 2}, {15, 2}, {16, 2}, {17, 1}, {18, 1}, {19, 1}, {20, 1}, {21, 1}}; } @Override protected int[] getExpectedIndices() { - return new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21}; + return new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21}; } } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromHasherCollectionTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromHasherCollectionTest.java index a8c84492c..d339add48 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromHasherCollectionTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromHasherCollectionTest.java @@ -38,13 +38,13 @@ public class BitCountProducerFromHasherCollectionTest extends AbstractBitCountPr @Override protected int[] getExpectedIndices() { - return new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + return new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 2, 9, 16, 23, 30, 37, 44, 51, 58, 65, 0, 7, 14, 21, 28, 35, 42}; } @Override protected int[][] getExpectedBitCount() { - return new int[][]{{0, 2}, {1, 1}, {2, 2}, {3, 1}, {4, 1}, {5, 1}, {6, 1}, {7, 2}, {8, 1}, + return new int[][] {{0, 2}, {1, 1}, {2, 2}, {3, 1}, {4, 1}, {5, 1}, {6, 1}, {7, 2}, {8, 1}, {9, 2}, {10, 1}, {11, 1}, {12, 1}, {13, 1}, {14, 2}, {15, 1}, {16, 2}, {21, 1}, {23, 1}, {28, 1}, {30, 1}, {35, 1}, {37, 1}, {42, 1}, {44, 1}, {51, 1}, {58, 1}, {65, 1} }; } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromHasherTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromHasherTest.java index 6c382ea25..8c1e84698 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromHasherTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromHasherTest.java @@ -37,11 +37,11 @@ public class BitCountProducerFromHasherTest extends AbstractBitCountProducerTest @Override protected int[] getExpectedIndices() { - return new int[]{4, 12, 20, 28, 36, 44, 52, 60, 68, 4, 12, 20, 28, 36, 44, 52, 60}; + return new int[] {4, 12, 20, 28, 36, 44, 52, 60, 68, 4, 12, 20, 28, 36, 44, 52, 60}; } @Override protected int[][] getExpectedBitCount() { - return new int[][]{{4, 2}, {12, 2}, {20, 2}, {28, 2}, {36, 2}, {44, 2}, {52, 2}, {60, 2}, {68, 1}}; + return new int[][] {{4, 2}, {12, 2}, {20, 2}, {28, 2}, {36, 2}, {44, 2}, {52, 2}, {60, 2}, {68, 1}}; } } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromSimpleBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromSimpleBloomFilterTest.java index f4bc102cb..f366452f6 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromSimpleBloomFilterTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromSimpleBloomFilterTest.java @@ -41,6 +41,6 @@ public class BitCountProducerFromSimpleBloomFilterTest extends AbstractBitCountP @Override protected int[] getExpectedIndices() { - return new int[]{3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35}; + return new int[] {3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35}; } } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromSparseBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromSparseBloomFilterTest.java index 2e26cbc04..4b9ed0e0a 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromSparseBloomFilterTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromSparseBloomFilterTest.java @@ -43,6 +43,6 @@ public class BitCountProducerFromSparseBloomFilterTest extends AbstractBitCountP @Override protected int[] getExpectedIndices() { - return new int[]{2, 4, 9, 11, 16, 18, 23, 25, 30, 32, 37, 39, 44, 46, 53, 60, 67}; + return new int[] {2, 4, 9, 11, 16, 18, 23, 25, 30, 32, 37, 39, 44, 46, 53, 60, 67}; } } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromUniqueHasherCollectionTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromUniqueHasherCollectionTest.java index 9602e3324..f854f68f9 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromUniqueHasherCollectionTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromUniqueHasherCollectionTest.java @@ -39,11 +39,11 @@ public class BitCountProducerFromUniqueHasherCollectionTest extends AbstractBitC @Override protected int[] getExpectedIndices() { - return new int[]{1, 2, 3, 4, 5, 7, 9, 1, 3, 5}; + return new int[] {1, 2, 3, 4, 5, 7, 9, 1, 3, 5}; } @Override protected int[][] getExpectedBitCount() { - return new int[][]{{1, 2}, {2, 1}, {3, 2}, {4, 1}, {5, 2}, {7, 1}, {9, 1}}; + return new int[][] {{1, 2}, {2, 1}, {3, 2}, {4, 1}, {5, 2}, {7, 1}, {9, 1}}; } } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromUniqueHasherTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromUniqueHasherTest.java index 0910249b6..18e7f7936 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromUniqueHasherTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BitCountProducerFromUniqueHasherTest.java @@ -37,6 +37,6 @@ public class BitCountProducerFromUniqueHasherTest extends AbstractBitCountProduc @Override protected int[] getExpectedIndices() { - return new int[]{4, 12, 20, 28, 36, 44, 52, 60, 68}; + return new int[] {4, 12, 20, 28, 36, 44, 52, 60, 68}; } } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromLongArrayTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromLongArrayTest.java index 77bc6ed45..64f7a7be6 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromLongArrayTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromLongArrayTest.java @@ -28,7 +28,7 @@ public class BitMapProducerFromLongArrayTest extends AbstractBitMapProducerTest @Override protected BitMapProducer createProducer() { - long[] ary = new long[] { 1L, 2L, 3L, 4L, 5L }; + long[] ary = new long[] {1L, 2L, 3L, 4L, 5L}; return BitMapProducer.fromBitMapArray(ary); } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBitCountProducerTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBitCountProducerTest.java index 0dac74e03..52268cdb0 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBitCountProducerTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBitCountProducerTest.java @@ -59,13 +59,13 @@ public class DefaultBitCountProducerTest extends AbstractBitCountProducerTest { @Override protected int getForEachIndexBehaviour() { - // the default method has the same behaviour as the forEachCount() method. + // The default method has the same behaviour as the forEachCount() method. return 0; } @Override protected int getForEachCountBehaviour() { - // the implemented mehtod returns unordered duplicates. + // The implemented method returns unordered duplicates. return 0; } } 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 8a0372258..dcf25d3db 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBitMapProducerTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBitMapProducerTest.java @@ -26,7 +26,7 @@ import org.junit.jupiter.api.Test; public class DefaultBitMapProducerTest extends AbstractBitMapProducerTest { - long[] values = generateLongArray( 5 ); + long[] values = generateLongArray(5); @Override protected BitMapProducer createProducer() { @@ -76,15 +76,15 @@ public class DefaultBitMapProducerTest extends AbstractBitMapProducerTest { IndexProducer ip = IndexProducer.fromIndexArray(expected); long[] ary = BitMapProducer.fromIndexProducer(ip, 256).asBitMapArray(); for (int idx : expected) { - assertTrue( BitMap.contains(ary, idx)); + assertTrue(BitMap.contains(ary, idx)); } } @Test public void testFromBitMapArray() { int nOfBitMaps = BitMap.numberOfBitMaps(256); - long[] expected = generateLongArray( nOfBitMaps ); + long[] expected = generateLongArray(nOfBitMaps); long[] ary = BitMapProducer.fromBitMapArray(expected).asBitMapArray(); - assertArrayEquals( expected, ary ); + 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 eb23d84a3..4da638535 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBloomFilterTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBloomFilterTest.java @@ -42,7 +42,6 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest= shape.getNumberOfBits()) { - throw new IllegalArgumentException(String.format("Value in list %s is greater than maximum value (%s)", - indices.last(), shape.getNumberOfBits())); + throw new IllegalArgumentException( + String.format("Value in list %s is greater than maximum value (%s)", indices.last(), + shape.getNumberOfBits())); } if (indices.first() < 0) { throw new IllegalArgumentException( - String.format("Value in list %s is less than 0", indices.first())); + String.format("Value in list %s is less than 0", indices.first())); } } } @@ -136,7 +136,7 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest String.format("failure with dividend=%s and divisor=%s.", dividend, divisor)); } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/HasherCollectionTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/HasherCollectionTest.java index 70e82446a..53c57f48a 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/HasherCollectionTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/HasherCollectionTest.java @@ -37,8 +37,8 @@ public class HasherCollectionTest extends AbstractHasherTest { @Override protected int[] getExpectedIndices() { - return new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 2, 4, 6, 8, 10, 12, 14, 16, 18, - 20, 22, 24, 26, 28, 30, 32, 34 }; + return new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 2, 4, 6, 8, 10, 12, 14, 16, 18, + 20, 22, 24, 26, 28, 30, 32, 34}; } @Override diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexFilterTest.java index 8e22c47e0..42ac583d6 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexFilterTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexFilterTest.java @@ -55,7 +55,13 @@ public class IndexFilterTest { } @ParameterizedTest - @CsvSource({ "1, 64", "2, 64", "3, 64", "7, 357", "7, 17", }) + @CsvSource({ + "1, 64", + "2, 64", + "3, 64", + "7, 357", + "7, 17", + }) void testFilter(int k, int m) { Shape shape = Shape.fromKM(k, m); BitSet used = new BitSet(m); diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromBitmapProducerTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromBitmapProducerTest.java index 5eeaaf76b..10c6fdf4d 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromBitmapProducerTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromBitmapProducerTest.java @@ -45,13 +45,13 @@ public class IndexProducerFromBitmapProducerTest extends AbstractIndexProducerTe 3L => ...0011 @formatter:on */ - TestingBitMapProducer producer = new TestingBitMapProducer(new long[] { 1L, 2L, 3L }); + TestingBitMapProducer producer = new TestingBitMapProducer(new long[] {1L, 2L, 3L}); return IndexProducer.fromBitMapProducer(producer); } @Override protected int[] getExpectedIndices() { - return new int[]{0, 65, 128, 129}; + return new int[] {0, 65, 128, 129}; } @Override @@ -72,7 +72,7 @@ public class IndexProducerFromBitmapProducerTest extends AbstractIndexProducerTe assertEquals(Integer.valueOf(0 + 128), lst.get(2)); assertEquals(Integer.valueOf(1 + 128), lst.get(3)); - BitMapProducer producer = new TestingBitMapProducer(new long[] { 0xFFFFFFFFFFFFFFFFL }); + BitMapProducer producer = new TestingBitMapProducer(new long[] {0xFFFFFFFFFFFFFFFFL}); underTest = IndexProducer.fromBitMapProducer(producer); lst = new ArrayList<>(); 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 fc11df639..e9de0f80c 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerTest.java @@ -28,7 +28,7 @@ public class IndexProducerTest { @Test public void fromBitMapProducerTest() { - TestingBitMapProducer producer = new TestingBitMapProducer(new long[] { 1L, 2L, 3L }); + TestingBitMapProducer producer = new TestingBitMapProducer(new long[] {1L, 2L, 3L}); IndexProducer underTest = IndexProducer.fromBitMapProducer(producer); List lst = new ArrayList<>(); @@ -39,7 +39,7 @@ public class IndexProducerTest { assertEquals(Integer.valueOf(0 + 128), lst.get(2)); assertEquals(Integer.valueOf(1 + 128), lst.get(3)); - producer = new TestingBitMapProducer(new long[] { 0xFFFFFFFFFFFFFFFFL }); + producer = new TestingBitMapProducer(new long[] {0xFFFFFFFFFFFFFFFFL}); underTest = IndexProducer.fromBitMapProducer(producer); lst = new ArrayList<>(); 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 98a62604f..246ce83fc 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/SetOperationsTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/SetOperationsTest.java @@ -36,7 +36,6 @@ public class SetOperationsTest { protected final long bigHashValue = 0xFFFFFFEL; private final Shape shape = Shape.fromKM(17, 72); - private static void assertSymmetricOperation(int expected, ToIntBiFunction operation, BloomFilter filter1, BloomFilter filter2) { assertEquals(expected, operation.applyAsInt(filter1, filter2), "op(filter1, filter2)"); @@ -71,7 +70,7 @@ public class SetOperationsTest { BloomFilter filter2 = createFilter(shape, from1); // identical filters should have no distance. - double expected = 0; + double expected = 0; assertSymmetricOperation(expected, SetOperations::cosineDistance, filter1, filter2); Shape shape2 = Shape.fromKM(2, 72); @@ -215,16 +214,16 @@ public class SetOperationsTest { @Test public final void testOrCardinality() { 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(new int[] {1, 63, 64})); + BloomFilter filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {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(new int[] {1, 63})); + filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {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(new int[] {5, 63})); + filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69})); assertSymmetricOperation(4, SetOperations::orCardinality, filter1, filter2); } @@ -232,32 +231,32 @@ public class SetOperationsTest { public final void testOrCardinalityWithDifferentLengthFilters() { Shape shape = Shape.fromKM(3, 128); 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(new int[] {1, 63, 64})); + BloomFilter filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {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(new int[] {1, 63})); + filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {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(new int[] {5, 63})); + filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169})); assertSymmetricOperation(4, SetOperations::orCardinality, filter1, filter2); } @Test public final void testAndCardinality() { 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(new int[] {1, 63, 64})); + BloomFilter filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {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(new int[] {1, 63})); + filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {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(new int[] {5, 63})); + filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69})); assertSymmetricOperation(1, SetOperations::andCardinality, filter1, filter2); } @@ -265,37 +264,37 @@ public class SetOperationsTest { public final void testAndCardinalityWithDifferentLengthFilters() { Shape shape = Shape.fromKM(3, 128); 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(new int[] {1, 63, 64})); + BloomFilter filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {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(new int[] {1, 63})); + filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {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(new int[] {5, 63})); + filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169})); assertSymmetricOperation(1, SetOperations::andCardinality, filter1, filter2); } @Test public final void testXorCardinality() { 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(new int[] {1, 63, 64})); + BloomFilter filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {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(new int[] {1, 63})); + filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {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(new int[] {5, 63})); + filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69})); assertSymmetricOperation(3, SetOperations::xorCardinality, filter1, filter2); 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(new int[] {1, 63, 185})); + filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 63, 69})); assertSymmetricOperation(4, SetOperations::xorCardinality, filter1, filter2); } @@ -304,24 +303,23 @@ public class SetOperationsTest { Shape shape = Shape.fromKM(3, 128); 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(new int[] {1, 63, 64})); + BloomFilter filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {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(new int[] {1, 63})); + filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {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(new int[] {5, 63})); + filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169})); assertSymmetricOperation(3, SetOperations::xorCardinality, filter1, filter2); } - @Test public final void testCommutativityOnMismatchedSizes() { - BitMapProducer p1 = BitMapProducer.fromBitMapArray(new long[] { 0x3L, 0x5L }); - BitMapProducer p2 = BitMapProducer.fromBitMapArray(new long[] { 0x1L }); + BitMapProducer p1 = BitMapProducer.fromBitMapArray(new long[] {0x3L, 0x5L}); + BitMapProducer p2 = BitMapProducer.fromBitMapArray(new long[] {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 b37c0ffe8..b4b4014ee 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/SimpleBloomFilterTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/SimpleBloomFilterTest.java @@ -16,7 +16,6 @@ */ package org.apache.commons.collections4.bloomfilter; - /** * Tests for the {@link SimpleBloomFilter}. */ diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/SparseBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/SparseBloomFilterTest.java index 95484d967..adfff8909 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/SparseBloomFilterTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/SparseBloomFilterTest.java @@ -33,7 +33,7 @@ public class SparseBloomFilterTest extends AbstractBloomFilterTest { @@ -68,7 +68,7 @@ public class SparseBloomFilterTest extends AbstractBloomFilterTest {