Claudenw commented on code in PR #358:
URL:
https://github.com/apache/commons-collections/pull/358#discussion_r1020765271
##########
src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilter.java:
##########
@@ -214,26 +215,48 @@ default boolean isFull() {
* <p>By default this is the rounding of the {@code
Shape.estimateN(cardinality)} calculation for the
* shape and cardinality of this filter.</p>
*
- * <p>This produces an estimate roughly equivalent to the number of
Hashers that have been merged into the filter.</p>
+ * <p>This produces an estimate roughly equivalent to the number of
Hashers that have been merged into the filter
+ * by rounding the value from the calculation described in the {@link
Shape} class javadoc.</p>
*
- * @return an estimate of the number of items in the bloom filter.
+ * <p><em>Note:</em></p>
+ * <ul>
+ * <li>if cardinality == numberOfBits, then result is
Integer.MAX_VALUE.</li>
+ * <li>if cardinality > numberOfBits, then an IllegalArgumentException
is thrown.</li>
+ * </ul>
+ *
+ * @return an estimate of the number of items in the bloom filter. Will
return Integer.MAX_VALUE if the
+ * estimate is larger than Integer.MAX_VALUE.
+ * @throws IllegalArgumentException if the cardinality is >
numberOfBits as defined in Shape.
* @see Shape#estimateN(int)
+ * @see Shape
*/
default int estimateN() {
- return (int) Math.round(getShape().estimateN(cardinality()));
+ double d = getShape().estimateN(cardinality());
+ if (Double.isInfinite(d)) {
+ return Integer.MAX_VALUE;
+ }
+ if (Double.isNaN(d)) {
+ throw new IllegalArgumentException("Cardinality too large: " +
cardinality());
+ }
+ long l = Math.round(d);
+ return l > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) l;
Review Comment:
leaving as is to verify test coverage
--
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]