Claudenw commented on code in PR #258:
URL: 
https://github.com/apache/commons-collections/pull/258#discussion_r897686210


##########
src/main/java/org/apache/commons/collections4/bloomfilter/ArrayCountingBloomFilter.java:
##########
@@ -258,107 +192,93 @@ public boolean subtract(final CountingBloomFilter other) 
{
      *
      * <p><em>Implementation note</em>
      *
-     * <p>The state transition to invalid is permanent.
+     * <p>The state transition to invalid is permanent.</p>
      *
      * <p>This implementation does not correct negative counts to zero or 
integer
      * overflow counts to {@link Integer#MAX_VALUE}. Thus the operation that
      * generated invalid counts can be reversed by using the complement of the
      * original operation with the same Bloom filter. This will restore the 
counts
      * to the state prior to the invalid operation. Counts can then be 
extracted
-     * using {@link #forEachCount(BitCountConsumer)}.
+     * using {@link #forEachCount(BitCountConsumer)}.</p>
      */
     @Override
     public boolean isValid() {
         return state >= 0;
     }
 
     @Override
-    public void forEachCount(final BitCountConsumer action) {
+    public boolean forEachCount(final BitCountProducer.BitCountConsumer 
consumer) {
+        Objects.requireNonNull(consumer, "consumer");
         for (int i = 0; i < counts.length; i++) {
-            if (counts[i] != 0) {
-                action.accept(i, counts[i]);
+            if (counts[i] != 0 && !consumer.test(i, counts[i])) {
+                return false;
             }
         }
+        return true;
     }
 
-    /**
-     * Apply the action for each index in the Bloom filter.
-     */
-    private void applyAsBloomFilter(final BloomFilter other, final IntConsumer 
action) {
-        verifyShape(other);
-        if (other instanceof ArrayCountingBloomFilter) {
-            // Only use the presence of non-zero and not the counts
-            final int[] counts2 = ((ArrayCountingBloomFilter) other).counts;
-            for (int i = 0; i < counts2.length; i++) {
-                if (counts2[i] != 0) {
-                    action.accept(i);
-                }
+    @Override
+    public boolean forEachIndex(IntPredicate consumer) {
+        Objects.requireNonNull(consumer, "consumer");
+        for (int i = 0; i < counts.length; i++) {
+            if (counts[i] != 0 && !consumer.test(i)) {
+                return false;
             }
-        } else {
-            BitSet.valueOf(other.getBits()).stream().forEach(action);
         }
+        return true;
     }
 
-    /**
-     * Apply the action for each index in the hasher.
-     */
-    private void applyAsHasher(final Hasher hasher, final IntConsumer action) {
-        verifyHasher(hasher);
-        // We do not naturally handle duplicates so filter them.
-        IndexFilters.distinctIndexes(hasher, getShape(), action);
-    }
-
-    /**
-     * Apply the action for each index in the Bloom filter.
-     */
-    private void applyAsCountingBloomFilter(final CountingBloomFilter other, 
final BitCountConsumer action) {
-        verifyShape(other);
-        other.forEachCount(action);
-    }
-
-    /**
-     * Increment to the count for the bit index.
-     *
-     * @param idx the index
-     */
-    private void increment(final int idx) {
-        final int updated = counts[idx] + 1;
-        state |= updated;
-        counts[idx] = updated;
-    }
-
-    /**
-     * Decrement from the count for the bit index.
-     *
-     * @param idx the index
-     */
-    private void decrement(final int idx) {
-        final int updated = counts[idx] - 1;
-        state |= updated;
-        counts[idx] = updated;
+    @Override
+    public boolean forEachBitMap(LongPredicate consumer) {
+        Objects.requireNonNull(consumer, "consumer");
+        return BitMapProducer.fromIndexProducer(this, 
shape.getNumberOfBits()).forEachBitMap(consumer);

Review Comment:
   created https://issues.apache.org/jira/browse/COLLECTIONS-823 to track this



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to