From 1a647d5c11f57d96412fda0c3b2eba7f2f5975e7 Mon Sep 17 00:00:00 2001 From: Claude Warren Date: Fri, 30 Jun 2023 19:55:22 +0200 Subject: [PATCH] Cleaned up javadoc and BiPredicate processing --- .../bloomfilter/BloomFilterBiPredicate.java | 37 --------------- .../bloomfilter/BloomFilterProducer.java | 12 ++++- ...rPredicate.java => CountingPredicate.java} | 47 +++++++++++-------- 3 files changed, 38 insertions(+), 58 deletions(-) delete mode 100644 src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilterBiPredicate.java rename src/main/java/org/apache/commons/collections4/bloomfilter/{CountingBloomFilterPredicate.java => CountingPredicate.java} (55%) diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilterBiPredicate.java b/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilterBiPredicate.java deleted file mode 100644 index ce38ea542f..0000000000 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilterBiPredicate.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.collections4.bloomfilter; - -/** - * Represents a function that accepts a two Bloom argument and produces a boolean result. - * This is the boolean returning specialization for {@code BiPredicate}. - * - * This is a functional interface whose functional method is {@code test(BloomFilter,BloomFilter)}. - * - * @since 4.5 - */ -@FunctionalInterface -public interface BloomFilterBiPredicate { - - /** - * A function that takes to long arguments and returns a boolean. - * @param x the first Bloom filter argument. - * @param y the second Bloom filter argument. - * @return true or false. - */ - boolean test(BloomFilter x, BloomFilter y); -} diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilterProducer.java b/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilterProducer.java index 284d25d677..fb220066b5 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilterProducer.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilterProducer.java @@ -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 @@ -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 func) { + final CountingPredicate p = new CountingPredicate<>(asBloomFilterArray(), func); return other.forEachBloomFilter(p) && p.forEachRemaining(); } diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilterPredicate.java b/src/main/java/org/apache/commons/collections4/bloomfilter/CountingPredicate.java similarity index 55% rename from src/main/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilterPredicate.java rename to src/main/java/org/apache/commons/collections4/bloomfilter/CountingPredicate.java index a9ea7a10a3..f42b84e4b2 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilterPredicate.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/CountingPredicate.java @@ -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 the type of object being compared. + * + * @Since 4.5 */ -class CountingBloomFilterPredicate implements Predicate { +class CountingPredicate implements Predicate { private int idx = 0; - private final BloomFilter[] ary; - private final BloomFilterBiPredicate func; + private final T[] ary; + private final BiPredicate 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 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++;