aherbert commented on code in PR #357:
URL:
https://github.com/apache/commons-collections/pull/357#discussion_r1015160690
##########
src/main/java/org/apache/commons/collections4/bloomfilter/Hasher.java:
##########
@@ -61,4 +61,10 @@ default IndexProducer uniqueIndices(Shape shape) {
return
Hasher.this.indices(shape).forEachIndex(IndexFilter.create(shape, consumer));
};
}
+
+ /**
+ * Returns {@code true} if the hasher is empty and will return no values.
+ * @return {@code true} if the hasher is empty and will return no values.
+ */
+ boolean isEmpty();
Review Comment:
I think this should have a default implementation of `return false;`.
There are very few places where it has to be overridden. When this has a
default implementation the interface can remain a functional interface.
##########
src/test/java/org/apache/commons/collections4/bloomfilter/AbstractHasherTest.java:
##########
@@ -85,4 +86,7 @@ public void testHashing(int k, int m) {
});
assertEquals(1, count[0], "did not exit early");
}
+
+ @Test
+ public abstract void testIsEmpty();
Review Comment:
Why is this abstract?
```Java
public void testIsEmpty() {
Assertions.assertTrue(createEmptyHasher().isEmpty());
Assertions.assertFalse(createHasher().isEmpty());
}
```
The specific use case in HasherCollection with a non-empty collection of
empty hashers can be left to override this test.
##########
src/main/java/org/apache/commons/collections4/bloomfilter/HasherCollection.java:
##########
@@ -66,6 +66,16 @@ public HasherCollection(Hasher... hashers) {
this(Arrays.asList(hashers));
}
+ @Override
+ public boolean isEmpty() {
+ for (Hasher h : hashers) {
+ if (!h.isEmpty()) {
+ return false;
+ }
+ }
+ return true;
Review Comment:
I am fine with a non-stream method to avoid the stream object creation
overhead.
--
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]