in src/main/java/org/apache/commons/collections4/bloomfilter/BloomFilter.java [148:175]
default int estimateIntersection(final BloomFilter<?> other) {
Objects.requireNonNull(other, "other");
final double eThis = getShape().estimateN(cardinality());
final double eOther = getShape().estimateN(other.cardinality());
if (Double.isInfinite(eThis) && Double.isInfinite(eOther)) {
// if both are infinite the union is infinite and we return Integer.MAX_VALUE
return Integer.MAX_VALUE;
}
long estimate;
// if one is infinite the intersection is the other.
if (Double.isInfinite(eThis)) {
estimate = Math.round(eOther);
} else if (Double.isInfinite(eOther)) {
estimate = Math.round(eThis);
} else {
final T union = this.copy();
union.merge(other);
final double eUnion = getShape().estimateN(union.cardinality());
if (Double.isInfinite(eUnion)) {
throw new IllegalArgumentException("The estimated N for the union of the filters is infinite");
}
// maximum estimate value using integer values is: 46144189292 thus
// eThis + eOther cannot overflow the long value.
estimate = Math.round(eThis + eOther - eUnion);
estimate = estimate < 0 ? 0 : estimate;
}
return estimate > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) estimate;
}