Skip to content

Commit

Permalink
Cleaned up javadoc and BiPredicate<BloomFilter,BloomFilter> processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudenw committed Jun 30, 2023
1 parent 0123c3f commit 1a647d5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 58 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@
package org.apache.commons.collections4.bloomfilter;

import java.util.Arrays;
import java.util.function.BiPredicate;
import java.util.function.Predicate;

/**
* Produces Bloom filters that are copies of Bloom filters in a collection (e.g.
* LayerBloomFilter).
*
* @since 4.5
*/
public interface BloomFilterProducer {
/**
* Executes a Bloom filter Predicate on each Bloom filter in the manager in
Expand Down Expand Up @@ -76,8 +83,9 @@ BloomFilter[] toArray() {
* @return A LongPredicate that tests this BitMapProducers bitmap values in
* order.
*/
default boolean forEachBloomFilterPair(final BloomFilterProducer other, final BloomFilterBiPredicate func) {
final CountingBloomFilterPredicate p = new CountingBloomFilterPredicate(asBloomFilterArray(), func);
default boolean forEachBloomFilterPair(final BloomFilterProducer other,
final BiPredicate<BloomFilter, BloomFilter> func) {
final CountingPredicate<BloomFilter> p = new CountingPredicate<>(asBloomFilterArray(), func);
return other.forEachBloomFilter(p) && p.forEachRemaining();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,58 @@
*/
package org.apache.commons.collections4.bloomfilter;

import java.util.function.LongPredicate;
import java.util.function.BiPredicate;
import java.util.function.Predicate;

/**
* 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
* execute the @code{text} with a zero value for each remaining @{code idx} value.
* A 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 {@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{text} with a
* {@code null} value for each remaining @{code idx} value.
*
* @param <T> the type of object being compared.
*
* @Since 4.5
*/
class CountingBloomFilterPredicate implements Predicate<BloomFilter> {
class CountingPredicate<T> implements Predicate<T> {
private int idx = 0;
private final BloomFilter[] ary;
private final BloomFilterBiPredicate func;
private final T[] ary;
private final BiPredicate<T, T> func;

/**
* Constructs an instance that will compare the elements in @{code ary} with the elements returned by @{code func}.
* function is called as @{code func.test( idxValue, otherValue )}. If there are more @{code otherValue} values than
* @{code idxValues} then @{code func} is called as @{code func.test( 0, otherValue )}.
* @param ary The array of long values to compare.
* Constructs an instance that will compare the elements in @{code ary} with the
* elements returned by @{code func}. function is called as @{code func.test(
* idxValue, otherValue )}. If there are more @{code otherValue} values than
*
* @{code idxValues} then @{code func} is called as @{code func.test( null,
* otherValue )}.
* @param ary The array of long values to compare.
* @param func The function to apply to the pairs of long values.
*/
CountingBloomFilterPredicate(final BloomFilter[] ary, final BloomFilterBiPredicate func) {
CountingPredicate(final T[] ary, final BiPredicate<T, T> func) {
this.ary = ary;
this.func = func;
}

@Override
public boolean test(final BloomFilter other) {
public boolean test(final T other) {
return func.test(idx == ary.length ? null : ary[idx++], other);
}

/**
* 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
* unpaired bitmaps. The second argument to the bi-predicate will be zero.
* Call the T-T consuming bi-predicate for each remaining unpaired T in the
* input array. This method should be invoked after the predicate has been
* passed to a @{code TProducer#forEachT(BiPredicate(T,T))} to consume any
* unpaired Ts. The second argument to the bi-predicate will be @{code null}.
*
* @return true if all calls the predicate were successful
*/
boolean forEachRemaining() {
// uses local references for optimization benefit.
int i = idx;
final BloomFilter[] a = ary;
final T[] a = ary;
final int limit = a.length;
while (i != limit && func.test(a[i], null)) {
i++;
Expand Down

0 comments on commit 1a647d5

Please sign in to comment.