You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/05/28 14:00:25 UTC
(commons-collections) branch master updated: [COLLECTIONS-854] renaming bloomfilter components and methods as per ticket (#492)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-collections.git
The following commit(s) were added to refs/heads/master by this push:
new 4a2aa76d4 [COLLECTIONS-854] renaming bloomfilter components and methods as per ticket (#492)
4a2aa76d4 is described below
commit 4a2aa76d4bafd3ac7992844aa15dbcabd76b26d8
Author: Claude Warren <cl...@apache.org>
AuthorDate: Tue May 28 15:00:20 2024 +0100
[COLLECTIONS-854] renaming bloomfilter components and methods as per ticket (#492)
* Changed BitMap to BitMaps and CellConsumer to CellPredicate
* Renamed IndexProducer to IndexExtractor
* Renamed BitmapProducer to BitMapExtractor
* Renamed BitmapProducer to BitMapExtractor and BloomFilterProducer to BloomFilterExtractor
* change forEachBitMap to processBitMap
* change forEachBloomFilter to processBloomFilters
* change processBitMap to processBitMaps
* change forEachCell to processCells
* change forEachIndex to processIndices
* renaming cleanup
* replaced [Pp]roducer with [Ee]xtractor
* changed forEachX to processXs. Updated documentation
* Update package-info.java as per review comments
* Updated as per review
* fixed javadoc
---
.../bloomfilter/ArrayCountingBloomFilter.java | 36 ++---
.../{BitMapProducer.java => BitMapExtractor.java} | 55 ++++----
.../bloomfilter/{BitMap.java => BitMaps.java} | 6 +-
.../collections4/bloomfilter/BloomFilter.java | 58 ++++----
...lterProducer.java => BloomFilterExtractor.java} | 39 +++---
.../{CellProducer.java => CellExtractor.java} | 48 +++----
.../bloomfilter/CountingBloomFilter.java | 150 +++++++++++----------
.../bloomfilter/CountingLongPredicate.java | 8 +-
.../bloomfilter/CountingPredicate.java | 8 +-
.../bloomfilter/EnhancedDoubleHasher.java | 12 +-
.../commons/collections4/bloomfilter/Hasher.java | 10 +-
.../{IndexProducer.java => IndexExtractor.java} | 48 +++----
.../collections4/bloomfilter/IndexFilter.java | 8 +-
.../collections4/bloomfilter/IndexUtils.java | 4 +-
.../collections4/bloomfilter/LayerManager.java | 4 +-
.../bloomfilter/LayeredBloomFilter.java | 85 ++++++------
.../collections4/bloomfilter/SetOperations.java | 88 ++++++------
.../commons/collections4/bloomfilter/Shape.java | 2 +-
.../bloomfilter/SimpleBloomFilter.java | 44 +++---
.../bloomfilter/SparseBloomFilter.java | 38 +++---
.../bloomfilter/WrappedBloomFilter.java | 28 ++--
.../collections4/bloomfilter/package-info.java | 54 ++++++--
...rTest.java => AbstractBitMapExtractorTest.java} | 60 ++++-----
....java => AbstractBloomFilterExtractorTest.java} | 28 ++--
.../bloomfilter/AbstractBloomFilterTest.java | 118 ++++++++--------
...cerTest.java => AbstractCellExtractorTest.java} | 58 ++++----
.../AbstractCountingBloomFilterTest.java | 74 +++++-----
.../bloomfilter/AbstractHasherTest.java | 10 +-
...erTest.java => AbstractIndexExtractorTest.java} | 76 +++++------
.../collections4/bloomfilter/ArrayHasher.java | 10 +-
...ExtractorFromArrayCountingBloomFilterTest.java} | 6 +-
... => BitMapExtractorFromIndexExtractorTest.java} | 30 ++---
...BitMapExtractorFromLayeredBloomFilterTest.java} | 6 +-
....java => BitMapExtractorFromLongArrayTest.java} | 20 +--
... BitMapExtractorFromSimpleBloomFilterTest.java} | 6 +-
... BitMapExtractorFromSparseBloomFilterTest.java} | 6 +-
...BitMapExtractorFromWrappedBloomFilterTest.java} | 6 +-
.../{BitMapTest.java => BitMapsTest.java} | 66 ++++-----
...mFilteExtractorFromLayeredBloomFilterTest.java} | 4 +-
...omFilterExtractorFromBloomFilterArrayTest.java} | 6 +-
...ExtractorFromArrayCountingBloomFilterTest.java} | 6 +-
...ellExtractorFromDefaultIndexExtractorTest.java} | 10 +-
...> CellExtractorFromLayeredBloomFilterTest.java} | 10 +-
.../bloomfilter/CountingPredicateTest.java | 12 +-
...erTest.java => DefaultBitMapExtractorTest.java} | 34 ++---
...t.java => DefaultBloomFilterExtractorTest.java} | 4 +-
.../bloomfilter/DefaultBloomFilterTest.java | 38 +++---
...ucerTest.java => DefaultCellExtractorTest.java} | 6 +-
...cerTest.java => DefaultIndexExtractorTest.java} | 20 +--
.../bloomfilter/IncrementingHasher.java | 12 +-
...ExtractorFromArrayCountingBloomFilterTest.java} | 6 +-
... => IndexExtractorFromBitmapExtractorTest.java} | 34 ++---
...Test.java => IndexExtractorFromHasherTest.java} | 6 +-
...st.java => IndexExtractorFromIntArrayTest.java} | 10 +-
...> IndexExtractorFromSimpleBloomFilterTest.java} | 6 +-
...> IndexExtractorFromSparseBloomFilterTest.java} | 6 +-
...ava => IndexExtractorFromUniqueHasherTest.java} | 6 +-
...exProducerTest.java => IndexExtractorTest.java} | 24 ++--
.../collections4/bloomfilter/LayerManagerTest.java | 6 +-
.../bloomfilter/LayeredBloomFilterTest.java | 36 ++---
.../collections4/bloomfilter/NullHasher.java | 8 +-
.../bloomfilter/SetOperationsTest.java | 84 ++++++------
.../bloomfilter/SimpleBloomFilterTest.java | 8 +-
.../bloomfilter/SparseBloomFilterTest.java | 20 +--
.../collections4/bloomfilter/TestingHashers.java | 2 +-
65 files changed, 937 insertions(+), 900 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 746c5bf6e..aac95f77e 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/ArrayCountingBloomFilter.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/ArrayCountingBloomFilter.java
@@ -46,7 +46,7 @@ import java.util.stream.IntStream;
* consumption of approximately 8 GB.
*
* @see Shape
- * @see CellProducer
+ * @see CellExtractor
* @since 4.5
*/
public final class ArrayCountingBloomFilter implements CountingBloomFilter {
@@ -105,9 +105,9 @@ public final class ArrayCountingBloomFilter implements CountingBloomFilter {
}
@Override
- public boolean add(final CellProducer other) {
+ public boolean add(final CellExtractor other) {
Objects.requireNonNull(other, "other");
- other.forEachCell(this::add);
+ other.processCells(this::add);
return isValid();
}
@@ -151,13 +151,13 @@ public final class ArrayCountingBloomFilter implements CountingBloomFilter {
}
@Override
- public boolean contains(final BitMapProducer bitMapProducer) {
- return contains(IndexProducer.fromBitMapProducer(bitMapProducer));
+ public boolean contains(final BitMapExtractor bitMapExtractor) {
+ return contains(IndexExtractor.fromBitMapExtractor(bitMapExtractor));
}
@Override
- public boolean contains(final IndexProducer indexProducer) {
- return indexProducer.forEachIndex(idx -> this.cells[idx] != 0);
+ public boolean contains(final IndexExtractor indexExtractor) {
+ return indexExtractor.processIndices(idx -> this.cells[idx] != 0);
}
@Override
@@ -166,9 +166,9 @@ public final class ArrayCountingBloomFilter implements CountingBloomFilter {
}
@Override
- public boolean forEachBitMap(final LongPredicate consumer) {
+ public boolean processBitMaps(final LongPredicate consumer) {
Objects.requireNonNull(consumer, "consumer");
- final int blocksm1 = BitMap.numberOfBitMaps(cells.length) - 1;
+ final int blocksm1 = BitMaps.numberOfBitMaps(cells.length) - 1;
int i = 0;
long value;
// must break final block separate as the number of bits may not fall on the long boundary
@@ -176,7 +176,7 @@ public final class ArrayCountingBloomFilter implements CountingBloomFilter {
value = 0;
for (int k = 0; k < Long.SIZE; k++) {
if (cells[i++] != 0) {
- value |= BitMap.getLongBit(k);
+ value |= BitMaps.getLongBit(k);
}
}
if (!consumer.test(value)) {
@@ -187,14 +187,14 @@ public final class ArrayCountingBloomFilter implements CountingBloomFilter {
value = 0;
for (int k = 0; i < cells.length; k++) {
if (cells[i++] != 0) {
- value |= BitMap.getLongBit(k);
+ value |= BitMaps.getLongBit(k);
}
}
return consumer.test(value);
}
@Override
- public boolean forEachCell(final CellProducer.CellConsumer consumer) {
+ public boolean processCells(final CellPredicate consumer) {
Objects.requireNonNull(consumer, "consumer");
for (int i = 0; i < cells.length; i++) {
if (cells[i] != 0 && !consumer.test(i, cells[i])) {
@@ -205,7 +205,7 @@ public final class ArrayCountingBloomFilter implements CountingBloomFilter {
}
@Override
- public boolean forEachIndex(final IntPredicate consumer) {
+ public boolean processIndices(final IntPredicate consumer) {
Objects.requireNonNull(consumer, "consumer");
for (int i = 0; i < cells.length; i++) {
if (cells[i] != 0 && !consumer.test(i)) {
@@ -221,9 +221,9 @@ public final class ArrayCountingBloomFilter implements CountingBloomFilter {
}
@Override
- public int getMaxInsert(final CellProducer cellProducer) {
+ public int getMaxInsert(final CellExtractor cellExtractor) {
final int[] max = {Integer.MAX_VALUE};
- cellProducer.forEachCell( (x, y) -> {
+ cellExtractor.processCells( (x, y) -> {
final int count = cells[x] / y;
if (count < max[0]) {
max[0] = count;
@@ -250,7 +250,7 @@ public final class ArrayCountingBloomFilter implements CountingBloomFilter {
* generated invalid cells can be reversed by using the complement of the
* original operation with the same Bloom filter. This will restore the cells
* to the state prior to the invalid operation. Cells can then be extracted
- * using {@link #forEachCell(CellConsumer)}.</p>
+ * using {@link #processCells(CellPredicate)}.</p>
*/
@Override
public boolean isValid() {
@@ -258,9 +258,9 @@ public final class ArrayCountingBloomFilter implements CountingBloomFilter {
}
@Override
- public boolean subtract(final CellProducer other) {
+ public boolean subtract(final CellExtractor other) {
Objects.requireNonNull(other, "other");
- other.forEachCell(this::subtract);
+ other.processCells(this::subtract);
return isValid();
}
diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/BitMapProducer.java b/src/main/java/org/apache/commons/collections4/bloomfilter/BitMapExtractor.java
similarity index 70%
rename from src/main/java/org/apache/commons/collections4/bloomfilter/BitMapProducer.java
rename to src/main/java/org/apache/commons/collections4/bloomfilter/BitMapExtractor.java
index 6ef8c5ece..84659fc1d 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/BitMapProducer.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/BitMapExtractor.java
@@ -36,22 +36,22 @@ import java.util.function.LongPredicate;
* @since 4.5
*/
@FunctionalInterface
-public interface BitMapProducer {
+public interface BitMapExtractor {
/**
- * Creates a BitMapProducer from an array of Long.
+ * Creates a BitMapExtractor from an array of Long.
* @param bitMaps the bit maps to return.
- * @return a BitMapProducer.
+ * @return a BitMapExtractor.
*/
- static BitMapProducer fromBitMapArray(final long... bitMaps) {
- return new BitMapProducer() {
+ static BitMapExtractor fromBitMapArray(final long... bitMaps) {
+ return new BitMapExtractor() {
@Override
public long[] asBitMapArray() {
return Arrays.copyOf(bitMaps, bitMaps.length);
}
@Override
- public boolean forEachBitMap(final LongPredicate predicate) {
+ public boolean processBitMaps(final LongPredicate predicate) {
for (final long word : bitMaps) {
if (!predicate.test(word)) {
return false;
@@ -61,33 +61,32 @@ public interface BitMapProducer {
}
@Override
- public boolean forEachBitMapPair(final BitMapProducer other, final LongBiPredicate func) {
+ public boolean processBitMapPairs(final BitMapExtractor other, final LongBiPredicate func) {
final CountingLongPredicate p = new CountingLongPredicate(bitMaps, func);
- return other.forEachBitMap(p) && p.forEachRemaining();
+ return other.processBitMaps(p) && p.processRemaining();
}
};
}
/**
- * Creates a BitMapProducer from an IndexProducer.
- * @param producer the IndexProducer that specifies the indexes of the bits to enable.
+ * Creates a BitMapExtractor from an IndexExtractor.
+ * @param extractor the IndexExtractor that specifies the indexes of the bits to enable.
* @param numberOfBits the number of bits in the Bloom filter.
- * @return A BitMapProducer that produces the bit maps equivalent of the Indices from the producer.
+ * @return A BitMapExtractor that produces the bit maps equivalent of the Indices from the extractor.
*/
- static BitMapProducer fromIndexProducer(final IndexProducer producer, final int numberOfBits) {
- Objects.requireNonNull(producer, "producer");
- Objects.requireNonNull(numberOfBits, "numberOfBits");
+ static BitMapExtractor fromIndexExtractor(final IndexExtractor extractor, final int numberOfBits) {
+ Objects.requireNonNull(extractor, "extractor");
- final long[] result = new long[BitMap.numberOfBitMaps(numberOfBits)];
- producer.forEachIndex(i -> {
- BitMap.set(result, i);
+ final long[] result = new long[BitMaps.numberOfBitMaps(numberOfBits)];
+ extractor.processIndices(i -> {
+ BitMaps.set(result, i);
return true;
});
return fromBitMapArray(result);
}
/**
- * Return a copy of the BitMapProducer data as a bit map array.
+ * Return a copy of the BitMapExtractor data as a bit map array.
* <p>
* The default implementation of this method is slow. It is recommended
* that implementing classes reimplement this method.
@@ -95,7 +94,7 @@ public interface BitMapProducer {
* @return An array of bit map data.
*/
default long[] asBitMapArray() {
- class Bits {
+ final class Bits {
private long[] data = new long[16];
private int size;
@@ -117,7 +116,7 @@ public interface BitMapProducer {
}
}
final Bits bits = new Bits();
- forEachBitMap(bits::add);
+ processBitMaps(bits::add);
return bits.toArray();
}
@@ -126,7 +125,7 @@ public interface BitMapProducer {
* bit map value, if the predicate returns {@code false} the execution is stopped, {@code false}
* is returned, and no further bit maps are processed.
*
- * <p>If the producer is empty this method will return true.</p>
+ * <p>If the extractor is empty this method will return true.</p>
*
* <p>Any exceptions thrown by the action are relayed to the caller.</p>
*
@@ -134,22 +133,22 @@ public interface BitMapProducer {
* @return {@code true} if all bit maps returned {@code true}, {@code false} otherwise.
* @throws NullPointerException if the specified consumer is null
*/
- boolean forEachBitMap(LongPredicate predicate);
+ boolean processBitMaps(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)
+ * BitMapExtractor to this extractor. If this extractor does not have as many bit maps it will provide 0 (zero)
* for all excess calls to the LongBiPredicate.
* <p>
* <em>The default implementation of this method uses {@code asBitMapArray()}. It is recommended that implementations
- * of BitMapProducer that have local arrays reimplement this method.</em></p>
+ * of BitMapExtractor that have local arrays reimplement this method.</em></p>
*
- * @param other The other BitMapProducer that provides the y values in the (x,y) pair.
+ * @param other The other BitMapExtractor that provides the y values in the (x,y) pair.
* @param func The function to apply.
- * @return A LongPredicate that tests this BitMapProducers bitmap values in order.
+ * @return A LongPredicate that tests this BitMapExtractor's bitmap values in order.
*/
- default boolean forEachBitMapPair(final BitMapProducer other, final LongBiPredicate func) {
+ default boolean processBitMapPairs(final BitMapExtractor other, final LongBiPredicate func) {
final CountingLongPredicate p = new CountingLongPredicate(asBitMapArray(), func);
- return other.forEachBitMap(p) && p.forEachRemaining();
+ return other.processBitMaps(p) && p.processRemaining();
}
}
diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/BitMap.java b/src/main/java/org/apache/commons/collections4/bloomfilter/BitMaps.java
similarity index 98%
rename from src/main/java/org/apache/commons/collections4/bloomfilter/BitMap.java
rename to src/main/java/org/apache/commons/collections4/bloomfilter/BitMaps.java
index 99fd96fd8..f08d3ad19 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/BitMap.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/BitMaps.java
@@ -20,11 +20,11 @@ package org.apache.commons.collections4.bloomfilter;
* Contains functions to convert {@code int} indices into Bloom filter bit positions and visa versa.
*
* <p>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.</p>
+ * in memory as a little-endian long value. This matches the requirements of the BitMapExtractor interface.</p>
*
* @since 4.5
*/
-public class BitMap {
+public class BitMaps {
/** A bit shift to apply to an integer to divided by 64 (2^6). */
private static final int DIVIDE_BY_64 = 6;
@@ -136,6 +136,6 @@ public class BitMap {
}
/** Do not instantiate. */
- private BitMap() {
+ private BitMaps() {
}
}
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 41ec91058..3fcdf6c94 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilter.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilter.java
@@ -21,13 +21,13 @@ import java.util.Objects;
/**
* The interface that describes a Bloom filter.
* <p>
- * <em>See implementation notes for BitMapProducer and IndexProducer.</em>
+ * <em>See implementation notes for BitMapExtractor and IndexExtractor.</em>
* </p>
- * @see BitMapProducer
- * @see IndexProducer
+ * @see BitMapExtractor
+ * @see IndexExtractor
* @since 4.5
*/
-public interface BloomFilter extends IndexProducer, BitMapProducer {
+public interface BloomFilter extends IndexExtractor, BitMapExtractor {
/**
* The sparse characteristic used to determine the best method for matching.
@@ -64,13 +64,13 @@ public interface BloomFilter extends IndexProducer, BitMapProducer {
/**
* Returns {@code true} if this filter contains the bits specified in the bit maps produced by the
- * bitMapProducer.
+ * bitMapExtractor.
*
- * @param bitMapProducer the {@code BitMapProducer} to provide the bit maps.
+ * @param bitMapExtractor the {@code BitMapExtractor} to provide the bit maps.
* @return {@code true} if this filter is enabled for all bits specified by the bit maps
*/
- default boolean contains(final BitMapProducer bitMapProducer) {
- return forEachBitMapPair(bitMapProducer, (x, y) -> (x & y) == y);
+ default boolean contains(final BitMapExtractor bitMapExtractor) {
+ return processBitMapPairs(bitMapExtractor, (x, y) -> (x & y) == y);
}
/**
@@ -86,7 +86,7 @@ public interface BloomFilter extends IndexProducer, BitMapProducer {
*/
default boolean contains(final BloomFilter other) {
Objects.requireNonNull(other, "other");
- return (characteristics() & SPARSE) != 0 ? contains((IndexProducer) other) : contains((BitMapProducer) other);
+ return (characteristics() & SPARSE) != 0 ? contains((IndexExtractor) other) : contains((BitMapExtractor) other);
}
/**
@@ -106,15 +106,15 @@ public interface BloomFilter extends IndexProducer, BitMapProducer {
}
/**
- * Returns {@code true} if this filter contains the indices specified IndexProducer.
+ * Returns {@code true} if this filter contains the indices specified IndexExtractor.
*
* <p>Specifically this returns {@code true} if this filter is enabled for all bit indexes
- * identified by the {@code IndexProducer}.</p>
+ * identified by the {@code IndexExtractor}.</p>
*
- * @param indexProducer the IndexProducer to provide the indexes
- * @return {@code true} if this filter is enabled for all bits specified by the IndexProducer
+ * @param indexExtractor the IndexExtractor to provide the indexes
+ * @return {@code true} if this filter is enabled for all bits specified by the IndexExtractor
*/
- boolean contains(IndexProducer indexProducer);
+ boolean contains(IndexExtractor indexExtractor);
/**
* Creates a new instance of the BloomFilter with the same properties as the current one.
@@ -245,7 +245,7 @@ public interface BloomFilter extends IndexProducer, BitMapProducer {
* @return {@code true} if no bits are enabled, {@code false} otherwise.
*/
default boolean isEmpty() {
- return forEachBitMap(y -> y == 0);
+ return processBitMaps(y -> y == 0);
}
/**
@@ -261,18 +261,18 @@ public interface BloomFilter extends IndexProducer, BitMapProducer {
/**
* Merges the specified hasher into this Bloom filter. Specifically all
- * bit indexes that are identified by the {@code producer} will be enabled in this filter.
+ * bit indexes that are identified by the {@code bitMapExtractor} will be enabled in this filter.
*
* <p><em>Note: This method should return {@code true} even if no additional bit indexes were
* enabled. A {@code false} result indicates that this filter may or may not contain all the indexes
- * enabled in the {@code producer}.</em> This state may occur in complex Bloom filter implementations like
+ * enabled in the {@code bitMapExtractor}.</em> This state may occur in complex Bloom filter implementations like
* counting Bloom filters.</p>
*
- * @param bitMapProducer The producer to merge.
+ * @param bitMapExtractor The BitMapExtractor to merge.
* @return true if the merge was successful
- * @throws IllegalArgumentException if producer sends illegal value.
+ * @throws IllegalArgumentException if bitMapExtractor sends illegal value.
*/
- boolean merge(BitMapProducer bitMapProducer);
+ boolean merge(BitMapExtractor bitMapExtractor);
/**
* Merges the specified Bloom filter into this Bloom filter.
@@ -289,7 +289,7 @@ public interface BloomFilter extends IndexProducer, BitMapProducer {
* @return true if the merge was successful
*/
default boolean merge(final BloomFilter other) {
- return (characteristics() & SPARSE) != 0 ? merge((IndexProducer) other) : merge((BitMapProducer) other);
+ return (characteristics() & SPARSE) != 0 ? merge((IndexExtractor) other) : merge((BitMapExtractor) other);
}
/**
@@ -311,25 +311,25 @@ public interface BloomFilter extends IndexProducer, BitMapProducer {
}
/**
- * Merges the specified IndexProducer into this Bloom filter. Specifically all
- * bit indexes that are identified by the {@code producer} will be enabled in this filter.
+ * Merges the specified IndexExtractor into this Bloom filter. Specifically all
+ * bit indexes that are identified by the {@code indexExtractor} will be enabled in this filter.
*
* <p><em>Note: This method should return {@code true} even if no additional bit indexes were
* enabled. A {@code false} result indicates that this filter may or may not contain all the indexes of
- * the {@code producer}.</em> This state may occur in complex Bloom filter implementations like
+ * the {@code indexExtractor}.</em> This state may occur in complex Bloom filter implementations like
* counting Bloom filters.</p>
*
- * @param indexProducer The IndexProducer to merge.
+ * @param indexExtractor The IndexExtractor to merge.
* @return true if the merge was successful
- * @throws IllegalArgumentException if producer sends illegal value.
+ * @throws IllegalArgumentException if indexExtractor sends illegal value.
*/
- boolean merge(IndexProducer indexProducer);
+ boolean merge(IndexExtractor indexExtractor);
/**
- * Most Bloom filters create unique IndexProducers.
+ * Most Bloom filters create unique IndexExtractors.
*/
@Override
- default IndexProducer uniqueIndices() {
+ default IndexExtractor uniqueIndices() {
return this;
}
}
diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilterProducer.java b/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilterExtractor.java
similarity index 76%
rename from src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilterProducer.java
rename to src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilterExtractor.java
index 280813ff7..7ad82713e 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilterProducer.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilterExtractor.java
@@ -27,10 +27,11 @@ import java.util.function.Predicate;
*
* @since 4.5
*/
-public interface BloomFilterProducer {
+@FunctionalInterface
+public interface BloomFilterExtractor {
/**
- * Creates a BloomFilterProducer from an array of Bloom filters.
+ * Creates a BloomFilterExtractor from an array of Bloom filters.
*
* <ul>
* <li>The asBloomFilterArray() method returns a copy of the original array
@@ -39,12 +40,12 @@ public interface BloomFilterProducer {
* </ul>
* <p><em>All modifications to the Bloom filters are reflected in the original filters</em></p>
*
- * @param filters The filters to be returned by the producer.
- * @return THe BloomFilterProducer containing the filters.
+ * @param filters The filters to be returned by the extractor.
+ * @return THe BloomFilterExtractor containing the filters.
*/
- static BloomFilterProducer fromBloomFilterArray(final BloomFilter... filters) {
+ static BloomFilterExtractor fromBloomFilterArray(final BloomFilter... filters) {
Objects.requireNonNull(filters, "filters");
- return new BloomFilterProducer() {
+ return new BloomFilterExtractor() {
/**
* This implementation returns a copy the original array, the contained Bloom filters
* are references to the originals, any modifications to them are reflected in the original
@@ -56,7 +57,7 @@ public interface BloomFilterProducer {
}
@Override
- public boolean forEachBloomFilter(final Predicate<BloomFilter> predicate) {
+ public boolean processBloomFilters(final Predicate<BloomFilter> predicate) {
for (final BloomFilter filter : filters) {
if (!predicate.test(filter)) {
return false;
@@ -70,10 +71,10 @@ public interface BloomFilterProducer {
* filters are reflected in the originals.
*/
@Override
- public boolean forEachBloomFilterPair(final BloomFilterProducer other,
- final BiPredicate<BloomFilter, BloomFilter> func) {
+ public boolean processBloomFilterPair(final BloomFilterExtractor other,
+ final BiPredicate<BloomFilter, BloomFilter> func) {
final CountingPredicate<BloomFilter> p = new CountingPredicate<>(filters, func);
- return other.forEachBloomFilter(p) && p.forEachRemaining();
+ return other.processBloomFilters(p) && p.processRemaining();
}
};
}
@@ -88,7 +89,7 @@ public interface BloomFilterProducer {
*/
default BloomFilter[] asBloomFilterArray() {
final List<BloomFilter> filters = new ArrayList<>();
- forEachBloomFilter(f -> filters.add(f.copy()));
+ processBloomFilters(f -> filters.add(f.copy()));
return filters.toArray(new BloomFilter[0]);
}
@@ -100,7 +101,7 @@ public interface BloomFilterProducer {
*/
default BloomFilter flatten() {
final BloomFilter[] bf = {null};
- forEachBloomFilter( x -> {
+ processBloomFilters(x -> {
if (bf[0] == null) {
bf[0] = new SimpleBloomFilter( x.getShape());
}
@@ -117,27 +118,27 @@ public interface BloomFilterProducer {
* @return {@code false} when the first filter fails the predicate test. Returns
* {@code true} if all filters pass the test.
*/
- boolean forEachBloomFilter(Predicate<BloomFilter> bloomFilterPredicate);
+ boolean processBloomFilters(Predicate<BloomFilter> bloomFilterPredicate);
/**
* Applies the {@code func} to each Bloom filter pair in order. Will apply all
- * of the Bloom filters from the other BloomFilterProducer to this producer. If
- * either {@code this} producer or {@code other} producer has fewer BloomFilters
+ * of the Bloom filters from the other BloomFilterExtractor to this extractor. If
+ * either {@code this} extractor or {@code other} extractor has fewer BloomFilters
* ths method will provide {@code null} for all excess calls to the {@code func}.
*
* <p><em>This implementation returns references to the Bloom filter. Other implementations
* should specify if the array contains deep copies, immutable instances,
* or references to the filters in the collection.</em></p>
*
- * @param other The other BloomFilterProducer that provides the y values in the
+ * @param other The other BloomFilterExtractor that provides the y values in the
* (x,y) pair.
* @param func The function to apply.
* @return {@code true} if the {@code func} returned {@code true} for every pair,
* {@code false} otherwise.
*/
- default boolean forEachBloomFilterPair(final BloomFilterProducer other,
- final BiPredicate<BloomFilter, BloomFilter> func) {
+ default boolean processBloomFilterPair(final BloomFilterExtractor other,
+ final BiPredicate<BloomFilter, BloomFilter> func) {
final CountingPredicate<BloomFilter> p = new CountingPredicate<>(asBloomFilterArray(), func);
- return other.forEachBloomFilter(p) && p.forEachRemaining();
+ return other.processBloomFilters(p) && p.processRemaining();
}
}
diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/CellProducer.java b/src/main/java/org/apache/commons/collections4/bloomfilter/CellExtractor.java
similarity index 74%
rename from src/main/java/org/apache/commons/collections4/bloomfilter/CellProducer.java
rename to src/main/java/org/apache/commons/collections4/bloomfilter/CellExtractor.java
index 928f1d4e6..6ff79374e 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/CellProducer.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/CellExtractor.java
@@ -22,26 +22,26 @@ import java.util.function.IntPredicate;
/**
* Some Bloom filter implementations use a count rather than a bit flag. The term {@code Cell} is used to
- * refer to these counts and their associated index. This class is the equivalent of the index producer except
+ * refer to these counts and their associated index. This class is the equivalent of the index extractor except
* that it produces cells.
*
- * <p>Note that a CellProducer must not return duplicate indices and must be ordered.</p>
+ * <p>Note that a CellExtractor must not return duplicate indices and must be ordered.</p>
*
* <p>Implementations must guarantee that:</p>
*
* <ul>
- * <li>The IndexProducer implementation returns unique ordered indices.</li>
- * <li>The cells are produced in IndexProducer order.</li>
- * <li>For every value produced by the IndexProducer there will be only one matching
- * cell produced by the CellProducer.</li>
- * <li>The CellProducer will not generate cells with indices that are not output by the IndexProducer.</li>
- * <li>The IndexProducer will not generate indices that have a zero count for the cell.</li>
+ * <li>The IndexExtractor implementation returns unique ordered indices.</li>
+ * <li>The cells are produced in IndexExtractor order.</li>
+ * <li>For every value produced by the IndexExtractor there will be only one matching
+ * cell produced by the CellExtractor.</li>
+ * <li>The CellExtractor will not generate cells with indices that are not output by the IndexExtractor.</li>
+ * <li>The IndexExtractor will not generate indices that have a zero count for the cell.</li>
* </ul>
*
* @since 4.5
*/
@FunctionalInterface
-public interface CellProducer extends IndexProducer {
+public interface CellExtractor extends IndexExtractor {
/**
* Represents an operation that accepts an {@code <index, count>} pair.
@@ -51,7 +51,7 @@ public interface CellProducer extends IndexProducer {
* {@link java.util.function.BiPredicate} for {@code int}.</p>
*/
@FunctionalInterface
- interface CellConsumer {
+ interface CellPredicate {
/**
* Performs an operation on the given {@code <index, count>} pair.
*
@@ -63,15 +63,15 @@ public interface CellProducer extends IndexProducer {
}
/**
- * Creates a CellProducer from an IndexProducer.
+ * Creates a CellExtractor from an IndexExtractor.
*
* <p>Note the following properties:
* <ul>
- * <li>Each index returned from the IndexProducer is assumed to have a cell value of 1.</li>
- * <li>The CellProducer aggregates duplicate indices from the IndexProducer.</li>
+ * <li>Each index returned from the IndexExtractor is assumed to have a cell value of 1.</li>
+ * <li>The CellExtractor aggregates duplicate indices from the IndexExtractor.</li>
* </ul>
*
- * <p>A CellProducer that outputs the mapping [(1,2),(2,3),(3,1)] can be created from many combinations
+ * <p>A CellExtractor that outputs the mapping [(1,2),(2,3),(3,1)] can be created from many combinations
* of indices including:
* <pre>
* [1, 1, 2, 2, 2, 3]
@@ -80,11 +80,11 @@ public interface CellProducer extends IndexProducer {
* ...
* </pre>
*
- * @param producer An index producer.
- * @return A CellProducer with the same indices as the IndexProducer.
+ * @param indexExtractor An index indexExtractor.
+ * @return A CellExtractor with the same indices as the IndexExtractor.
*/
- static CellProducer from(final IndexProducer producer) {
- return new CellProducer() {
+ static CellExtractor from(final IndexExtractor indexExtractor) {
+ return new CellExtractor() {
/**
* Class to track cell values in the TreeMap.
*/
@@ -112,7 +112,7 @@ public interface CellProducer extends IndexProducer {
}
@Override
- public boolean forEachCell(final CellConsumer consumer) {
+ public boolean processCells(final CellPredicate consumer) {
populate();
for (final CounterCell cell : counterCells.values()) {
if (!consumer.test(cell.idx, cell.count)) {
@@ -124,7 +124,7 @@ public interface CellProducer extends IndexProducer {
private void populate() {
if (counterCells.isEmpty()) {
- producer.forEachIndex( idx -> {
+ indexExtractor.processIndices(idx -> {
final CounterCell cell = new CounterCell(idx, 1);
final CounterCell counter = counterCells.get(cell);
if (counter == null) {
@@ -153,18 +153,18 @@ public interface CellProducer extends IndexProducer {
* @return {@code true} if all cells return true from consumer, {@code false} otherwise.
* @throws NullPointerException if the specified consumer is null
*/
- boolean forEachCell(CellConsumer consumer);
+ boolean processCells(CellPredicate consumer);
/**
* The default implementation returns distinct and ordered indices for all cells with a non-zero count.
*/
@Override
- default boolean forEachIndex(final IntPredicate predicate) {
- return forEachCell((i, v) -> predicate.test(i));
+ default boolean processIndices(final IntPredicate predicate) {
+ return processCells((i, v) -> predicate.test(i));
}
@Override
- default IndexProducer uniqueIndices() {
+ default IndexExtractor uniqueIndices() {
return this;
}
}
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 503bde72d..af1ef4328 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilter.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilter.java
@@ -51,15 +51,15 @@ import java.util.Objects;
* of the filter after such an operation. For example are the cells not updated,
* partially updated or updated entirely before the exception is raised.</p>
*
- * @see CellProducer
+ * @see CellExtractor
* @since 4.5
*/
-public interface CountingBloomFilter extends BloomFilter, CellProducer {
+public interface CountingBloomFilter extends BloomFilter, CellExtractor {
// Query Operations
/**
- * Adds the specified CellProducer to this Bloom filter.
+ * Adds the specified CellExtractor to this Bloom filter.
*
* <p>Specifically
* all cells for the indexes identified by the {@code other} will be incremented
@@ -67,12 +67,12 @@ public interface CountingBloomFilter extends BloomFilter, CellProducer {
*
* <p>This method will return {@code true} if the filter is valid after the operation.</p>
*
- * @param other the CellProducer to add.
+ * @param other the CellExtractor to add.
* @return {@code true} if the addition was successful and the state is valid
* @see #isValid()
- * @see #subtract(CellProducer)
+ * @see #subtract(CellExtractor)
*/
- boolean add(CellProducer other);
+ boolean add(CellExtractor other);
/**
* Creates a new instance of the CountingBloomFilter with the same properties as the current one.
@@ -88,19 +88,19 @@ public interface CountingBloomFilter extends BloomFilter, CellProducer {
int getMaxCell();
/**
- * Determines the maximum number of times the BitMapProducer could have been merged into this
+ * Determines the maximum number of times the BitMapExtractor could have been merged into this
* counting filter.
- * @param bitMapProducer the BitMapProducer to provide the indices.
- * @return the maximum number of times the BitMapProducer could have been inserted.
+ * @param bitMapExtractor the BitMapExtractor to provide the indices.
+ * @return the maximum number of times the BitMapExtractor could have been inserted.
*/
- default int getMaxInsert(final BitMapProducer bitMapProducer) {
- if (!contains(bitMapProducer)) {
+ default int getMaxInsert(final BitMapExtractor bitMapExtractor) {
+ if (!contains(bitMapExtractor)) {
return 0;
}
- final long[] bitMaps = bitMapProducer.asBitMapArray();
+ final long[] bitMaps = bitMapExtractor.asBitMapArray();
final int[] max = { Integer.MAX_VALUE };
- forEachCell((x, y) -> {
- if ((bitMaps[BitMap.getLongIndex(x)] & BitMap.getLongBit(x)) != 0) {
+ processCells((x, y) -> {
+ if ((bitMaps[BitMaps.getLongIndex(x)] & BitMaps.getLongBit(x)) != 0) {
max[0] = max[0] <= y ? max[0] : y;
}
return true;
@@ -115,15 +115,15 @@ public interface CountingBloomFilter extends BloomFilter, CellProducer {
* @return the maximum number of times the Bloom filter could have been inserted.
*/
default int getMaxInsert(final BloomFilter bloomFilter) {
- return getMaxInsert((BitMapProducer) bloomFilter);
+ return getMaxInsert((BitMapExtractor) bloomFilter);
}
/**
- * Determines the maximum number of times the Cell Producer could have been add.
- * @param cellProducer the producer of cells.
- * @return the maximum number of times the CellProducer could have been inserted.
+ * Determines the maximum number of times the Cell Extractor could have been added.
+ * @param cellExtractor the extractor of cells.
+ * @return the maximum number of times the CellExtractor could have been inserted.
*/
- int getMaxInsert(CellProducer cellProducer);
+ int getMaxInsert(CellExtractor cellExtractor);
/**
* Determines the maximum number of times the Hasher could have been merged into this
@@ -138,16 +138,16 @@ public interface CountingBloomFilter extends BloomFilter, CellProducer {
// Modification Operations
/**
- * Determines the maximum number of times the IndexProducer could have been merged
+ * Determines the maximum number of times the IndexExtractor could have been merged
* into this counting filter.
- * <p>To determine how many times an indxProducer could have been added create a CellProducer
- * from the indexProducer and check that</p>
- * @param idxProducer the producer to drive the count check.
- * @return the maximum number of times the IndexProducer could have been inserted.
- * @see #getMaxInsert(CellProducer)
+ * <p>To determine how many times an indexExtractor could have been added create a CellExtractor
+ * from the indexExtractor and check that</p>
+ * @param indexExtractor the extractor to drive the count check.
+ * @return the maximum number of times the IndexExtractor could have been inserted.
+ * @see #getMaxInsert(CellExtractor)
*/
- default int getMaxInsert(final IndexProducer idxProducer) {
- return getMaxInsert(CellProducer.from(idxProducer.uniqueIndices()) );
+ default int getMaxInsert(final IndexExtractor indexExtractor) {
+ return getMaxInsert(CellExtractor.from(indexExtractor.uniqueIndices()) );
}
/**
@@ -172,21 +172,20 @@ public interface CountingBloomFilter extends BloomFilter, CellProducer {
boolean isValid();
/**
- * Merges the specified BitMap producer into this Bloom filter.
+ * Merges the specified BitMap extractor into this Bloom filter.
*
- * <p>Specifically: all cells for the indexes identified by the {@code bitMapProducer} will be incremented by 1.</p>
+ * <p>Specifically: all cells for the indexes identified by the {@code bitMapExtractor} will be incremented by 1.</p>
*
* <p>This method will return {@code true} if the filter is valid after the operation.</p>
*
- * @param bitMapProducer the BitMapProducer
+ * @param bitMapExtractor the BitMapExtractor
* @return {@code true} if the removal was successful and the state is valid
* @see #isValid()
- * @see #add(CellProducer)
+ * @see #add(CellExtractor)
*/
@Override
- default boolean merge(final BitMapProducer bitMapProducer) {
- Objects.requireNonNull(bitMapProducer, "bitMapProducer");
- return merge(IndexProducer.fromBitMapProducer(bitMapProducer));
+ default boolean merge(final BitMapExtractor bitMapExtractor) {
+ return merge(IndexExtractor.fromBitMapExtractor(bitMapExtractor));
}
/**
@@ -195,19 +194,19 @@ public interface CountingBloomFilter extends BloomFilter, CellProducer {
* <p>Specifically: all cells for the indexes identified by the {@code other} filter will be incremented by 1.</p>
*
* <p>Note: If the other filter is a counting Bloom filter the other filter's cells are ignored and it is treated as an
- * IndexProducer.</p>
+ * IndexExtractor.</p>
*
* <p>This method will return {@code true} if the filter is valid after the operation.</p>
*
* @param other the other Bloom filter
* @return {@code true} if the removal was successful and the state is valid
* @see #isValid()
- * @see #add(CellProducer)
+ * @see #add(CellExtractor)
*/
@Override
default boolean merge(final BloomFilter other) {
Objects.requireNonNull(other, "other");
- return merge((IndexProducer) other);
+ return merge((IndexExtractor) other);
}
/**
@@ -220,7 +219,7 @@ public interface CountingBloomFilter extends BloomFilter, CellProducer {
* @param hasher the hasher
* @return {@code true} if the removal was successful and the state is valid
* @see #isValid()
- * @see #add(CellProducer)
+ * @see #add(CellExtractor)
*/
@Override
default boolean merge(final Hasher hasher) {
@@ -229,25 +228,28 @@ public interface CountingBloomFilter extends BloomFilter, CellProducer {
}
/**
- * Merges the specified index producer into this Bloom filter.
+ * Merges the specified index extractor into this Bloom filter.
*
- * <p>Specifically: all unique cells for the indices identified by the {@code indexProducer} will be incremented by 1.</p>
+ * <p>Specifically: all unique cells for the indices identified by the {@code indexExtractor} will be incremented by 1.</p>
*
* <p>This method will return {@code true} if the filter is valid after the operation.</p>
*
- * <p>Note: If indices that are returned multiple times should be incremented multiple times convert the IndexProducer
- * to a CellProducer and add that.</p>
- *
- * @param indexProducer the IndexProducer
+ * <p>Notes:</p>
+ * <ul>
+ * <li>If indices that are returned multiple times should be incremented multiple times convert the IndexExtractor
+ * to a CellExtractor and add that.</li>
+ * <li>Implementations should throw {@code IllegalArgumentException} and no other exception on bad input.</li>
+ * </ul>
+ * @param indexExtractor the IndexExtractor
* @return {@code true} if the removal was successful and the state is valid
* @see #isValid()
- * @see #add(CellProducer)
+ * @see #add(CellExtractor)
*/
@Override
- default boolean merge(final IndexProducer indexProducer) {
- Objects.requireNonNull(indexProducer, "indexProducer");
+ default boolean merge(final IndexExtractor indexExtractor) {
+ Objects.requireNonNull(indexExtractor, "indexExtractor");
try {
- return add(CellProducer.from(indexProducer.uniqueIndices()));
+ return add(CellExtractor.from(indexExtractor.uniqueIndices()));
} catch (final IndexOutOfBoundsException e) {
throw new IllegalArgumentException(
String.format("Filter only accepts values in the [0,%d) range", getShape().getNumberOfBits()), e);
@@ -255,21 +257,20 @@ public interface CountingBloomFilter extends BloomFilter, CellProducer {
}
/**
- * Removes the specified BitMapProducer from this Bloom filter.
+ * Removes the specified BitMapExtractor from this Bloom filter.
*
- * <p>Specifically all cells for the indices produced by the {@code bitMapProducer} will be
+ * <p>Specifically all cells for the indices produced by the {@code bitMapExtractor} will be
* decremented by 1.</p>
*
* <p>This method will return {@code true} if the filter is valid after the operation.</p>
*
- * @param bitMapProducer the BitMapProducer to provide the indexes
+ * @param bitMapExtractor the BitMapExtractor to provide the indexes
* @return {@code true} if the removal was successful and the state is valid
* @see #isValid()
- * @see #subtract(CellProducer)
+ * @see #subtract(CellExtractor)
*/
- default boolean remove(final BitMapProducer bitMapProducer) {
- Objects.requireNonNull(bitMapProducer, "bitMapProducer");
- return remove(IndexProducer.fromBitMapProducer(bitMapProducer));
+ default boolean remove(final BitMapExtractor bitMapExtractor) {
+ return remove(IndexExtractor.fromBitMapExtractor(bitMapExtractor));
}
/**
@@ -278,18 +279,17 @@ public interface CountingBloomFilter extends BloomFilter, CellProducer {
* <p>Specifically: all cells for the indexes identified by the {@code other} filter will be decremented by 1.</p>
*
* <p>Note: If the other filter is a counting Bloom filter the other filter's cells are ignored and it is treated as an
- * IndexProducer.</p>
+ * IndexExtractor.</p>
*
* <p>This method will return {@code true} if the filter is valid after the operation.</p>
*
* @param other the other Bloom filter
* @return {@code true} if the removal was successful and the state is valid
* @see #isValid()
- * @see #subtract(CellProducer)
+ * @see #subtract(CellExtractor)
*/
default boolean remove(final BloomFilter other) {
- Objects.requireNonNull(other, "other");
- return remove((IndexProducer) other);
+ return remove((IndexExtractor) other);
}
/**
@@ -303,7 +303,7 @@ public interface CountingBloomFilter extends BloomFilter, CellProducer {
* @param hasher the hasher to provide the indexes
* @return {@code true} if the removal was successful and the state is valid
* @see #isValid()
- * @see #subtract(CellProducer)
+ * @see #subtract(CellExtractor)
*/
default boolean remove(final Hasher hasher) {
Objects.requireNonNull(hasher, "hasher");
@@ -311,25 +311,25 @@ public interface CountingBloomFilter extends BloomFilter, CellProducer {
}
/**
- * Removes the values from the specified IndexProducer from the Bloom filter from this Bloom filter.
+ * Removes the values from the specified IndexExtractor from the Bloom filter from this Bloom filter.
*
* <p>Specifically all cells for the unique indices produced by the {@code hasher} will be
* decremented by 1.</p>
*
* <p>This method will return {@code true} if the filter is valid after the operation.</p>
*
- * <p>Note: If indices that are returned multiple times should be decremented multiple times convert the IndexProducer
- * to a CellProducer and subtract that.</p>
+ * <p>Note: If indices that are returned multiple times should be decremented multiple times convert the IndexExtractor
+ * to a CellExtractor and subtract that.</p>
*
- * @param indexProducer the IndexProducer to provide the indexes
+ * @param indexExtractor the IndexExtractor to provide the indexes
* @return {@code true} if the removal was successful and the state is valid
* @see #isValid()
- * @see #subtract(CellProducer)
+ * @see #subtract(CellExtractor)
*/
- default boolean remove(final IndexProducer indexProducer) {
- Objects.requireNonNull(indexProducer, "indexProducer");
+ default boolean remove(final IndexExtractor indexExtractor) {
+ Objects.requireNonNull(indexExtractor, "indexExtractor");
try {
- return subtract(CellProducer.from(indexProducer.uniqueIndices()));
+ return subtract(CellExtractor.from(indexExtractor.uniqueIndices()));
} catch (final IndexOutOfBoundsException e) {
throw new IllegalArgumentException(
String.format("Filter only accepts values in the [0,%d) range", getShape().getNumberOfBits()));
@@ -338,7 +338,7 @@ public interface CountingBloomFilter extends BloomFilter, CellProducer {
/**
- * Adds the specified CellProducer to this Bloom filter.
+ * Adds the specified CellExtractor to this Bloom filter.
*
* <p>Specifically
* all cells for the indexes identified by the {@code other} will be decremented
@@ -346,15 +346,19 @@ public interface CountingBloomFilter extends BloomFilter, CellProducer {
*
* <p>This method will return true if the filter is valid after the operation.</p>
*
- * @param other the CellProducer to subtract.
+ * @param other the CellExtractor to subtract.
* @return {@code true} if the subtraction was successful and the state is valid
* @see #isValid()
- * @see #add(CellProducer)
+ * @see #add(CellExtractor)
*/
- boolean subtract(CellProducer other);
+ boolean subtract(CellExtractor other);
+ /**
+ * The default implementation is a no-op since the counting bloom filter returns an unique IndexExtractor by default.
+ * @return this counting Bloom filter.
+ */
@Override
- default IndexProducer uniqueIndices() {
+ default IndexExtractor uniqueIndices() {
return this;
}
}
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 90ef5647b..a9e5b31af 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/CountingLongPredicate.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/CountingLongPredicate.java
@@ -21,7 +21,7 @@ import java.util.function.LongPredicate;
/**
* A long predicate that applies the test func to each member of the {@code ary} in sequence for each call to {@code test()}.
* if the {@code ary} is exhausted, the subsequent calls to {@code test} are executed with a zero value.
- * If the calls to {@code test} do not exhaust the {@code ary} the {@code forEachRemaining} method can be called to
+ * If the calls to {@code test} do not exhaust the {@code ary} the {@code processRemaining} method can be called to
* execute the @{code test} with a zero value for each remaining {@code idx} value.
* @since 4.5
*/
@@ -45,12 +45,12 @@ class CountingLongPredicate implements LongPredicate {
/**
* Call the long-long consuming bi-predicate for each remaining unpaired long in
* the input array. This method should be invoked after the predicate has been
- * passed to {@link BitMapProducer#forEachBitMap(LongPredicate)} to consume any
+ * passed to {@link BitMapExtractor#processBitMaps(LongPredicate)} to consume any
* unpaired bitmaps. The second argument to the bi-predicate will be zero.
*
- * @return true if all calls the predicate were successful
+ * @return true if all calls to the predicate were successful
*/
- boolean forEachRemaining() {
+ boolean processRemaining() {
// uses local references for optimization benefit.
int i = idx;
final long[] a = ary;
diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/CountingPredicate.java b/src/main/java/org/apache/commons/collections4/bloomfilter/CountingPredicate.java
index 05a354362..ba8049da7 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/CountingPredicate.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/CountingPredicate.java
@@ -24,7 +24,7 @@ import java.util.function.Predicate;
* sequence for each call to {@code test()}. if the {@code ary} is exhausted,
* the subsequent calls to {@code test} are executed with a {@code null} value.
* If the calls to {@code test} do not exhaust the {@code ary} the {@code
- * forEachRemaining} method can be called to execute the @{code test} with a
+ * processRemaining} method can be called to execute the @{code test} with a
* {@code null} value for each remaining {@code idx} value.
*
* @param <T> the type of object being compared.
@@ -52,12 +52,12 @@ class CountingPredicate<T> implements Predicate<T> {
/**
* Call {@code BiPredicate<T, T>} for each remaining unpaired {@code <T>} in the
* input array. This method should be invoked after the predicate has been
- * passed to a {@code Producer.forEach<T>(BiPredicate<T, T>)} to consume any
+ * passed to a {@code Extractor.forEach<T>(BiPredicate<T, T>)} to consume any
* unpaired {@code <T>}s. The second argument to the BiPredicate will be {@code null}.
*
- * @return true if all calls the predicate were successful
+ * @return true if all calls to the predicate were successful
*/
- boolean forEachRemaining() {
+ boolean processRemaining() {
// uses local references for optimization benefit.
int i = idx;
final T[] a = ary;
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 12115e5ce..761803e49 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/EnhancedDoubleHasher.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/EnhancedDoubleHasher.java
@@ -130,10 +130,10 @@ public class EnhancedDoubleHasher implements Hasher {
}
@Override
- public IndexProducer indices(final Shape shape) {
+ public IndexExtractor indices(final Shape shape) {
Objects.requireNonNull(shape, "shape");
- return new IndexProducer() {
+ return new IndexExtractor() {
@Override
public int[] asIndexArray() {
@@ -142,7 +142,7 @@ public class EnhancedDoubleHasher implements Hasher {
// This method needs to return duplicate indices
- forEachIndex(i -> {
+ processIndices(i -> {
result[idx[0]++] = i;
return true;
});
@@ -150,7 +150,7 @@ public class EnhancedDoubleHasher implements Hasher {
}
@Override
- public boolean forEachIndex(final IntPredicate consumer) {
+ public boolean processIndices(final IntPredicate consumer) {
Objects.requireNonNull(consumer, "consumer");
final int bits = shape.getNumberOfBits();
// Enhanced double hashing:
@@ -166,8 +166,8 @@ public class EnhancedDoubleHasher implements Hasher {
// The final hash is:
// hash[i] = ( h1(x) - i*h2(x) - (i*i*i - i)/6 ) wrapped in [0, bits)
- int index = BitMap.mod(initial, bits);
- int inc = BitMap.mod(increment, bits);
+ int index = BitMaps.mod(initial, bits);
+ int inc = BitMaps.mod(increment, bits);
final int k = shape.getNumberOfHashFunctions();
if (k > bits) {
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 e2c30d5d2..dcc13c711 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/Hasher.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/Hasher.java
@@ -17,7 +17,7 @@
package org.apache.commons.collections4.bloomfilter;
/**
- * A Hasher creates IndexProducer based on the hash implementation and the
+ * A Hasher creates IndexExtractor based on the hash implementation and the
* provided Shape.
*
* @since 4.5
@@ -25,14 +25,14 @@ package org.apache.commons.collections4.bloomfilter;
public interface Hasher {
/**
- * Creates an IndexProducer for this hasher based on the Shape.
+ * Creates an IndexExtractor for this hasher based on the Shape.
*
- * <p>The {@code IndexProducer} will create indices within the range defined by the number of bits in
+ * <p>The {@code IndexExtractor} will create indices within the range defined by the number of bits in
* the shape. The total number of indices will respect the number of hash functions per item
* defined by the shape. However the count of indices may not be a multiple of the number of
* hash functions if the implementation has removed duplicates.</p>
*
- * <p>This IndexProducer must be deterministic in that it must return the same indices for the
+ * <p>This IndexExtractor must be deterministic in that it must return the same indices for the
* same Shape.</p>
*
* <p>No guarantee is made as to order of indices.</p>
@@ -41,5 +41,5 @@ public interface Hasher {
* @param shape the shape of the desired Bloom filter.
* @return the iterator of integers
*/
- IndexProducer indices(Shape shape);
+ IndexExtractor indices(Shape shape);
}
diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/IndexProducer.java b/src/main/java/org/apache/commons/collections4/bloomfilter/IndexExtractor.java
similarity index 77%
rename from src/main/java/org/apache/commons/collections4/bloomfilter/IndexProducer.java
rename to src/main/java/org/apache/commons/collections4/bloomfilter/IndexExtractor.java
index 792328876..d6a33537e 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/IndexProducer.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/IndexExtractor.java
@@ -31,15 +31,15 @@ import java.util.function.LongPredicate;
* @since 4.5
*/
@FunctionalInterface
-public interface IndexProducer {
+public interface IndexExtractor {
/**
- * Creates an IndexProducer from a {@code BitMapProducer}.
- * @param producer the {@code BitMapProducer}
- * @return a new {@code IndexProducer}.
+ * Creates an IndexExtractor from a {@code BitMapExtractor}.
+ * @param bitMapExtractor the {@code BitMapExtractor}
+ * @return a new {@code IndexExtractor}.
*/
- static IndexProducer fromBitMapProducer(final BitMapProducer producer) {
- Objects.requireNonNull(producer, "producer");
+ static IndexExtractor fromBitMapExtractor(final BitMapExtractor bitMapExtractor) {
+ Objects.requireNonNull(bitMapExtractor, "bitMapExtractor");
return consumer -> {
final LongPredicate longPredicate = new LongPredicate() {
int wordIdx;
@@ -58,17 +58,17 @@ public interface IndexProducer {
return true;
}
};
- return producer.forEachBitMap(longPredicate::test);
+ return bitMapExtractor.processBitMaps(longPredicate::test);
};
}
/**
- * Creates an IndexProducer from an array of integers.
+ * Creates an IndexExtractor from an array of integers.
* @param values the index values
- * @return an IndexProducer that uses the values.
+ * @return an IndexExtractor that uses the values.
*/
- static IndexProducer fromIndexArray(final int... values) {
- return new IndexProducer() {
+ static IndexExtractor fromIndexArray(final int... values) {
+ return new IndexExtractor() {
@Override
public int[] asIndexArray() {
@@ -76,7 +76,7 @@ public interface IndexProducer {
}
@Override
- public boolean forEachIndex(final IntPredicate predicate) {
+ public boolean processIndices(final IntPredicate predicate) {
for (final int value : values) {
if (!predicate.test(value)) {
return false;
@@ -88,7 +88,7 @@ public interface IndexProducer {
}
/**
- * Return a copy of the IndexProducer data as an int array.
+ * Return a copy of the IndexExtractor data as an int array.
*
* <p>Indices ordering and uniqueness is not guaranteed.</p>
*
@@ -117,7 +117,7 @@ public interface IndexProducer {
}
}
final Indices indices = new Indices();
- forEachIndex(indices::add);
+ processIndices(indices::add);
return indices.toArray();
}
@@ -134,31 +134,31 @@ public interface IndexProducer {
* @return {@code true} if all indexes return true from consumer, {@code false} otherwise.
* @throws NullPointerException if the specified action is null
*/
- boolean forEachIndex(IntPredicate predicate);
+ boolean processIndices(IntPredicate predicate);
/**
- * Creates an IndexProducer comprising the unique indices for this producer.
+ * Creates an IndexExtractor comprising the unique indices for this extractor.
*
- * <p>By default creates a new producer with some overhead to remove
- * duplicates. IndexProducers that return unique indices by default
+ * <p>By default creates a new extractor with some overhead to remove
+ * duplicates. IndexExtractors that return unique indices by default
* should override this to return {@code this}.</p>
*
* <p>The default implementation will filter the indices from this instance
* and return them in ascending order.</p>
*
- * @return the IndexProducer of unique values.
+ * @return the IndexExtractor of unique values.
* @throws IndexOutOfBoundsException if any index is less than zero.
*/
- default IndexProducer uniqueIndices() {
+ default IndexExtractor uniqueIndices() {
final BitSet bitSet = new BitSet();
- forEachIndex(i -> {
+ processIndices(i -> {
bitSet.set(i);
return true;
});
- return new IndexProducer() {
+ return new IndexExtractor() {
@Override
- public boolean forEachIndex(final IntPredicate predicate) {
+ public boolean processIndices(final IntPredicate predicate) {
for (int idx = bitSet.nextSetBit(0); idx >= 0; idx = bitSet.nextSetBit(idx + 1)) {
if (!predicate.test(idx)) {
return false;
@@ -168,7 +168,7 @@ public interface IndexProducer {
}
@Override
- public IndexProducer uniqueIndices() {
+ public IndexExtractor uniqueIndices() {
return this;
}
};
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 4fc4bab5e..070a49fda 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/IndexFilter.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/IndexFilter.java
@@ -71,13 +71,13 @@ public final class IndexFilter {
* @param shape The shape that is being generated.
*/
BitMapTracker(final Shape shape) {
- bits = new long[BitMap.numberOfBitMaps(shape.getNumberOfBits())];
+ bits = new long[BitMaps.numberOfBitMaps(shape.getNumberOfBits())];
}
@Override
public boolean test(final int number) {
- final boolean retval = !BitMap.contains(bits, number);
- BitMap.set(bits, number);
+ final boolean retval = !BitMaps.contains(bits, number);
+ BitMaps.set(bits, number);
return retval;
}
}
@@ -105,7 +105,7 @@ public final class IndexFilter {
private IndexFilter(final Shape shape, final IntPredicate consumer) {
this.size = shape.getNumberOfBits();
this.consumer = consumer;
- if (BitMap.numberOfBitMaps(shape.getNumberOfBits()) * Long.BYTES < (long) shape.getNumberOfHashFunctions()
+ if (BitMaps.numberOfBitMaps(shape.getNumberOfBits()) * Long.BYTES < (long) shape.getNumberOfHashFunctions()
* Integer.BYTES) {
this.tracker = new BitMapTracker(shape);
} else {
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 10537e91b..fca9595d4 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/IndexUtils.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/IndexUtils.java
@@ -19,8 +19,8 @@ package org.apache.commons.collections4.bloomfilter;
import java.util.Arrays;
/**
- * Provides functions to assist in IndexProducer creation and manipulation.
- * @see IndexProducer
+ * Provides functions to assist in IndexExtractor creation and manipulation.
+ * @see IndexExtractor
*/
final class IndexUtils {
diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/LayerManager.java b/src/main/java/org/apache/commons/collections4/bloomfilter/LayerManager.java
index 2e2b903a1..8ab7e6fc8 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/LayerManager.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/LayerManager.java
@@ -51,7 +51,7 @@ import java.util.function.Supplier;
*
* @since 4.5
*/
-public class LayerManager<T extends BloomFilter> implements BloomFilterProducer {
+public class LayerManager<T extends BloomFilter> implements BloomFilterExtractor {
/**
* Builder to create Layer Manager
@@ -358,7 +358,7 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
* {@code true} if all filters pass the test.
*/
@Override
- public boolean forEachBloomFilter(final Predicate<BloomFilter> bloomFilterPredicate) {
+ public boolean processBloomFilters(final Predicate<BloomFilter> bloomFilterPredicate) {
for (final BloomFilter bf : filters) {
if (!bloomFilterPredicate.test(bf)) {
return false;
diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/LayeredBloomFilter.java b/src/main/java/org/apache/commons/collections4/bloomfilter/LayeredBloomFilter.java
index 058fe4aee..ee39bae65 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/LayeredBloomFilter.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/LayeredBloomFilter.java
@@ -62,7 +62,7 @@ import java.util.function.Predicate;
* @param <T> The type of Bloom Filter that is used for the layers.
* @since 4.5
*/
-public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, BloomFilterProducer {
+public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, BloomFilterExtractor {
/**
* A class used to locate matching filters across all the layers.
*/
@@ -131,15 +131,15 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
}
@Override
- public boolean contains(final BitMapProducer bitMapProducer) {
- return contains(createFilter(bitMapProducer));
+ public boolean contains(final BitMapExtractor bitMapExtractor) {
+ return contains(createFilter(bitMapExtractor));
}
/**
* Returns {@code true} if this any layer contained by this filter contains the
* specified filter.
* <p>
- * If the {@code other} is a BloomFilterProducer each filter within the
+ * If the {@code other} is a BloomFilterExtractor each filter within the
* {@code other} is checked to see if it exits within this filter.
* </p>
*
@@ -148,23 +148,23 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
*/
@Override
public boolean contains(final BloomFilter other) {
- return other instanceof BloomFilterProducer ? contains((BloomFilterProducer) other)
- : !forEachBloomFilter(x -> !x.contains(other));
+ return other instanceof BloomFilterExtractor ? contains((BloomFilterExtractor) other)
+ : !processBloomFilters(x -> !x.contains(other));
}
/**
- * Returns {@code true} if each filter within the {@code producer} exits within
+ * Returns {@code true} if each filter within the {@code bloomFilterExtractor} exits within
* this filter.
*
- * @param producer the BloomFilterProducer that provides the filters to check
+ * @param bloomFilterExtractor the BloomFilterExtractor that provides the filters to check
* for.
* @return {@code true} if this filter contains all of the filters contained in
- * the {@code producer}.
+ * the {@code bloomFilterExtractor}.
*/
- public boolean contains(final BloomFilterProducer producer) {
+ public boolean contains(final BloomFilterExtractor bloomFilterExtractor) {
final boolean[] result = { true };
// return false when we have found a match to short circuit checks
- return producer.forEachBloomFilter(x -> {
+ return bloomFilterExtractor.processBloomFilters(x -> {
result[0] &= contains(x);
return result[0];
});
@@ -176,8 +176,8 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
}
@Override
- public boolean contains(final IndexProducer indexProducer) {
- return contains(createFilter(indexProducer));
+ public boolean contains(final IndexExtractor indexExtractor) {
+ return contains(createFilter(indexExtractor));
}
@Override
@@ -186,14 +186,14 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
}
/**
- * Creates a Bloom filter from a BitMapProducer.
+ * Creates a Bloom filter from a BitMapExtractor.
*
- * @param bitMapProducer the BitMapProducer to create the filter from.
+ * @param bitMapExtractor the BitMapExtractor to create the filter from.
* @return the BloomFilter.
*/
- private BloomFilter createFilter(final BitMapProducer bitMapProducer) {
+ private BloomFilter createFilter(final BitMapExtractor bitMapExtractor) {
final SimpleBloomFilter bf = new SimpleBloomFilter(shape);
- bf.merge(bitMapProducer);
+ bf.merge(bitMapExtractor);
return bf;
}
@@ -210,14 +210,14 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
}
/**
- * Creates a Bloom filter from an IndexProducer.
+ * Creates a Bloom filter from an IndexExtractor.
*
- * @param indexProducer the IndexProducer to create the filter from.
+ * @param indexExtractor the IndexExtractor to create the filter from.
* @return the BloomFilter.
*/
- private BloomFilter createFilter(final IndexProducer indexProducer) {
+ private BloomFilter createFilter(final IndexExtractor indexExtractor) {
final SimpleBloomFilter bf = new SimpleBloomFilter(shape);
- bf.merge(indexProducer);
+ bf.merge(indexExtractor);
return bf;
}
@@ -235,14 +235,14 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
}
/**
- * Finds the layers in which the BitMapProducer is found.
+ * Finds the layers in which the BitMapExtractor is found.
*
- * @param bitMapProducer the BitMapProducer to search for.
+ * @param bitMapExtractor the BitMapExtractor to search for.
* @return an array of layer indices in which the Bloom filter is found.
*/
- public int[] find(final BitMapProducer bitMapProducer) {
+ public int[] find(final BitMapExtractor bitMapExtractor) {
final SimpleBloomFilter bf = new SimpleBloomFilter(shape);
- bf.merge(bitMapProducer);
+ bf.merge(bitMapExtractor);
return find(bf);
}
@@ -254,7 +254,7 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
*/
public int[] find(final BloomFilter bf) {
final Finder finder = new Finder(bf);
- forEachBloomFilter(finder);
+ processBloomFilters(finder);
return finder.getResult();
}
@@ -271,14 +271,14 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
}
/**
- * Finds the layers in which the IndexProducer is found.
+ * Finds the layers in which the IndexExtractor is found.
*
- * @param indexProducer the Index producer to search for.
+ * @param indexExtractor the Index extractor to search for.
* @return an array of layer indices in which the Bloom filter is found.
*/
- public int[] find(final IndexProducer indexProducer) {
+ public int[] find(final IndexExtractor indexExtractor) {
final SimpleBloomFilter bf = new SimpleBloomFilter(shape);
- bf.merge(indexProducer);
+ bf.merge(indexExtractor);
return find(bf);
}
@@ -291,13 +291,13 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
@Override
public BloomFilter flatten() {
final BloomFilter bf = new SimpleBloomFilter(shape);
- forEachBloomFilter(bf::merge);
+ processBloomFilters(bf::merge);
return bf;
}
@Override
- public boolean forEachBitMap(final LongPredicate predicate) {
- return flatten().forEachBitMap(predicate);
+ public boolean processBitMaps(final LongPredicate predicate) {
+ return flatten().processBitMaps(predicate);
}
/**
@@ -310,13 +310,13 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
* otherwise.
*/
@Override
- public final boolean forEachBloomFilter(final Predicate<BloomFilter> bloomFilterPredicate) {
- return layerManager.forEachBloomFilter(bloomFilterPredicate);
+ public final boolean processBloomFilters(final Predicate<BloomFilter> bloomFilterPredicate) {
+ return layerManager.processBloomFilters(bloomFilterPredicate);
}
@Override
- public boolean forEachIndex(final IntPredicate predicate) {
- return forEachBloomFilter(bf -> bf.forEachIndex(predicate));
+ public boolean processIndices(final IntPredicate predicate) {
+ return processBloomFilters(bf -> bf.processIndices(predicate));
}
/**
@@ -347,12 +347,12 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
@Override
public boolean isEmpty() {
- return forEachBloomFilter(BloomFilter::isEmpty);
+ return processBloomFilters(BloomFilter::isEmpty);
}
@Override
- public boolean merge(final BitMapProducer bitMapProducer) {
- return layerManager.getTarget().merge(bitMapProducer);
+ public boolean merge(final BitMapExtractor bitMapExtractor) {
+ return layerManager.getTarget().merge(bitMapExtractor);
}
@Override
@@ -361,8 +361,8 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
}
@Override
- public boolean merge(final IndexProducer indexProducer) {
- return layerManager.getTarget().merge(indexProducer);
+ public boolean merge(final IndexExtractor indexExtractor) {
+ return layerManager.getTarget().merge(indexExtractor);
}
/**
@@ -376,4 +376,5 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
public void next() {
layerManager.next();
}
+
}
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 1cb57262d..54f4598fd 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/SetOperations.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/SetOperations.java
@@ -19,7 +19,7 @@ package org.apache.commons.collections4.bloomfilter;
import java.util.function.LongBinaryOperator;
/**
- * Implementations of set operations on BitMapProducers.
+ * Implementations of set operations on BitMapExtractors.
*
* @since 4.5
*/
@@ -27,23 +27,23 @@ public final class SetOperations {
/**
* Calculates the cardinality of the logical {@code AND} of the bit maps for the two filters.
- * @param first the first BitMapProducer.
- * @param second the second BitMapProducer
+ * @param first the first BitMapExtractor.
+ * @param second the second BitMapExtractor
* @return the cardinality of the {@code AND} of the filters.
*/
- public static int andCardinality(final BitMapProducer first, final BitMapProducer second) {
+ public static int andCardinality(final BitMapExtractor first, final BitMapExtractor second) {
return cardinality(first, second, (x, y) -> x & y);
}
/**
- * 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.
+ * Calculates the cardinality of a BitMapExtractor. By necessity this method will visit each bit map
+ * created by the bitMapExtractor.
+ * @param bitMapExtractor the extractor to calculate the cardinality for.
+ * @return the cardinality of the bit maps produced by the bitMapExtractor.
*/
- public static int cardinality(final BitMapProducer producer) {
+ public static int cardinality(final BitMapExtractor bitMapExtractor) {
final int[] cardinality = new int[1];
- producer.forEachBitMap(l -> {
+ bitMapExtractor.processBitMaps(l -> {
cardinality[0] += Long.bitCount(l);
return true;
});
@@ -52,16 +52,16 @@ public final class SetOperations {
/**
* Calculates the cardinality of the result of a LongBinaryOperator using the
- * {@code BitMapProducer.makePredicate} method.
- * @param first the first BitMapProducer
- * @param second the second BitMapProducer
- * @param op a long binary operation on where x = {@code first} and y = {@code second} bitmap producers.
+ * {@code BitMapExtractor.makePredicate} method.
+ * @param first the first BitMapExtractor
+ * @param second the second BitMapExtractor
+ * @param op a long binary operation on where x = {@code first} and y = {@code second} bitmap extractors.
* @return the calculated cardinality.
*/
- private static int cardinality(final BitMapProducer first, final BitMapProducer second, final LongBinaryOperator op) {
+ private static int cardinality(final BitMapExtractor first, final BitMapExtractor second, final LongBinaryOperator op) {
final int[] cardinality = new int[1];
- first.forEachBitMapPair(second, (x, y) -> {
+ first.processBitMapPairs(second, (x, y) -> {
cardinality[0] += Long.bitCount(op.applyAsLong(x, y));
return true;
});
@@ -69,30 +69,30 @@ public final class SetOperations {
}
/**
- * Calculates the Cosine distance between two BitMapProducer.
+ * Calculates the Cosine distance between two BitMapExtractor.
*
* <p>Cosine distance is defined as {@code 1 - Cosine similarity}</p>
*
- * @param first the first BitMapProducer.
- * @param second the second BitMapProducer.
+ * @param first the first BitMapExtractor.
+ * @param second the second BitMapExtractor.
* @return the jaccard distance.
*/
- public static double cosineDistance(final BitMapProducer first, final BitMapProducer second) {
+ public static double cosineDistance(final BitMapExtractor first, final BitMapExtractor second) {
return 1.0 - cosineSimilarity(first, second);
}
/**
- * Calculates the Cosine similarity between two BitMapProducers.
+ * Calculates the Cosine similarity between two BitMapExtractors.
* <p> Also known as Orchini similarity and the Tucker coefficient of congruence or
* Ochiai similarity.</p>
*
- * <p>If either producer is empty the result is 0 (zero)</p>
+ * <p>If either extractor is empty the result is 0 (zero)</p>
*
- * @param first the first BitMapProducer.
- * @param second the second BitMapProducer.
+ * @param first the first BitMapExtractor.
+ * @param second the second BitMapExtractor.
* @return the Cosine similarity.
*/
- public static double cosineSimilarity(final BitMapProducer first, final BitMapProducer second) {
+ public static double cosineSimilarity(final BitMapExtractor first, final BitMapExtractor second) {
final int numerator = andCardinality(first, second);
// Given that the cardinality is an int then the product as a double will not
// overflow, we can use one sqrt:
@@ -120,41 +120,41 @@ public final class SetOperations {
}
/**
- * Calculates the Hamming distance between two BitMapProducers.
+ * Calculates the Hamming distance between two BitMapExtractors.
*
- * @param first the first BitMapProducer.
- * @param second the second BitMapProducer.
+ * @param first the first BitMapExtractor.
+ * @param second the second BitMapExtractor.
* @return the Hamming distance.
*/
- public static int hammingDistance(final BitMapProducer first, final BitMapProducer second) {
+ public static int hammingDistance(final BitMapExtractor first, final BitMapExtractor second) {
return xorCardinality(first, second);
}
/**
- * Calculates the Jaccard distance between two BitMapProducer.
+ * Calculates the Jaccard distance between two BitMapExtractor.
*
* <p>Jaccard distance is defined as {@code 1 - Jaccard similarity}</p>
*
- * @param first the first BitMapProducer.
- * @param second the second BitMapProducer.
+ * @param first the first BitMapExtractor.
+ * @param second the second BitMapExtractor.
* @return the Jaccard distance.
*/
- public static double jaccardDistance(final BitMapProducer first, final BitMapProducer second) {
+ public static double jaccardDistance(final BitMapExtractor first, final BitMapExtractor second) {
return 1.0 - jaccardSimilarity(first, second);
}
/**
- * Calculates the Jaccard similarity between two BitMapProducer.
+ * Calculates the Jaccard similarity between two BitMapExtractor.
*
* <p>Also known as Jaccard index, Intersection over Union, and Jaccard similarity coefficient</p>
*
- * @param first the first BitMapProducer.
- * @param second the second BitMapProducer.
+ * @param first the first BitMapExtractor.
+ * @param second the second BitMapExtractor.
* @return the Jaccard similarity.
*/
- public static double jaccardSimilarity(final BitMapProducer first, final BitMapProducer second) {
+ public static double jaccardSimilarity(final BitMapExtractor first, final BitMapExtractor second) {
final int[] cardinality = new int[2];
- first.forEachBitMapPair(second, (x, y) -> {
+ first.processBitMapPairs(second, (x, y) -> {
cardinality[0] += Long.bitCount(x & y);
cardinality[1] += Long.bitCount(x | y);
return true;
@@ -165,21 +165,21 @@ public final class SetOperations {
/**
* Calculates the cardinality of the logical {@code OR} of the bit maps for the two filters.
- * @param first the first BitMapProducer.
- * @param second the second BitMapProducer
+ * @param first the first BitMapExtractor.
+ * @param second the second BitMapExtractor
* @return the cardinality of the {@code OR} of the filters.
*/
- public static int orCardinality(final BitMapProducer first, final BitMapProducer second) {
+ public static int orCardinality(final BitMapExtractor first, final BitMapExtractor second) {
return cardinality(first, second, (x, y) -> x | y);
}
/**
* Calculates the cardinality of the logical {@code XOR} of the bit maps for the two filters.
- * @param first the first BitMapProducer.
- * @param second the second BitMapProducer
+ * @param first the first BitMapExtractor.
+ * @param second the second BitMapExtractor
* @return the cardinality of the {@code XOR} of the filters.
*/
- public static int xorCardinality(final BitMapProducer first, final BitMapProducer second) {
+ public static int xorCardinality(final BitMapExtractor first, final BitMapExtractor second) {
return cardinality(first, second, (x, y) -> x ^ y);
}
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 8a184e7da..2be155d8d 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/Shape.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/Shape.java
@@ -483,7 +483,7 @@ public final class Shape {
* (number of indexes) is less than or equal to 2*number of bit maps the
* cardinality is sparse within the shape.
*/
- return cardinality <= BitMap.numberOfBitMaps(getNumberOfBits()) * 2;
+ return cardinality <= BitMaps.numberOfBitMaps(getNumberOfBits()) * 2;
}
@Override
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 4cf672394..c5f55405e 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/SimpleBloomFilter.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/SimpleBloomFilter.java
@@ -51,7 +51,7 @@ public final class SimpleBloomFilter implements BloomFilter {
public SimpleBloomFilter(final Shape shape) {
Objects.requireNonNull(shape, "shape");
this.shape = shape;
- this.bitMap = new long[BitMap.numberOfBitMaps(shape.getNumberOfBits())];
+ this.bitMap = new long[BitMaps.numberOfBitMaps(shape.getNumberOfBits())];
this.cardinality = 0;
}
@@ -92,8 +92,8 @@ public final class SimpleBloomFilter implements BloomFilter {
}
@Override
- public boolean contains(final IndexProducer indexProducer) {
- return indexProducer.forEachIndex(idx -> BitMap.contains(bitMap, idx));
+ public boolean contains(final IndexExtractor indexExtractor) {
+ return indexExtractor.processIndices(idx -> BitMaps.contains(bitMap, idx));
}
@Override
@@ -102,7 +102,7 @@ public final class SimpleBloomFilter implements BloomFilter {
}
@Override
- public boolean forEachBitMap(final LongPredicate consumer) {
+ public boolean processBitMaps(final LongPredicate consumer) {
Objects.requireNonNull(consumer, "consumer");
for (final long l : bitMap) {
if (!consumer.test(l)) {
@@ -113,15 +113,15 @@ public final class SimpleBloomFilter implements BloomFilter {
}
@Override
- public boolean forEachBitMapPair(final BitMapProducer other, final LongBiPredicate func) {
+ public boolean processBitMapPairs(final BitMapExtractor other, final LongBiPredicate func) {
final CountingLongPredicate p = new CountingLongPredicate(bitMap, func);
- return other.forEachBitMap(p) && p.forEachRemaining();
+ return other.processBitMaps(p) && p.processRemaining();
}
@Override
- public boolean forEachIndex(final IntPredicate consumer) {
+ public boolean processIndices(final IntPredicate consumer) {
Objects.requireNonNull(consumer, "consumer");
- return IndexProducer.fromBitMapProducer(this).forEachIndex(consumer);
+ return IndexExtractor.fromBitMapExtractor(this).processIndices(consumer);
}
@Override
@@ -131,33 +131,33 @@ public final class SimpleBloomFilter implements BloomFilter {
@Override
public boolean isEmpty() {
- return cardinality == 0 || forEachBitMap(y -> y == 0);
+ return cardinality == 0 || processBitMaps(y -> y == 0);
}
@Override
- public boolean merge(final BitMapProducer bitMapProducer) {
- Objects.requireNonNull(bitMapProducer, "bitMapProducer");
+ public boolean merge(final BitMapExtractor bitMapExtractor) {
+ Objects.requireNonNull(bitMapExtractor, "bitMapExtractor");
try {
final int[] idx = new int[1];
- bitMapProducer.forEachBitMap(value -> {
+ bitMapExtractor.processBitMaps(value -> {
bitMap[idx[0]++] |= value;
return true;
});
// idx[0] will be limit+1 so decrement it
idx[0]--;
- final int idxLimit = BitMap.getLongIndex(shape.getNumberOfBits());
+ final int idxLimit = BitMaps.getLongIndex(shape.getNumberOfBits());
if (idxLimit == idx[0]) {
final long excess = bitMap[idxLimit] >> shape.getNumberOfBits();
if (excess != 0) {
throw new IllegalArgumentException(
- String.format("BitMapProducer set a bit higher than the limit for the shape: %s",
+ String.format("BitMapExtractor set a bit higher than the limit for the shape: %s",
shape.getNumberOfBits()));
}
}
cardinality = -1;
} catch (final IndexOutOfBoundsException e) {
throw new IllegalArgumentException(
- String.format("BitMapProducer should send at most %s maps", bitMap.length), e);
+ String.format("BitMapExtractor should send at most %s maps", bitMap.length), e);
}
return true;
}
@@ -166,9 +166,9 @@ public final class SimpleBloomFilter implements BloomFilter {
public boolean merge(final BloomFilter other) {
Objects.requireNonNull(other, "other");
if ((other.characteristics() & SPARSE) != 0) {
- merge((IndexProducer) other);
+ merge((IndexExtractor) other);
} else {
- merge((BitMapProducer) other);
+ merge((BitMapExtractor) other);
}
return true;
}
@@ -180,14 +180,14 @@ public final class SimpleBloomFilter implements BloomFilter {
}
@Override
- public boolean merge(final IndexProducer indexProducer) {
- Objects.requireNonNull(indexProducer, "indexProducer");
- indexProducer.forEachIndex(idx -> {
+ public boolean merge(final IndexExtractor indexExtractor) {
+ Objects.requireNonNull(indexExtractor, "indexExtractor");
+ indexExtractor.processIndices(idx -> {
if (idx < 0 || idx >= shape.getNumberOfBits()) {
throw new IllegalArgumentException(String.format(
- "IndexProducer should only send values in the range[0,%s)", shape.getNumberOfBits()));
+ "IndexExtractor should only send values in the range[0,%s)", shape.getNumberOfBits()));
}
- BitMap.set(bitMap, idx);
+ BitMaps.set(bitMap, idx);
return true;
});
cardinality = -1;
diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/SparseBloomFilter.java b/src/main/java/org/apache/commons/collections4/bloomfilter/SparseBloomFilter.java
index 736a0412d..6c0a3d147 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/SparseBloomFilter.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/SparseBloomFilter.java
@@ -66,9 +66,9 @@ public final class SparseBloomFilter implements BloomFilter {
@Override
public long[] asBitMapArray() {
- final long[] result = new long[BitMap.numberOfBitMaps(shape.getNumberOfBits())];
+ final long[] result = new long[BitMaps.numberOfBitMaps(shape.getNumberOfBits())];
for (final int i : indices) {
- BitMap.set(result, i);
+ BitMaps.set(result, i);
}
return result;
}
@@ -89,13 +89,13 @@ public final class SparseBloomFilter implements BloomFilter {
}
@Override
- public boolean contains(final BitMapProducer bitMapProducer) {
- return contains(IndexProducer.fromBitMapProducer(bitMapProducer));
+ public boolean contains(final BitMapExtractor bitMapExtractor) {
+ return contains(IndexExtractor.fromBitMapExtractor(bitMapExtractor));
}
@Override
- public boolean contains(final IndexProducer indexProducer) {
- return indexProducer.forEachIndex(indices::contains);
+ public boolean contains(final IndexExtractor indexExtractor) {
+ return indexExtractor.processIndices(indices::contains);
}
@Override
@@ -104,9 +104,9 @@ public final class SparseBloomFilter implements BloomFilter {
}
@Override
- public boolean forEachBitMap(final LongPredicate consumer) {
+ public boolean processBitMaps(final LongPredicate consumer) {
Objects.requireNonNull(consumer, "consumer");
- final int limit = BitMap.numberOfBitMaps(shape.getNumberOfBits());
+ final int limit = BitMaps.numberOfBitMaps(shape.getNumberOfBits());
/*
* because our indices are always in order we can shorten the time necessary to
* create the longs for the consumer
@@ -116,14 +116,14 @@ public final class SparseBloomFilter implements BloomFilter {
// the bitmap we are working on
int idx = 0;
for (final int i : indices) {
- while (BitMap.getLongIndex(i) != idx) {
+ while (BitMaps.getLongIndex(i) != idx) {
if (!consumer.test(bitMap)) {
return false;
}
bitMap = 0;
idx++;
}
- bitMap |= BitMap.getLongBit(i);
+ bitMap |= BitMaps.getLongBit(i);
}
// we fall through with data in the bitMap
if (!consumer.test(bitMap)) {
@@ -142,7 +142,7 @@ public final class SparseBloomFilter implements BloomFilter {
}
@Override
- public boolean forEachIndex(final IntPredicate consumer) {
+ public boolean processIndices(final IntPredicate consumer) {
Objects.requireNonNull(consumer, "consumer");
for (final int value : indices) {
if (!consumer.test(value)) {
@@ -163,16 +163,16 @@ public final class SparseBloomFilter implements BloomFilter {
}
@Override
- public boolean merge(final BitMapProducer bitMapProducer) {
- Objects.requireNonNull(bitMapProducer, "bitMapProducer");
- return this.merge(IndexProducer.fromBitMapProducer(bitMapProducer));
+ public boolean merge(final BitMapExtractor bitMapExtractor) {
+ Objects.requireNonNull(bitMapExtractor, "bitMapExtractor");
+ return this.merge(IndexExtractor.fromBitMapExtractor(bitMapExtractor));
}
@Override
public boolean merge(final BloomFilter other) {
Objects.requireNonNull(other, "other");
- final IndexProducer producer = (other.characteristics() & SPARSE) != 0 ? (IndexProducer) other : IndexProducer.fromBitMapProducer(other);
- merge(producer);
+ final IndexExtractor indexExtractor = (other.characteristics() & SPARSE) != 0 ? (IndexExtractor) other : IndexExtractor.fromBitMapExtractor(other);
+ merge(indexExtractor);
return true;
}
@@ -184,9 +184,9 @@ public final class SparseBloomFilter implements BloomFilter {
}
@Override
- public boolean merge(final IndexProducer indexProducer) {
- Objects.requireNonNull(indexProducer, "indexProducer");
- indexProducer.forEachIndex(this::add);
+ public boolean merge(final IndexExtractor indexExtractor) {
+ Objects.requireNonNull(indexExtractor, "indexExtractor");
+ indexExtractor.processIndices(this::add);
if (!this.indices.isEmpty()) {
if (this.indices.last() >= shape.getNumberOfBits()) {
throw new IllegalArgumentException(String.format("Value in list %s is greater than maximum value (%s)",
diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/WrappedBloomFilter.java b/src/main/java/org/apache/commons/collections4/bloomfilter/WrappedBloomFilter.java
index 2a59fcf01..4e259d2a5 100644
--- a/src/main/java/org/apache/commons/collections4/bloomfilter/WrappedBloomFilter.java
+++ b/src/main/java/org/apache/commons/collections4/bloomfilter/WrappedBloomFilter.java
@@ -62,8 +62,8 @@ public abstract class WrappedBloomFilter implements BloomFilter {
}
@Override
- public boolean contains(final BitMapProducer bitMapProducer) {
- return wrapped.contains(bitMapProducer);
+ public boolean contains(final BitMapExtractor bitMapExtractor) {
+ return wrapped.contains(bitMapExtractor);
}
@Override
@@ -77,8 +77,8 @@ public abstract class WrappedBloomFilter implements BloomFilter {
}
@Override
- public boolean contains(final IndexProducer indexProducer) {
- return wrapped.contains(indexProducer);
+ public boolean contains(final IndexExtractor indexExtractor) {
+ return wrapped.contains(indexExtractor);
}
@Override
@@ -97,18 +97,18 @@ public abstract class WrappedBloomFilter implements BloomFilter {
}
@Override
- public boolean forEachBitMap(final LongPredicate predicate) {
- return wrapped.forEachBitMap(predicate);
+ public boolean processBitMaps(final LongPredicate predicate) {
+ return wrapped.processBitMaps(predicate);
}
@Override
- public boolean forEachBitMapPair(final BitMapProducer other, final LongBiPredicate func) {
- return wrapped.forEachBitMapPair(other, func);
+ public boolean processBitMapPairs(final BitMapExtractor other, final LongBiPredicate func) {
+ return wrapped.processBitMapPairs(other, func);
}
@Override
- public boolean forEachIndex(final IntPredicate predicate) {
- return wrapped.forEachIndex(predicate);
+ public boolean processIndices(final IntPredicate predicate) {
+ return wrapped.processIndices(predicate);
}
@Override
@@ -126,8 +126,8 @@ public abstract class WrappedBloomFilter implements BloomFilter {
}
@Override
- public boolean merge(final BitMapProducer bitMapProducer) {
- return wrapped.merge(bitMapProducer);
+ public boolean merge(final BitMapExtractor bitMapExtractor) {
+ return wrapped.merge(bitMapExtractor);
}
@Override
@@ -141,7 +141,7 @@ public abstract class WrappedBloomFilter implements BloomFilter {
}
@Override
- public boolean merge(final IndexProducer indexProducer) {
- return wrapped.merge(indexProducer);
+ public boolean merge(final IndexExtractor indexExtractor) {
+ return wrapped.merge(indexExtractor);
}
}
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 d2c435593..ce3657ac3 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
@@ -21,7 +21,7 @@
* <h2>Background:</h2>
*
* <p>The Bloom filter is a probabilistic data structure that indicates where things are not. Conceptually it is a bit
- * vector. You create a Bloom filter by creating hashes and converting those to enabled bits in the vector. Multiple
+ * vector or BitMap. You create a Bloom filter by creating hashes and converting those to enabled bits in the map. Multiple
* Bloom filters may be merged together into one Bloom filter. It is possible to test if a filter {@code B} has merged
* into another filter {@code A} by verifying that {@code (A & B) == B}.</p>
*
@@ -41,12 +41,43 @@
* {@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.</p>
*
- * <p>In addition the architecture is designed so that the implementation of the storage of bits is abstracted.
- * Programs that utilize the Bloom filters may use the {@code BitMapProducer} or {@code IndexProducer} to retrieve a
- * representation of the internal structure. Additional methods are available in the {@code BitMap} to assist in
- * manipulation of the representations.</p>
+ * <h4>Nomenclature</h4>
*
- * <p>The Bloom filter code is an interface that requires implementation of 9 methods:</p>
+ * <ul>
+ * <li>BitMap - In the bloomfilter package a BitMap is not a structure but a logical construct. It is conceptualized
+ * as an ordered collection of {@code long} values each of which is interpreted as the enabled true/false state of 64 continuous indices. The mapping of
+ * bits into the {@code long} values is described in the {@code BitMaps} javadoc.</li>
+ *
+ * <li>Index - In the bloomfilter package an Index is a logical collection of {@code int}s specifying the enabled
+ * bits in the BitMap.</li>
+ *
+ * <li>Cell - Some Bloom filters (e.g. CountingBloomFilter) use counters rather than bits. In the bloomfilter package
+ * Cells are pairs of ints representing an index and a value. They are not {@code Pair} objects. </li>
+ *
+ * <li>Extractor - The Extractors are {@code FunctionalInterfaces} that are conceptually iterators on a {@code BitMap}, an {@code Index}, or a
+ * collection of {@code Cell}s, with an early termination switch. Extractors have
+ * names like {@code BitMapExtractor} or {@code IndexExtractor} and have a {@code processXs} methods that take a
+ * {@code Predicate<X>} argument (e.g. {@code processBitMaps(LongPredicate)} or {@code processIndicies(IntPredicate)}).
+ * That predicate is expected to process each of the Xs in turn and return {@code true} if the processing should continue
+ * or {@code false} to stop it. </li>
+ * </ul>
+ *
+ * <p>There is an obvious association between the BitMap and the Index, as defined above, in that if bit 5 is enabled in the
+ * BitMap than the Index must contain the value 5.</p>
+ *
+ *
+ * <h4>Implementation Notes</h4>
+ *
+ * <p>The architecture is designed so that the implementation of the storage of bits is abstracted. Rather than specifying a
+ * specific state representation we require that all Bloom filters implement the BitMapExtractor and IndexExtractor interfaces,
+ * Counting-based Bloom filters implement {@code CellExtractor} as well. There are static
+ * methods in the various Extractor interfaces to convert from one type to another.</p>
+ *
+ * <p>Programs that utilize the Bloom filters may use the {@code BitMapExtractor} or {@code IndexExtractor} to retrieve
+ * or process a representation of the internal structure.
+ * Additional methods are available in the {@code BitMaps} class to assist in manipulation of BitMap representations.</p>
+ *
+ * <p>The Bloom filter is an interface that requires implementation of 9 methods:</p>
* <ul>
* <li>{@link BloomFilter#cardinality()} returns the number of bits enabled in the Bloom filter.</li>
*
@@ -54,17 +85,17 @@
*
* <li>{@link BloomFilter#clear()} which resets the Bloomfilter to its initial empty state.</li>
*
- * <li>{@link BloomFilter#contains(IndexProducer)} which returns true if the bits specified by the indices generated by
- * IndexProducer are enabled in the Bloom filter.</li>
+ * <li>{@link BloomFilter#contains(IndexExtractor)} which returns true if the bits specified by the indices generated by
+ * IndexExtractor are enabled in the Bloom filter.</li>
*
* <li>{@link BloomFilter#copy()} which returns a fresh copy of the bitmap.</li>
*
* <li>{@link BloomFilter#getShape()} which returns the shape the Bloom filter was created with.</li>
*
- * <li>{@link BloomFilter#merge(BitMapProducer)} which merges the BitMaps from the BitMapProducer into the internal
+ * <li>{@link BloomFilter#merge(BitMapExtractor)} which merges the BitMaps from the BitMapExtractor into the internal
* representation of the Bloom filter.</li>
*
- * <li>{@link BloomFilter#merge(IndexProducer)} which merges the indices from the IndexProducer into the internal
+ * <li>{@link BloomFilter#merge(IndexExtractor)} which merges the indices from the IndexExtractor into the internal
* representation of the Bloom filter.</li>
* </ul>
*
@@ -83,7 +114,8 @@
*
* <h3>Shape</h3>
*
- * <p>The Shape describes the Bloom filter using the number of bits and the number of hash functions</p>
+ * <p>The Shape describes the Bloom filter using the number of bits and the number of hash functions. It can be specified
+ * by the number of expected items and desired false positive rate.</p>
*
* <h3>Hasher</h3>
*
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBitMapProducerTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBitMapExtractorTest.java
similarity index 59%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBitMapProducerTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBitMapExtractorTest.java
index ed47f1ec0..0a631158f 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBitMapProducerTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBitMapExtractorTest.java
@@ -25,7 +25,7 @@ import java.util.function.LongPredicate;
import org.junit.jupiter.api.Test;
-public abstract class AbstractBitMapProducerTest {
+public abstract class AbstractBitMapExtractorTest {
/**
* A testing consumer that always returns false.
@@ -38,16 +38,16 @@ public abstract class AbstractBitMapProducerTest {
static final LongPredicate TRUE_CONSUMER = arg0 -> true;
/**
- * Creates an producer without data.
- * @return a producer that has no data.
+ * Creates a BitMapExtractor without data.
+ * @return a BitMap extractor that has no data.
*/
- protected abstract BitMapProducer createEmptyProducer();
+ protected abstract BitMapExtractor createEmptyExtractor();
/**
- * Creates a producer with some data.
- * @return a producer with some data
+ * Creates a BitMapExtractor with some data.
+ * @return a BitMap extractor with some data
*/
- protected abstract BitMapProducer createProducer();
+ protected abstract BitMapExtractor createExtractor();
protected boolean emptyIsZeroLength() {
return false;
@@ -55,32 +55,32 @@ public abstract class AbstractBitMapProducerTest {
@Test
public final void testAsBitMapArray() {
- long[] array = createEmptyProducer().asBitMapArray();
+ long[] array = createEmptyExtractor().asBitMapArray();
for (int i = 0; i < array.length; i++) {
assertEquals(0, array[i], "Wrong value at " + i);
}
- array = createProducer().asBitMapArray();
+ array = createExtractor().asBitMapArray();
assertFalse(array.length == 0);
}
@Test
public final void testForEachBitMap() {
- assertFalse(createProducer().forEachBitMap(FALSE_CONSUMER), "non-empty should be false");
+ assertFalse(createExtractor().processBitMaps(FALSE_CONSUMER), "non-empty should be false");
if (emptyIsZeroLength()) {
- assertTrue(createEmptyProducer().forEachBitMap(FALSE_CONSUMER), "empty should be true");
+ assertTrue(createEmptyExtractor().processBitMaps(FALSE_CONSUMER), "empty should be true");
} else {
- assertFalse(createEmptyProducer().forEachBitMap(FALSE_CONSUMER), "empty should be false");
+ assertFalse(createEmptyExtractor().processBitMaps(FALSE_CONSUMER), "empty should be false");
}
- assertTrue(createProducer().forEachBitMap(TRUE_CONSUMER), "non-empty should be true");
- assertTrue(createEmptyProducer().forEachBitMap(TRUE_CONSUMER), "empty should be true");
+ assertTrue(createExtractor().processBitMaps(TRUE_CONSUMER), "non-empty should be true");
+ assertTrue(createEmptyExtractor().processBitMaps(TRUE_CONSUMER), "empty should be true");
}
@Test
public void testForEachBitMapEarlyExit() {
final int[] passes = new int[1];
- assertFalse(createProducer().forEachBitMap(l -> {
+ assertFalse(createExtractor().processBitMaps(l -> {
passes[0]++;
return false;
}));
@@ -88,13 +88,13 @@ public abstract class AbstractBitMapProducerTest {
passes[0] = 0;
if (emptyIsZeroLength()) {
- assertTrue(createEmptyProducer().forEachBitMap(l -> {
+ assertTrue(createEmptyExtractor().processBitMaps(l -> {
passes[0]++;
return false;
}));
assertEquals(0, passes[0]);
} else {
- assertFalse(createEmptyProducer().forEachBitMap(l -> {
+ assertFalse(createEmptyExtractor().processBitMaps(l -> {
passes[0]++;
return false;
}));
@@ -105,12 +105,12 @@ public abstract class AbstractBitMapProducerTest {
@Test
public final void testForEachBitMapPair() {
final LongBiPredicate func = (x, y) -> x == y;
- assertTrue(createEmptyProducer().forEachBitMapPair(createEmptyProducer(), func), "empty == empty failed");
- assertFalse(createEmptyProducer().forEachBitMapPair(createProducer(), func), "empty == not_empty failed");
- assertFalse(createProducer().forEachBitMapPair(createEmptyProducer(), func), "not_empty == empty passed");
- assertTrue(createProducer().forEachBitMapPair(createProducer(), func), "not_empty == not_empty failed");
+ assertTrue(createEmptyExtractor().processBitMapPairs(createEmptyExtractor(), func), "empty == empty failed");
+ assertFalse(createEmptyExtractor().processBitMapPairs(createExtractor(), func), "empty == not_empty failed");
+ assertFalse(createExtractor().processBitMapPairs(createEmptyExtractor(), func), "not_empty == empty passed");
+ assertTrue(createExtractor().processBitMapPairs(createExtractor(), func), "not_empty == not_empty failed");
- // test BitMapProducers of different length send 0 for missing values.
+ // test BitMapExtractors of different length send 0 for missing values.
final int[] count = new int[3];
final LongBiPredicate lbp = (x, y) -> {
if (x == 0) {
@@ -122,38 +122,38 @@ public abstract class AbstractBitMapProducerTest {
count[2]++;
return true;
};
- createEmptyProducer().forEachBitMapPair(createProducer(), lbp);
+ createEmptyExtractor().processBitMapPairs(createExtractor(), lbp);
assertEquals(count[2], count[0]);
Arrays.fill(count, 0);
- createProducer().forEachBitMapPair(createEmptyProducer(), lbp);
+ createExtractor().processBitMapPairs(createEmptyExtractor(), lbp);
assertEquals(count[2], count[1]);
- // test where the created producer does not process all records because the predicate function
+ // test where the created extractor does not process all records because the predicate function
// returns false before the processing is completed.
final int[] limit = new int[1];
final LongBiPredicate shortFunc = (x, y) -> {
limit[0]++;
return limit[0] < 2;
};
- final BitMapProducer shortProducer = l -> true;
- assertFalse(createProducer().forEachBitMapPair(shortProducer, shortFunc));
+ final BitMapExtractor shortExtractor = l -> true;
+ assertFalse(createExtractor().processBitMapPairs(shortExtractor, shortFunc));
}
@Test
public void testForEachBitMapPairEarlyExit() {
- // test BitMapProducers of different length send 0 for missing values.
+ // test BitMapExtractir of different length send 0 for missing values.
final int[] count = new int[1];
final LongBiPredicate lbp = (x, y) -> {
count[0]++;
return false;
};
- createProducer().forEachBitMapPair(createEmptyProducer(), lbp);
+ createExtractor().processBitMapPairs(createEmptyExtractor(), lbp);
assertEquals(1, count[0]);
Arrays.fill(count, 0);
- createEmptyProducer().forEachBitMapPair(createProducer(), lbp);
+ createEmptyExtractor().processBitMapPairs(createExtractor(), lbp);
assertEquals(1, count[0]);
}
}
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilterProducerTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilterExtractorTest.java
similarity index 77%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilterProducerTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilterExtractorTest.java
index 102ba9bcf..7dd03625a 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilterProducerTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilterExtractorTest.java
@@ -26,7 +26,7 @@ import java.util.function.BiPredicate;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-public abstract class AbstractBloomFilterProducerTest {
+public abstract class AbstractBloomFilterExtractorTest {
private final Shape shape = Shape.fromKM(17, 72);
BloomFilter one = new SimpleBloomFilter(shape);
@@ -46,16 +46,16 @@ public abstract class AbstractBloomFilterProducerTest {
return true;
};
- private BloomFilterProducer createUnderTest() {
+ private BloomFilterExtractor createUnderTest() {
return createUnderTest(one, two);
}
/**
- * Creates a BloomFilterProducer that returns the filters (or their copy) in the order presented.
+ * Creates a BloomFilterExtractor that returns the filters (or their copy) in the order presented.
* @param filters The filters to return.
- * @return A BloomFilterProducer that returns the filters in order.
+ * @return A BloomFilterExtractor that returns the filters in order.
*/
- protected abstract BloomFilterProducer createUnderTest(BloomFilter... filters);
+ protected abstract BloomFilterExtractor createUnderTest(BloomFilter... filters);
/**
* The shape of the Bloom filters for testing.
@@ -72,9 +72,9 @@ public abstract class AbstractBloomFilterProducerTest {
@BeforeEach
public void setup() {
one.clear();
- one.merge(IndexProducer.fromIndexArray(1));
+ one.merge(IndexExtractor.fromIndexArray(1));
two.clear();
- two.merge(IndexProducer.fromIndexArray(2, 3));
+ two.merge(IndexExtractor.fromIndexArray(2, 3));
nullCount[0] = 0;
nullCount[1] = 0;
equalityCount[0] = 0;
@@ -92,13 +92,13 @@ public abstract class AbstractBloomFilterProducerTest {
public void testFlatten() {
final BloomFilter underTest = createUnderTest().flatten();
final BloomFilter expected = new SimpleBloomFilter(shape);
- expected.merge(IndexProducer.fromIndexArray(1, 2, 3));
+ expected.merge(IndexExtractor.fromIndexArray(1, 2, 3));
assertArrayEquals(expected.asBitMapArray(), underTest.asBitMapArray());
}
@Test
public void testForEachPairArrayTooLong() {
- assertTrue(createUnderTest().forEachBloomFilterPair(BloomFilterProducer.fromBloomFilterArray(one, two, one),
+ assertTrue(createUnderTest().processBloomFilterPair(BloomFilterExtractor.fromBloomFilterArray(one, two, one),
counter));
assertEquals(1, nullCount[0]);
assertEquals(0, nullCount[1]);
@@ -107,7 +107,7 @@ public abstract class AbstractBloomFilterProducerTest {
@Test
public void testForEachPairArrayTooShort() {
- assertTrue(createUnderTest().forEachBloomFilterPair(BloomFilterProducer.fromBloomFilterArray(one), counter));
+ assertTrue(createUnderTest().processBloomFilterPair(BloomFilterExtractor.fromBloomFilterArray(one), counter));
assertEquals(0, nullCount[0]);
assertEquals(1, nullCount[1]);
assertEquals(1, equalityCount[0]);
@@ -115,20 +115,20 @@ public abstract class AbstractBloomFilterProducerTest {
@Test
public void testForEachPairCompleteMatch() {
- assertTrue(createUnderTest().forEachBloomFilterPair(createUnderTest(), counter));
+ assertTrue(createUnderTest().processBloomFilterPair(createUnderTest(), counter));
assertArrayEquals(new int[] { 0, 0 }, nullCount);
assertEquals(2, equalityCount[0]);
}
@Test
public void testForEachPairReturnFalseEarly() {
- assertFalse(createUnderTest().forEachBloomFilterPair(BloomFilterProducer.fromBloomFilterArray(one, two, one),
+ assertFalse(createUnderTest().processBloomFilterPair(BloomFilterExtractor.fromBloomFilterArray(one, two, one),
(x, y) -> false));
}
@Test
public void testForEachPairReturnFalseLate() {
- assertFalse(createUnderTest().forEachBloomFilterPair(BloomFilterProducer.fromBloomFilterArray(one, two, one),
+ assertFalse(createUnderTest().processBloomFilterPair(BloomFilterExtractor.fromBloomFilterArray(one, two, one),
counter.and((x, y) -> x != null && y != null)));
assertEquals(1, nullCount[0]);
assertEquals(0, nullCount[1]);
@@ -137,7 +137,7 @@ public abstract class AbstractBloomFilterProducerTest {
@Test
public void testForEachPairReturnFalseLateShortArray() {
- assertFalse(createUnderTest().forEachBloomFilterPair(BloomFilterProducer.fromBloomFilterArray(one),
+ assertFalse(createUnderTest().processBloomFilterPair(BloomFilterExtractor.fromBloomFilterArray(one),
counter.and((x, y) -> x != null && y != null)));
assertEquals(0, nullCount[0]);
assertEquals(1, nullCount[1]);
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 a0eaa4a5c..93646935a 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilterTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilterTest.java
@@ -40,28 +40,28 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
*/
public static class BadHasher implements Hasher {
- IndexProducer producer;
+ IndexExtractor extractor;
public BadHasher(final int value) {
- this.producer = IndexProducer.fromIndexArray(value);
+ this.extractor = IndexExtractor.fromIndexArray(value);
}
@Override
- public IndexProducer indices(final Shape shape) {
- return producer;
+ public IndexExtractor indices(final Shape shape) {
+ return extractor;
}
}
- private void assertFailedIndexProducerConstructor(final Shape shape, final int[] values) {
- final IndexProducer indices = IndexProducer.fromIndexArray(values);
+ private void assertFailedIndexExtractorConstructor(final Shape shape, final int[] values) {
+ final IndexExtractor indices = IndexExtractor.fromIndexArray(values);
assertThrows(IllegalArgumentException.class, () -> createFilter(shape, indices));
}
- private void assertIndexProducerMerge(final Shape shape, final int[] values, final int[] expected) {
- final IndexProducer indices = IndexProducer.fromIndexArray(values);
+ private void assertIndexExtractorMerge(final Shape shape, final int[] values, final int[] expected) {
+ final IndexExtractor indices = IndexExtractor.fromIndexArray(values);
final BloomFilter filter = createFilter(shape, indices);
final List<Integer> lst = new ArrayList<>();
- filter.forEachIndex(x -> {
+ filter.processIndices(x -> {
lst.add(x);
return true;
});
@@ -83,12 +83,12 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
* Create the BloomFilter implementation we are testing.
*
* @param shape the shape of the filter.
- * @param producer A BitMap producer to build the filter with.
+ * @param extractor A BitMap extractor to build the filter with.
* @return a BloomFilter implementation.
*/
- protected final T createFilter(final Shape shape, final BitMapProducer producer) {
+ protected final T createFilter(final Shape shape, final BitMapExtractor extractor) {
final T bf = createEmptyFilter(shape);
- bf.merge(producer);
+ bf.merge(extractor);
return bf;
}
@@ -109,12 +109,12 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
* Create the BloomFilter implementation we are testing.
*
* @param shape the shape of the filter.
- * @param producer An Index producer to build the filter with.
+ * @param extractor An Index extractor to build the filter with.
* @return a BloomFilter implementation.
*/
- protected final T createFilter(final Shape shape, final IndexProducer producer) {
+ protected final T createFilter(final Shape shape, final IndexExtractor extractor) {
final T bf = createEmptyFilter(shape);
- bf.merge(producer);
+ bf.merge(extractor);
return bf;
}
@@ -146,20 +146,20 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
}
@Test
- public void testBitMapProducerSize() {
+ public void testBitMapExtractorSize() {
final int[] idx = new int[1];
- createFilter(getTestShape(), TestingHashers.FROM1).forEachBitMap(i -> {
+ createFilter(getTestShape(), TestingHashers.FROM1).processBitMaps(i -> {
idx[0]++;
return true;
});
- assertEquals(BitMap.numberOfBitMaps(getTestShape().getNumberOfBits()), idx[0]);
+ assertEquals(BitMaps.numberOfBitMaps(getTestShape().getNumberOfBits()), idx[0]);
idx[0] = 0;
- createEmptyFilter(getTestShape()).forEachBitMap(i -> {
+ createEmptyFilter(getTestShape()).processBitMaps(i -> {
idx[0]++;
return true;
});
- assertEquals(BitMap.numberOfBitMaps(getTestShape().getNumberOfBits()), idx[0]);
+ assertEquals(BitMaps.numberOfBitMaps(getTestShape().getNumberOfBits()), idx[0]);
}
@Test
@@ -169,7 +169,7 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
/**
* Test cardinality and isEmpty. Bloom filter must be able to accept multiple
- * IndexProducer merges until all the bits are populated.
+ * IndexExtractor merges until all the bits are populated.
*
* @param bf The Bloom filter to test.
*/
@@ -177,7 +177,7 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
assertTrue(bf.isEmpty());
assertEquals(0, bf.cardinality());
for (int i = 0; i < getTestShape().getNumberOfBits(); i++) {
- bf.merge(IndexProducer.fromIndexArray(i));
+ bf.merge(IndexExtractor.fromIndexArray(i));
assertFalse(bf.isEmpty(), "Wrong value at " + i);
assertEquals(i + 1, bf.cardinality(), "Wrong value at " + i);
}
@@ -187,7 +187,7 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
assertEquals(0, bf.cardinality());
assertTrue(bf.isEmpty());
for (int i = 0; i < getTestShape().getNumberOfBits(); i++) {
- bf.merge(IndexProducer.fromIndexArray(i));
+ bf.merge(IndexExtractor.fromIndexArray(i));
assertEquals(i + 1, bf.cardinality(), "Wrong value at " + i);
assertFalse(bf.isEmpty(), "Wrong value at " + i);
}
@@ -213,16 +213,16 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
assertTrue(bf2.contains(new IncrementingHasher(1, 1)), "BF2 Should contain this hasher");
assertFalse(bf2.contains(new IncrementingHasher(1, 3)), "BF2 Should not contain this hasher");
- IndexProducer indexProducer = new IncrementingHasher(1, 1).indices(getTestShape());
- assertTrue(bf2.contains(indexProducer), "BF2 Should contain this hasher");
- indexProducer = new IncrementingHasher(1, 3).indices(getTestShape());
- assertFalse(bf2.contains(indexProducer), "BF2 Should not contain this hasher");
+ IndexExtractor indexExtractor = new IncrementingHasher(1, 1).indices(getTestShape());
+ assertTrue(bf2.contains(indexExtractor), "BF2 Should contain this hasher");
+ indexExtractor = new IncrementingHasher(1, 3).indices(getTestShape());
+ assertFalse(bf2.contains(indexExtractor), "BF2 Should not contain this hasher");
- BitMapProducer bitMapProducer = BitMapProducer.fromIndexProducer(new IncrementingHasher(1, 1).indices(getTestShape()),
+ BitMapExtractor bitMapExtractor = BitMapExtractor.fromIndexExtractor(new IncrementingHasher(1, 1).indices(getTestShape()),
getTestShape().getNumberOfBits());
- assertTrue(bf2.contains(bitMapProducer), "BF2 Should contain this hasher");
- bitMapProducer = BitMapProducer.fromIndexProducer(new IncrementingHasher(1, 3).indices(getTestShape()), getTestShape().getNumberOfBits());
- assertFalse(bf2.contains(bitMapProducer), "BF2 Should not contain this hasher");
+ assertTrue(bf2.contains(bitMapExtractor), "BF2 Should contain this hasher");
+ bitMapExtractor = BitMapExtractor.fromIndexExtractor(new IncrementingHasher(1, 3).indices(getTestShape()), getTestShape().getNumberOfBits());
+ assertFalse(bf2.contains(bitMapExtractor), "BF2 Should not contain this hasher");
// Test different lengths
bf1 = createFilter(getTestShape(), TestingHashers.FROM1);
@@ -242,7 +242,7 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
// test the case where is empty after merge
// in this case the internal cardinality == -1
final BloomFilter bf = createEmptyFilter(getTestShape());
- bf.merge(IndexProducer.fromIndexArray());
+ bf.merge(IndexExtractor.fromIndexArray());
assertTrue(bf.isEmpty());
}
@@ -316,18 +316,18 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
}
@Test
- public void testIndexProducerMerge() {
+ public void testIndexExtractorMerge() {
final Shape shape = Shape.fromKM(5, 10);
- assertIndexProducerMerge(shape, new int[] {0, 2, 4, 6, 8}, new int[] {0, 2, 4, 6, 8});
+ assertIndexExtractorMerge(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});
+ assertIndexExtractorMerge(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});
+ assertFailedIndexExtractorConstructor(shape, new int[] {0, 2, 4, -2, 8});
// test index too large
- assertFailedIndexProducerConstructor(shape, new int[] {0, 2, 4, 12, 8});
+ assertFailedIndexExtractorConstructor(shape, new int[] {0, 2, 4, 12, 8});
// test no indices
- assertIndexProducerMerge(shape, new int[0], new int[0]);
+ assertIndexExtractorMerge(shape, new int[0], new int[0]);
}
/**
@@ -412,53 +412,53 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
}
@Test
- public void testMergeWithBitMapProducer() {
- final int bitMapCount = BitMap.numberOfBitMaps(getTestShape().getNumberOfBits());
+ public void testMergeWithBitMapExtractor() {
+ final int bitMapCount = BitMaps.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())) {
- BitMap.set(values, idx);
+ for (final int idx : DefaultIndexExtractorTest.generateIntArray(getTestShape().getNumberOfHashFunctions(), getTestShape().getNumberOfBits())) {
+ BitMaps.set(values, idx);
}
- final BloomFilter f = createFilter(getTestShape(), BitMapProducer.fromBitMapArray(values));
+ final BloomFilter f = createFilter(getTestShape(), BitMapExtractor.fromBitMapArray(values));
final List<Long> lst = new ArrayList<>();
for (final long l : values) {
lst.add(l);
}
- assertTrue(f.forEachBitMap(l -> lst.remove(Long.valueOf(l))));
+ assertTrue(f.processBitMaps(l -> lst.remove(Long.valueOf(l))));
assertTrue(lst.isEmpty());
}
// values too large
final long[] values = new long[bitMapCount];
Arrays.fill(values, Long.MAX_VALUE);
- final BitMapProducer badProducer = BitMapProducer.fromBitMapArray(values);
+ final BitMapExtractor badExtractor = BitMapExtractor.fromBitMapArray(values);
final BloomFilter bf = createEmptyFilter(getTestShape());
- assertThrows(IllegalArgumentException.class, () -> bf.merge(badProducer));
+ assertThrows(IllegalArgumentException.class, () -> bf.merge(badExtractor));
// test where merged bits exceed expected bits but both bitmaps are the same length.
- final BitMapProducer badProducer2 = BitMapProducer.fromBitMapArray(0x80_00_00_00_00_00_00_00L);
+ final BitMapExtractor badExtractor2 = BitMapExtractor.fromBitMapArray(0x80_00_00_00_00_00_00_00L);
final BloomFilter bf2 = createEmptyFilter(Shape.fromKM(3, 32));
- assertThrows(IllegalArgumentException.class, () -> bf2.merge(badProducer2));
+ assertThrows(IllegalArgumentException.class, () -> bf2.merge(badExtractor2));
}
@Test
public void testMergeWithHasher() {
for (int i = 0; i < 5; i++) {
final BloomFilter f = createEmptyFilter(getTestShape());
- final int[] expected = DefaultIndexProducerTest.generateIntArray(getTestShape().getNumberOfHashFunctions(), getTestShape().getNumberOfBits());
+ final int[] expected = DefaultIndexExtractorTest.generateIntArray(getTestShape().getNumberOfHashFunctions(), getTestShape().getNumberOfBits());
final Hasher hasher = new ArrayHasher(expected);
f.merge(hasher);
// create sorted unique array of expected values
- assertArrayEquals(DefaultIndexProducerTest.unique(expected), f.asIndexArray());
+ assertArrayEquals(DefaultIndexExtractorTest.unique(expected), f.asIndexArray());
}
}
@Test
- public void testMergeWithIndexProducer() {
+ public void testMergeWithIndexExtractor() {
for (int i = 0; i < 5; i++) {
- final int[] values = DefaultIndexProducerTest.generateIntArray(getTestShape().getNumberOfHashFunctions(), getTestShape().getNumberOfBits());
- final BloomFilter f = createFilter(getTestShape(), IndexProducer.fromIndexArray(values));
- final BitSet uniqueValues = DefaultIndexProducerTest.uniqueSet(values);
- assertTrue(f.forEachIndex(idx -> {
+ final int[] values = DefaultIndexExtractorTest.generateIntArray(getTestShape().getNumberOfHashFunctions(), getTestShape().getNumberOfBits());
+ final BloomFilter f = createFilter(getTestShape(), IndexExtractor.fromIndexArray(values));
+ final BitSet uniqueValues = DefaultIndexExtractorTest.uniqueSet(values);
+ assertTrue(f.processIndices(idx -> {
final boolean result = uniqueValues.get(idx);
uniqueValues.clear(idx);
return result;
@@ -468,17 +468,17 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
// value to large
final BloomFilter f1 = createEmptyFilter(getTestShape());
assertThrows(IllegalArgumentException.class,
- () -> f1.merge(IndexProducer.fromIndexArray(getTestShape().getNumberOfBits())));
+ () -> f1.merge(IndexExtractor.fromIndexArray(getTestShape().getNumberOfBits())));
// negative value
final BloomFilter f2 = createEmptyFilter(getTestShape());
assertThrows(IllegalArgumentException.class,
- () -> f2.merge(IndexProducer.fromIndexArray(-1)));
+ () -> f2.merge(IndexExtractor.fromIndexArray(-1)));
}
@Test
public final void testNegativeIntersection() {
- 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);
+ final IndexExtractor p1 = IndexExtractor.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 IndexExtractor p2 = IndexExtractor.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 BloomFilter filter1 = createEmptyFilter(Shape.fromKM(17, 72));
filter1.merge(p1);
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractCellProducerTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractCellExtractorTest.java
similarity index 67%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/AbstractCellProducerTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/AbstractCellExtractorTest.java
index b48c0a8dd..02c00c678 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractCellProducerTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractCellExtractorTest.java
@@ -25,33 +25,33 @@ import static org.junit.jupiter.api.Assertions.fail;
import java.util.Arrays;
import java.util.BitSet;
-import org.apache.commons.collections4.bloomfilter.CellProducer.CellConsumer;
+import org.apache.commons.collections4.bloomfilter.CellExtractor.CellPredicate;
import org.junit.jupiter.api.Test;
-public abstract class AbstractCellProducerTest extends AbstractIndexProducerTest {
+public abstract class AbstractCellExtractorTest extends AbstractIndexExtractorTest {
/**
* A testing CellConsumer that always returns true.
*/
- private static final CellConsumer TRUE_CONSUMER = (i, j) -> true;
+ private static final CellPredicate TRUE_CONSUMER = (i, j) -> true;
/**
* A testing CellConsumer that always returns false.
*/
- private static final CellConsumer FALSE_CONSUMER = (i, j) -> false;
+ private static final CellPredicate FALSE_CONSUMER = (i, j) -> false;
/**
- * Creates a producer without data.
- * @return a producer that has no data.
+ * Creates a CellExtractor without data.
+ * @return a cell extractor that has no data.
*/
@Override
- protected abstract CellProducer createEmptyProducer();
+ protected abstract CellExtractor createEmptyExtractor();
/**
- * Creates a producer with some data.
- * @return a producer with some data
+ * Creates a CellExtractor with some data.
+ * @return a cell extractor with some data
*/
@Override
- protected abstract CellProducer createProducer();
+ protected abstract CellExtractor createExtractor();
@Override
protected final int getAsIndexArrayBehaviour() {
@@ -61,19 +61,19 @@ public abstract class AbstractCellProducerTest extends AbstractIndexProducerTest
/**
* Creates an array of expected values that aligns with the expected indices entries.
* @return an array of expected values.
- * @see AbstractIndexProducerTest#getExpectedIndices()
+ * @see AbstractIndexExtractorTest#getExpectedIndices()
*/
protected abstract int[] getExpectedValues();
/**
- * Test the behavior of {@link CellProducer#forEachCell(CellConsumer)} with respect
+ * Test the behavior of {@link CellExtractor#processCells(CellPredicate)} with respect
* to ordered and distinct indices. Currently the behavior is assumed to be the same as
- * {@link IndexProducer#forEachIndex(java.util.function.IntPredicate)}.
+ * {@link IndexExtractor#processIndices(java.util.function.IntPredicate)}.
*/
@Test
public final void testBehaviourForEachCell() {
final IntList list = new IntList();
- createProducer().forEachCell((i, j) -> list.add(i));
+ createExtractor().processCells((i, j) -> list.add(i));
final int[] actual = list.toArray();
// check order
final int[] expected = Arrays.stream(actual).sorted().toArray();
@@ -84,11 +84,11 @@ public abstract class AbstractCellProducerTest extends AbstractIndexProducerTest
}
@Test
- public final void testEmptyCellProducer() {
- final CellProducer empty = createEmptyProducer();
+ public final void testEmptyCellExtractor() {
+ final CellExtractor empty = createEmptyExtractor();
final int[] ary = empty.asIndexArray();
assertEquals(0, ary.length);
- assertTrue(empty.forEachCell((i, j) -> {
+ assertTrue(empty.processCells((i, j) -> {
fail("forEachCell consumer should not be called");
return false;
}));
@@ -97,13 +97,13 @@ public abstract class AbstractCellProducerTest extends AbstractIndexProducerTest
@Test
public void testForEachCellEarlyExit() {
final int[] passes = new int[1];
- assertTrue(createEmptyProducer().forEachCell((i, j) -> {
+ assertTrue(createEmptyExtractor().processCells((i, j) -> {
passes[0]++;
return false;
}));
assertEquals(0, passes[0]);
- assertFalse(createProducer().forEachCell((i, j) -> {
+ assertFalse(createExtractor().processCells((i, j) -> {
passes[0]++;
return false;
}));
@@ -112,14 +112,14 @@ public abstract class AbstractCellProducerTest extends AbstractIndexProducerTest
@Test
public final void testForEachCellPredicates() {
- final CellProducer populated = createProducer();
- final CellProducer empty = createEmptyProducer();
+ final CellExtractor populated = createExtractor();
+ final CellExtractor empty = createEmptyExtractor();
- assertFalse(populated.forEachCell(FALSE_CONSUMER), "non-empty should be false");
- assertTrue(empty.forEachCell(FALSE_CONSUMER), "empty should be true");
+ assertFalse(populated.processCells(FALSE_CONSUMER), "non-empty should be false");
+ assertTrue(empty.processCells(FALSE_CONSUMER), "empty should be true");
- assertTrue(populated.forEachCell(TRUE_CONSUMER), "non-empty should be true");
- assertTrue(empty.forEachCell(TRUE_CONSUMER), "empty should be true");
+ assertTrue(populated.processCells(TRUE_CONSUMER), "non-empty should be true");
+ assertTrue(empty.processCells(TRUE_CONSUMER), "empty should be true");
}
@Test
@@ -128,7 +128,7 @@ public abstract class AbstractCellProducerTest extends AbstractIndexProducerTest
final int[] expectedValue = getExpectedValues();
assertEquals(expectedIdx.length, expectedValue.length, "expected index length and value length do not match");
final int[] idx = {0};
- createProducer().forEachCell((i, j) -> {
+ createExtractor().processCells((i, j) -> {
assertEquals(expectedIdx[idx[0]], i, "bad index at " + idx[0]);
assertEquals(expectedValue[idx[0]], j, "bad value at " + idx[0]);
idx[0]++;
@@ -138,14 +138,14 @@ public abstract class AbstractCellProducerTest extends AbstractIndexProducerTest
@Test
public final void testIndexConsistency() {
- final CellProducer producer = createProducer();
+ final CellExtractor extractor = createExtractor();
final BitSet bs1 = new BitSet();
final BitSet bs2 = new BitSet();
- producer.forEachIndex(i -> {
+ extractor.processIndices(i -> {
bs1.set(i);
return true;
});
- producer.forEachCell((i, j) -> {
+ extractor.processCells((i, j) -> {
bs2.set(i);
return true;
});
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 d67a0c8b5..2b3dc7ad8 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractCountingBloomFilterTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractCountingBloomFilterTest.java
@@ -48,7 +48,7 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
*/
private static void assertCounts(final CountingBloomFilter bf, final int[] expected) {
final Map<Integer, Integer> m = new HashMap<>();
- bf.forEachCell((i, c) -> {
+ bf.processCells((i, c) -> {
m.put(i, c);
return true;
});
@@ -65,7 +65,7 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
}
private void assertCell3(final CountingBloomFilter bf, final int value) {
- bf.forEachCell((k, v) -> {
+ bf.processCells((k, v) -> {
if (k == 3) {
assertEquals(value, v, "Mismatch at position 3");
} else {
@@ -75,7 +75,7 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
});
}
- protected final CellProducer getMaximumValueProducer(final int maxValue) {
+ protected final CellExtractor getMaximumValueExtractor(final int maxValue) {
return consumer -> {
for (int i = 1; i < 18; i++) {
if (!consumer.test(i, maxValue)) {
@@ -91,8 +91,8 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
final CountingBloomFilter f1 = createEmptyFilter(Shape.fromKM(1, 10));
final CountingBloomFilter f2 = f1.copy();
final CountingBloomFilter f3 = f1.copy();
- // index producer produces 3 two times.
- final IndexProducer ip = p -> {
+ // index extractor produces 3 two times.
+ final IndexExtractor ip = p -> {
p.test(3);
p.test(3);
return true;
@@ -102,22 +102,22 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
assertCell3(f1, 1);
// The add should increment cells 3 by 2
- f2.add(CellProducer.from(ip));
+ f2.add(CellExtractor.from(ip));
assertCell3(f2, 2);
}
@Test
public void removeDecrementsAllCellsTest() {
final CountingBloomFilter f1 = createEmptyFilter(Shape.fromKM(1, 10));
- final CellProducer cp = p -> {
+ final CellExtractor cp = p -> {
p.test(3, 3);
return true;
};
f1.add(cp);
final CountingBloomFilter f2 = f1.copy();
final CountingBloomFilter f3 = f1.copy();
- // index producer produces 3 two times.
- final IndexProducer ip = p -> {
+ // index extractor produces 3 two times.
+ final IndexExtractor ip = p -> {
p.test(3);
p.test(3);
return true;
@@ -127,11 +127,11 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
assertCell3(f1, 2);
// The add should decrement cells 3 by 2
- f2.subtract(CellProducer.from(ip));
+ f2.subtract(CellExtractor.from(ip));
assertCell3(f2, 1);
// This merge will decrement by 1 as the round-trip makes the indices unique
- f3.remove(IndexProducer.fromIndexArray(ip.asIndexArray()));
+ f3.remove(IndexExtractor.fromIndexArray(ip.asIndexArray()));
assertCell3(f3, 2);
}
@@ -150,7 +150,7 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
// test overflow
final CountingBloomFilter bf2 = createEmptyFilter(getTestShape());
- assertTrue(bf2.add(getMaximumValueProducer(bf2.getMaxCell())), "Should add to empty");
+ assertTrue(bf2.add(getMaximumValueExtractor(bf2.getMaxCell())), "Should add to empty");
assertTrue(bf2.isValid(), "Should be valid");
assertFalse(bf2.add(createFilter(getTestShape(), TestingHashers.FROM1)), "Should not add");
@@ -167,8 +167,8 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
assertTrue(bf2.contains(bf2), "BF2 Should contain itself");
assertFalse(bf.contains(bf2), "BF should not contain BF2");
assertTrue(bf2.contains(bf), "BF2 should contain BF");
- final BitMapProducer producer = bf2;
- assertTrue(bf2.contains(producer), "BF2 should contain BF bitMapProducer");
+ final BitMapExtractor extractor = bf2;
+ assertTrue(bf2.contains(extractor), "BF2 should contain BF bitMapExtractor");
}
/**
@@ -180,7 +180,7 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
// verify hasher duplicates are counted.
// bit hasher has duplicates for 11, 12,13,14,15,16, and 17
final CountingBloomFilter bf = createFilter(getTestShape(), TestingHashers.FROM1);
- bf.add(CellProducer.from(TestingHashers.FROM11.indices(getTestShape())));
+ bf.add(CellExtractor.from(TestingHashers.FROM11.indices(getTestShape())));
final long[] lb = bf.asBitMapArray();
assertEquals(2, lb.length);
@@ -214,7 +214,7 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
// test overflow
final CountingBloomFilter bf5 = createEmptyFilter(getTestShape());
- assertTrue(bf5.add(getMaximumValueProducer(bf5.getMaxCell())), "Should add to empty");
+ assertTrue(bf5.add(getMaximumValueExtractor(bf5.getMaxCell())), "Should add to empty");
assertTrue(bf5.isValid(), "Should be valid");
final CountingBloomFilter bf6 = bf5.copy();
@@ -234,7 +234,7 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
CountingBloomFilter bf1 = createFilter(shape, hasher);
assertEquals(6, bf1.cardinality());
- bf1.forEachCell((x, y) -> {
+ bf1.processCells((x, y) -> {
assertEquals(1, y, "Hasher in constructor results in value not equal to 1");
return true;
});
@@ -242,7 +242,7 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
bf1 = createEmptyFilter(shape);
bf1.merge(hasher);
assertEquals(6, bf1.cardinality());
- bf1.forEachCell((x, y) -> {
+ bf1.processCells((x, y) -> {
assertEquals(1, y, "Hasher in merge results in value not equal to 1");
return true;
});
@@ -251,7 +251,7 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
bf1.merge(hasher);
bf1.remove(hasher);
assertEquals(0, bf1.cardinality());
- assertTrue(bf1.forEachCell((x, y) -> false), "Hasher in removes results in value not equal to 0");
+ assertTrue(bf1.processCells((x, y) -> false), "Hasher in removes results in value not equal to 0");
}
@Test
@@ -284,7 +284,7 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
simple.merge(TestingHashers.FROM11);
final CountingBloomFilter bf1 = createFilter(getTestShape(), TestingHashers.FROM1);
- bf1.add(CellProducer.from(TestingHashers.FROM11.indices(getTestShape())));
+ bf1.add(CellExtractor.from(TestingHashers.FROM11.indices(getTestShape())));
assertTrue(bf1.remove(simple), "Remove should work");
assertFalse(bf1.contains(TestingHashers.FROM11), "Should not contain");
@@ -294,7 +294,7 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
// with hasher
final CountingBloomFilter bf2 = createFilter(getTestShape(), TestingHashers.FROM1);
- bf2.add(CellProducer.from(TestingHashers.FROM11.indices(getTestShape())));
+ bf2.add(CellExtractor.from(TestingHashers.FROM11.indices(getTestShape())));
assertTrue(bf2.remove(TestingHashers.FROM11), "Remove should work");
assertFalse(bf2.contains(TestingHashers.FROM11), "Should not contain");
@@ -311,11 +311,11 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
assertCounts(bf3, new int[] {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1});
- // with IndexProducer
- final IndexProducer ip = TestingHashers.FROM11.indices(getTestShape());
+ // with IndexExtractor
+ final IndexExtractor ip = TestingHashers.FROM11.indices(getTestShape());
final CountingBloomFilter bf4 = createFilter(getTestShape(), TestingHashers.FROM1);
- bf4.add(CellProducer.from(TestingHashers.FROM11.indices(getTestShape())));
+ bf4.add(CellExtractor.from(TestingHashers.FROM11.indices(getTestShape())));
assertTrue(bf4.remove(ip), "Remove should work");
assertFalse(bf4.contains(TestingHashers.FROM11), "Should not contain");
@@ -323,10 +323,10 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
assertCounts(bf4, from1Counts);
- // with BitMapProducer
- final BitMapProducer bmp = BitMapProducer.fromIndexProducer(ip, getTestShape().getNumberOfBits());
+ // with BitMapExtractor
+ final BitMapExtractor bmp = BitMapExtractor.fromIndexExtractor(ip, getTestShape().getNumberOfBits());
final CountingBloomFilter bf5 = createFilter(getTestShape(), TestingHashers.FROM1);
- bf5.add(CellProducer.from(TestingHashers.FROM11.indices(getTestShape())));
+ bf5.add(CellExtractor.from(TestingHashers.FROM11.indices(getTestShape())));
assertTrue(bf5.remove(bmp), "Remove should work");
assertFalse(bf5.contains(TestingHashers.FROM11), "Should not contain");
@@ -334,13 +334,13 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
assertCounts(bf5, from1Counts);
- // test producer errors
- final IndexProducer ip2 = IndexProducer.fromIndexArray(1, 2, getTestShape().getNumberOfBits());
+ // test extractor errors
+ final IndexExtractor ip2 = IndexExtractor.fromIndexArray(1, 2, getTestShape().getNumberOfBits());
final CountingBloomFilter bf6 = createFilter(getTestShape(), TestingHashers.FROM1);
assertThrows(IllegalArgumentException.class, () -> bf6.remove(ip2));
final CountingBloomFilter bf7 = createFilter(getTestShape(), TestingHashers.FROM1);
- final BitMapProducer bmp2 = BitMapProducer.fromIndexProducer(ip2, getTestShape().getNumberOfBits());
+ final BitMapExtractor bmp2 = BitMapExtractor.fromIndexExtractor(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())));
@@ -353,7 +353,7 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
@Test
public final void testSubtract() {
final CountingBloomFilter bf1 = createFilter(getTestShape(), TestingHashers.FROM1);
- bf1.add(CellProducer.from(TestingHashers.FROM11.indices(getTestShape())));
+ bf1.add(CellExtractor.from(TestingHashers.FROM11.indices(getTestShape())));
final CountingBloomFilter bf2 = createFilter(getTestShape(), TestingHashers.FROM11);
@@ -389,17 +389,17 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
assertEquals(0, bf.getMaxInsert(new IncrementingHasher(0, 1)));
assertEquals(0, bf.getMaxInsert(bfFrom0));
- assertEquals(0, bf.getMaxInsert((BitMapProducer) bfFrom0));
- assertEquals(0, bf.getMaxInsert((IndexProducer) bfFrom0));
+ assertEquals(0, bf.getMaxInsert((BitMapExtractor) bfFrom0));
+ assertEquals(0, bf.getMaxInsert((IndexExtractor) bfFrom0));
assertEquals(from1, bf.getMaxInsert(TestingHashers.FROM1));
assertEquals(from1, bf.getMaxInsert(bfFrom1));
- assertEquals(from1, bf.getMaxInsert((BitMapProducer) bfFrom1));
- assertEquals(from1, bf.getMaxInsert((IndexProducer) bfFrom1));
+ assertEquals(from1, bf.getMaxInsert((BitMapExtractor) bfFrom1));
+ assertEquals(from1, bf.getMaxInsert((IndexExtractor) bfFrom1));
assertEquals(from11, bf.getMaxInsert(TestingHashers.FROM11));
assertEquals(from11, bf.getMaxInsert(bfFrom11));
- assertEquals(from11, bf.getMaxInsert((BitMapProducer) bfFrom11));
- assertEquals(from11, bf.getMaxInsert((IndexProducer) bfFrom11));
+ assertEquals(from11, bf.getMaxInsert((BitMapExtractor) bfFrom11));
+ assertEquals(from11, bf.getMaxInsert((IndexExtractor) bfFrom11));
}
}
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 782d49451..98452c50a 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractHasherTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractHasherTest.java
@@ -22,19 +22,19 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
-public abstract class AbstractHasherTest extends AbstractIndexProducerTest {
+public abstract class AbstractHasherTest extends AbstractIndexExtractorTest {
protected abstract Hasher createEmptyHasher();
@Override
- protected IndexProducer createEmptyProducer() {
+ protected IndexExtractor createEmptyExtractor() {
return createEmptyHasher().indices(getTestShape());
}
protected abstract Hasher createHasher();
@Override
- protected IndexProducer createProducer() {
+ protected IndexExtractor createExtractor() {
return createHasher().indices(getTestShape());
}
@@ -68,7 +68,7 @@ public abstract class AbstractHasherTest extends AbstractIndexProducerTest {
public void testHashing(final int k, final int m) {
final int[] count = {0};
final Hasher hasher = createHasher();
- hasher.indices(Shape.fromKM(k, m)).forEachIndex(i -> {
+ hasher.indices(Shape.fromKM(k, m)).processIndices(i -> {
assertTrue(i >= 0 && i < m, () -> "Out of range: " + i + ", m=" + m);
count[0]++;
return true;
@@ -78,7 +78,7 @@ public abstract class AbstractHasherTest extends AbstractIndexProducerTest {
// test early exit
count[0] = 0;
- hasher.indices(Shape.fromKM(k, m)).forEachIndex(i -> {
+ hasher.indices(Shape.fromKM(k, m)).processIndices(i -> {
assertTrue(i >= 0 && i < m, () -> "Out of range: " + i + ", m=" + m);
count[0]++;
return false;
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractIndexProducerTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractIndexExtractorTest.java
similarity index 73%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/AbstractIndexProducerTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/AbstractIndexExtractorTest.java
index c1a3d3aa3..455885014 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractIndexProducerTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractIndexExtractorTest.java
@@ -29,9 +29,9 @@ import java.util.function.IntPredicate;
import org.junit.jupiter.api.Test;
/**
- * Test for IndexProducer.
+ * Test for IndexExtractor.
*/
-public abstract class AbstractIndexProducerTest {
+public abstract class AbstractIndexExtractorTest {
/**
* An expandable list of int values.
@@ -66,26 +66,26 @@ public abstract class AbstractIndexProducerTest {
private static final IntPredicate TRUE_PREDICATE = i -> true;
private static final IntPredicate FALSE_PREDICATE = i -> false;
- /** Flag to indicate the indices are ordered, e.g. from {@link IndexProducer#forEachIndex(IntPredicate)}. */
+ /** Flag to indicate the indices are ordered, e.g. from {@link IndexExtractor#processIndices(IntPredicate)}. */
protected static final int ORDERED = 0x1;
- /** Flag to indicate the indices are distinct, e.g. from {@link IndexProducer#forEachIndex(IntPredicate)}. */
+ /** Flag to indicate the indices are distinct, e.g. from {@link IndexExtractor#processIndices(IntPredicate)}. */
protected static final int DISTINCT = 0x2;
/**
- * Creates an producer without data.
- * @return a producer that has no data.
+ * Creates an extractor without data.
+ * @return an IndexExtractor that has no data.
*/
- protected abstract IndexProducer createEmptyProducer();
+ protected abstract IndexExtractor createEmptyExtractor();
/**
- * Creates a producer with some data.
- * @return a producer with some data
+ * Creates an extractor with some data.
+ * @return an IndexExtractor with some data
*/
- protected abstract IndexProducer createProducer();
+ protected abstract IndexExtractor createExtractor();
/**
- * Gets the behavior of the {@link IndexProducer#asIndexArray()} method.
+ * Gets the behavior of the {@link IndexExtractor#asIndexArray()} method.
* @return the behavior.
* @see #ORDERED
* @see #DISTINCT
@@ -94,13 +94,13 @@ public abstract class AbstractIndexProducerTest {
/**
* Creates an array of expected indices.
- * The expected indices are dependent upon the producer created in the {@code createProducer()} method.
+ * The expected indices are dependent upon the extractor created in the {@code createExtractor()} method.
* @return an array of expected indices.
*/
protected abstract int[] getExpectedIndices();
/**
- * Gets the behavior of the {@link IndexProducer#forEachIndex(IntPredicate)} method.
+ * Gets the behavior of the {@link IndexExtractor#processIndices(IntPredicate)} method.
* By default returns the value of {@code getAsIndexArrayBehaviour()} method.
* @return the behavior.
* @see #ORDERED
@@ -116,14 +116,14 @@ public abstract class AbstractIndexProducerTest {
@Test
public final void testAsIndexArrayValues() {
final BitSet bs = new BitSet();
- Arrays.stream(createProducer().asIndexArray()).forEach(bs::set);
+ Arrays.stream(createExtractor().asIndexArray()).forEach(bs::set);
for (final int i : getExpectedIndices()) {
assertTrue(bs.get(i), () -> "Missing " + i);
}
}
/**
- * Tests the behavior of {@code IndexProducer.asIndexArray()}.
+ * Tests the behavior of {@code IndexExtractor.asIndexArray()}.
* The expected behavior is defined by the {@code getBehaviour()} method.
* The index array may be Ordered, Distinct or both.
* If the index array is not distinct then all elements returned by the {@code getExpectedIndices()}
@@ -132,7 +132,7 @@ public abstract class AbstractIndexProducerTest {
@Test
public final void testBehaviourAsIndexArray() {
final int flags = getAsIndexArrayBehaviour();
- final int[] actual = createProducer().asIndexArray();
+ final int[] actual = createExtractor().asIndexArray();
if ((flags & ORDERED) != 0) {
final int[] expected = Arrays.stream(actual).sorted().toArray();
assertArrayEquals(expected, actual);
@@ -151,15 +151,15 @@ public abstract class AbstractIndexProducerTest {
}
/**
- * Tests the behavior of {@code IndexProducer.forEachIndex()}.
+ * Tests the behavior of {@code IndexExtractor.forEachIndex()}.
* The expected behavior is defined by the {@code getBehaviour()} method.
- * The order is assumed to follow the order produced by {@code IndexProducer.asIndexArray()}.
+ * The order is assumed to follow the order produced by {@code IndexExtractor.asIndexArray()}.
*/
@Test
public final void testBehaviourForEachIndex() {
final int flags = getForEachIndexBehaviour();
final IntList list = new IntList();
- createProducer().forEachIndex(list::add);
+ createExtractor().processIndices(list::add);
final int[] actual = list.toArray();
if ((flags & ORDERED) != 0) {
final int[] expected = Arrays.stream(actual).sorted().toArray();
@@ -178,15 +178,15 @@ public abstract class AbstractIndexProducerTest {
}
/**
- * Test the distinct indices output from the producer are consistent.
+ * Test the distinct indices output from the extractor are consistent.
*/
@Test
public final void testConsistency() {
- final IndexProducer producer = createProducer();
+ final IndexExtractor extractor = createExtractor();
final BitSet bs1 = new BitSet();
final BitSet bs2 = new BitSet();
- Arrays.stream(producer.asIndexArray()).forEach(bs1::set);
- producer.forEachIndex(i -> {
+ Arrays.stream(extractor.asIndexArray()).forEach(bs1::set);
+ extractor.processIndices(i -> {
bs2.set(i);
return true;
});
@@ -194,24 +194,24 @@ public abstract class AbstractIndexProducerTest {
}
@Test
- public final void testEmptyProducer() {
- final IndexProducer empty = createEmptyProducer();
+ public final void testEmptyExtractor() {
+ final IndexExtractor empty = createEmptyExtractor();
final int[] ary = empty.asIndexArray();
assertEquals(0, ary.length);
- assertTrue(empty.forEachIndex(i -> {
- throw new AssertionError("forEach predictate should not be called");
+ assertTrue(empty.processIndices(i -> {
+ throw new AssertionError("processIndices predictate should not be called");
}));
}
/**
- * Test to ensure that for each index returns each expected index at least once.
+ * Test to ensure that processIndices returns each expected index at least once.
*/
@Test
public final void testForEachIndex() {
final BitSet bs1 = new BitSet();
final BitSet bs2 = new BitSet();
Arrays.stream(getExpectedIndices()).forEach(bs1::set);
- createProducer().forEachIndex(i -> {
+ createExtractor().processIndices(i -> {
bs2.set(i);
return true;
});
@@ -221,14 +221,14 @@ public abstract class AbstractIndexProducerTest {
@Test
public void testForEachIndexEarlyExit() {
final int[] passes = new int[1];
- assertFalse(createProducer().forEachIndex(i -> {
+ assertFalse(createExtractor().processIndices(i -> {
passes[0]++;
return false;
}));
assertEquals(1, passes[0]);
passes[0] = 0;
- assertTrue(createEmptyProducer().forEachIndex(i -> {
+ assertTrue(createEmptyExtractor().processIndices(i -> {
passes[0]++;
return false;
}));
@@ -237,19 +237,19 @@ public abstract class AbstractIndexProducerTest {
@Test
public final void testForEachIndexPredicates() {
- final IndexProducer populated = createProducer();
- final IndexProducer empty = createEmptyProducer();
+ final IndexExtractor populated = createExtractor();
+ final IndexExtractor empty = createEmptyExtractor();
- assertFalse(populated.forEachIndex(FALSE_PREDICATE), "non-empty should be false");
- assertTrue(empty.forEachIndex(FALSE_PREDICATE), "empty should be true");
+ assertFalse(populated.processIndices(FALSE_PREDICATE), "non-empty should be false");
+ assertTrue(empty.processIndices(FALSE_PREDICATE), "empty should be true");
- assertTrue(populated.forEachIndex(TRUE_PREDICATE), "non-empty should be true");
- assertTrue(empty.forEachIndex(TRUE_PREDICATE), "empty should be true");
+ assertTrue(populated.processIndices(TRUE_PREDICATE), "non-empty should be true");
+ assertTrue(empty.processIndices(TRUE_PREDICATE), "empty should be true");
}
@Test
public void testUniqueReturnsSelf() {
- final IndexProducer expected = createProducer().uniqueIndices();
+ final IndexExtractor expected = createExtractor().uniqueIndices();
assertSame(expected, expected.uniqueIndices());
}
}
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/ArrayHasher.java b/src/test/java/org/apache/commons/collections4/bloomfilter/ArrayHasher.java
index 239947e7e..f65fdadf1 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/ArrayHasher.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/ArrayHasher.java
@@ -25,15 +25,15 @@ import java.util.function.IntPredicate;
* <p>To be used for testing only.</p>
*/
public final class ArrayHasher implements Hasher {
- private final class Producer implements IndexProducer {
+ private final class Extractor implements IndexExtractor {
Shape shape;
- Producer(final Shape shape) {
+ Extractor(final Shape shape) {
this.shape = shape;
}
@Override
- public boolean forEachIndex(final IntPredicate consumer) {
+ public boolean processIndices(final IntPredicate consumer) {
Objects.requireNonNull(consumer, "consumer");
int pos = 0;
@@ -55,8 +55,8 @@ public final class ArrayHasher implements Hasher {
}
@Override
- public IndexProducer indices(final Shape shape) {
+ public IndexExtractor indices(final Shape shape) {
Objects.requireNonNull(shape, "shape");
- return new Producer(shape);
+ return new Extractor(shape);
}
}
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromArrayCountingBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapExtractorFromArrayCountingBloomFilterTest.java
similarity index 85%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromArrayCountingBloomFilterTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/BitMapExtractorFromArrayCountingBloomFilterTest.java
index 63ec52a66..e7c341bcf 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromArrayCountingBloomFilterTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapExtractorFromArrayCountingBloomFilterTest.java
@@ -16,17 +16,17 @@
*/
package org.apache.commons.collections4.bloomfilter;
-public class BitMapProducerFromArrayCountingBloomFilterTest extends AbstractBitMapProducerTest {
+public class BitMapExtractorFromArrayCountingBloomFilterTest extends AbstractBitMapExtractorTest {
protected Shape shape = Shape.fromKM(17, 72);
@Override
- protected BitMapProducer createEmptyProducer() {
+ protected BitMapExtractor createEmptyExtractor() {
return new ArrayCountingBloomFilter(shape);
}
@Override
- protected BitMapProducer createProducer() {
+ protected BitMapExtractor createExtractor() {
final ArrayCountingBloomFilter filter = new ArrayCountingBloomFilter(shape);
final Hasher hasher = new IncrementingHasher(0, 1);
filter.merge(hasher);
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromIndexProducerTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapExtractorFromIndexExtractorTest.java
similarity index 57%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromIndexProducerTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/BitMapExtractorFromIndexExtractorTest.java
index 38b336cbd..e0a91ea79 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromIndexProducerTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapExtractorFromIndexExtractorTest.java
@@ -23,31 +23,31 @@ import java.util.List;
import org.junit.jupiter.api.Test;
-public class BitMapProducerFromIndexProducerTest extends AbstractBitMapProducerTest {
+public class BitMapExtractorFromIndexExtractorTest extends AbstractBitMapExtractorTest {
@Override
- protected BitMapProducer createEmptyProducer() {
- final IndexProducer iProducer = consumer -> true;
- return BitMapProducer.fromIndexProducer(iProducer, 200);
+ protected BitMapExtractor createEmptyExtractor() {
+ final IndexExtractor indexExtractor = consumer -> true;
+ return BitMapExtractor.fromIndexExtractor(indexExtractor, 200);
}
@Override
- protected BitMapProducer createProducer() {
- final IndexProducer iProducer = consumer -> consumer.test(0) && consumer.test(1) && consumer.test(63) && consumer.test(64)
+ protected BitMapExtractor createExtractor() {
+ final IndexExtractor indexExtractor = consumer -> consumer.test(0) && consumer.test(1) && consumer.test(63) && consumer.test(64)
&& consumer.test(127) && consumer.test(128);
- return BitMapProducer.fromIndexProducer(iProducer, 200);
+ return BitMapExtractor.fromIndexExtractor(indexExtractor, 200);
}
@Test
- public final void testFromIndexProducer() {
+ public final void testFromIndexExtractor() {
final List<Long> lst = new ArrayList<>();
- createProducer().forEachBitMap(lst::add);
+ createExtractor().processBitMaps(lst::add);
final long[] buckets = lst.stream().mapToLong(Long::longValue).toArray();
- assertTrue(BitMap.contains(buckets, 0));
- assertTrue(BitMap.contains(buckets, 1));
- assertTrue(BitMap.contains(buckets, 63));
- assertTrue(BitMap.contains(buckets, 64));
- assertTrue(BitMap.contains(buckets, 127));
- assertTrue(BitMap.contains(buckets, 128));
+ assertTrue(BitMaps.contains(buckets, 0));
+ assertTrue(BitMaps.contains(buckets, 1));
+ assertTrue(BitMaps.contains(buckets, 63));
+ assertTrue(BitMaps.contains(buckets, 64));
+ assertTrue(BitMaps.contains(buckets, 127));
+ assertTrue(BitMaps.contains(buckets, 128));
}
}
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromLayeredBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapExtractorFromLayeredBloomFilterTest.java
similarity index 85%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromLayeredBloomFilterTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/BitMapExtractorFromLayeredBloomFilterTest.java
index 246ef518c..b191aa09a 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromLayeredBloomFilterTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapExtractorFromLayeredBloomFilterTest.java
@@ -16,17 +16,17 @@
*/
package org.apache.commons.collections4.bloomfilter;
-public class BitMapProducerFromLayeredBloomFilterTest extends AbstractBitMapProducerTest {
+public class BitMapExtractorFromLayeredBloomFilterTest extends AbstractBitMapExtractorTest {
protected Shape shape = Shape.fromKM(17, 72);
@Override
- protected BitMapProducer createEmptyProducer() {
+ protected BitMapExtractor createEmptyExtractor() {
return LayeredBloomFilterTest.fixed(shape, 10);
}
@Override
- protected BitMapProducer createProducer() {
+ protected BitMapExtractor createExtractor() {
final Hasher hasher = new IncrementingHasher(0, 1);
final BloomFilter bf = LayeredBloomFilterTest.fixed(shape, 10);
bf.merge(hasher);
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromLongArrayTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapExtractorFromLongArrayTest.java
similarity index 77%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromLongArrayTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/BitMapExtractorFromLongArrayTest.java
index 165ea404c..7a2c68461 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromLongArrayTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapExtractorFromLongArrayTest.java
@@ -23,12 +23,12 @@ import java.util.List;
import org.junit.jupiter.api.Test;
-public class BitMapProducerFromLongArrayTest extends AbstractBitMapProducerTest {
+public class BitMapExtractorFromLongArrayTest extends AbstractBitMapExtractorTest {
@Test
public void constructorTest() {
final List<Long> lst = new ArrayList<>();
- createProducer().forEachBitMap(lst::add);
+ createExtractor().processBitMaps(lst::add);
assertEquals(Long.valueOf(1), lst.get(0));
assertEquals(Long.valueOf(2), lst.get(1));
assertEquals(Long.valueOf(3), lst.get(2));
@@ -37,14 +37,14 @@ public class BitMapProducerFromLongArrayTest extends AbstractBitMapProducerTest
}
@Override
- protected BitMapProducer createEmptyProducer() {
- return BitMapProducer.fromBitMapArray();
+ protected BitMapExtractor createEmptyExtractor() {
+ return BitMapExtractor.fromBitMapArray();
}
@Override
- protected BitMapProducer createProducer() {
+ protected BitMapExtractor createExtractor() {
final long[] ary = {1L, 2L, 3L, 4L, 5L};
- return BitMapProducer.fromBitMapArray(ary);
+ return BitMapExtractor.fromBitMapArray(ary);
}
@Override
@@ -53,9 +53,9 @@ public class BitMapProducerFromLongArrayTest extends AbstractBitMapProducerTest
}
@Test
- public void testFromIndexProducer() {
+ public void testFromIndexExtractor() {
final int limit = Integer.SIZE + Long.SIZE;
- final IndexProducer iProducer = consumer -> {
+ final IndexExtractor indexExtractor = consumer -> {
for (int i = 0; i < limit; i++) {
if (!consumer.test(i)) {
return false;
@@ -63,9 +63,9 @@ public class BitMapProducerFromLongArrayTest extends AbstractBitMapProducerTest
}
return true;
};
- final BitMapProducer producer = BitMapProducer.fromIndexProducer(iProducer, limit);
+ final BitMapExtractor bitMapExtractor = BitMapExtractor.fromIndexExtractor(indexExtractor, limit);
final List<Long> lst = new ArrayList<>();
- producer.forEachBitMap(lst::add);
+ bitMapExtractor.processBitMaps(lst::add);
long expected = ~0L;
assertEquals(expected, lst.get(0).longValue());
expected &= 0XFFFFFFFFL;
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromSimpleBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapExtractorFromSimpleBloomFilterTest.java
similarity index 85%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromSimpleBloomFilterTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/BitMapExtractorFromSimpleBloomFilterTest.java
index 8e1d2ca20..5ed9acdad 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromSimpleBloomFilterTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapExtractorFromSimpleBloomFilterTest.java
@@ -16,17 +16,17 @@
*/
package org.apache.commons.collections4.bloomfilter;
-public class BitMapProducerFromSimpleBloomFilterTest extends AbstractBitMapProducerTest {
+public class BitMapExtractorFromSimpleBloomFilterTest extends AbstractBitMapExtractorTest {
protected Shape shape = Shape.fromKM(17, 72);
@Override
- protected BitMapProducer createEmptyProducer() {
+ protected BitMapExtractor createEmptyExtractor() {
return new SimpleBloomFilter(shape);
}
@Override
- protected BitMapProducer createProducer() {
+ protected BitMapExtractor createExtractor() {
final Hasher hasher = new IncrementingHasher(0, 1);
final BloomFilter bf = new SimpleBloomFilter(shape);
bf.merge(hasher);
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromSparseBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapExtractorFromSparseBloomFilterTest.java
similarity index 85%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromSparseBloomFilterTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/BitMapExtractorFromSparseBloomFilterTest.java
index 6c15eda45..638a0350f 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromSparseBloomFilterTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapExtractorFromSparseBloomFilterTest.java
@@ -16,17 +16,17 @@
*/
package org.apache.commons.collections4.bloomfilter;
-public class BitMapProducerFromSparseBloomFilterTest extends AbstractBitMapProducerTest {
+public class BitMapExtractorFromSparseBloomFilterTest extends AbstractBitMapExtractorTest {
protected Shape shape = Shape.fromKM(17, 72);
@Override
- protected BitMapProducer createEmptyProducer() {
+ protected BitMapExtractor createEmptyExtractor() {
return new SparseBloomFilter(shape);
}
@Override
- protected BitMapProducer createProducer() {
+ protected BitMapExtractor createExtractor() {
final Hasher hasher = new IncrementingHasher(0, 1);
final BloomFilter bf = new SparseBloomFilter(shape);
bf.merge(hasher);
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromWrappedBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapExtractorFromWrappedBloomFilterTest.java
similarity index 90%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromWrappedBloomFilterTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/BitMapExtractorFromWrappedBloomFilterTest.java
index 9716dd408..4040efb95 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapProducerFromWrappedBloomFilterTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapExtractorFromWrappedBloomFilterTest.java
@@ -16,12 +16,12 @@
*/
package org.apache.commons.collections4.bloomfilter;
-public class BitMapProducerFromWrappedBloomFilterTest extends AbstractBitMapProducerTest {
+public class BitMapExtractorFromWrappedBloomFilterTest extends AbstractBitMapExtractorTest {
protected Shape shape = Shape.fromKM(17, 72);
@Override
- protected BitMapProducer createEmptyProducer() {
+ protected BitMapExtractor createEmptyExtractor() {
return new WrappedBloomFilter(new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape)) {
@Override
public BloomFilter copy() {
@@ -33,7 +33,7 @@ public class BitMapProducerFromWrappedBloomFilterTest extends AbstractBitMapProd
}
@Override
- protected BitMapProducer createProducer() {
+ protected BitMapExtractor createExtractor() {
final Hasher hasher = new IncrementingHasher(0, 1);
final BloomFilter bf = new WrappedBloomFilter(new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape)) {
@Override
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapsTest.java
similarity index 64%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/BitMapTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/BitMapsTest.java
index 2997a8683..274614f01 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BitMapsTest.java
@@ -24,10 +24,10 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
-public class BitMapTest {
+public class BitMapsTest {
/**
- * Assert the {@link BitMap#mod(long, int)} method functions as an unsigned modulus.
+ * Assert the {@link BitMaps#mod(long, int)} method functions as an unsigned modulus.
*
* @param dividend the dividend
* @param divisor the divisor
@@ -35,7 +35,7 @@ public class BitMapTest {
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),
+ assertEquals((int) Long.remainderUnsigned(dividend, divisor), BitMaps.mod(dividend, divisor),
() -> String.format("failure with dividend=%s and divisor=%s.", dividend, divisor));
}
@@ -45,12 +45,12 @@ public class BitMapTest {
for (int i = 0; i < 64; i++) {
bitMaps[0] = 0L;
- BitMap.set(bitMaps, i);
+ BitMaps.set(bitMaps, i);
for (int j = 0; j < 64; j++) {
if (j == i) {
- assertTrue(BitMap.contains(bitMaps, j), String.format("Failed at index: %d for %d", i, j));
+ assertTrue(BitMaps.contains(bitMaps, j), String.format("Failed at index: %d for %d", i, j));
} else {
- assertFalse(BitMap.contains(bitMaps, j), String.format("Failed at index %d for %d", i, j));
+ assertFalse(BitMaps.contains(bitMaps, j), String.format("Failed at index %d for %d", i, j));
}
}
}
@@ -59,38 +59,38 @@ public class BitMapTest {
long[] ary = new long[1];
final long[] aryT = ary;
- assertThrows(ArrayIndexOutOfBoundsException.class, () -> BitMap.contains(aryT, -1));
- assertFalse(BitMap.contains(ary, 0));
+ assertThrows(ArrayIndexOutOfBoundsException.class, () -> BitMaps.contains(aryT, -1));
+ assertFalse(BitMaps.contains(ary, 0));
ary[0] = 0x01;
- assertTrue(BitMap.contains(ary, 0));
+ assertTrue(BitMaps.contains(ary, 0));
- assertFalse(BitMap.contains(ary, 63));
+ assertFalse(BitMaps.contains(ary, 63));
ary[0] = 1L << 63;
- assertTrue(BitMap.contains(ary, 63));
- assertThrows(ArrayIndexOutOfBoundsException.class, () -> BitMap.contains(aryT, 64));
+ assertTrue(BitMaps.contains(ary, 63));
+ assertThrows(ArrayIndexOutOfBoundsException.class, () -> BitMaps.contains(aryT, 64));
ary = new long[2];
- assertFalse(BitMap.contains(ary, 64));
+ assertFalse(BitMaps.contains(ary, 64));
ary[1] = 1;
- assertTrue(BitMap.contains(ary, 64));
+ assertTrue(BitMaps.contains(ary, 64));
}
@Test
public final void testGetLongBit() {
- assertEquals(1, BitMap.getLongBit(0));
- assertEquals(0x8000000000000000L, BitMap.getLongBit(63));
- assertEquals(1, BitMap.getLongBit(64));
- assertEquals(0x8000000000000000L, BitMap.getLongBit(127));
- assertEquals(1, BitMap.getLongBit(128));
+ assertEquals(1, BitMaps.getLongBit(0));
+ assertEquals(0x8000000000000000L, BitMaps.getLongBit(63));
+ assertEquals(1, BitMaps.getLongBit(64));
+ assertEquals(0x8000000000000000L, BitMaps.getLongBit(127));
+ assertEquals(1, BitMaps.getLongBit(128));
}
@Test
public final void testGetLongIndex() {
- assertEquals(0, BitMap.getLongIndex(0));
- assertEquals(0, BitMap.getLongIndex(63));
- assertEquals(1, BitMap.getLongIndex(64));
- assertEquals(1, BitMap.getLongIndex(127));
- assertEquals(2, BitMap.getLongIndex(128));
+ assertEquals(0, BitMaps.getLongIndex(0));
+ assertEquals(0, BitMaps.getLongIndex(63));
+ assertEquals(1, BitMaps.getLongIndex(64));
+ assertEquals(1, BitMaps.getLongIndex(127));
+ assertEquals(2, BitMaps.getLongIndex(128));
}
@Test
@@ -106,29 +106,29 @@ public class BitMapTest {
@Test
public void testModEdgeCases() {
for (final long dividend : new long[] {0, -1, 1, Long.MAX_VALUE}) {
- assertThrows(ArithmeticException.class, () -> BitMap.mod(dividend, 0));
+ assertThrows(ArithmeticException.class, () -> BitMaps.mod(dividend, 0));
}
- assertNotEquals(Math.floorMod(5, -1), BitMap.mod(5, -1));
+ assertNotEquals(Math.floorMod(5, -1), BitMaps.mod(5, -1));
}
@Test
public final void testNumberOfBitMaps() {
- assertEquals(0, BitMap.numberOfBitMaps(0), "Number of bits 0");
+ assertEquals(0, BitMaps.numberOfBitMaps(0), "Number of bits 0");
for (int i = 1; i < 65; i++) {
- assertEquals(1, BitMap.numberOfBitMaps(i), String.format("Number of bits %d", i));
+ assertEquals(1, BitMaps.numberOfBitMaps(i), String.format("Number of bits %d", i));
}
for (int i = 65; i < 129; i++) {
- assertEquals(2, BitMap.numberOfBitMaps(i), String.format("Number of bits %d", i));
+ assertEquals(2, BitMaps.numberOfBitMaps(i), String.format("Number of bits %d", i));
}
- assertEquals(3, BitMap.numberOfBitMaps(129), "Number of bits 129");
+ assertEquals(3, BitMaps.numberOfBitMaps(129), "Number of bits 129");
}
@Test
public final void testSet() {
- final long[] bitMaps = new long[BitMap.numberOfBitMaps(129)];
+ final long[] bitMaps = new long[BitMaps.numberOfBitMaps(129)];
for (int i = 0; i < 129; i++) {
- BitMap.set(bitMaps, i);
- assertTrue(BitMap.contains(bitMaps, i), String.format("Failed at index: %d", i));
+ BitMaps.set(bitMaps, i);
+ assertTrue(BitMaps.contains(bitMaps, i), String.format("Failed at index: %d", i));
}
assertEquals(0xFFFFFFFFFFFFFFFFL, bitMaps[0]);
assertEquals(0xFFFFFFFFFFFFFFFFL, bitMaps[1]);
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BloomFilterProducerFromLayeredBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BloomFilteExtractorFromLayeredBloomFilterTest.java
similarity index 88%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/BloomFilterProducerFromLayeredBloomFilterTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/BloomFilteExtractorFromLayeredBloomFilterTest.java
index 1c298f80e..f66522d29 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/BloomFilterProducerFromLayeredBloomFilterTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BloomFilteExtractorFromLayeredBloomFilterTest.java
@@ -16,10 +16,10 @@
*/
package org.apache.commons.collections4.bloomfilter;
-public class BloomFilterProducerFromLayeredBloomFilterTest extends AbstractBloomFilterProducerTest {
+public class BloomFilteExtractorFromLayeredBloomFilterTest extends AbstractBloomFilterExtractorTest {
@Override
- protected BloomFilterProducer createUnderTest(final BloomFilter... filters) {
+ protected BloomFilterExtractor createUnderTest(final BloomFilter... filters) {
final Shape shape = filters[0].getShape();
final LayerManager layerManager = LayerManager.builder().setSupplier(() -> new SimpleBloomFilter(shape))
.setExtendCheck(LayerManager.ExtendCheck.advanceOnPopulated()).setCleanup(LayerManager.Cleanup.noCleanup()).build();
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BloomFilterProducerFromBloomFilterArrayTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BloomFilterExtractorFromBloomFilterArrayTest.java
similarity index 77%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/BloomFilterProducerFromBloomFilterArrayTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/BloomFilterExtractorFromBloomFilterArrayTest.java
index f18025e5b..c3419335d 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/BloomFilterProducerFromBloomFilterArrayTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BloomFilterExtractorFromBloomFilterArrayTest.java
@@ -16,10 +16,10 @@
*/
package org.apache.commons.collections4.bloomfilter;
-public class BloomFilterProducerFromBloomFilterArrayTest extends AbstractBloomFilterProducerTest {
+public class BloomFilterExtractorFromBloomFilterArrayTest extends AbstractBloomFilterExtractorTest {
@Override
- protected BloomFilterProducer createUnderTest(final BloomFilter... filters) {
- return BloomFilterProducer.fromBloomFilterArray(filters);
+ protected BloomFilterExtractor createUnderTest(final BloomFilter... filters) {
+ return BloomFilterExtractor.fromBloomFilterArray(filters);
}
}
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/CellProducerFromArrayCountingBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/CellExtractorFromArrayCountingBloomFilterTest.java
similarity index 88%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/CellProducerFromArrayCountingBloomFilterTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/CellExtractorFromArrayCountingBloomFilterTest.java
index 7f054fcc6..43571a17f 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/CellProducerFromArrayCountingBloomFilterTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/CellExtractorFromArrayCountingBloomFilterTest.java
@@ -16,17 +16,17 @@
*/
package org.apache.commons.collections4.bloomfilter;
-public class CellProducerFromArrayCountingBloomFilterTest extends AbstractCellProducerTest {
+public class CellExtractorFromArrayCountingBloomFilterTest extends AbstractCellExtractorTest {
protected Shape shape = Shape.fromKM(17, 72);
@Override
- protected CellProducer createEmptyProducer() {
+ protected CellExtractor createEmptyExtractor() {
return new ArrayCountingBloomFilter(shape);
}
@Override
- protected CellProducer createProducer() {
+ protected CellExtractor createExtractor() {
final ArrayCountingBloomFilter filter = new ArrayCountingBloomFilter(shape);
filter.merge(new IncrementingHasher(0, 1));
filter.merge(new IncrementingHasher(5, 1));
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/CellProducerFromDefaultIndexProducerTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/CellExtractorFromDefaultIndexExtractorTest.java
similarity index 78%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/CellProducerFromDefaultIndexProducerTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/CellExtractorFromDefaultIndexExtractorTest.java
index c8a819c55..3543fb39a 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/CellProducerFromDefaultIndexProducerTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/CellExtractorFromDefaultIndexExtractorTest.java
@@ -16,20 +16,20 @@
*/
package org.apache.commons.collections4.bloomfilter;
-public class CellProducerFromDefaultIndexProducerTest extends AbstractCellProducerTest {
+public class CellExtractorFromDefaultIndexExtractorTest extends AbstractCellExtractorTest {
int[] data = {0, 63, 1, 64, 128, 1, 127};
int[] indices = {0, 1, 63, 64, 127, 128};
int[] values = {1, 2, 1, 1, 1, 1 };
@Override
- protected CellProducer createEmptyProducer() {
- return CellProducer.from(IndexProducer.fromIndexArray());
+ protected CellExtractor createEmptyExtractor() {
+ return CellExtractor.from(IndexExtractor.fromIndexArray());
}
@Override
- protected CellProducer createProducer() {
- return CellProducer.from(IndexProducer.fromIndexArray(data));
+ protected CellExtractor createExtractor() {
+ return CellExtractor.from(IndexExtractor.fromIndexArray(data));
}
@Override
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/CellProducerFromLayeredBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/CellExtractorFromLayeredBloomFilterTest.java
similarity index 82%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/CellProducerFromLayeredBloomFilterTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/CellExtractorFromLayeredBloomFilterTest.java
index ad3fa8c1c..7b0b00145 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/CellProducerFromLayeredBloomFilterTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/CellExtractorFromLayeredBloomFilterTest.java
@@ -16,21 +16,21 @@
*/
package org.apache.commons.collections4.bloomfilter;
-public class CellProducerFromLayeredBloomFilterTest extends AbstractCellProducerTest {
+public class CellExtractorFromLayeredBloomFilterTest extends AbstractCellExtractorTest {
protected Shape shape = Shape.fromKM(17, 72);
@Override
- protected CellProducer createEmptyProducer() {
- return CellProducer.from(LayeredBloomFilterTest.fixed(shape, 10));
+ protected CellExtractor createEmptyExtractor() {
+ return CellExtractor.from(LayeredBloomFilterTest.fixed(shape, 10));
}
@Override
- protected CellProducer createProducer() {
+ protected CellExtractor createExtractor() {
final Hasher hasher = new IncrementingHasher(3, 2);
final BloomFilter bf = LayeredBloomFilterTest.fixed(shape, 10);
bf.merge(hasher);
- return CellProducer.from(bf);
+ return CellExtractor.from(bf);
}
@Override
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/CountingPredicateTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/CountingPredicateTest.java
index 2e925db0a..59ba2bfc6 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/CountingPredicateTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/CountingPredicateTest.java
@@ -55,17 +55,17 @@ public class CountingPredicateTest {
assertTrue(cp.test(Integer.valueOf(3)));
assertEquals(expected, result);
expected.add(Pair.of(2, null));
- assertTrue(cp.forEachRemaining());
+ assertTrue(cp.processRemaining());
assertEquals(expected, result);
// if the other array is zero length then cp.test() will not be called so
- // we can just call cp.forEachRemaining() here.
+ // we can just call cp.processRemaining() here.
expected.clear();
expected.add(Pair.of(1, null));
expected.add(Pair.of(2, null));
result.clear();
cp = new CountingPredicate<>(ary, makeFunc((x, y) -> x != null, result));
- assertTrue(cp.forEachRemaining());
+ assertTrue(cp.processRemaining());
assertEquals(expected, result);
// If a test fails then the result should be false and the rest of the list should
@@ -74,7 +74,7 @@ public class CountingPredicateTest {
expected.add(Pair.of(1, null));
result.clear();
cp = new CountingPredicate<>(ary, makeFunc((x, y) -> x == Integer.valueOf(1), result));
- assertFalse(cp.forEachRemaining());
+ assertFalse(cp.processRemaining());
assertEquals(expected, result);
}
@@ -92,7 +92,7 @@ public class CountingPredicateTest {
assertTrue(cp.test(3));
assertTrue(cp.test(3));
assertEquals(expected, result);
- assertTrue(cp.forEachRemaining());
+ assertTrue(cp.processRemaining());
assertEquals(expected, result);
}
@@ -112,7 +112,7 @@ public class CountingPredicateTest {
assertTrue(cp.test(i));
}
assertEquals(expected, result);
- assertTrue(cp.forEachRemaining());
+ assertTrue(cp.processRemaining());
assertEquals(expected, result);
}
}
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBitMapProducerTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBitMapExtractorTest.java
similarity index 68%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBitMapProducerTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBitMapExtractorTest.java
index 3f45b8145..d0a5e20c9 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBitMapProducerTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBitMapExtractorTest.java
@@ -24,17 +24,17 @@ import java.util.function.LongPredicate;
import org.junit.jupiter.api.Test;
-public class DefaultBitMapProducerTest extends AbstractBitMapProducerTest {
+public class DefaultBitMapExtractorTest extends AbstractBitMapExtractorTest {
- class DefaultBitMapProducer implements BitMapProducer {
+ class DefaultBitMapExtractor implements BitMapExtractor {
long[] bitMaps;
- DefaultBitMapProducer(final long[] bitMaps) {
+ DefaultBitMapExtractor(final long[] bitMaps) {
this.bitMaps = bitMaps;
}
@Override
- public boolean forEachBitMap(final LongPredicate predicate) {
+ public boolean processBitMaps(final LongPredicate predicate) {
for (final long bitmap : bitMaps) {
if (!predicate.test(bitmap)) {
return false;
@@ -56,13 +56,13 @@ public class DefaultBitMapProducerTest extends AbstractBitMapProducerTest {
long[] values = generateLongArray(5);
@Override
- protected BitMapProducer createEmptyProducer() {
- return new DefaultBitMapProducer(new long[0]);
+ protected BitMapExtractor createEmptyExtractor() {
+ return new DefaultBitMapExtractor(new long[0]);
}
@Override
- protected BitMapProducer createProducer() {
- return new DefaultBitMapProducer(values);
+ protected BitMapExtractor createExtractor() {
+ return new DefaultBitMapExtractor(values);
}
@Override
@@ -73,7 +73,7 @@ public class DefaultBitMapProducerTest extends AbstractBitMapProducerTest {
@Test
public void testAsBitMapArrayLargeArray() {
final long[] expected = generateLongArray(32);
- final BitMapProducer producer = predicate -> {
+ final BitMapExtractor bitMapExtractor = predicate -> {
for (final long l : expected) {
if (!predicate.test(l)) {
return false;
@@ -81,25 +81,25 @@ public class DefaultBitMapProducerTest extends AbstractBitMapProducerTest {
}
return true;
};
- final long[] ary = producer.asBitMapArray();
+ final long[] ary = bitMapExtractor.asBitMapArray();
assertArrayEquals(expected, ary);
}
@Test
public void testFromBitMapArray() {
- final int nOfBitMaps = BitMap.numberOfBitMaps(256);
+ final int nOfBitMaps = BitMaps.numberOfBitMaps(256);
final long[] expected = generateLongArray(nOfBitMaps);
- final long[] ary = BitMapProducer.fromBitMapArray(expected).asBitMapArray();
+ final long[] ary = BitMapExtractor.fromBitMapArray(expected).asBitMapArray();
assertArrayEquals(expected, ary);
}
@Test
- public void testFromIndexProducer() {
- final int[] expected = DefaultIndexProducerTest.generateIntArray(10, 256);
- final IndexProducer ip = IndexProducer.fromIndexArray(expected);
- final long[] ary = BitMapProducer.fromIndexProducer(ip, 256).asBitMapArray();
+ public void testFromIndexExtractor() {
+ final int[] expected = DefaultIndexExtractorTest.generateIntArray(10, 256);
+ final IndexExtractor indexExtractor = IndexExtractor.fromIndexArray(expected);
+ final long[] ary = BitMapExtractor.fromIndexExtractor(indexExtractor, 256).asBitMapArray();
for (final int idx : expected) {
- assertTrue(BitMap.contains(ary, idx));
+ assertTrue(BitMaps.contains(ary, idx));
}
}
}
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBloomFilterProducerTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBloomFilterExtractorTest.java
similarity index 86%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBloomFilterProducerTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBloomFilterExtractorTest.java
index d588fafad..4de666477 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBloomFilterProducerTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBloomFilterExtractorTest.java
@@ -16,10 +16,10 @@
*/
package org.apache.commons.collections4.bloomfilter;
-public class DefaultBloomFilterProducerTest extends AbstractBloomFilterProducerTest {
+public class DefaultBloomFilterExtractorTest extends AbstractBloomFilterExtractorTest {
@Override
- protected BloomFilterProducer createUnderTest(final BloomFilter... filters) {
+ protected BloomFilterExtractor createUnderTest(final BloomFilter... filters) {
return bloomFilterPredicate -> {
for (final BloomFilter bf : filters) {
if (!bloomFilterPredicate.test(bf)) {
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 480bb89e3..e67201043 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBloomFilterTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultBloomFilterTest.java
@@ -64,22 +64,22 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest<DefaultBloom
}
@Override
- public boolean contains(final BitMapProducer bitMapProducer) {
- return contains(IndexProducer.fromBitMapProducer(bitMapProducer));
+ public boolean contains(final BitMapExtractor bitMapExtractor) {
+ return contains(IndexExtractor.fromBitMapExtractor(bitMapExtractor));
}
@Override
- public boolean contains(final IndexProducer indexProducer) {
- return indexProducer.forEachIndex(indices::contains);
+ public boolean contains(final IndexExtractor indexExtractor) {
+ return indexExtractor.processIndices(indices::contains);
}
@Override
- public boolean forEachBitMap(final LongPredicate consumer) {
- return BitMapProducer.fromIndexProducer(this, shape.getNumberOfBits()).forEachBitMap(consumer);
+ public boolean processBitMaps(final LongPredicate consumer) {
+ return BitMapExtractor.fromIndexExtractor(this, shape.getNumberOfBits()).processBitMaps(consumer);
}
@Override
- public boolean forEachIndex(final IntPredicate consumer) {
+ public boolean processIndices(final IntPredicate consumer) {
for (final Integer i : indices) {
if (!consumer.test(i)) {
return false;
@@ -94,13 +94,13 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest<DefaultBloom
}
@Override
- public boolean merge(final BitMapProducer bitMapProducer) {
- return merge(IndexProducer.fromBitMapProducer(bitMapProducer));
+ public boolean merge(final BitMapExtractor bitMapExtractor) {
+ return merge(IndexExtractor.fromBitMapExtractor(bitMapExtractor));
}
@Override
- public boolean merge(final IndexProducer indexProducer) {
- final boolean result = indexProducer.forEachIndex(x -> {
+ public boolean merge(final IndexExtractor indexExtractor) {
+ final boolean result = indexExtractor.processIndices(x -> {
indices.add(x);
return true;
});
@@ -193,7 +193,7 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest<DefaultBloom
final Shape s = Shape.fromKM(1, Integer.MAX_VALUE);
// create a very large filter with Integer.MAX_VALUE-1 bits set.
final BloomFilter bf1 = new SimpleBloomFilter(s);
- bf1.merge((BitMapProducer) predicate -> {
+ bf1.merge((BitMapExtractor) predicate -> {
int limit = Integer.MAX_VALUE - 1;
while (limit > 64) {
predicate.test(0xFFFFFFFFFFFFFFFFL);
@@ -201,7 +201,7 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest<DefaultBloom
}
long last = 0L;
for (int i = 0; i < limit; i++) {
- last |= BitMap.getLongBit(i);
+ last |= BitMaps.getLongBit(i);
}
predicate.test(last);
return true;
@@ -224,13 +224,13 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest<DefaultBloom
BloomFilter bf1 = new NonSparseDefaultBloomFilter(getTestShape());
bf1.merge(hasher);
- assertTrue(BitMapProducer.fromIndexProducer(hasher.indices(getTestShape()), getTestShape().getNumberOfBits())
- .forEachBitMapPair(bf1, (x, y) -> x == y));
+ assertTrue(BitMapExtractor.fromIndexExtractor(hasher.indices(getTestShape()), getTestShape().getNumberOfBits())
+ .processBitMapPairs(bf1, (x, y) -> x == y));
bf1 = new SparseDefaultBloomFilter(getTestShape());
bf1.merge(hasher);
- assertTrue(BitMapProducer.fromIndexProducer(hasher.indices(getTestShape()), getTestShape().getNumberOfBits())
- .forEachBitMapPair(bf1, (x, y) -> x == y));
+ assertTrue(BitMapExtractor.fromIndexExtractor(hasher.indices(getTestShape()), getTestShape().getNumberOfBits())
+ .processBitMapPairs(bf1, (x, y) -> x == y));
}
@Test
@@ -238,7 +238,7 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest<DefaultBloom
final Shape s = Shape.fromKM(1, Integer.MAX_VALUE);
// create a very large filter with Integer.MAX_VALUE-1 bit set.
final BloomFilter bf1 = new SimpleBloomFilter(s);
- bf1.merge((BitMapProducer) predicate -> {
+ bf1.merge((BitMapExtractor) predicate -> {
int limit = Integer.MAX_VALUE - 1;
while (limit > 64) {
predicate.test(0xFFFFFFFFFFFFFFFFL);
@@ -246,7 +246,7 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest<DefaultBloom
}
long last = 0L;
for (int i = 0; i < limit; i++) {
- last |= BitMap.getLongBit(i);
+ last |= BitMaps.getLongBit(i);
}
predicate.test(last);
return true;
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultCellProducerTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultCellExtractorTest.java
similarity index 90%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/DefaultCellProducerTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/DefaultCellExtractorTest.java
index eb6c18417..5711360ce 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultCellProducerTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultCellExtractorTest.java
@@ -16,19 +16,19 @@
*/
package org.apache.commons.collections4.bloomfilter;
-public class DefaultCellProducerTest extends AbstractCellProducerTest {
+public class DefaultCellExtractorTest extends AbstractCellExtractorTest {
/** Make forEachIndex unordered and contain duplicates. */
private final int[] indices = {1, 2, 3, 5};
private final int[] values = {1, 4, 9, 25};
@Override
- protected CellProducer createEmptyProducer() {
+ protected CellExtractor createEmptyExtractor() {
return consumer -> true;
}
@Override
- protected CellProducer createProducer() {
+ protected CellExtractor createExtractor() {
return consumer -> {
for (int i = 0; i < indices.length; i++) {
if (!consumer.test(indices[i], values[i] )) {
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultIndexProducerTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultIndexExtractorTest.java
similarity index 85%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/DefaultIndexProducerTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/DefaultIndexExtractorTest.java
index 8fa0a3db9..0d58fbcda 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultIndexProducerTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/DefaultIndexExtractorTest.java
@@ -28,7 +28,7 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
-public class DefaultIndexProducerTest extends AbstractIndexProducerTest {
+public class DefaultIndexExtractorTest extends AbstractIndexExtractorTest {
/**
* Generates an array of integers.
@@ -64,7 +64,7 @@ public class DefaultIndexProducerTest extends AbstractIndexProducerTest {
private final int[] values = {10, 1, 10, 1};
@Override
- protected IndexProducer createEmptyProducer() {
+ protected IndexExtractor createEmptyExtractor() {
return predicate -> {
Objects.requireNonNull(predicate);
return true;
@@ -72,7 +72,7 @@ public class DefaultIndexProducerTest extends AbstractIndexProducerTest {
}
@Override
- protected IndexProducer createProducer() {
+ protected IndexExtractor createExtractor() {
return predicate -> {
Objects.requireNonNull(predicate);
for (final int i : values) {
@@ -104,7 +104,7 @@ public class DefaultIndexProducerTest extends AbstractIndexProducerTest {
@ValueSource(ints = {32, 33})
public void testEntries(final int size) {
final int[] values = IntStream.range(0, size).toArray();
- final IndexProducer producer = predicate -> {
+ final IndexExtractor indexExtractor = predicate -> {
Objects.requireNonNull(predicate);
for (final int i : values) {
if (!predicate.test(i)) {
@@ -113,19 +113,19 @@ public class DefaultIndexProducerTest extends AbstractIndexProducerTest {
}
return true;
};
- final int[] other = producer.asIndexArray();
+ final int[] other = indexExtractor.asIndexArray();
assertArrayEquals(values, other);
}
@Test
- public void testFromBitMapProducer() {
+ public void testFromBitMapExtractor() {
for (int i = 0; i < 5; i++) {
final int[] expected = generateIntArray(7, 256);
- final long[] bits = new long[BitMap.numberOfBitMaps(256)];
+ final long[] bits = new long[BitMaps.numberOfBitMaps(256)];
for (final int bitIndex : expected) {
- BitMap.set(bits, bitIndex);
+ BitMaps.set(bits, bitIndex);
}
- final IndexProducer ip = IndexProducer.fromBitMapProducer(BitMapProducer.fromBitMapArray(bits));
+ final IndexExtractor ip = IndexExtractor.fromBitMapExtractor(BitMapExtractor.fromBitMapArray(bits));
assertArrayEquals(unique(expected), ip.asIndexArray());
}
}
@@ -134,7 +134,7 @@ public class DefaultIndexProducerTest extends AbstractIndexProducerTest {
public void testFromIndexArray() {
for (int i = 0; i < 5; i++) {
final int[] expected = generateIntArray(10, 256);
- final IndexProducer ip = IndexProducer.fromIndexArray(expected);
+ final IndexExtractor ip = IndexExtractor.fromIndexArray(expected);
assertArrayEquals(expected, ip.asIndexArray());
}
}
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/IncrementingHasher.java b/src/test/java/org/apache/commons/collections4/bloomfilter/IncrementingHasher.java
index b7f9b6271..778a9d541 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/IncrementingHasher.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/IncrementingHasher.java
@@ -52,10 +52,10 @@ public final class IncrementingHasher implements Hasher {
}
@Override
- public IndexProducer indices(final Shape shape) {
+ public IndexExtractor indices(final Shape shape) {
Objects.requireNonNull(shape, "shape");
- return new IndexProducer() {
+ return new IndexExtractor() {
@Override
public int[] asIndexArray() {
final int[] result = new int[shape.getNumberOfHashFunctions()];
@@ -63,7 +63,7 @@ public final class IncrementingHasher implements Hasher {
// This method needs to return duplicate indices
- forEachIndex(i -> {
+ processIndices(i -> {
result[idx[0]++] = i;
return true;
});
@@ -71,7 +71,7 @@ public final class IncrementingHasher implements Hasher {
}
@Override
- public boolean forEachIndex(final IntPredicate consumer) {
+ public boolean processIndices(final IntPredicate consumer) {
Objects.requireNonNull(consumer, "consumer");
final int bits = shape.getNumberOfBits();
@@ -80,8 +80,8 @@ public final class IncrementingHasher implements Hasher {
// This avoids any modulus operation inside the while loop. It uses a long index
// to avoid overflow.
- long index = BitMap.mod(initial, bits);
- final int inc = BitMap.mod(increment, bits);
+ long index = BitMaps.mod(initial, bits);
+ final int inc = BitMaps.mod(increment, bits);
for (int functionalCount = 0; functionalCount < shape.getNumberOfHashFunctions(); functionalCount++) {
if (!consumer.test((int) index)) {
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromArrayCountingBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorFromArrayCountingBloomFilterTest.java
similarity index 88%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromArrayCountingBloomFilterTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorFromArrayCountingBloomFilterTest.java
index 857c1f51e..118a2ec46 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromArrayCountingBloomFilterTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorFromArrayCountingBloomFilterTest.java
@@ -16,17 +16,17 @@
*/
package org.apache.commons.collections4.bloomfilter;
-public class IndexProducerFromArrayCountingBloomFilterTest extends AbstractIndexProducerTest {
+public class IndexExtractorFromArrayCountingBloomFilterTest extends AbstractIndexExtractorTest {
protected Shape shape = Shape.fromKM(17, 72);
@Override
- protected IndexProducer createEmptyProducer() {
+ protected IndexExtractor createEmptyExtractor() {
return new ArrayCountingBloomFilter(shape);
}
@Override
- protected IndexProducer createProducer() {
+ protected IndexExtractor createExtractor() {
final ArrayCountingBloomFilter filter = new ArrayCountingBloomFilter(shape);
filter.merge(new IncrementingHasher(0, 1));
filter.merge(new IncrementingHasher(5, 1));
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromBitmapProducerTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorFromBitmapExtractorTest.java
similarity index 67%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromBitmapProducerTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorFromBitmapExtractorTest.java
index 3de474b9a..0c8cd27c7 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromBitmapProducerTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorFromBitmapExtractorTest.java
@@ -24,17 +24,17 @@ import java.util.function.LongPredicate;
import org.junit.jupiter.api.Test;
-public class IndexProducerFromBitmapProducerTest extends AbstractIndexProducerTest {
+public class IndexExtractorFromBitmapExtractorTest extends AbstractIndexExtractorTest {
- private static final class TestingBitMapProducer implements BitMapProducer {
+ private static final class TestingBitMapExtractor implements BitMapExtractor {
long[] values;
- TestingBitMapProducer(final long[] values) {
+ TestingBitMapExtractor(final long[] values) {
this.values = values;
}
@Override
- public boolean forEachBitMap(final LongPredicate consumer) {
+ public boolean processBitMaps(final LongPredicate consumer) {
for (final long l : values) {
if (!consumer.test(l)) {
return false;
@@ -45,14 +45,14 @@ public class IndexProducerFromBitmapProducerTest extends AbstractIndexProducerTe
}
@Override
- protected IndexProducer createEmptyProducer() {
- final TestingBitMapProducer producer = new TestingBitMapProducer(new long[0]);
- return IndexProducer.fromBitMapProducer(producer);
+ protected IndexExtractor createEmptyExtractor() {
+ final TestingBitMapExtractor testingBitMapExtractor = new TestingBitMapExtractor(new long[0]);
+ return IndexExtractor.fromBitMapExtractor(testingBitMapExtractor);
}
@Override
- protected IndexProducer createProducer() {
- /* Creates an index producer that produces the values:
+ protected IndexExtractor createExtractor() {
+ /* Creates an index testingBitMapExtractor that produces the values:
* 0, 65, 128, and 129
@formatter:off
Index2 Index1 Index0
@@ -63,8 +63,8 @@ public class IndexProducerFromBitmapProducerTest extends AbstractIndexProducerTe
3L => ...0011
@formatter:on
*/
- final TestingBitMapProducer producer = new TestingBitMapProducer(new long[] {1L, 2L, 3L});
- return IndexProducer.fromBitMapProducer(producer);
+ final TestingBitMapExtractor testingBitMapExtractor = new TestingBitMapExtractor(new long[] {1L, 2L, 3L});
+ return IndexExtractor.fromBitMapExtractor(testingBitMapExtractor);
}
@Override
@@ -79,22 +79,22 @@ public class IndexProducerFromBitmapProducerTest extends AbstractIndexProducerTe
}
@Test
- public final void testFromBitMapProducerTest() {
- IndexProducer underTest = createProducer();
+ public final void testFromBitMapExtractor() {
+ IndexExtractor underTest = createExtractor();
List<Integer> lst = new ArrayList<>();
- underTest.forEachIndex(lst::add);
+ underTest.processIndices(lst::add);
assertEquals(4, lst.size());
assertEquals(Integer.valueOf(0), lst.get(0));
assertEquals(Integer.valueOf(1 + 64), lst.get(1));
assertEquals(Integer.valueOf(0 + 128), lst.get(2));
assertEquals(Integer.valueOf(1 + 128), lst.get(3));
- final BitMapProducer producer = new TestingBitMapProducer(new long[] {0xFFFFFFFFFFFFFFFFL});
- underTest = IndexProducer.fromBitMapProducer(producer);
+ final BitMapExtractor bitMapExtractor = new TestingBitMapExtractor(new long[] {0xFFFFFFFFFFFFFFFFL});
+ underTest = IndexExtractor.fromBitMapExtractor(bitMapExtractor);
lst = new ArrayList<>();
- underTest.forEachIndex(lst::add);
+ underTest.processIndices(lst::add);
assertEquals(64, lst.size());
for (int i = 0; i < 64; i++) {
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromHasherTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorFromHasherTest.java
similarity index 87%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromHasherTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorFromHasherTest.java
index c617146b6..c647e8084 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromHasherTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorFromHasherTest.java
@@ -16,15 +16,15 @@
*/
package org.apache.commons.collections4.bloomfilter;
-public class IndexProducerFromHasherTest extends AbstractIndexProducerTest {
+public class IndexExtractorFromHasherTest extends AbstractIndexExtractorTest {
@Override
- protected IndexProducer createEmptyProducer() {
+ protected IndexExtractor createEmptyExtractor() {
return NullHasher.INSTANCE.indices(Shape.fromKM(17, 72));
}
@Override
- protected IndexProducer createProducer() {
+ protected IndexExtractor createExtractor() {
// hasher has collisions and wraps
return new IncrementingHasher(4, 8).indices(Shape.fromKM(17, 72));
}
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromIntArrayTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorFromIntArrayTest.java
similarity index 79%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromIntArrayTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorFromIntArrayTest.java
index b813a0caf..1bab6146a 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromIntArrayTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorFromIntArrayTest.java
@@ -16,18 +16,18 @@
*/
package org.apache.commons.collections4.bloomfilter;
-public class IndexProducerFromIntArrayTest extends AbstractIndexProducerTest {
+public class IndexExtractorFromIntArrayTest extends AbstractIndexExtractorTest {
int[] data = {6, 8, 1, 2, 4, 4, 5};
@Override
- protected IndexProducer createEmptyProducer() {
- return IndexProducer.fromIndexArray();
+ protected IndexExtractor createEmptyExtractor() {
+ return IndexExtractor.fromIndexArray();
}
@Override
- protected IndexProducer createProducer() {
- return IndexProducer.fromIndexArray(data);
+ protected IndexExtractor createExtractor() {
+ return IndexExtractor.fromIndexArray(data);
}
@Override
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromSimpleBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorFromSimpleBloomFilterTest.java
similarity index 88%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromSimpleBloomFilterTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorFromSimpleBloomFilterTest.java
index 75e14a7be..aa13658ac 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromSimpleBloomFilterTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorFromSimpleBloomFilterTest.java
@@ -16,17 +16,17 @@
*/
package org.apache.commons.collections4.bloomfilter;
-public class IndexProducerFromSimpleBloomFilterTest extends AbstractIndexProducerTest {
+public class IndexExtractorFromSimpleBloomFilterTest extends AbstractIndexExtractorTest {
protected Shape shape = Shape.fromKM(17, 72);
@Override
- protected IndexProducer createEmptyProducer() {
+ protected IndexExtractor createEmptyExtractor() {
return new SimpleBloomFilter(shape);
}
@Override
- protected IndexProducer createProducer() {
+ protected IndexExtractor createExtractor() {
final Hasher hasher = new IncrementingHasher(3, 2);
final BloomFilter bf = new SimpleBloomFilter(shape);
bf.merge(hasher);
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromSparseBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorFromSparseBloomFilterTest.java
similarity index 88%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromSparseBloomFilterTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorFromSparseBloomFilterTest.java
index 6ad25e440..e7febe1aa 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromSparseBloomFilterTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorFromSparseBloomFilterTest.java
@@ -16,17 +16,17 @@
*/
package org.apache.commons.collections4.bloomfilter;
-public class IndexProducerFromSparseBloomFilterTest extends AbstractIndexProducerTest {
+public class IndexExtractorFromSparseBloomFilterTest extends AbstractIndexExtractorTest {
protected Shape shape = Shape.fromKM(17, 72);
@Override
- protected IndexProducer createEmptyProducer() {
+ protected IndexExtractor createEmptyExtractor() {
return new SparseBloomFilter(shape);
}
@Override
- protected IndexProducer createProducer() {
+ protected IndexExtractor createExtractor() {
final Hasher hasher = new IncrementingHasher(4, 7);
final BloomFilter bf = new SparseBloomFilter(shape);
bf.merge(hasher);
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromUniqueHasherTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorFromUniqueHasherTest.java
similarity index 87%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromUniqueHasherTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorFromUniqueHasherTest.java
index ccddd9d4b..f1a8ff3f6 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerFromUniqueHasherTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorFromUniqueHasherTest.java
@@ -16,15 +16,15 @@
*/
package org.apache.commons.collections4.bloomfilter;
-public class IndexProducerFromUniqueHasherTest extends AbstractIndexProducerTest {
+public class IndexExtractorFromUniqueHasherTest extends AbstractIndexExtractorTest {
@Override
- protected IndexProducer createEmptyProducer() {
+ protected IndexExtractor createEmptyExtractor() {
return NullHasher.INSTANCE.indices(Shape.fromKM(17, 72));
}
@Override
- protected IndexProducer createProducer() {
+ protected IndexExtractor createExtractor() {
// hasher has collisions and wraps
return new IncrementingHasher(4, 8).indices(Shape.fromKM(17, 72)).uniqueIndices();
}
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorTest.java
similarity index 74%
rename from src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerTest.java
rename to src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorTest.java
index a8343d94d..82010ca49 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/IndexProducerTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/IndexExtractorTest.java
@@ -27,17 +27,17 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
-public class IndexProducerTest {
+public class IndexExtractorTest {
- private static final class TestingBitMapProducer implements BitMapProducer {
+ private static final class TestingBitMapExtractor implements BitMapExtractor {
long[] values;
- TestingBitMapProducer(final long[] values) {
+ TestingBitMapExtractor(final long[] values) {
this.values = values;
}
@Override
- public boolean forEachBitMap(final LongPredicate consumer) {
+ public boolean processBitMaps(final LongPredicate consumer) {
for (final long l : values) {
if (!consumer.test(l)) {
return false;
@@ -48,23 +48,23 @@ public class IndexProducerTest {
}
@Test
- public void fromBitMapProducerTest() {
- TestingBitMapProducer producer = new TestingBitMapProducer(new long[] {1L, 2L, 3L});
- IndexProducer underTest = IndexProducer.fromBitMapProducer(producer);
+ public void testFromBitMapExtractor() {
+ TestingBitMapExtractor testingBitMapExtractor = new TestingBitMapExtractor(new long[] {1L, 2L, 3L});
+ IndexExtractor underTest = IndexExtractor.fromBitMapExtractor(testingBitMapExtractor);
List<Integer> lst = new ArrayList<>();
- underTest.forEachIndex(lst::add);
+ underTest.processIndices(lst::add);
assertEquals(4, lst.size());
assertEquals(Integer.valueOf(0), lst.get(0));
assertEquals(Integer.valueOf(1 + 64), lst.get(1));
assertEquals(Integer.valueOf(0 + 128), lst.get(2));
assertEquals(Integer.valueOf(1 + 128), lst.get(3));
- producer = new TestingBitMapProducer(new long[] {0xFFFFFFFFFFFFFFFFL});
- underTest = IndexProducer.fromBitMapProducer(producer);
+ testingBitMapExtractor = new TestingBitMapExtractor(new long[] {0xFFFFFFFFFFFFFFFFL});
+ underTest = IndexExtractor.fromBitMapExtractor(testingBitMapExtractor);
lst = new ArrayList<>();
- underTest.forEachIndex(lst::add);
+ underTest.processIndices(lst::add);
assertEquals(64, lst.size());
for (int i = 0; i < 64; i++) {
@@ -75,7 +75,7 @@ public class IndexProducerTest {
@ParameterizedTest
@ValueSource(ints = {32, 33})
void testAsIndexArray(final int n) {
- final IndexProducer ip = i -> {
+ final IndexExtractor 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/LayerManagerTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/LayerManagerTest.java
index 09ffac2e7..ca90f0d0d 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/LayerManagerTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/LayerManagerTest.java
@@ -134,7 +134,7 @@ public class LayerManagerTest {
assertEquals(underTest.getDepth(), copy.getDepth());
assertTrue(
- underTest.forEachBloomFilterPair(copy, (x, y) -> Arrays.equals(x.asBitMapArray(), y.asBitMapArray())));
+ underTest.processBloomFilterPair(copy, (x, y) -> Arrays.equals(x.asBitMapArray(), y.asBitMapArray())));
}
@Test
@@ -150,7 +150,7 @@ public class LayerManagerTest {
underTest.getTarget().merge(bf);
}
final List<BloomFilter> lst2 = new ArrayList<>();
- underTest.forEachBloomFilter(lst2::add);
+ underTest.processBloomFilters(lst2::add);
assertEquals(10, lst.size());
assertEquals(10, lst2.size());
for (int i = 0; i < lst.size(); i++) {
@@ -242,7 +242,7 @@ public class LayerManagerTest {
assertTrue(list.isEmpty());
// does not remove a populated filter.
- bf.merge(IndexProducer.fromIndexArray(1));
+ bf.merge(IndexExtractor.fromIndexArray(1));
list.add(bf);
assertEquals(bf, list.get(0));
underTest.accept(list);
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/LayeredBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/LayeredBloomFilterTest.java
index 32a47c17c..24a143b85 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/LayeredBloomFilterTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/LayeredBloomFilterTest.java
@@ -201,14 +201,14 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
return bf;
}
- protected BloomFilter makeFilter(final IndexProducer p) {
+ protected BloomFilter makeFilter(final IndexExtractor p) {
final BloomFilter bf = new SparseBloomFilter(getTestShape());
bf.merge(p);
return bf;
}
protected BloomFilter makeFilter(final int... values) {
- return makeFilter(IndexProducer.fromIndexArray(values));
+ return makeFilter(IndexExtractor.fromIndexArray(values));
}
private LayeredBloomFilter<BloomFilter> setupFindTest() {
@@ -291,7 +291,7 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
for (int i = 0; i < 10; i++) {
underTest.merge(TestingHashers.randomHasher());
}
- underTest.forEachBloomFilter(dbg.and(x -> lst.add(((TimestampedBloomFilter) x).timestamp)));
+ underTest.processBloomFilters(dbg.and(x -> lst.add(((TimestampedBloomFilter) x).timestamp)));
assertTrue(underTest.getDepth() > 1);
Thread.sleep(300);
@@ -299,38 +299,38 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
underTest.merge(TestingHashers.randomHasher());
}
dbgInstrument.add("=== AFTER 300 milliseconds ====\n");
- underTest.forEachBloomFilter(dbg);
+ underTest.processBloomFilters(dbg);
Thread.sleep(150);
for (int i = 0; i < 10; i++) {
underTest.merge(TestingHashers.randomHasher());
}
dbgInstrument.add("=== AFTER 450 milliseconds ====\n");
- underTest.forEachBloomFilter(dbg);
+ underTest.processBloomFilters(dbg);
// sleep 200 milliseconds to ensure we cross the 600 millisecond boundary
Thread.sleep(200);
underTest.merge(TestingHashers.randomHasher());
dbgInstrument.add("=== AFTER 600 milliseconds ====\n");
- assertTrue(underTest.forEachBloomFilter(dbg.and(x -> !lst.contains(((TimestampedBloomFilter) x).timestamp))),
+ assertTrue(underTest.processBloomFilters(dbg.and(x -> !lst.contains(((TimestampedBloomFilter) x).timestamp))),
"Found filter that should have been deleted: " + dbgInstrument.get(dbgInstrument.size() - 1));
}
@Test
- public void testFindBitMapProducer() {
+ public void testFindBitMapExtractor() {
final LayeredBloomFilter<BloomFilter> filter = setupFindTest();
- IndexProducer idxProducer = TestingHashers.FROM1.indices(getTestShape());
- BitMapProducer producer = BitMapProducer.fromIndexProducer(idxProducer, getTestShape().getNumberOfBits());
+ IndexExtractor indexExtractor = TestingHashers.FROM1.indices(getTestShape());
+ BitMapExtractor bitMapExtractor = BitMapExtractor.fromIndexExtractor(indexExtractor, getTestShape().getNumberOfBits());
int[] expected = {0, 3};
- int[] result = filter.find(producer);
+ int[] result = filter.find(bitMapExtractor);
assertArrayEquals(expected, result);
expected = new int[]{1, 3};
- idxProducer = TestingHashers.FROM11.indices(getTestShape());
- producer = BitMapProducer.fromIndexProducer(idxProducer, getTestShape().getNumberOfBits());
- result = filter.find(producer);
+ indexExtractor = TestingHashers.FROM11.indices(getTestShape());
+ bitMapExtractor = BitMapExtractor.fromIndexExtractor(indexExtractor, getTestShape().getNumberOfBits());
+ result = filter.find(bitMapExtractor);
assertArrayEquals(expected, result);
}
@@ -346,17 +346,17 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
}
@Test
- public void testFindIndexProducer() {
- IndexProducer producer = TestingHashers.FROM1.indices(getTestShape());
+ public void testFindIndexExtractor() {
+ IndexExtractor indexExtractor = TestingHashers.FROM1.indices(getTestShape());
final LayeredBloomFilter<BloomFilter> filter = setupFindTest();
int[] expected = {0, 3};
- int[] result = filter.find(producer);
+ int[] result = filter.find(indexExtractor);
assertArrayEquals(expected, result);
expected = new int[] {1, 3};
- producer = TestingHashers.FROM11.indices(getTestShape());
- result = filter.find(producer);
+ indexExtractor = TestingHashers.FROM11.indices(getTestShape());
+ result = filter.find(indexExtractor);
assertArrayEquals(expected, result);
}
diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/NullHasher.java b/src/test/java/org/apache/commons/collections4/bloomfilter/NullHasher.java
index 1bafc5ea9..290eaf7c1 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/NullHasher.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/NullHasher.java
@@ -31,14 +31,14 @@ final class NullHasher implements Hasher {
*/
static final NullHasher INSTANCE = new NullHasher();
- private static final IndexProducer PRODUCER = new IndexProducer() {
+ private static final IndexExtractor INDEX_EXTRACTOR = new IndexExtractor() {
@Override
public int[] asIndexArray() {
return new int[0];
}
@Override
- public boolean forEachIndex(final IntPredicate consumer) {
+ public boolean processIndices(final IntPredicate consumer) {
Objects.requireNonNull(consumer, "consumer");
return true;
}
@@ -49,8 +49,8 @@ final class NullHasher implements Hasher {
}
@Override
- public IndexProducer indices(final Shape shape) {
+ public IndexExtractor indices(final Shape shape) {
Objects.requireNonNull(shape, "shape");
- return PRODUCER;
+ return INDEX_EXTRACTOR;
}
}
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 075cddb72..5abb6bfbe 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/SetOperationsTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/SetOperationsTest.java
@@ -48,25 +48,25 @@ public class SetOperationsTest {
return bf;
}
- private BloomFilter createFilter(final Shape shape, final IndexProducer producer) {
+ private BloomFilter createFilter(final Shape shape, final IndexExtractor indexExtractor) {
final BloomFilter bf = new SparseBloomFilter(shape);
- bf.merge(producer);
+ bf.merge(indexExtractor);
return bf;
}
@Test
public final void testAndCardinality() {
final Shape shape = Shape.fromKM(3, 128);
- BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63, 64));
- BloomFilter filter2 = createFilter(shape, IndexProducer.fromIndexArray(5, 64, 69));
+ BloomFilter filter1 = createFilter(shape, IndexExtractor.fromIndexArray(1, 63, 64));
+ BloomFilter filter2 = createFilter(shape, IndexExtractor.fromIndexArray(5, 64, 69));
assertSymmetricOperation(1, SetOperations::andCardinality, filter1, filter2);
- filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63));
- filter2 = createFilter(shape, IndexProducer.fromIndexArray(5, 64, 69));
+ filter1 = createFilter(shape, IndexExtractor.fromIndexArray(1, 63));
+ filter2 = createFilter(shape, IndexExtractor.fromIndexArray(5, 64, 69));
assertSymmetricOperation(0, SetOperations::andCardinality, filter1, filter2);
- filter1 = createFilter(shape, IndexProducer.fromIndexArray(5, 63));
- filter2 = createFilter(shape, IndexProducer.fromIndexArray(5, 64, 69));
+ filter1 = createFilter(shape, IndexExtractor.fromIndexArray(5, 63));
+ filter2 = createFilter(shape, IndexExtractor.fromIndexArray(5, 64, 69));
assertSymmetricOperation(1, SetOperations::andCardinality, filter1, filter2);
}
@@ -74,23 +74,23 @@ public class SetOperationsTest {
public final void testAndCardinalityWithDifferentLengthFilters() {
final Shape shape = Shape.fromKM(3, 128);
final Shape shape2 = Shape.fromKM(3, 192);
- BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63, 64));
- BloomFilter filter2 = createFilter(shape2, IndexProducer.fromIndexArray(5, 64, 169));
+ BloomFilter filter1 = createFilter(shape, IndexExtractor.fromIndexArray(1, 63, 64));
+ BloomFilter filter2 = createFilter(shape2, IndexExtractor.fromIndexArray(5, 64, 169));
assertSymmetricOperation(1, SetOperations::andCardinality, filter1, filter2);
- filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63));
- filter2 = createFilter(shape2, IndexProducer.fromIndexArray(5, 64, 169));
+ filter1 = createFilter(shape, IndexExtractor.fromIndexArray(1, 63));
+ filter2 = createFilter(shape2, IndexExtractor.fromIndexArray(5, 64, 169));
assertSymmetricOperation(0, SetOperations::andCardinality, filter1, filter2);
- filter1 = createFilter(shape, IndexProducer.fromIndexArray(5, 63));
- filter2 = createFilter(shape2, IndexProducer.fromIndexArray(5, 64, 169));
+ filter1 = createFilter(shape, IndexExtractor.fromIndexArray(5, 63));
+ filter2 = createFilter(shape2, IndexExtractor.fromIndexArray(5, 64, 169));
assertSymmetricOperation(1, SetOperations::andCardinality, filter1, filter2);
}
@Test
public final void testCommutativityOnMismatchedSizes() {
- final BitMapProducer p1 = BitMapProducer.fromBitMapArray(0x3L, 0x5L);
- final BitMapProducer p2 = BitMapProducer.fromBitMapArray(0x1L);
+ final BitMapExtractor p1 = BitMapExtractor.fromBitMapArray(0x3L, 0x5L);
+ final BitMapExtractor p2 = BitMapExtractor.fromBitMapArray(0x1L);
assertEquals(SetOperations.orCardinality(p1, p2), SetOperations.orCardinality(p2, p1));
assertEquals(SetOperations.xorCardinality(p1, p2), SetOperations.xorCardinality(p2, p1));
@@ -256,16 +256,16 @@ public class SetOperationsTest {
@Test
public final void testOrCardinality() {
final Shape shape = Shape.fromKM(3, 128);
- BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63, 64));
- BloomFilter filter2 = createFilter(shape, IndexProducer.fromIndexArray(5, 64, 69));
+ BloomFilter filter1 = createFilter(shape, IndexExtractor.fromIndexArray(1, 63, 64));
+ BloomFilter filter2 = createFilter(shape, IndexExtractor.fromIndexArray(5, 64, 69));
assertSymmetricOperation(5, SetOperations::orCardinality, filter1, filter2);
- filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63));
- filter2 = createFilter(shape, IndexProducer.fromIndexArray(5, 64, 69));
+ filter1 = createFilter(shape, IndexExtractor.fromIndexArray(1, 63));
+ filter2 = createFilter(shape, IndexExtractor.fromIndexArray(5, 64, 69));
assertSymmetricOperation(5, SetOperations::orCardinality, filter1, filter2);
- filter1 = createFilter(shape, IndexProducer.fromIndexArray(5, 63));
- filter2 = createFilter(shape, IndexProducer.fromIndexArray(5, 64, 69));
+ filter1 = createFilter(shape, IndexExtractor.fromIndexArray(5, 63));
+ filter2 = createFilter(shape, IndexExtractor.fromIndexArray(5, 64, 69));
assertSymmetricOperation(4, SetOperations::orCardinality, filter1, filter2);
}
@@ -273,37 +273,37 @@ public class SetOperationsTest {
public final void testOrCardinalityWithDifferentLengthFilters() {
final Shape shape = Shape.fromKM(3, 128);
final Shape shape2 = Shape.fromKM(3, 192);
- BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63, 64));
- BloomFilter filter2 = createFilter(shape2, IndexProducer.fromIndexArray(5, 64, 169));
+ BloomFilter filter1 = createFilter(shape, IndexExtractor.fromIndexArray(1, 63, 64));
+ BloomFilter filter2 = createFilter(shape2, IndexExtractor.fromIndexArray(5, 64, 169));
assertSymmetricOperation(5, SetOperations::orCardinality, filter1, filter2);
- filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63));
- filter2 = createFilter(shape2, IndexProducer.fromIndexArray(5, 64, 169));
+ filter1 = createFilter(shape, IndexExtractor.fromIndexArray(1, 63));
+ filter2 = createFilter(shape2, IndexExtractor.fromIndexArray(5, 64, 169));
assertSymmetricOperation(5, SetOperations::orCardinality, filter1, filter2);
- filter1 = createFilter(shape, IndexProducer.fromIndexArray(5, 63));
- filter2 = createFilter(shape2, IndexProducer.fromIndexArray(5, 64, 169));
+ filter1 = createFilter(shape, IndexExtractor.fromIndexArray(5, 63));
+ filter2 = createFilter(shape2, IndexExtractor.fromIndexArray(5, 64, 169));
assertSymmetricOperation(4, SetOperations::orCardinality, filter1, filter2);
}
@Test
public final void testXorCardinality() {
final Shape shape = Shape.fromKM(3, 128);
- BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63, 64));
- BloomFilter filter2 = createFilter(shape, IndexProducer.fromIndexArray(5, 64, 69));
+ BloomFilter filter1 = createFilter(shape, IndexExtractor.fromIndexArray(1, 63, 64));
+ BloomFilter filter2 = createFilter(shape, IndexExtractor.fromIndexArray(5, 64, 69));
assertSymmetricOperation(4, SetOperations::xorCardinality, filter1, filter2);
- filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63));
- filter2 = createFilter(shape, IndexProducer.fromIndexArray(5, 64, 69));
+ filter1 = createFilter(shape, IndexExtractor.fromIndexArray(1, 63));
+ filter2 = createFilter(shape, IndexExtractor.fromIndexArray(5, 64, 69));
assertSymmetricOperation(5, SetOperations::xorCardinality, filter1, filter2);
- filter1 = createFilter(shape, IndexProducer.fromIndexArray(5, 63));
- filter2 = createFilter(shape, IndexProducer.fromIndexArray(5, 64, 69));
+ filter1 = createFilter(shape, IndexExtractor.fromIndexArray(5, 63));
+ filter2 = createFilter(shape, IndexExtractor.fromIndexArray(5, 64, 69));
assertSymmetricOperation(3, SetOperations::xorCardinality, filter1, filter2);
final Shape bigShape = Shape.fromKM(3, 192);
- filter1 = createFilter(bigShape, IndexProducer.fromIndexArray(1, 63, 185));
- filter2 = createFilter(shape, IndexProducer.fromIndexArray(5, 63, 69));
+ filter1 = createFilter(bigShape, IndexExtractor.fromIndexArray(1, 63, 185));
+ filter2 = createFilter(shape, IndexExtractor.fromIndexArray(5, 63, 69));
assertSymmetricOperation(4, SetOperations::xorCardinality, filter1, filter2);
}
@@ -312,16 +312,16 @@ public class SetOperationsTest {
final Shape shape = Shape.fromKM(3, 128);
final Shape shape2 = Shape.fromKM(3, 192);
- BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63, 64));
- BloomFilter filter2 = createFilter(shape2, IndexProducer.fromIndexArray(5, 64, 169));
+ BloomFilter filter1 = createFilter(shape, IndexExtractor.fromIndexArray(1, 63, 64));
+ BloomFilter filter2 = createFilter(shape2, IndexExtractor.fromIndexArray(5, 64, 169));
assertSymmetricOperation(4, SetOperations::xorCardinality, filter1, filter2);
- filter1 = createFilter(shape, IndexProducer.fromIndexArray(1, 63));
- filter2 = createFilter(shape2, IndexProducer.fromIndexArray(5, 64, 169));
+ filter1 = createFilter(shape, IndexExtractor.fromIndexArray(1, 63));
+ filter2 = createFilter(shape2, IndexExtractor.fromIndexArray(5, 64, 169));
assertSymmetricOperation(5, SetOperations::xorCardinality, filter1, filter2);
- filter1 = createFilter(shape, IndexProducer.fromIndexArray(5, 63));
- filter2 = createFilter(shape2, IndexProducer.fromIndexArray(5, 64, 169));
+ filter1 = createFilter(shape, IndexExtractor.fromIndexArray(5, 63));
+ filter2 = createFilter(shape2, IndexExtractor.fromIndexArray(5, 64, 169));
assertSymmetricOperation(3, SetOperations::xorCardinality, filter1, filter2);
}
}
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 1552e9c76..5710a4ca1 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/SimpleBloomFilterTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/SimpleBloomFilterTest.java
@@ -31,12 +31,12 @@ public class SimpleBloomFilterTest extends AbstractBloomFilterTest<SimpleBloomFi
}
@Test
- public void testMergeShortBitMapProducer() {
+ public void testMergeShortBitMapExtractor() {
final SimpleBloomFilter filter = createEmptyFilter(getTestShape());
- // create a producer that returns too few values
+ // create a bitMapExtractor that returns too few values
// shape expects 2 longs we are sending 1.
- final BitMapProducer producer = p -> p.test(2L);
- assertTrue(filter.merge(producer));
+ final BitMapExtractor bitMapExtractor = p -> p.test(2L);
+ assertTrue(filter.merge(bitMapExtractor));
assertEquals(1, filter.cardinality());
}
}
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 aa9a4cd6d..eb5483dd9 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/SparseBloomFilterTest.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/SparseBloomFilterTest.java
@@ -32,22 +32,22 @@ public class SparseBloomFilterTest extends AbstractBloomFilterTest<SparseBloomFi
}
@Test
- public void testBitMapProducerEdgeCases() {
+ public void testBitMapExtractorEdgeCases() {
int[] values = {1, 2, 3, 4, 5, 6, 7, 8, 9, 65, 66, 67, 68, 69, 70, 71};
- BloomFilter bf = createFilter(getTestShape(), IndexProducer.fromIndexArray(values));
+ BloomFilter bf = createFilter(getTestShape(), IndexExtractor.fromIndexArray(values));
// verify exit early before bitmap boundary
final int[] passes = new int[1];
- assertFalse(bf.forEachBitMap(l -> {
+ assertFalse(bf.processBitMaps(l -> {
passes[0]++;
return false;
}));
assertEquals(1, passes[0]);
// verify exit early at bitmap boundary
- bf = createFilter(getTestShape(), IndexProducer.fromIndexArray(values));
+ bf = createFilter(getTestShape(), IndexExtractor.fromIndexArray(values));
passes[0] = 0;
- assertFalse(bf.forEachBitMap(l -> {
+ assertFalse(bf.processBitMaps(l -> {
final boolean result = passes[0] == 0;
if (result) {
passes[0]++;
@@ -58,9 +58,9 @@ public class SparseBloomFilterTest extends AbstractBloomFilterTest<SparseBloomFi
// verify add extra if all values in first bitmap
values = new int[] {1, 2, 3, 4};
- bf = createFilter(getTestShape(), IndexProducer.fromIndexArray(values));
+ bf = createFilter(getTestShape(), IndexExtractor.fromIndexArray(values));
passes[0] = 0;
- assertTrue(bf.forEachBitMap(l -> {
+ assertTrue(bf.processBitMaps(l -> {
passes[0]++;
return true;
}));
@@ -69,9 +69,9 @@ public class SparseBloomFilterTest extends AbstractBloomFilterTest<SparseBloomFi
// verify exit early if all values in first bitmap and predicate returns false
// on 2nd block
values = new int[] {1, 2, 3, 4};
- bf = createFilter(getTestShape(), IndexProducer.fromIndexArray(values));
+ bf = createFilter(getTestShape(), IndexExtractor.fromIndexArray(values));
passes[0] = 0;
- assertFalse(bf.forEachBitMap(l -> {
+ assertFalse(bf.processBitMaps(l -> {
final boolean result = passes[0] == 0;
if (result) {
passes[0]++;
@@ -87,6 +87,6 @@ public class SparseBloomFilterTest extends AbstractBloomFilterTest<SparseBloomFi
final BloomFilter bf2 = new SimpleBloomFilter(getTestShape());
bf2.merge(TestingHashers.FROM1);
bf1.merge(bf2);
- assertTrue(bf2.forEachBitMapPair(bf1, (x, y) -> x == y));
+ assertTrue(bf2.processBitMapPairs(bf1, (x, y) -> x == y));
}
}
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 78f95ace2..391444c54 100644
--- a/src/test/java/org/apache/commons/collections4/bloomfilter/TestingHashers.java
+++ b/src/test/java/org/apache/commons/collections4/bloomfilter/TestingHashers.java
@@ -75,7 +75,7 @@ public class TestingHashers {
* @return {@code filter} for chaining
*/
public static <T extends BloomFilter> T populateRange(final T filter, final int start, final int end) {
- filter.merge((IndexProducer) p -> {
+ filter.merge((IndexExtractor) p -> {
for (int i = start; i <= end; i++) {
if (!p.test(i)) {
return false;