mirror of
https://github.com/apache/commons-collections.git
synced 2025-02-08 11:05:46 +00:00
Add missing @Override
Use diamonds Use final
This commit is contained in:
parent
8618b108f8
commit
e37d375d83
@ -150,7 +150,7 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
|
||||
* @return {@code true} if the Bag contains all the collection
|
||||
*/
|
||||
boolean containsAll(final Bag<?> other) {
|
||||
for (Object current : other.uniqueSet()) {
|
||||
for (final Object current : other.uniqueSet()) {
|
||||
if (getCount(current) < other.getCount(current)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ public final class ArrayCountingBloomFilter implements CountingBloomFilter {
|
||||
counts = new int[shape.getNumberOfBits()];
|
||||
}
|
||||
|
||||
private ArrayCountingBloomFilter(ArrayCountingBloomFilter source) {
|
||||
private ArrayCountingBloomFilter(final ArrayCountingBloomFilter source) {
|
||||
this.shape = source.shape;
|
||||
this.state = source.state;
|
||||
this.counts = source.counts.clone();
|
||||
@ -170,7 +170,7 @@ public final class ArrayCountingBloomFilter implements CountingBloomFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEachIndex(IntPredicate consumer) {
|
||||
public boolean forEachIndex(final IntPredicate consumer) {
|
||||
Objects.requireNonNull(consumer, "consumer");
|
||||
for (int i = 0; i < counts.length; i++) {
|
||||
if (counts[i] != 0 && !consumer.test(i)) {
|
||||
@ -181,7 +181,7 @@ public final class ArrayCountingBloomFilter implements CountingBloomFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEachBitMap(LongPredicate consumer) {
|
||||
public boolean forEachBitMap(final LongPredicate consumer) {
|
||||
Objects.requireNonNull(consumer, "consumer");
|
||||
final int blocksm1 = BitMap.numberOfBitMaps(counts.length) - 1;
|
||||
int i = 0;
|
||||
@ -242,12 +242,12 @@ public final class ArrayCountingBloomFilter implements CountingBloomFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IndexProducer indexProducer) {
|
||||
public boolean contains(final IndexProducer indexProducer) {
|
||||
return indexProducer.forEachIndex(idx -> this.counts[idx] != 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(BitMapProducer bitMapProducer) {
|
||||
public boolean contains(final BitMapProducer bitMapProducer) {
|
||||
return contains(IndexProducer.fromBitMapProducer(bitMapProducer));
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ public interface BitCountProducer extends IndexProducer {
|
||||
* The default implementation returns indices with ordering and uniqueness of {@code forEachCount()}.
|
||||
*/
|
||||
@Override
|
||||
default boolean forEachIndex(IntPredicate predicate) {
|
||||
default boolean forEachIndex(final IntPredicate predicate) {
|
||||
return forEachCount((i, v) -> predicate.test(i));
|
||||
}
|
||||
|
||||
@ -85,10 +85,10 @@ public interface BitCountProducer extends IndexProducer {
|
||||
* @param idx An index producer.
|
||||
* @return A BitCountProducer with the same indices as the IndexProducer.
|
||||
*/
|
||||
static BitCountProducer from(IndexProducer idx) {
|
||||
static BitCountProducer from(final IndexProducer idx) {
|
||||
return new BitCountProducer() {
|
||||
@Override
|
||||
public boolean forEachCount(BitCountConsumer consumer) {
|
||||
public boolean forEachCount(final BitCountConsumer consumer) {
|
||||
return idx.forEachIndex(i -> consumer.test(i, 1));
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ public interface BitCountProducer extends IndexProducer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEachIndex(IntPredicate predicate) {
|
||||
public boolean forEachIndex(final IntPredicate predicate) {
|
||||
return idx.forEachIndex(predicate);
|
||||
}
|
||||
};
|
||||
|
@ -40,7 +40,7 @@ public class BitMap {
|
||||
* @param numberOfBits the number of bits to store in the array of bit maps.
|
||||
* @return the number of bit maps necessary.
|
||||
*/
|
||||
public static int numberOfBitMaps(int numberOfBits) {
|
||||
public static int numberOfBitMaps(final int numberOfBits) {
|
||||
return ((numberOfBits - 1) >> DIVIDE_BY_64) + 1;
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ public class BitMap {
|
||||
* @return {@code true} if the bit is enabled, {@code false} otherwise.
|
||||
* @throws IndexOutOfBoundsException if bitIndex specifies a bit not in the range being tracked.
|
||||
*/
|
||||
public static boolean contains(long[] bitMaps, int bitIndex) {
|
||||
public static boolean contains(final long[] bitMaps, final int bitIndex) {
|
||||
return (bitMaps[getLongIndex(bitIndex)] & getLongBit(bitIndex)) != 0;
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ public class BitMap {
|
||||
* @param bitIndex the index of the bit to set.
|
||||
* @throws IndexOutOfBoundsException if bitIndex specifies a bit not in the range being tracked.
|
||||
*/
|
||||
public static void set(long[] bitMaps, int bitIndex) {
|
||||
public static void set(final long[] bitMaps, final int bitIndex) {
|
||||
bitMaps[getLongIndex(bitIndex)] |= getLongBit(bitIndex);
|
||||
}
|
||||
|
||||
|
@ -65,8 +65,8 @@ public interface BitMapProducer {
|
||||
* @param func The function to apply.
|
||||
* @return A LongPredicate that tests this BitMapProducers bitmap values in order.
|
||||
*/
|
||||
default boolean forEachBitMapPair(BitMapProducer other, LongBiPredicate func) {
|
||||
CountingLongPredicate p = new CountingLongPredicate(asBitMapArray(), func);
|
||||
default boolean forEachBitMapPair(final BitMapProducer other, final LongBiPredicate func) {
|
||||
final CountingLongPredicate p = new CountingLongPredicate(asBitMapArray(), func);
|
||||
return other.forEachBitMap(p) && p.forEachRemaining();
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ public interface BitMapProducer {
|
||||
private long[] data = new long[16];
|
||||
private int size;
|
||||
|
||||
boolean add(long bits) {
|
||||
boolean add(final long bits) {
|
||||
if (size == data.length) {
|
||||
// This will throw an out-of-memory error if there are too many bits.
|
||||
// Since bits are addressed using 32-bit signed integer indices
|
||||
@ -100,7 +100,7 @@ public interface BitMapProducer {
|
||||
return size == data.length ? data : Arrays.copyOf(data, size);
|
||||
}
|
||||
}
|
||||
Bits bits = new Bits();
|
||||
final Bits bits = new Bits();
|
||||
forEachBitMap(bits::add);
|
||||
return bits.toArray();
|
||||
}
|
||||
@ -110,11 +110,11 @@ public interface BitMapProducer {
|
||||
* @param bitMaps the bit maps to return.
|
||||
* @return a BitMapProducer.
|
||||
*/
|
||||
static BitMapProducer fromBitMapArray(long... bitMaps) {
|
||||
static BitMapProducer fromBitMapArray(final long... bitMaps) {
|
||||
return new BitMapProducer() {
|
||||
@Override
|
||||
public boolean forEachBitMap(LongPredicate predicate) {
|
||||
for (long word : bitMaps) {
|
||||
public boolean forEachBitMap(final LongPredicate predicate) {
|
||||
for (final long word : bitMaps) {
|
||||
if (!predicate.test(word)) {
|
||||
return false;
|
||||
}
|
||||
@ -128,8 +128,8 @@ public interface BitMapProducer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEachBitMapPair(BitMapProducer other, LongBiPredicate func) {
|
||||
CountingLongPredicate p = new CountingLongPredicate(bitMaps, func);
|
||||
public boolean forEachBitMapPair(final BitMapProducer other, final LongBiPredicate func) {
|
||||
final CountingLongPredicate p = new CountingLongPredicate(bitMaps, func);
|
||||
return other.forEachBitMap(p) && p.forEachRemaining();
|
||||
}
|
||||
};
|
||||
@ -141,11 +141,11 @@ public interface BitMapProducer {
|
||||
* @param numberOfBits the number of bits in the Bloom filter.
|
||||
* @return A BitMapProducer that produces the bit maps equivalent of the Indices from the producer.
|
||||
*/
|
||||
static BitMapProducer fromIndexProducer(IndexProducer producer, int numberOfBits) {
|
||||
static BitMapProducer fromIndexProducer(final IndexProducer producer, final int numberOfBits) {
|
||||
Objects.requireNonNull(producer, "producer");
|
||||
Objects.requireNonNull(numberOfBits, "numberOfBits");
|
||||
|
||||
long[] result = new long[BitMap.numberOfBitMaps(numberOfBits)];
|
||||
final long[] result = new long[BitMap.numberOfBitMaps(numberOfBits)];
|
||||
producer.forEachIndex(i -> {
|
||||
BitMap.set(result, i);
|
||||
return true;
|
||||
|
@ -76,7 +76,7 @@ public interface BloomFilter extends IndexProducer, BitMapProducer {
|
||||
* @param other the other Bloom filter
|
||||
* @return true if all enabled bits in the other filter are enabled in this filter.
|
||||
*/
|
||||
default boolean contains(BloomFilter other) {
|
||||
default boolean contains(final BloomFilter other) {
|
||||
Objects.requireNonNull(other, "other");
|
||||
return (characteristics() & SPARSE) != 0 ? contains((IndexProducer) other) : contains((BitMapProducer) other);
|
||||
}
|
||||
@ -91,9 +91,9 @@ public interface BloomFilter extends IndexProducer, BitMapProducer {
|
||||
* @param hasher the hasher to provide the indexes
|
||||
* @return true if this filter is enabled for all bits specified by the hasher
|
||||
*/
|
||||
default boolean contains(Hasher hasher) {
|
||||
default boolean contains(final Hasher hasher) {
|
||||
Objects.requireNonNull(hasher, "Hasher");
|
||||
Shape shape = getShape();
|
||||
final Shape shape = getShape();
|
||||
return contains(hasher.indices(shape));
|
||||
}
|
||||
|
||||
@ -115,7 +115,7 @@ public interface BloomFilter extends IndexProducer, BitMapProducer {
|
||||
* @param bitMapProducer the the {@code BitMapProducer} to provide the bit maps.
|
||||
* @return {@code true} if this filter is enabled for all bits specified by the bit maps
|
||||
*/
|
||||
default boolean contains(BitMapProducer bitMapProducer) {
|
||||
default boolean contains(final BitMapProducer bitMapProducer) {
|
||||
return forEachBitMapPair(bitMapProducer, (x, y) -> (x & y) == y);
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ public interface BloomFilter extends IndexProducer, BitMapProducer {
|
||||
* @param other The bloom filter to merge into this one.
|
||||
* @return true if the merge was successful
|
||||
*/
|
||||
default boolean merge(BloomFilter other) {
|
||||
default boolean merge(final BloomFilter other) {
|
||||
return (characteristics() & SPARSE) != 0 ? merge((IndexProducer) other) : merge((BitMapProducer) other);
|
||||
}
|
||||
|
||||
@ -151,7 +151,7 @@ public interface BloomFilter extends IndexProducer, BitMapProducer {
|
||||
* @param hasher The hasher to merge.
|
||||
* @return true if the merge was successful
|
||||
*/
|
||||
default boolean merge(Hasher hasher) {
|
||||
default boolean merge(final Hasher hasher) {
|
||||
Objects.requireNonNull(hasher, "hasher");
|
||||
return merge(hasher.indices(getShape()));
|
||||
}
|
||||
@ -235,9 +235,9 @@ public interface BloomFilter extends IndexProducer, BitMapProducer {
|
||||
* @return an estimate of the number of items in the union.
|
||||
* @see #estimateN()
|
||||
*/
|
||||
default int estimateUnion(BloomFilter other) {
|
||||
default int estimateUnion(final BloomFilter other) {
|
||||
Objects.requireNonNull(other, "other");
|
||||
BloomFilter cpy = this.copy();
|
||||
final BloomFilter cpy = this.copy();
|
||||
cpy.merge(other);
|
||||
return cpy.estimateN();
|
||||
}
|
||||
@ -253,7 +253,7 @@ public interface BloomFilter extends IndexProducer, BitMapProducer {
|
||||
* @param other The other Bloom filter
|
||||
* @return an estimate of the number of items in the intersection.
|
||||
*/
|
||||
default int estimateIntersection(BloomFilter other) {
|
||||
default int estimateIntersection(final BloomFilter other) {
|
||||
Objects.requireNonNull(other, "other");
|
||||
return estimateN() + other.estimateN() - estimateUnion(other);
|
||||
}
|
||||
|
@ -94,6 +94,7 @@ public interface CountingBloomFilter extends BloomFilter, BitCountProducer {
|
||||
* @see #isValid()
|
||||
* @see #add(BitCountProducer)
|
||||
*/
|
||||
@Override
|
||||
default boolean merge(final BloomFilter other) {
|
||||
Objects.requireNonNull(other, "other");
|
||||
return merge((IndexProducer) other);
|
||||
@ -111,6 +112,7 @@ public interface CountingBloomFilter extends BloomFilter, BitCountProducer {
|
||||
* @see #isValid()
|
||||
* @see #add(BitCountProducer)
|
||||
*/
|
||||
@Override
|
||||
default boolean merge(final Hasher hasher) {
|
||||
Objects.requireNonNull(hasher, "hasher");
|
||||
return merge(hasher.uniqueIndices(getShape()));
|
||||
@ -130,11 +132,12 @@ public interface CountingBloomFilter extends BloomFilter, BitCountProducer {
|
||||
* @see #isValid()
|
||||
* @see #add(BitCountProducer)
|
||||
*/
|
||||
@Override
|
||||
default boolean merge(final IndexProducer indexProducer) {
|
||||
Objects.requireNonNull(indexProducer, "indexProducer");
|
||||
try {
|
||||
return add(BitCountProducer.from(indexProducer));
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
} catch (final IndexOutOfBoundsException e) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Filter only accepts values in the [0,%d) range", getShape().getNumberOfBits()), e);
|
||||
}
|
||||
@ -152,6 +155,7 @@ public interface CountingBloomFilter extends BloomFilter, BitCountProducer {
|
||||
* @see #isValid()
|
||||
* @see #add(BitCountProducer)
|
||||
*/
|
||||
@Override
|
||||
default boolean merge(final BitMapProducer bitMapProducer) {
|
||||
Objects.requireNonNull(bitMapProducer, "bitMapProducer");
|
||||
return merge(IndexProducer.fromBitMapProducer(bitMapProducer));
|
||||
@ -217,7 +221,7 @@ public interface CountingBloomFilter extends BloomFilter, BitCountProducer {
|
||||
Objects.requireNonNull(indexProducer, "indexProducer");
|
||||
try {
|
||||
return subtract(BitCountProducer.from(indexProducer));
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
} catch (final IndexOutOfBoundsException e) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Filter only accepts values in the [0,%d) range", getShape().getNumberOfBits()));
|
||||
}
|
||||
|
@ -37,13 +37,13 @@ class CountingLongPredicate implements LongPredicate {
|
||||
* @param ary The array of long values to compare.
|
||||
* @param func The function to apply to the pairs of long values.
|
||||
*/
|
||||
CountingLongPredicate(long[] ary, LongBiPredicate func) {
|
||||
CountingLongPredicate(final long[] ary, final LongBiPredicate func) {
|
||||
this.ary = ary;
|
||||
this.func = func;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(long other) {
|
||||
public boolean test(final long other) {
|
||||
return func.test(idx == ary.length ? 0 : ary[idx++], other);
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ public class EnhancedDoubleHasher implements Hasher {
|
||||
* @param len the length of the extraction, may be longer than 8.
|
||||
* @return
|
||||
*/
|
||||
private static long toLong(byte[] byteArray, int offset, int len) {
|
||||
private static long toLong(final byte[] byteArray, final int offset, final int len) {
|
||||
long val = 0;
|
||||
int shift = Long.SIZE;
|
||||
final int end = offset + Math.min(len, Long.BYTES);
|
||||
@ -93,12 +93,12 @@ public class EnhancedDoubleHasher implements Hasher {
|
||||
* @param buffer the buffer to extract the longs from.
|
||||
* @throws IllegalArgumentException is buffer length is zero.
|
||||
*/
|
||||
public EnhancedDoubleHasher(byte[] buffer) {
|
||||
public EnhancedDoubleHasher(final byte[] buffer) {
|
||||
if (buffer.length == 0) {
|
||||
throw new IllegalArgumentException("buffer length must be greater than 0");
|
||||
}
|
||||
// divide by 2
|
||||
int segment = buffer.length / 2;
|
||||
final int segment = buffer.length / 2;
|
||||
this.initial = toLong(buffer, 0, segment);
|
||||
this.increment = toLong(buffer, segment, buffer.length - segment);
|
||||
}
|
||||
@ -108,7 +108,7 @@ public class EnhancedDoubleHasher implements Hasher {
|
||||
* @param initial The initial value for the hasher.
|
||||
* @param increment The value to increment the hash by on each iteration.
|
||||
*/
|
||||
public EnhancedDoubleHasher(long initial, long increment) {
|
||||
public EnhancedDoubleHasher(final long initial, final long increment) {
|
||||
this.initial = initial;
|
||||
this.increment = increment;
|
||||
}
|
||||
@ -135,7 +135,7 @@ public class EnhancedDoubleHasher implements Hasher {
|
||||
* @param divisor the divisor for the modulus calculation.
|
||||
* @return the remainder or modulus value.
|
||||
*/
|
||||
static int mod(long dividend, int divisor) {
|
||||
static int mod(final long dividend, final int divisor) {
|
||||
// See Hacker's Delight (2nd ed), section 9.3.
|
||||
// Assume divisor is positive.
|
||||
// Divide half the unsigned number and then double the quotient result.
|
||||
@ -152,7 +152,7 @@ public class EnhancedDoubleHasher implements Hasher {
|
||||
return new IndexProducer() {
|
||||
|
||||
@Override
|
||||
public boolean forEachIndex(IntPredicate consumer) {
|
||||
public boolean forEachIndex(final IntPredicate consumer) {
|
||||
Objects.requireNonNull(consumer, "consumer");
|
||||
final int bits = shape.getNumberOfBits();
|
||||
// Enhanced double hashing:
|
||||
@ -211,8 +211,8 @@ public class EnhancedDoubleHasher implements Hasher {
|
||||
|
||||
@Override
|
||||
public int[] asIndexArray() {
|
||||
int[] result = new int[shape.getNumberOfHashFunctions()];
|
||||
int[] idx = new int[1];
|
||||
final int[] result = new int[shape.getNumberOfHashFunctions()];
|
||||
final int[] idx = new int[1];
|
||||
|
||||
// This method needs to return duplicate indices
|
||||
|
||||
|
@ -55,7 +55,7 @@ public interface Hasher {
|
||||
* @param shape the shape of the desired Bloom filter.
|
||||
* @return the iterator of integers
|
||||
*/
|
||||
default IndexProducer uniqueIndices(Shape shape) {
|
||||
default IndexProducer uniqueIndices(final Shape shape) {
|
||||
return consumer -> {
|
||||
Objects.requireNonNull(consumer, "consumer");
|
||||
return Hasher.this.indices(shape).forEachIndex(IndexFilter.create(shape, consumer));
|
||||
|
@ -62,7 +62,7 @@ public class HasherCollection implements Hasher {
|
||||
*
|
||||
* @param hashers A list of Hashers to initialize the collection with.
|
||||
*/
|
||||
public HasherCollection(Hasher... hashers) {
|
||||
public HasherCollection(final Hasher... hashers) {
|
||||
this(Arrays.asList(hashers));
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ public class HasherCollection implements Hasher {
|
||||
* Adds a hasher to the collection.
|
||||
* @param hasher The hasher to add.
|
||||
*/
|
||||
public void add(Hasher hasher) {
|
||||
public void add(final Hasher hasher) {
|
||||
Objects.requireNonNull(hasher, "hasher");
|
||||
hashers.add(hasher);
|
||||
}
|
||||
@ -79,7 +79,7 @@ public class HasherCollection implements Hasher {
|
||||
* Add all the Hashers in a collection to this HasherCollection.
|
||||
* @param hashers The hashers to add.
|
||||
*/
|
||||
public void add(Collection<Hasher> hashers) {
|
||||
public void add(final Collection<Hasher> hashers) {
|
||||
Objects.requireNonNull(hashers, "hashers");
|
||||
this.hashers.addAll(hashers);
|
||||
}
|
||||
@ -109,8 +109,8 @@ public class HasherCollection implements Hasher {
|
||||
Objects.requireNonNull(shape, "shape");
|
||||
return new HasherCollectionIndexProducer(shape) {
|
||||
@Override
|
||||
public boolean forEachIndex(IntPredicate consumer) {
|
||||
for (Hasher hasher : hashers) {
|
||||
public boolean forEachIndex(final IntPredicate consumer) {
|
||||
for (final Hasher hasher : hashers) {
|
||||
if (!hasher.uniqueIndices(shape).forEachIndex(consumer)) {
|
||||
return false;
|
||||
}
|
||||
@ -131,7 +131,7 @@ public class HasherCollection implements Hasher {
|
||||
* @return the iterator of integers
|
||||
*/
|
||||
public IndexProducer absoluteUniqueIndices(final Shape shape) {
|
||||
int kCount = hashers.size() > 0 ? hashers.size() : 1;
|
||||
final int kCount = hashers.size() > 0 ? hashers.size() : 1;
|
||||
return consumer -> {
|
||||
Objects.requireNonNull(consumer, "consumer");
|
||||
// shape must handle maximum unique indices
|
||||
@ -160,13 +160,13 @@ public class HasherCollection implements Hasher {
|
||||
*
|
||||
* @param shape The shape for the filter.
|
||||
*/
|
||||
HasherCollectionIndexProducer(Shape shape) {
|
||||
HasherCollectionIndexProducer(final Shape shape) {
|
||||
this.shape = shape;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEachIndex(IntPredicate consumer) {
|
||||
for (Hasher hasher : hashers) {
|
||||
public boolean forEachIndex(final IntPredicate consumer) {
|
||||
for (final Hasher hasher : hashers) {
|
||||
if (!hasher.indices(shape).forEachIndex(consumer)) {
|
||||
return false;
|
||||
}
|
||||
@ -176,8 +176,8 @@ public class HasherCollection implements Hasher {
|
||||
|
||||
@Override
|
||||
public int[] asIndexArray() {
|
||||
int[] result = new int[shape.getNumberOfHashFunctions() * hashers.size()];
|
||||
int[] idx = new int[1];
|
||||
final int[] result = new int[shape.getNumberOfHashFunctions() * hashers.size()];
|
||||
final int[] idx = new int[1];
|
||||
|
||||
// This method needs to return duplicate indices
|
||||
|
||||
|
@ -37,7 +37,7 @@ public final class IndexFilter {
|
||||
* @param consumer The consumer to accept the values.
|
||||
* @return an IndexFilter optimized for the specified shape.
|
||||
*/
|
||||
public static IntPredicate create(Shape shape, IntPredicate consumer) {
|
||||
public static IntPredicate create(final Shape shape, final IntPredicate consumer) {
|
||||
return new IndexFilter(shape, consumer)::test;
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ public final class IndexFilter {
|
||||
* @param shape The shape that is being generated.
|
||||
* @param consumer The consumer to accept the values.
|
||||
*/
|
||||
private IndexFilter(Shape shape, IntPredicate consumer) {
|
||||
private IndexFilter(final Shape shape, final IntPredicate consumer) {
|
||||
this.size = shape.getNumberOfBits();
|
||||
this.consumer = consumer;
|
||||
if (BitMap.numberOfBitMaps(shape.getNumberOfBits()) * Long.BYTES < (long) shape.getNumberOfHashFunctions()
|
||||
@ -68,7 +68,7 @@ public final class IndexFilter {
|
||||
* @param number the number to check.
|
||||
* @return {@code true} if processing should continue, {@code false} otherwise.
|
||||
*/
|
||||
public boolean test(int number) {
|
||||
public boolean test(final int number) {
|
||||
if (number >= size) {
|
||||
throw new IndexOutOfBoundsException(String.format("number too large %d >= %d", number, size));
|
||||
}
|
||||
@ -81,19 +81,19 @@ public final class IndexFilter {
|
||||
* @since 4.5
|
||||
*/
|
||||
static class ArrayTracker implements IntPredicate {
|
||||
private int[] seen;
|
||||
private final int[] seen;
|
||||
private int populated;
|
||||
|
||||
/**
|
||||
* Constructs the tracker based on the shape.
|
||||
* @param shape the shape to build the tracker for.
|
||||
*/
|
||||
ArrayTracker(Shape shape) {
|
||||
ArrayTracker(final Shape shape) {
|
||||
seen = new int[shape.getNumberOfHashFunctions()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(int number) {
|
||||
public boolean test(final int number) {
|
||||
if (number < 0) {
|
||||
throw new IndexOutOfBoundsException("number may not be less than zero. " + number);
|
||||
}
|
||||
@ -113,19 +113,19 @@ public final class IndexFilter {
|
||||
* @since 4.5
|
||||
*/
|
||||
static class BitMapTracker implements IntPredicate {
|
||||
private long[] bits;
|
||||
private final long[] bits;
|
||||
|
||||
/**
|
||||
* Constructs a bit map based tracker for the specified shape.
|
||||
* @param shape The shape that is being generated.
|
||||
*/
|
||||
BitMapTracker(Shape shape) {
|
||||
BitMapTracker(final Shape shape) {
|
||||
bits = new long[BitMap.numberOfBitMaps(shape.getNumberOfBits())];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(int number) {
|
||||
boolean retval = !BitMap.contains(bits, number);
|
||||
public boolean test(final int number) {
|
||||
final boolean retval = !BitMap.contains(bits, number);
|
||||
BitMap.set(bits, number);
|
||||
return retval;
|
||||
}
|
||||
|
@ -56,8 +56,8 @@ public interface IndexProducer {
|
||||
return new IndexProducer() {
|
||||
|
||||
@Override
|
||||
public boolean forEachIndex(IntPredicate predicate) {
|
||||
for (int value : values) {
|
||||
public boolean forEachIndex(final IntPredicate predicate) {
|
||||
for (final int value : values) {
|
||||
if (!predicate.test(value)) {
|
||||
return false;
|
||||
}
|
||||
@ -77,12 +77,12 @@ public interface IndexProducer {
|
||||
* @param producer the {@code BitMapProducer}
|
||||
* @return a new {@code IndexProducer}.
|
||||
*/
|
||||
static IndexProducer fromBitMapProducer(BitMapProducer producer) {
|
||||
static IndexProducer fromBitMapProducer(final BitMapProducer producer) {
|
||||
Objects.requireNonNull(producer, "producer");
|
||||
return new IndexProducer() {
|
||||
@Override
|
||||
public boolean forEachIndex(IntPredicate consumer) {
|
||||
LongPredicate longPredicate = new LongPredicate() {
|
||||
public boolean forEachIndex(final IntPredicate consumer) {
|
||||
final LongPredicate longPredicate = new LongPredicate() {
|
||||
int wordIdx = 0;
|
||||
|
||||
@Override
|
||||
@ -122,7 +122,7 @@ public interface IndexProducer {
|
||||
* @return An int array of the data.
|
||||
*/
|
||||
default int[] asIndexArray() {
|
||||
BitSet result = new BitSet();
|
||||
final BitSet result = new BitSet();
|
||||
forEachIndex(i -> {
|
||||
result.set(i);
|
||||
return true;
|
||||
|
@ -33,8 +33,8 @@ public final class SetOperations {
|
||||
* @param op a long binary operation on where x = {@code first} and y = {@code second} bitmap producers.
|
||||
* @return the calculated cardinality.
|
||||
*/
|
||||
private static int cardinality(BitMapProducer first, BitMapProducer second, LongBinaryOperator op) {
|
||||
int[] cardinality = new int[1];
|
||||
private static int cardinality(final BitMapProducer first, final BitMapProducer second, final LongBinaryOperator op) {
|
||||
final int[] cardinality = new int[1];
|
||||
|
||||
first.forEachBitMapPair(second, (x, y) -> {
|
||||
cardinality[0] += Long.bitCount(op.applyAsLong(x, y));
|
||||
@ -49,8 +49,8 @@ public final class SetOperations {
|
||||
* @param producer the Producer to calculate the cardinality for.
|
||||
* @return the cardinality of the bit maps produced by the producer.
|
||||
*/
|
||||
public static int cardinality(BitMapProducer producer) {
|
||||
int[] cardinality = new int[1];
|
||||
public static int cardinality(final BitMapProducer producer) {
|
||||
final int[] cardinality = new int[1];
|
||||
producer.forEachBitMap(l -> {
|
||||
cardinality[0] += Long.bitCount(l);
|
||||
return true;
|
||||
@ -173,7 +173,7 @@ public final class SetOperations {
|
||||
* @return the Jaccard similarity.
|
||||
*/
|
||||
public static double jaccardSimilarity(final BitMapProducer first, final BitMapProducer second) {
|
||||
int[] cardinality = new int[2];
|
||||
final int[] cardinality = new int[2];
|
||||
first.forEachBitMapPair(second, (x, y) -> {
|
||||
cardinality[0] += Long.bitCount(x & y);
|
||||
cardinality[1] += Long.bitCount(x | y);
|
||||
|
@ -79,10 +79,10 @@ public final class Shape {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(final Object obj) {
|
||||
// Shape is final so no check for the same class as inheritance is not possible
|
||||
if (obj instanceof Shape) {
|
||||
Shape other = (Shape) obj;
|
||||
final Shape other = (Shape) obj;
|
||||
return numberOfBits == other.numberOfBits &&
|
||||
numberOfHashFunctions == other.numberOfHashFunctions;
|
||||
}
|
||||
@ -131,7 +131,7 @@ public final class Shape {
|
||||
* @param numberOfItems the number of items hashed into the Bloom filter.
|
||||
* @return the probability of false positives.
|
||||
*/
|
||||
public double getProbability(int numberOfItems) {
|
||||
public double getProbability(final int numberOfItems) {
|
||||
if (numberOfItems < 0) {
|
||||
throw new IllegalArgumentException("Number of items must be greater than or equal to 0: " + numberOfItems);
|
||||
}
|
||||
@ -155,7 +155,7 @@ public final class Shape {
|
||||
* @param cardinality the cardinality to check.
|
||||
* @return true if the cardinality is sparse within the shape.
|
||||
*/
|
||||
public boolean isSparse(int cardinality) {
|
||||
public boolean isSparse(final int cardinality) {
|
||||
/*
|
||||
* Since the size of a bit map is a long and the size of an index is an int,
|
||||
* there can be 2 indexes for each bit map. In Bloom filters indexes are evenly
|
||||
@ -178,10 +178,10 @@ public final class Shape {
|
||||
* @param cardinality the number of enabled bits also known as the hamming value.
|
||||
* @return An estimate of the number of items in the Bloom filter.
|
||||
*/
|
||||
public double estimateN(int cardinality) {
|
||||
double c = cardinality;
|
||||
double m = numberOfBits;
|
||||
double k = numberOfHashFunctions;
|
||||
public double estimateN(final int cardinality) {
|
||||
final double c = cardinality;
|
||||
final double m = numberOfBits;
|
||||
final double k = numberOfHashFunctions;
|
||||
return -(m / k) * Math.log1p(-c / m);
|
||||
}
|
||||
|
||||
@ -226,7 +226,7 @@ public final class Shape {
|
||||
// similarly we can not produce a number greater than numberOfBits so we
|
||||
// do not have to check for Integer.MAX_VALUE either.
|
||||
|
||||
Shape shape = new Shape(numberOfHashFunctions, numberOfBits);
|
||||
final Shape shape = new Shape(numberOfHashFunctions, numberOfBits);
|
||||
// check that probability is within range
|
||||
checkCalculatedProbability(shape.getProbability((int) n));
|
||||
return shape;
|
||||
@ -262,10 +262,10 @@ public final class Shape {
|
||||
if (m > Integer.MAX_VALUE) {
|
||||
throw new IllegalArgumentException("Resulting filter has more than " + Integer.MAX_VALUE + " bits: " + m);
|
||||
}
|
||||
int numberOfBits = (int) m;
|
||||
final int numberOfBits = (int) m;
|
||||
|
||||
int numberOfHashFunctions = calculateNumberOfHashFunctions(numberOfItems, numberOfBits);
|
||||
Shape shape = new Shape(numberOfHashFunctions, numberOfBits);
|
||||
final int numberOfHashFunctions = calculateNumberOfHashFunctions(numberOfItems, numberOfBits);
|
||||
final Shape shape = new Shape(numberOfHashFunctions, numberOfBits);
|
||||
// check that probability is within range
|
||||
checkCalculatedProbability(shape.getProbability(numberOfItems));
|
||||
return shape;
|
||||
@ -304,8 +304,8 @@ public final class Shape {
|
||||
public static Shape fromNM(final int numberOfItems, final int numberOfBits) {
|
||||
checkNumberOfItems(numberOfItems);
|
||||
checkNumberOfBits(numberOfBits);
|
||||
int numberOfHashFunctions = calculateNumberOfHashFunctions(numberOfItems, numberOfBits);
|
||||
Shape shape = new Shape(numberOfHashFunctions, numberOfBits);
|
||||
final int numberOfHashFunctions = calculateNumberOfHashFunctions(numberOfItems, numberOfBits);
|
||||
final Shape shape = new Shape(numberOfHashFunctions, numberOfBits);
|
||||
// check that probability is within range
|
||||
checkCalculatedProbability(shape.getProbability(numberOfItems));
|
||||
return shape;
|
||||
@ -331,7 +331,7 @@ public final class Shape {
|
||||
checkNumberOfBits(numberOfBits);
|
||||
checkNumberOfHashFunctions(numberOfHashFunctions);
|
||||
// check that probability is within range
|
||||
Shape shape = new Shape(numberOfHashFunctions, numberOfBits);
|
||||
final Shape shape = new Shape(numberOfHashFunctions, numberOfBits);
|
||||
// check that probability is within range
|
||||
checkCalculatedProbability(shape.getProbability(numberOfItems));
|
||||
return shape;
|
||||
|
@ -48,7 +48,7 @@ public final class SimpleBloomFilter implements BloomFilter {
|
||||
*
|
||||
* @param shape The shape for the filter.
|
||||
*/
|
||||
public SimpleBloomFilter(Shape shape) {
|
||||
public SimpleBloomFilter(final Shape shape) {
|
||||
Objects.requireNonNull(shape, "shape");
|
||||
this.shape = shape;
|
||||
this.bitMap = new long[BitMap.numberOfBitMaps(shape.getNumberOfBits())];
|
||||
@ -59,7 +59,7 @@ public final class SimpleBloomFilter implements BloomFilter {
|
||||
* Copy constructor for {@code copy()} use.
|
||||
* @param source
|
||||
*/
|
||||
private SimpleBloomFilter(SimpleBloomFilter source) {
|
||||
private SimpleBloomFilter(final SimpleBloomFilter source) {
|
||||
this.shape = source.shape;
|
||||
this.bitMap = source.bitMap.clone();
|
||||
this.cardinality = source.cardinality;
|
||||
@ -77,8 +77,8 @@ public final class SimpleBloomFilter implements BloomFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEachBitMapPair(BitMapProducer other, LongBiPredicate func) {
|
||||
CountingLongPredicate p = new CountingLongPredicate(bitMap, func);
|
||||
public boolean forEachBitMapPair(final BitMapProducer other, final LongBiPredicate func) {
|
||||
final CountingLongPredicate p = new CountingLongPredicate(bitMap, func);
|
||||
return other.forEachBitMap(p) && p.forEachRemaining();
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ public final class SimpleBloomFilter implements BloomFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean merge(IndexProducer indexProducer) {
|
||||
public boolean merge(final IndexProducer indexProducer) {
|
||||
Objects.requireNonNull(indexProducer, "indexProducer");
|
||||
indexProducer.forEachIndex(idx -> {
|
||||
if (idx < 0 || idx >= shape.getNumberOfBits()) {
|
||||
@ -103,23 +103,23 @@ public final class SimpleBloomFilter implements BloomFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean merge(BitMapProducer bitMapProducer) {
|
||||
public boolean merge(final BitMapProducer bitMapProducer) {
|
||||
Objects.requireNonNull(bitMapProducer, "bitMapProducer");
|
||||
try {
|
||||
int[] idx = new int[1];
|
||||
final int[] idx = new int[1];
|
||||
bitMapProducer.forEachBitMap(value -> {
|
||||
bitMap[idx[0]++] |= value;
|
||||
return true;
|
||||
});
|
||||
// idx[0] will be limit+1 so decrement it
|
||||
idx[0]--;
|
||||
int idxLimit = BitMap.getLongIndex(shape.getNumberOfBits());
|
||||
final int idxLimit = BitMap.getLongIndex(shape.getNumberOfBits());
|
||||
if (idxLimit < idx[0]) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"BitMapProducer set a bit higher than the limit for the shape: %s", shape.getNumberOfBits() - 1));
|
||||
}
|
||||
if (idxLimit == idx[0]) {
|
||||
long excess = (bitMap[idxLimit] >> shape.getNumberOfBits());
|
||||
final long excess = (bitMap[idxLimit] >> shape.getNumberOfBits());
|
||||
if (excess != 0) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("BitMapProducer set a bit higher than the limit for the shape: %s",
|
||||
@ -127,7 +127,7 @@ public final class SimpleBloomFilter implements BloomFilter {
|
||||
}
|
||||
}
|
||||
cardinality = -1;
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
} catch (final IndexOutOfBoundsException e) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("BitMapProducer should send at most %s maps", bitMap.length), e);
|
||||
}
|
||||
@ -135,13 +135,13 @@ public final class SimpleBloomFilter implements BloomFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean merge(Hasher hasher) {
|
||||
public boolean merge(final Hasher hasher) {
|
||||
Objects.requireNonNull(hasher, "hasher");
|
||||
return merge(hasher.indices(shape));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean merge(BloomFilter other) {
|
||||
public boolean merge(final BloomFilter other) {
|
||||
Objects.requireNonNull(other, "other");
|
||||
if ((other.characteristics() & SPARSE) != 0) {
|
||||
merge((IndexProducer) other);
|
||||
@ -172,15 +172,15 @@ public final class SimpleBloomFilter implements BloomFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEachIndex(IntPredicate consumer) {
|
||||
public boolean forEachIndex(final IntPredicate consumer) {
|
||||
Objects.requireNonNull(consumer, "consumer");
|
||||
return IndexProducer.fromBitMapProducer(this).forEachIndex(consumer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEachBitMap(LongPredicate consumer) {
|
||||
public boolean forEachBitMap(final LongPredicate consumer) {
|
||||
Objects.requireNonNull(consumer, "consumer");
|
||||
for (long l : bitMap) {
|
||||
for (final long l : bitMap) {
|
||||
if (!consumer.test(l)) {
|
||||
return false;
|
||||
}
|
||||
@ -189,7 +189,7 @@ public final class SimpleBloomFilter implements BloomFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IndexProducer indexProducer) {
|
||||
public boolean contains(final IndexProducer indexProducer) {
|
||||
return indexProducer.forEachIndex(idx -> BitMap.contains(bitMap, idx));
|
||||
}
|
||||
}
|
||||
|
@ -43,21 +43,21 @@ public final class SparseBloomFilter implements BloomFilter {
|
||||
*
|
||||
* @param shape The shape of the filter.
|
||||
*/
|
||||
public SparseBloomFilter(Shape shape) {
|
||||
public SparseBloomFilter(final Shape shape) {
|
||||
Objects.requireNonNull(shape, "shape");
|
||||
this.shape = shape;
|
||||
this.indices = new TreeSet<>();
|
||||
}
|
||||
|
||||
private SparseBloomFilter(SparseBloomFilter source) {
|
||||
private SparseBloomFilter(final SparseBloomFilter source) {
|
||||
shape = source.shape;
|
||||
indices = new TreeSet<>(source.indices);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long[] asBitMapArray() {
|
||||
long[] result = new long[BitMap.numberOfBitMaps(shape.getNumberOfBits())];
|
||||
for (int i : indices) {
|
||||
final long[] result = new long[BitMap.numberOfBitMaps(shape.getNumberOfBits())];
|
||||
for (final int i : indices) {
|
||||
BitMap.set(result, i);
|
||||
}
|
||||
return result;
|
||||
@ -73,13 +73,13 @@ public final class SparseBloomFilter implements BloomFilter {
|
||||
* @param idx the index to add.
|
||||
* @return {@code true} always
|
||||
*/
|
||||
private boolean add(int idx) {
|
||||
private boolean add(final int idx) {
|
||||
indices.add(idx);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean merge(IndexProducer indexProducer) {
|
||||
public boolean merge(final IndexProducer indexProducer) {
|
||||
Objects.requireNonNull(indexProducer, "indexProducer");
|
||||
indexProducer.forEachIndex(this::add);
|
||||
if (!this.indices.isEmpty()) {
|
||||
@ -96,22 +96,22 @@ public final class SparseBloomFilter implements BloomFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean merge(BitMapProducer bitMapProducer) {
|
||||
public boolean merge(final BitMapProducer bitMapProducer) {
|
||||
Objects.requireNonNull(bitMapProducer, "bitMapProducer");
|
||||
return this.merge(IndexProducer.fromBitMapProducer(bitMapProducer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean merge(Hasher hasher) {
|
||||
public boolean merge(final Hasher hasher) {
|
||||
Objects.requireNonNull(hasher, "hasher");
|
||||
merge(hasher.indices(shape));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean merge(BloomFilter other) {
|
||||
public boolean merge(final BloomFilter other) {
|
||||
Objects.requireNonNull(other, "other");
|
||||
IndexProducer producer = (other.characteristics() & SPARSE) != 0 ? (IndexProducer) other : IndexProducer.fromBitMapProducer(other);
|
||||
final IndexProducer producer = (other.characteristics() & SPARSE) != 0 ? (IndexProducer) other : IndexProducer.fromBitMapProducer(other);
|
||||
merge(producer);
|
||||
return true;
|
||||
}
|
||||
@ -137,9 +137,9 @@ public final class SparseBloomFilter implements BloomFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEachIndex(IntPredicate consumer) {
|
||||
public boolean forEachIndex(final IntPredicate consumer) {
|
||||
Objects.requireNonNull(consumer, "consumer");
|
||||
for (int value : indices) {
|
||||
for (final int value : indices) {
|
||||
if (!consumer.test(value)) {
|
||||
return false;
|
||||
}
|
||||
@ -148,9 +148,9 @@ public final class SparseBloomFilter implements BloomFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEachBitMap(LongPredicate consumer) {
|
||||
public boolean forEachBitMap(final LongPredicate consumer) {
|
||||
Objects.requireNonNull(consumer, "consumer");
|
||||
int limit = BitMap.numberOfBitMaps(shape.getNumberOfBits());
|
||||
final int limit = BitMap.numberOfBitMaps(shape.getNumberOfBits());
|
||||
/*
|
||||
* because our indices are always in order we can shorten the time necessary to
|
||||
* create the longs for the consumer
|
||||
@ -159,7 +159,7 @@ public final class SparseBloomFilter implements BloomFilter {
|
||||
long bitMap = 0;
|
||||
// the bitmap we are working on
|
||||
int idx = 0;
|
||||
for (int i : indices) {
|
||||
for (final int i : indices) {
|
||||
while (BitMap.getLongIndex(i) != idx) {
|
||||
if (!consumer.test(bitMap)) {
|
||||
return false;
|
||||
@ -186,12 +186,12 @@ public final class SparseBloomFilter implements BloomFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IndexProducer indexProducer) {
|
||||
public boolean contains(final IndexProducer indexProducer) {
|
||||
return indexProducer.forEachIndex(indices::contains);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(BitMapProducer bitMapProducer) {
|
||||
public boolean contains(final BitMapProducer bitMapProducer) {
|
||||
return contains(IndexProducer.fromBitMapProducer(bitMapProducer));
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ public class ClosureUtilsTest {
|
||||
|
||||
a = new MockClosure<>();
|
||||
b = new MockClosure<>();
|
||||
Collection<Closure<Object>> coll = new ArrayList<>();
|
||||
final Collection<Closure<Object>> coll = new ArrayList<>();
|
||||
coll.add(b);
|
||||
coll.add(a);
|
||||
coll.add(b);
|
||||
@ -170,7 +170,7 @@ public class ClosureUtilsTest {
|
||||
() -> assertThrows(NullPointerException.class, () -> ClosureUtils.<Object>chainedClosure((Collection<Closure<Object>>) null)),
|
||||
() -> assertThrows(NullPointerException.class, () -> ClosureUtils.<Object>chainedClosure(null, null)),
|
||||
() -> {
|
||||
Collection<Closure<Object>> finalColl = new ArrayList<>();
|
||||
final Collection<Closure<Object>> finalColl = new ArrayList<>();
|
||||
finalColl.add(null);
|
||||
finalColl.add(null);
|
||||
assertThrows(NullPointerException.class, () -> ClosureUtils.chainedClosure(finalColl));
|
||||
|
@ -499,12 +499,12 @@ public class CollectionUtilsTest extends MockTestCase {
|
||||
public void extractSingleton() {
|
||||
assertAll(
|
||||
() -> {
|
||||
ArrayList<String> collNull = null;
|
||||
final ArrayList<String> collNull = null;
|
||||
assertThrows(NullPointerException.class, () -> CollectionUtils.extractSingleton(collNull),
|
||||
"expected NullPointerException from extractSingleton(null)");
|
||||
},
|
||||
() -> {
|
||||
ArrayList<String> collEmpty = new ArrayList<>();
|
||||
final ArrayList<String> collEmpty = new ArrayList<>();
|
||||
assertThrows(IllegalArgumentException.class, () -> CollectionUtils.extractSingleton(collEmpty),
|
||||
"expected IllegalArgumentException from extractSingleton(empty)");
|
||||
},
|
||||
@ -735,7 +735,7 @@ public class CollectionUtilsTest extends MockTestCase {
|
||||
assertEquals("one", CollectionUtils.get(en, 1));
|
||||
|
||||
// Enumerator, non-existent entry
|
||||
Enumeration<String> finalEn = en;
|
||||
final Enumeration<String> finalEn = en;
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> CollectionUtils.get(finalEn, 3),
|
||||
"Expecting IndexOutOfBoundsException.");
|
||||
|
||||
@ -785,7 +785,7 @@ public class CollectionUtilsTest extends MockTestCase {
|
||||
assertEquals(2, (int) CollectionUtils.get(iterator, 1));
|
||||
|
||||
// Iterator, non-existent entry
|
||||
Iterator<Integer> finalIterator = iterator;
|
||||
final Iterator<Integer> finalIterator = iterator;
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> CollectionUtils.get(finalIterator, 10),
|
||||
"Expecting IndexOutOfBoundsException.");
|
||||
|
||||
|
@ -445,7 +445,7 @@ public class FluentIterableTest {
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Test
|
||||
public void toArray() {
|
||||
final Long[] arr = new Long[] {1L, 2L, 3L, 4L, 5L};
|
||||
final Long[] arr = {1L, 2L, 3L, 4L, 5L};
|
||||
final Long[] result = FluentIterable.of(arr).toArray(Long.class);
|
||||
assertNotNull(result);
|
||||
assertArrayEquals(arr, result);
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
package org.apache.commons.collections4;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
@ -53,7 +54,7 @@ import junit.framework.TestSuite;
|
||||
public final class GuavaTestlibTest extends TestCase {
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite test = new TestSuite();
|
||||
final TestSuite test = new TestSuite();
|
||||
// Map
|
||||
test.addTest(suiteMap("HashedMap", HashedMap::new));
|
||||
test.addTest(suiteMap("LinkedMap", LinkedMap::new));
|
||||
@ -75,12 +76,12 @@ public final class GuavaTestlibTest extends TestCase {
|
||||
* @param factory factory to create new Maps
|
||||
* @return a JUnit 3, 4 Test Suite
|
||||
*/
|
||||
private static Test suiteMap(String name, Supplier<Map<String, String>> factory) {
|
||||
private static Test suiteMap(final String name, final Supplier<Map<String, String>> factory) {
|
||||
return MapTestSuiteBuilder.using(new TestStringMapGenerator() {
|
||||
@Override
|
||||
protected Map<String, String> create(Map.Entry<String, String>[] entries) {
|
||||
Map<String, String> map = factory.get();
|
||||
for (Map.Entry<String, String> entry : entries) {
|
||||
protected Map<String, String> create(final Map.Entry<String, String>[] entries) {
|
||||
final Map<String, String> map = factory.get();
|
||||
for (final Map.Entry<String, String> entry : entries) {
|
||||
map.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return map;
|
||||
@ -100,14 +101,12 @@ public final class GuavaTestlibTest extends TestCase {
|
||||
* @param features test features used in the tests
|
||||
* @return a JUnit 3, 4 Test Suite
|
||||
*/
|
||||
private static Test suiteList(String name, Supplier<List<String>> factory, Feature<?>... features) {
|
||||
private static Test suiteList(final String name, final Supplier<List<String>> factory, final Feature<?>... features) {
|
||||
final ListTestSuiteBuilder<String> suite = ListTestSuiteBuilder.using(new TestStringListGenerator() {
|
||||
@Override
|
||||
protected List<String> create(String[] elements) {
|
||||
List<String> list = factory.get();
|
||||
for (String element : elements) {
|
||||
list.add(element);
|
||||
}
|
||||
protected List<String> create(final String[] elements) {
|
||||
final List<String> list = factory.get();
|
||||
Collections.addAll(list, elements);
|
||||
return list;
|
||||
}
|
||||
})
|
||||
|
@ -261,7 +261,7 @@ public class IteratorUtilsTest {
|
||||
iterator = IteratorUtils.arrayListIterator(objArray, 3);
|
||||
assertTrue(iterator.hasNext());
|
||||
|
||||
ResettableListIterator<Object> finalIterator = iterator;
|
||||
final ResettableListIterator<Object> finalIterator = iterator;
|
||||
assertAll(
|
||||
() -> assertThrows(NoSuchElementException.class, () -> finalIterator.previous(),
|
||||
"Expecting NoSuchElementException."),
|
||||
@ -743,7 +743,7 @@ public class IteratorUtilsTest {
|
||||
assertEquals(2, (int) IteratorUtils.get(iterator, 1));
|
||||
|
||||
// Iterator, non-existent entry
|
||||
Iterator<Integer> finalIterator = iterator;
|
||||
final Iterator<Integer> finalIterator = iterator;
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> IteratorUtils.get(finalIterator, 10),
|
||||
"Expecting IndexOutOfBoundsException.");
|
||||
|
||||
|
@ -370,10 +370,10 @@ public class ListUtilsTest {
|
||||
assertThrows(NullPointerException.class, () -> ListUtils.removeAll(null, null),
|
||||
"expecting NullPointerException");
|
||||
|
||||
assertThrows(NullPointerException.class, () -> ListUtils.removeAll(null, new ArrayList<Object>()),
|
||||
assertThrows(NullPointerException.class, () -> ListUtils.removeAll(null, new ArrayList<>()),
|
||||
"expecting NullPointerException");
|
||||
|
||||
assertThrows(NullPointerException.class, () -> ListUtils.removeAll(new ArrayList<Object>(), null),
|
||||
assertThrows(NullPointerException.class, () -> ListUtils.removeAll(new ArrayList<>(), null),
|
||||
"expecting NullPointerException");
|
||||
}
|
||||
|
||||
|
@ -77,8 +77,8 @@ public abstract class AbstractBitCountProducerTest extends AbstractIndexProducer
|
||||
|
||||
@Test
|
||||
public final void testForEachCountPredicates() {
|
||||
BitCountProducer populated = createProducer();
|
||||
BitCountProducer empty = createEmptyProducer();
|
||||
final BitCountProducer populated = createProducer();
|
||||
final BitCountProducer empty = createEmptyProducer();
|
||||
|
||||
assertFalse(populated.forEachCount(FALSE_CONSUMER), "non-empty should be false");
|
||||
assertTrue(empty.forEachCount(FALSE_CONSUMER), "empty should be true");
|
||||
@ -89,8 +89,8 @@ public abstract class AbstractBitCountProducerTest extends AbstractIndexProducer
|
||||
|
||||
@Test
|
||||
public final void testEmptyBitCountProducer() {
|
||||
BitCountProducer empty = createEmptyProducer();
|
||||
int ary[] = empty.asIndexArray();
|
||||
final BitCountProducer empty = createEmptyProducer();
|
||||
final int ary[] = empty.asIndexArray();
|
||||
assertEquals(0, ary.length);
|
||||
assertTrue(empty.forEachCount((i, j) -> {
|
||||
Assertions.fail("forEachCount consumer should not be called");
|
||||
@ -100,9 +100,9 @@ public abstract class AbstractBitCountProducerTest extends AbstractIndexProducer
|
||||
|
||||
@Test
|
||||
public final void testIndexConsistency() {
|
||||
BitCountProducer producer = createProducer();
|
||||
BitSet bs1 = new BitSet();
|
||||
BitSet bs2 = new BitSet();
|
||||
final BitCountProducer producer = createProducer();
|
||||
final BitSet bs1 = new BitSet();
|
||||
final BitSet bs2 = new BitSet();
|
||||
producer.forEachIndex(i -> {
|
||||
bs1.set(i);
|
||||
return true;
|
||||
@ -135,24 +135,24 @@ public abstract class AbstractBitCountProducerTest extends AbstractIndexProducer
|
||||
*/
|
||||
@Test
|
||||
public final void testBehaviourForEachCount() {
|
||||
int flags = getForEachCountBehaviour();
|
||||
final int flags = getForEachCountBehaviour();
|
||||
assumeTrue((flags & (ORDERED | DISTINCT)) != 0);
|
||||
IntList list = new IntList();
|
||||
final IntList list = new IntList();
|
||||
createProducer().forEachCount((i, j) -> list.add(i));
|
||||
int[] actual = list.toArray();
|
||||
final int[] actual = list.toArray();
|
||||
if ((flags & ORDERED) != 0) {
|
||||
int[] expected = Arrays.stream(actual).sorted().toArray();
|
||||
final int[] expected = Arrays.stream(actual).sorted().toArray();
|
||||
assertArrayEquals(expected, actual);
|
||||
}
|
||||
if ((flags & DISTINCT) != 0) {
|
||||
long count = Arrays.stream(actual).distinct().count();
|
||||
final long count = Arrays.stream(actual).distinct().count();
|
||||
assertEquals(count, actual.length);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForEachCountEarlyExit() {
|
||||
int[] passes = new int[1];
|
||||
final int[] passes = new int[1];
|
||||
assertTrue(createEmptyProducer().forEachCount((i, j) -> {
|
||||
passes[0]++;
|
||||
return false;
|
||||
|
@ -33,7 +33,7 @@ public abstract class AbstractBitMapProducerTest {
|
||||
public static final LongPredicate FALSE_CONSUMER = new LongPredicate() {
|
||||
|
||||
@Override
|
||||
public boolean test(long arg0) {
|
||||
public boolean test(final long arg0) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@ -44,7 +44,7 @@ public abstract class AbstractBitMapProducerTest {
|
||||
public static final LongPredicate TRUE_CONSUMER = new LongPredicate() {
|
||||
|
||||
@Override
|
||||
public boolean test(long arg0) {
|
||||
public boolean test(final long arg0) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@ -91,18 +91,18 @@ public abstract class AbstractBitMapProducerTest {
|
||||
|
||||
@Test
|
||||
public final void testForEachBitMapPair() {
|
||||
LongBiPredicate func = (x, y) -> x == y;
|
||||
final LongBiPredicate func = (x, y) -> x == y;
|
||||
assertTrue(createEmptyProducer().forEachBitMapPair(createEmptyProducer(), func), "empty == empty failed");
|
||||
assertFalse(createEmptyProducer().forEachBitMapPair(createProducer(), func), "empty == not_empty failed");
|
||||
assertFalse(createProducer().forEachBitMapPair(createEmptyProducer(), func), "not_empty == empty passed");
|
||||
assertTrue(createProducer().forEachBitMapPair(createProducer(), func), "not_empty == not_empty failed");
|
||||
|
||||
// test BitMapProducers of different length send 0 for missing values.
|
||||
int[] count = new int[3];
|
||||
LongBiPredicate lbp = new LongBiPredicate() {
|
||||
final int[] count = new int[3];
|
||||
final LongBiPredicate lbp = new LongBiPredicate() {
|
||||
|
||||
@Override
|
||||
public boolean test(long x, long y) {
|
||||
public boolean test(final long x, final long y) {
|
||||
if (x == 0) {
|
||||
count[0]++;
|
||||
}
|
||||
@ -123,7 +123,7 @@ public abstract class AbstractBitMapProducerTest {
|
||||
|
||||
@Test
|
||||
public void testForEachBitMapEarlyExit() {
|
||||
int[] passes = new int[1];
|
||||
final int[] passes = new int[1];
|
||||
assertFalse(createProducer().forEachBitMap(l -> {
|
||||
passes[0]++;
|
||||
return false;
|
||||
@ -150,11 +150,11 @@ public abstract class AbstractBitMapProducerTest {
|
||||
public void testForEachBitMapPairEarlyExit() {
|
||||
|
||||
// test BitMapProducers of different length send 0 for missing values.
|
||||
int[] count = new int[1];
|
||||
LongBiPredicate lbp = new LongBiPredicate() {
|
||||
final int[] count = new int[1];
|
||||
final LongBiPredicate lbp = new LongBiPredicate() {
|
||||
|
||||
@Override
|
||||
public boolean test(long x, long y) {
|
||||
public boolean test(final long x, final long y) {
|
||||
count[0]++;
|
||||
return false;
|
||||
}
|
||||
|
@ -73,8 +73,8 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
|
||||
* @param hasher the hasher to use to create the filter.
|
||||
* @return a BloomFilter implementation.
|
||||
*/
|
||||
protected final T createFilter(Shape shape, Hasher hasher) {
|
||||
T bf = createEmptyFilter(shape);
|
||||
protected final T createFilter(final Shape shape, final Hasher hasher) {
|
||||
final T bf = createEmptyFilter(shape);
|
||||
bf.merge(hasher);
|
||||
return bf;
|
||||
}
|
||||
@ -86,8 +86,8 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
|
||||
* @param producer A BitMap producer to build the filter with.
|
||||
* @return a BloomFilter implementation.
|
||||
*/
|
||||
protected final T createFilter(Shape shape, BitMapProducer producer) {
|
||||
T bf = createEmptyFilter(shape);
|
||||
protected final T createFilter(final Shape shape, final BitMapProducer producer) {
|
||||
final T bf = createEmptyFilter(shape);
|
||||
bf.merge(producer);
|
||||
return bf;
|
||||
}
|
||||
@ -99,8 +99,8 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
|
||||
* @param producer An Index producer to build the filter with.
|
||||
* @return a BloomFilter implementation.
|
||||
*/
|
||||
protected final T createFilter(Shape shape, IndexProducer producer) {
|
||||
T bf = createEmptyFilter(shape);
|
||||
protected final T createFilter(final Shape shape, final IndexProducer producer) {
|
||||
final T bf = createEmptyFilter(shape);
|
||||
bf.merge(producer);
|
||||
return bf;
|
||||
}
|
||||
@ -115,7 +115,7 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> f.merge(new BadHasher(getTestShape().getNumberOfBits())));
|
||||
// negative value
|
||||
BloomFilter f2 = createEmptyFilter(getTestShape());
|
||||
final BloomFilter f2 = createEmptyFilter(getTestShape());
|
||||
assertThrows(IllegalArgumentException.class, () -> f2.merge(new BadHasher(-1)));
|
||||
}
|
||||
|
||||
@ -123,8 +123,8 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
|
||||
public void testMergeWithHasher() {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
final BloomFilter f = createEmptyFilter(getTestShape());
|
||||
int[] expected = DefaultIndexProducerTest.generateIntArray(getTestShape().getNumberOfHashFunctions(), getTestShape().getNumberOfBits());
|
||||
Hasher hasher = new ArrayHasher(expected);
|
||||
final int[] expected = DefaultIndexProducerTest.generateIntArray(getTestShape().getNumberOfHashFunctions(), getTestShape().getNumberOfBits());
|
||||
final Hasher hasher = new ArrayHasher(expected);
|
||||
f.merge(hasher);
|
||||
// create sorted unique array of expected values
|
||||
assertArrayEquals(DefaultIndexProducerTest.unique(expected), f.asIndexArray());
|
||||
@ -134,13 +134,13 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
|
||||
@Test
|
||||
public void testMergeWithBitMapProducer() {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
long[] values = new long[2];
|
||||
for (int idx : DefaultIndexProducerTest.generateIntArray(getTestShape().getNumberOfHashFunctions(), getTestShape().getNumberOfBits())) {
|
||||
final long[] values = new long[2];
|
||||
for (final int idx : DefaultIndexProducerTest.generateIntArray(getTestShape().getNumberOfHashFunctions(), getTestShape().getNumberOfBits())) {
|
||||
BitMap.set(values, idx);
|
||||
}
|
||||
BloomFilter f = createFilter(getTestShape(), BitMapProducer.fromBitMapArray(values));
|
||||
List<Long> lst = new ArrayList<>();
|
||||
for (long l : values) {
|
||||
final BloomFilter f = createFilter(getTestShape(), BitMapProducer.fromBitMapArray(values));
|
||||
final List<Long> lst = new ArrayList<>();
|
||||
for (final long l : values) {
|
||||
lst.add(l);
|
||||
}
|
||||
assertTrue(f.forEachBitMap(l -> {
|
||||
@ -162,9 +162,9 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
|
||||
@Test
|
||||
public void testMergeWithIndexProducer() {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
int[] values = DefaultIndexProducerTest.generateIntArray(getTestShape().getNumberOfHashFunctions(), getTestShape().getNumberOfBits());
|
||||
BloomFilter f = createFilter(getTestShape(), IndexProducer.fromIndexArray(values));
|
||||
BitSet uniqueValues = DefaultIndexProducerTest.uniqueSet(values);
|
||||
final int[] values = DefaultIndexProducerTest.generateIntArray(getTestShape().getNumberOfHashFunctions(), getTestShape().getNumberOfBits());
|
||||
final BloomFilter f = createFilter(getTestShape(), IndexProducer.fromIndexArray(values));
|
||||
final BitSet uniqueValues = DefaultIndexProducerTest.uniqueSet(values);
|
||||
assertTrue(f.forEachIndex(idx -> {
|
||||
final boolean result = uniqueValues.get(idx);
|
||||
uniqueValues.clear(idx);
|
||||
@ -222,7 +222,7 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
|
||||
|
||||
@Test
|
||||
public void testClear() {
|
||||
BloomFilter bf1 = createFilter(getTestShape(), from1);
|
||||
final BloomFilter bf1 = createFilter(getTestShape(), from1);
|
||||
assertNotEquals(0, bf1.cardinality());
|
||||
bf1.clear();
|
||||
assertEquals(0, bf1.cardinality());
|
||||
@ -269,7 +269,7 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
|
||||
@Test
|
||||
public final void testEstimateN() {
|
||||
// build a filter
|
||||
BloomFilter filter1 = createFilter(getTestShape(), from1);
|
||||
final BloomFilter filter1 = createFilter(getTestShape(), from1);
|
||||
assertEquals(1, filter1.estimateN());
|
||||
|
||||
// the data provided above do not generate an estimate that is equivalent to the
|
||||
@ -328,14 +328,14 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
|
||||
|
||||
// test with BloomFilter
|
||||
|
||||
long[] bf1Val = bf1.asBitMapArray();
|
||||
long[] bf2Val = bf2.asBitMapArray();
|
||||
final long[] bf1Val = bf1.asBitMapArray();
|
||||
final long[] bf2Val = bf2.asBitMapArray();
|
||||
for (int i = 0; i < bf1Val.length; i++) {
|
||||
bf1Val[i] |= bf2Val[i];
|
||||
}
|
||||
bf1.merge(bf2);
|
||||
|
||||
long[] bf1New = bf1.asBitMapArray();
|
||||
final long[] bf1New = bf1.asBitMapArray();
|
||||
for (int i = 0; i < bf1Val.length; i++) {
|
||||
assertEquals(bf1Val[i], bf1New[i], "Bad value at " + i);
|
||||
}
|
||||
@ -345,7 +345,7 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
|
||||
|
||||
// test with hasher
|
||||
|
||||
BloomFilter bf4 = createFilter(getTestShape(), from1);
|
||||
final BloomFilter bf4 = createFilter(getTestShape(), from1);
|
||||
bf4.merge(from11);
|
||||
|
||||
assertTrue(bf4.contains(bf2), "Should contain Bf2");
|
||||
@ -357,39 +357,39 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
|
||||
assertThrows(IllegalArgumentException.class, () -> bf1.merge(new BadHasher(-1)));
|
||||
|
||||
// test error when bloom filter returns values out of range
|
||||
BloomFilter bf5 = new SimpleBloomFilter(
|
||||
final BloomFilter bf5 = new SimpleBloomFilter(
|
||||
Shape.fromKM(getTestShape().getNumberOfHashFunctions(), 3 * Long.SIZE));
|
||||
bf5.merge(new IncrementingHasher(Long.SIZE * 2, 1));
|
||||
assertThrows(IllegalArgumentException.class, () -> bf1.merge(bf5));
|
||||
|
||||
BloomFilter bf6 = new SparseBloomFilter(
|
||||
final BloomFilter bf6 = new SparseBloomFilter(
|
||||
Shape.fromKM(getTestShape().getNumberOfHashFunctions(), 3 * Long.SIZE));
|
||||
bf6.merge(new IncrementingHasher(Long.SIZE * 2, 1));
|
||||
assertThrows(IllegalArgumentException.class, () -> bf1.merge(bf6));
|
||||
}
|
||||
|
||||
private void assertIndexProducerMerge(Shape shape, int[] values, int[] expected) {
|
||||
IndexProducer indices = IndexProducer.fromIndexArray(values);
|
||||
BloomFilter filter = createFilter(shape, indices);
|
||||
List<Integer> lst = new ArrayList<>();
|
||||
private void assertIndexProducerMerge(final Shape shape, final int[] values, final int[] expected) {
|
||||
final IndexProducer indices = IndexProducer.fromIndexArray(values);
|
||||
final BloomFilter filter = createFilter(shape, indices);
|
||||
final List<Integer> lst = new ArrayList<>();
|
||||
filter.forEachIndex(x -> {
|
||||
lst.add(x);
|
||||
return true;
|
||||
});
|
||||
assertEquals(expected.length, lst.size());
|
||||
for (int value : expected) {
|
||||
for (final int value : expected) {
|
||||
assertTrue(lst.contains(Integer.valueOf(value)), "Missing " + value);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertFailedIndexProducerConstructor(Shape shape, int[] values) {
|
||||
IndexProducer indices = IndexProducer.fromIndexArray(values);
|
||||
private void assertFailedIndexProducerConstructor(final Shape shape, final int[] values) {
|
||||
final IndexProducer indices = IndexProducer.fromIndexArray(values);
|
||||
assertThrows(IllegalArgumentException.class, () -> createFilter(shape, indices));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIndexProducerMerge() {
|
||||
Shape shape = Shape.fromKM(5, 10);
|
||||
final Shape shape = Shape.fromKM(5, 10);
|
||||
|
||||
assertIndexProducerMerge(shape, new int[] {0, 2, 4, 6, 8}, new int[] {0, 2, 4, 6, 8});
|
||||
// test duplicate values
|
||||
@ -404,7 +404,7 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
|
||||
|
||||
@Test
|
||||
public void testBitMapProducerSize() {
|
||||
int[] idx = new int[1];
|
||||
final int[] idx = new int[1];
|
||||
createFilter(getTestShape(), from1).forEachBitMap(i -> {
|
||||
idx[0]++;
|
||||
return true;
|
||||
@ -426,17 +426,17 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
|
||||
|
||||
IndexProducer producer;
|
||||
|
||||
BadHasher(int value) {
|
||||
BadHasher(final int value) {
|
||||
this.producer = IndexProducer.fromIndexArray(new int[] {value});
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndexProducer indices(Shape shape) {
|
||||
public IndexProducer indices(final Shape shape) {
|
||||
return producer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndexProducer uniqueIndices(Shape shape) {
|
||||
public IndexProducer uniqueIndices(final Shape shape) {
|
||||
return producer;
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
|
||||
protected final BitCountProducer maximumValueProducer = new BitCountProducer() {
|
||||
|
||||
@Override
|
||||
public boolean forEachCount(BitCountProducer.BitCountConsumer consumer) {
|
||||
public boolean forEachCount(final BitCountProducer.BitCountConsumer consumer) {
|
||||
for (int i = 1; i < 18; i++) {
|
||||
if (!consumer.test(i, Integer.MAX_VALUE)) {
|
||||
return false;
|
||||
@ -103,7 +103,7 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
|
||||
assertTrue(bf2.contains(bf2), "BF2 Should contain itself");
|
||||
assertFalse(bf.contains(bf2), "BF should not contain BF2");
|
||||
assertTrue(bf2.contains(bf), "BF2 should contain BF");
|
||||
BitMapProducer producer = bf2;
|
||||
final BitMapProducer producer = bf2;
|
||||
assertTrue(bf2.contains(producer), "BF2 should contain BF bitMapProducer");
|
||||
}
|
||||
|
||||
@ -135,8 +135,8 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
|
||||
assertTrue(bf5.add(maximumValueProducer), "Should add to empty");
|
||||
assertTrue(bf5.isValid(), "Should be valid");
|
||||
|
||||
CountingBloomFilter bf6 = bf5.copy();
|
||||
BloomFilter bf7 = new SimpleBloomFilter(getTestShape());
|
||||
final CountingBloomFilter bf6 = bf5.copy();
|
||||
final BloomFilter bf7 = new SimpleBloomFilter(getTestShape());
|
||||
bf7.merge(from1);
|
||||
bf6.merge(bf7);
|
||||
assertFalse(bf6.isValid(), "Should not be valid");
|
||||
@ -200,7 +200,7 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
|
||||
*/
|
||||
@Test
|
||||
public final void testRemove() {
|
||||
BloomFilter simple = new SimpleBloomFilter(getTestShape());
|
||||
final BloomFilter simple = new SimpleBloomFilter(getTestShape());
|
||||
simple.merge(from11);
|
||||
|
||||
final CountingBloomFilter bf1 = createFilter(getTestShape(), from1);
|
||||
@ -232,7 +232,7 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
|
||||
assertCounts(bf3, new int[] {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1});
|
||||
|
||||
// with IndexProducer
|
||||
IndexProducer ip = from11.indices(getTestShape());
|
||||
final IndexProducer ip = from11.indices(getTestShape());
|
||||
|
||||
final CountingBloomFilter bf4 = createFilter(getTestShape(), from1);
|
||||
bf4.add(BitCountProducer.from(from11.indices(getTestShape())));
|
||||
@ -255,7 +255,7 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
|
||||
assertCounts(bf5, from1Counts);
|
||||
|
||||
// test producer errors
|
||||
IndexProducer ip2 = IndexProducer.fromIndexArray(1, 2, getTestShape().getNumberOfBits());
|
||||
final IndexProducer ip2 = IndexProducer.fromIndexArray(1, 2, getTestShape().getNumberOfBits());
|
||||
final CountingBloomFilter bf6 = createFilter(getTestShape(), from1);
|
||||
assertThrows(IllegalArgumentException.class, () -> bf6.remove(ip2));
|
||||
|
||||
@ -269,8 +269,8 @@ public abstract class AbstractCountingBloomFilterTest<T extends CountingBloomFil
|
||||
|
||||
// create a hasher that produces duplicates with the specified shape.
|
||||
// this setup produces 5, 17, 29, 41, 53, 65 two times
|
||||
Shape shape = Shape.fromKM(12, 72);
|
||||
Hasher hasher = new IncrementingHasher(5, 12);
|
||||
final Shape shape = Shape.fromKM(12, 72);
|
||||
final Hasher hasher = new IncrementingHasher(5, 12);
|
||||
|
||||
CountingBloomFilter bf1 = createFilter(shape, hasher);
|
||||
assertEquals(6, bf1.cardinality());
|
||||
|
@ -65,9 +65,9 @@ public abstract class AbstractHasherTest extends AbstractIndexProducerTest {
|
||||
"5, 67868",
|
||||
"75, 10"
|
||||
})
|
||||
public void testHashing(int k, int m) {
|
||||
int[] count = {0};
|
||||
Hasher hasher = createHasher();
|
||||
public void testHashing(final int k, final int m) {
|
||||
final int[] count = {0};
|
||||
final Hasher hasher = createHasher();
|
||||
hasher.indices(Shape.fromKM(k, m)).forEachIndex(i -> {
|
||||
assertTrue(i >= 0 && i < m, () -> "Out of range: " + i + ", m=" + m);
|
||||
count[0]++;
|
||||
|
@ -51,7 +51,7 @@ public abstract class AbstractIndexProducerTest {
|
||||
* @param value the value
|
||||
* @return true if the list was modified
|
||||
*/
|
||||
boolean add(int value) {
|
||||
boolean add(final int value) {
|
||||
if (size == data.length) {
|
||||
data = Arrays.copyOf(data, size << 1);
|
||||
}
|
||||
@ -112,9 +112,9 @@ public abstract class AbstractIndexProducerTest {
|
||||
*/
|
||||
@Test
|
||||
public final void testAsIndexArrayValues() {
|
||||
BitSet bs = new BitSet();
|
||||
final BitSet bs = new BitSet();
|
||||
Arrays.stream(createProducer().asIndexArray()).forEach(bs::set);
|
||||
for (int i : getExpectedIndices()) {
|
||||
for (final int i : getExpectedIndices()) {
|
||||
assertTrue(bs.get(i), () -> "Missing " + i);
|
||||
}
|
||||
}
|
||||
@ -124,8 +124,8 @@ public abstract class AbstractIndexProducerTest {
|
||||
*/
|
||||
@Test
|
||||
public final void testForEachIndex() {
|
||||
BitSet bs1 = new BitSet();
|
||||
BitSet bs2 = new BitSet();
|
||||
final BitSet bs1 = new BitSet();
|
||||
final BitSet bs2 = new BitSet();
|
||||
Arrays.stream(getExpectedIndices()).forEach(bs1::set);
|
||||
createProducer().forEachIndex(i -> {
|
||||
bs2.set(i);
|
||||
@ -136,8 +136,8 @@ public abstract class AbstractIndexProducerTest {
|
||||
|
||||
@Test
|
||||
public final void testForEachIndexPredicates() {
|
||||
IndexProducer populated = createProducer();
|
||||
IndexProducer empty = createEmptyProducer();
|
||||
final IndexProducer populated = createProducer();
|
||||
final IndexProducer empty = createEmptyProducer();
|
||||
|
||||
assertFalse(populated.forEachIndex(FALSE_PREDICATE), "non-empty should be false");
|
||||
assertTrue(empty.forEachIndex(FALSE_PREDICATE), "empty should be true");
|
||||
@ -148,8 +148,8 @@ public abstract class AbstractIndexProducerTest {
|
||||
|
||||
@Test
|
||||
public final void testEmptyProducer() {
|
||||
IndexProducer empty = createEmptyProducer();
|
||||
int ary[] = empty.asIndexArray();
|
||||
final IndexProducer empty = createEmptyProducer();
|
||||
final int ary[] = empty.asIndexArray();
|
||||
Assertions.assertEquals(0, ary.length);
|
||||
assertTrue(empty.forEachIndex(i -> {
|
||||
throw new AssertionError("forEach predictate should not be called");
|
||||
@ -161,9 +161,9 @@ public abstract class AbstractIndexProducerTest {
|
||||
*/
|
||||
@Test
|
||||
public final void testConsistency() {
|
||||
IndexProducer producer = createProducer();
|
||||
BitSet bs1 = new BitSet();
|
||||
BitSet bs2 = new BitSet();
|
||||
final IndexProducer producer = createProducer();
|
||||
final BitSet bs1 = new BitSet();
|
||||
final BitSet bs2 = new BitSet();
|
||||
Arrays.stream(producer.asIndexArray()).forEach(bs1::set);
|
||||
producer.forEachIndex(i -> {
|
||||
bs2.set(i);
|
||||
@ -181,19 +181,19 @@ public abstract class AbstractIndexProducerTest {
|
||||
*/
|
||||
@Test
|
||||
public final void testBehaviourAsIndexArray() {
|
||||
int flags = getAsIndexArrayBehaviour();
|
||||
int[] actual = createProducer().asIndexArray();
|
||||
final int flags = getAsIndexArrayBehaviour();
|
||||
final int[] actual = createProducer().asIndexArray();
|
||||
if ((flags & ORDERED) != 0) {
|
||||
int[] expected = Arrays.stream(actual).sorted().toArray();
|
||||
final int[] expected = Arrays.stream(actual).sorted().toArray();
|
||||
Assertions.assertArrayEquals(expected, actual);
|
||||
}
|
||||
if ((flags & DISTINCT) != 0) {
|
||||
long count = Arrays.stream(actual).distinct().count();
|
||||
final long count = Arrays.stream(actual).distinct().count();
|
||||
Assertions.assertEquals(count, actual.length);
|
||||
} else {
|
||||
// if the array is not distinct all expected elements must be generated
|
||||
// This is modified so use a copy
|
||||
int[] expected = getExpectedIndices().clone();
|
||||
final int[] expected = getExpectedIndices().clone();
|
||||
Arrays.sort(expected);
|
||||
Arrays.sort(actual);
|
||||
Assertions.assertArrayEquals(expected, actual);
|
||||
@ -207,20 +207,20 @@ public abstract class AbstractIndexProducerTest {
|
||||
*/
|
||||
@Test
|
||||
public final void testBehaviourForEachIndex() {
|
||||
int flags = getForEachIndexBehaviour();
|
||||
IntList list = new IntList();
|
||||
final int flags = getForEachIndexBehaviour();
|
||||
final IntList list = new IntList();
|
||||
createProducer().forEachIndex(list::add);
|
||||
int[] actual = list.toArray();
|
||||
final int[] actual = list.toArray();
|
||||
if ((flags & ORDERED) != 0) {
|
||||
int[] expected = Arrays.stream(actual).sorted().toArray();
|
||||
final int[] expected = Arrays.stream(actual).sorted().toArray();
|
||||
Assertions.assertArrayEquals(expected, actual);
|
||||
}
|
||||
if ((flags & DISTINCT) != 0) {
|
||||
long count = Arrays.stream(actual).distinct().count();
|
||||
final long count = Arrays.stream(actual).distinct().count();
|
||||
Assertions.assertEquals(count, actual.length);
|
||||
} else {
|
||||
// if forEach is not distinct all expected elements must be generated
|
||||
int[] expected = getExpectedIndices().clone();
|
||||
final int[] expected = getExpectedIndices().clone();
|
||||
Arrays.sort(expected);
|
||||
Arrays.sort(actual);
|
||||
Assertions.assertArrayEquals(expected, actual);
|
||||
@ -229,7 +229,7 @@ public abstract class AbstractIndexProducerTest {
|
||||
|
||||
@Test
|
||||
public void testForEachIndexEarlyExit() {
|
||||
int[] passes = new int[1];
|
||||
final int[] passes = new int[1];
|
||||
assertFalse(createProducer().forEachIndex(i -> {
|
||||
passes[0]++;
|
||||
return false;
|
||||
|
@ -22,7 +22,7 @@ package org.apache.commons.collections4.bloomfilter;
|
||||
public class ArrayCountingBloomFilterTest extends AbstractCountingBloomFilterTest<ArrayCountingBloomFilter> {
|
||||
|
||||
@Override
|
||||
protected ArrayCountingBloomFilter createEmptyFilter(Shape shape) {
|
||||
protected ArrayCountingBloomFilter createEmptyFilter(final Shape shape) {
|
||||
return new ArrayCountingBloomFilter(shape);
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ final class ArrayHasher implements Hasher {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndexProducer uniqueIndices(Shape shape) {
|
||||
public IndexProducer uniqueIndices(final Shape shape) {
|
||||
Objects.requireNonNull(shape, "shape");
|
||||
return new Producer(shape);
|
||||
}
|
||||
@ -46,17 +46,17 @@ final class ArrayHasher implements Hasher {
|
||||
private class Producer implements IndexProducer {
|
||||
Shape shape;
|
||||
|
||||
Producer(Shape shape) {
|
||||
Producer(final Shape shape) {
|
||||
this.shape = shape;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEachIndex(IntPredicate consumer) {
|
||||
public boolean forEachIndex(final IntPredicate consumer) {
|
||||
Objects.requireNonNull(consumer, "consumer");
|
||||
|
||||
int pos = 0;
|
||||
for (int i = 0; i < shape.getNumberOfHashFunctions(); i++) {
|
||||
int result = values[pos++] % shape.getNumberOfBits();
|
||||
final int result = values[pos++] % shape.getNumberOfBits();
|
||||
pos = pos % values.length;
|
||||
if (!consumer.test(result)) {
|
||||
return false;
|
||||
|
@ -31,8 +31,8 @@ public class ArrayTrackerTest {
|
||||
|
||||
@Test
|
||||
public void testSeen() {
|
||||
Shape shape = Shape.fromKM(3, 12);
|
||||
IntPredicate tracker = new IndexFilter.ArrayTracker(shape);
|
||||
final Shape shape = Shape.fromKM(3, 12);
|
||||
final IntPredicate tracker = new IndexFilter.ArrayTracker(shape);
|
||||
|
||||
assertTrue(tracker.test(0));
|
||||
assertFalse(tracker.test(0));
|
||||
|
@ -22,7 +22,7 @@ public class BitCountProducerFromArrayCountingBloomFilterTest extends AbstractBi
|
||||
|
||||
@Override
|
||||
protected BitCountProducer createProducer() {
|
||||
ArrayCountingBloomFilter filter = new ArrayCountingBloomFilter(shape);
|
||||
final ArrayCountingBloomFilter filter = new ArrayCountingBloomFilter(shape);
|
||||
filter.merge(new IncrementingHasher(0, 1));
|
||||
filter.merge(new IncrementingHasher(5, 1));
|
||||
return filter;
|
||||
|
@ -22,8 +22,8 @@ public class BitCountProducerFromSimpleBloomFilterTest extends AbstractBitCountP
|
||||
|
||||
@Override
|
||||
protected BitCountProducer createProducer() {
|
||||
Hasher hasher = new IncrementingHasher(3, 2);
|
||||
BloomFilter bf = new SimpleBloomFilter(shape);
|
||||
final Hasher hasher = new IncrementingHasher(3, 2);
|
||||
final BloomFilter bf = new SimpleBloomFilter(shape);
|
||||
bf.merge(hasher);
|
||||
return BitCountProducer.from(bf);
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ public class BitCountProducerFromSparseBloomFilterTest extends AbstractBitCountP
|
||||
|
||||
@Override
|
||||
protected BitCountProducer createProducer() {
|
||||
Hasher hasher = new IncrementingHasher(4, 7);
|
||||
BloomFilter bf = new SparseBloomFilter(shape);
|
||||
final Hasher hasher = new IncrementingHasher(4, 7);
|
||||
final BloomFilter bf = new SparseBloomFilter(shape);
|
||||
bf.merge(hasher);
|
||||
return BitCountProducer.from(bf);
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ public class BitMapProducerFromArrayCountingBloomFilterTest extends AbstractBitM
|
||||
|
||||
@Override
|
||||
protected BitMapProducer createProducer() {
|
||||
ArrayCountingBloomFilter filter = new ArrayCountingBloomFilter(shape);
|
||||
Hasher hasher = new IncrementingHasher(0, 1);
|
||||
final ArrayCountingBloomFilter filter = new ArrayCountingBloomFilter(shape);
|
||||
final Hasher hasher = new IncrementingHasher(0, 1);
|
||||
filter.merge(hasher);
|
||||
return filter;
|
||||
}
|
||||
|
@ -28,10 +28,10 @@ public class BitMapProducerFromIndexProducerTest extends AbstractBitMapProducerT
|
||||
|
||||
@Override
|
||||
protected BitMapProducer createProducer() {
|
||||
IndexProducer iProducer = new IndexProducer() {
|
||||
final IndexProducer iProducer = new IndexProducer() {
|
||||
|
||||
@Override
|
||||
public boolean forEachIndex(IntPredicate consumer) {
|
||||
public boolean forEachIndex(final IntPredicate consumer) {
|
||||
return consumer.test(0) && consumer.test(1) && consumer.test(63) && consumer.test(64)
|
||||
&& consumer.test(127) && consumer.test(128);
|
||||
}
|
||||
@ -41,10 +41,10 @@ public class BitMapProducerFromIndexProducerTest extends AbstractBitMapProducerT
|
||||
|
||||
@Override
|
||||
protected BitMapProducer createEmptyProducer() {
|
||||
IndexProducer iProducer = new IndexProducer() {
|
||||
final IndexProducer iProducer = new IndexProducer() {
|
||||
|
||||
@Override
|
||||
public boolean forEachIndex(IntPredicate consumer) {
|
||||
public boolean forEachIndex(final IntPredicate consumer) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@ -53,9 +53,9 @@ public class BitMapProducerFromIndexProducerTest extends AbstractBitMapProducerT
|
||||
|
||||
@Test
|
||||
public final void testFromIndexProducer() {
|
||||
List<Long> lst = new ArrayList<>();
|
||||
final List<Long> lst = new ArrayList<>();
|
||||
createProducer().forEachBitMap(lst::add);
|
||||
long[] buckets = lst.stream().mapToLong(l -> l.longValue()).toArray();
|
||||
final long[] buckets = lst.stream().mapToLong(l -> l.longValue()).toArray();
|
||||
assertTrue(BitMap.contains(buckets, 0));
|
||||
assertTrue(BitMap.contains(buckets, 1));
|
||||
assertTrue(BitMap.contains(buckets, 63));
|
||||
|
@ -28,7 +28,7 @@ public class BitMapProducerFromLongArrayTest extends AbstractBitMapProducerTest
|
||||
|
||||
@Override
|
||||
protected BitMapProducer createProducer() {
|
||||
long[] ary = new long[] {1L, 2L, 3L, 4L, 5L};
|
||||
final long[] ary = {1L, 2L, 3L, 4L, 5L};
|
||||
return BitMapProducer.fromBitMapArray(ary);
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ public class BitMapProducerFromLongArrayTest extends AbstractBitMapProducerTest
|
||||
|
||||
@Test
|
||||
public void constructorTest() {
|
||||
List<Long> lst = new ArrayList<>();
|
||||
final List<Long> lst = new ArrayList<>();
|
||||
createProducer().forEachBitMap(lst::add);
|
||||
assertEquals(Long.valueOf(1), lst.get(0));
|
||||
assertEquals(Long.valueOf(2), lst.get(1));
|
||||
@ -55,11 +55,11 @@ public class BitMapProducerFromLongArrayTest extends AbstractBitMapProducerTest
|
||||
|
||||
@Test
|
||||
public void testFromIndexProducer() {
|
||||
int limit = Integer.SIZE + Long.SIZE;
|
||||
IndexProducer iProducer = new IndexProducer() {
|
||||
final int limit = Integer.SIZE + Long.SIZE;
|
||||
final IndexProducer iProducer = new IndexProducer() {
|
||||
|
||||
@Override
|
||||
public boolean forEachIndex(IntPredicate consumer) {
|
||||
public boolean forEachIndex(final IntPredicate consumer) {
|
||||
for (int i = 0; i < limit; i++) {
|
||||
if (!consumer.test(i)) {
|
||||
return false;
|
||||
@ -68,8 +68,8 @@ public class BitMapProducerFromLongArrayTest extends AbstractBitMapProducerTest
|
||||
return true;
|
||||
}
|
||||
};
|
||||
BitMapProducer producer = BitMapProducer.fromIndexProducer(iProducer, limit);
|
||||
List<Long> lst = new ArrayList<>();
|
||||
final BitMapProducer producer = BitMapProducer.fromIndexProducer(iProducer, limit);
|
||||
final List<Long> lst = new ArrayList<>();
|
||||
producer.forEachBitMap(lst::add);
|
||||
long expected = ~0L;
|
||||
assertEquals(expected, lst.get(0).longValue());
|
||||
|
@ -22,8 +22,8 @@ public class BitMapProducerFromSimpleBloomFilterTest extends AbstractBitMapProdu
|
||||
|
||||
@Override
|
||||
protected BitMapProducer createProducer() {
|
||||
Hasher hasher = new IncrementingHasher(0, 1);
|
||||
BloomFilter bf = new SimpleBloomFilter(shape);
|
||||
final Hasher hasher = new IncrementingHasher(0, 1);
|
||||
final BloomFilter bf = new SimpleBloomFilter(shape);
|
||||
bf.merge(hasher);
|
||||
return bf;
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ public class BitMapProducerFromSparseBloomFilterTest extends AbstractBitMapProdu
|
||||
|
||||
@Override
|
||||
protected BitMapProducer createProducer() {
|
||||
Hasher hasher = new IncrementingHasher(0, 1);
|
||||
BloomFilter bf = new SparseBloomFilter(shape);
|
||||
final Hasher hasher = new IncrementingHasher(0, 1);
|
||||
final BloomFilter bf = new SparseBloomFilter(shape);
|
||||
bf.merge(hasher);
|
||||
return bf;
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class BitMapTest {
|
||||
|
||||
@Test
|
||||
public final void testSet() {
|
||||
long[] bitMaps = new long[BitMap.numberOfBitMaps(129)];
|
||||
final long[] bitMaps = new long[BitMap.numberOfBitMaps(129)];
|
||||
for (int i = 0; i < 129; i++) {
|
||||
BitMap.set(bitMaps, i);
|
||||
assertTrue(BitMap.contains(bitMaps, i), String.format("Failed at index: %d", i));
|
||||
@ -69,7 +69,7 @@ public class BitMapTest {
|
||||
|
||||
@Test
|
||||
public final void testContains() {
|
||||
long[] bitMaps = new long[1];
|
||||
final long[] bitMaps = new long[1];
|
||||
|
||||
for (int i = 0; i < 64; i++) {
|
||||
bitMaps[0] = 0L;
|
||||
|
@ -30,8 +30,8 @@ public class BitMapTrackerTest {
|
||||
|
||||
@Test
|
||||
public void testSeen() {
|
||||
Shape shape = Shape.fromKM(3, 12);
|
||||
IntPredicate tracker = new IndexFilter.BitMapTracker(shape);
|
||||
final Shape shape = Shape.fromKM(3, 12);
|
||||
final IntPredicate tracker = new IndexFilter.BitMapTracker(shape);
|
||||
|
||||
assertTrue(tracker.test(0));
|
||||
assertFalse(tracker.test(0));
|
||||
|
@ -19,7 +19,7 @@ package org.apache.commons.collections4.bloomfilter;
|
||||
public class DefaultBitCountProducerTest extends AbstractBitCountProducerTest {
|
||||
|
||||
/** Make forEachIndex unordered and contain duplicates. */
|
||||
private int[] values = {10, 1, 10, 1};
|
||||
private final int[] values = {10, 1, 10, 1};
|
||||
|
||||
@Override
|
||||
protected int[] getExpectedIndices() {
|
||||
@ -30,8 +30,8 @@ public class DefaultBitCountProducerTest extends AbstractBitCountProducerTest {
|
||||
protected BitCountProducer createProducer() {
|
||||
return new BitCountProducer() {
|
||||
@Override
|
||||
public boolean forEachCount(BitCountConsumer consumer) {
|
||||
for (int i : values) {
|
||||
public boolean forEachCount(final BitCountConsumer consumer) {
|
||||
for (final int i : values) {
|
||||
if (!consumer.test(i, 1)) {
|
||||
return false;
|
||||
}
|
||||
@ -45,7 +45,7 @@ public class DefaultBitCountProducerTest extends AbstractBitCountProducerTest {
|
||||
protected BitCountProducer createEmptyProducer() {
|
||||
return new BitCountProducer() {
|
||||
@Override
|
||||
public boolean forEachCount(BitCountConsumer consumer) {
|
||||
public boolean forEachCount(final BitCountConsumer consumer) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
@ -46,13 +46,13 @@ public class DefaultBitMapProducerTest extends AbstractBitMapProducerTest {
|
||||
class DefaultBitMapProducer implements BitMapProducer {
|
||||
long[] bitMaps;
|
||||
|
||||
DefaultBitMapProducer(long[] bitMaps) {
|
||||
DefaultBitMapProducer(final long[] bitMaps) {
|
||||
this.bitMaps = bitMaps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEachBitMap(LongPredicate predicate) {
|
||||
for (long bitmap : bitMaps) {
|
||||
public boolean forEachBitMap(final LongPredicate predicate) {
|
||||
for (final long bitmap : bitMaps) {
|
||||
if (!predicate.test(bitmap)) {
|
||||
return false;
|
||||
}
|
||||
@ -66,25 +66,25 @@ public class DefaultBitMapProducerTest extends AbstractBitMapProducerTest {
|
||||
* @param size the number of values to generate
|
||||
* @return the array of random values.
|
||||
*/
|
||||
public static long[] generateLongArray(int size) {
|
||||
public static long[] generateLongArray(final int size) {
|
||||
return ThreadLocalRandom.current().longs(size).toArray();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromIndexProducer() {
|
||||
int[] expected = DefaultIndexProducerTest.generateIntArray(10, 256);
|
||||
IndexProducer ip = IndexProducer.fromIndexArray(expected);
|
||||
long[] ary = BitMapProducer.fromIndexProducer(ip, 256).asBitMapArray();
|
||||
for (int idx : expected) {
|
||||
final int[] expected = DefaultIndexProducerTest.generateIntArray(10, 256);
|
||||
final IndexProducer ip = IndexProducer.fromIndexArray(expected);
|
||||
final long[] ary = BitMapProducer.fromIndexProducer(ip, 256).asBitMapArray();
|
||||
for (final int idx : expected) {
|
||||
assertTrue(BitMap.contains(ary, idx));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromBitMapArray() {
|
||||
int nOfBitMaps = BitMap.numberOfBitMaps(256);
|
||||
long[] expected = generateLongArray(nOfBitMaps);
|
||||
long[] ary = BitMapProducer.fromBitMapArray(expected).asBitMapArray();
|
||||
final int nOfBitMaps = BitMap.numberOfBitMaps(256);
|
||||
final long[] expected = generateLongArray(nOfBitMaps);
|
||||
final long[] ary = BitMapProducer.fromBitMapArray(expected).asBitMapArray();
|
||||
assertArrayEquals(expected, ary);
|
||||
}
|
||||
}
|
||||
|
@ -36,25 +36,25 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest<DefaultBloom
|
||||
|
||||
@Test
|
||||
public void testDefaultBloomFilterSimpleSpecificMerge() {
|
||||
AbstractDefaultBloomFilter filter = new SparseDefaultBloomFilter(Shape.fromKM(3, 150));
|
||||
Hasher hasher = new IncrementingHasher(0, 1);
|
||||
final AbstractDefaultBloomFilter filter = new SparseDefaultBloomFilter(Shape.fromKM(3, 150));
|
||||
final Hasher hasher = new IncrementingHasher(0, 1);
|
||||
assertTrue(filter.merge(hasher));
|
||||
assertEquals(3, filter.cardinality());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultBloomFilterSparseSpecificMerge() {
|
||||
Shape shape = Shape.fromKM(3, 150);
|
||||
AbstractDefaultBloomFilter filter = new SparseDefaultBloomFilter(shape);
|
||||
AbstractDefaultBloomFilter filter2 = createFilter(shape, new IncrementingHasher(0, 1));
|
||||
BloomFilter newFilter = filter.copy();
|
||||
final Shape shape = Shape.fromKM(3, 150);
|
||||
final AbstractDefaultBloomFilter filter = new SparseDefaultBloomFilter(shape);
|
||||
final AbstractDefaultBloomFilter filter2 = createFilter(shape, new IncrementingHasher(0, 1));
|
||||
final BloomFilter newFilter = filter.copy();
|
||||
newFilter.merge(filter2);
|
||||
assertEquals(3, newFilter.cardinality());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasherBasedMergeWithDifferingSparseness() {
|
||||
Hasher hasher = new IncrementingHasher(1, 1);
|
||||
final Hasher hasher = new IncrementingHasher(1, 1);
|
||||
|
||||
BloomFilter bf1 = new NonSparseDefaultBloomFilter(getTestShape());
|
||||
bf1.merge(hasher);
|
||||
@ -68,10 +68,10 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest<DefaultBloom
|
||||
}
|
||||
|
||||
abstract static class AbstractDefaultBloomFilter implements BloomFilter {
|
||||
private Shape shape;
|
||||
private final Shape shape;
|
||||
protected TreeSet<Integer> indices;
|
||||
|
||||
AbstractDefaultBloomFilter(Shape shape) {
|
||||
AbstractDefaultBloomFilter(final Shape shape) {
|
||||
this.shape = shape;
|
||||
this.indices = new TreeSet<>();
|
||||
}
|
||||
@ -82,8 +82,8 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest<DefaultBloom
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEachIndex(IntPredicate consumer) {
|
||||
for (Integer i : indices) {
|
||||
public boolean forEachIndex(final IntPredicate consumer) {
|
||||
for (final Integer i : indices) {
|
||||
if (!consumer.test(i)) {
|
||||
return false;
|
||||
}
|
||||
@ -92,7 +92,7 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest<DefaultBloom
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEachBitMap(LongPredicate consumer) {
|
||||
public boolean forEachBitMap(final LongPredicate consumer) {
|
||||
return BitMapProducer.fromIndexProducer(this, shape.getNumberOfBits()).forEachBitMap(consumer);
|
||||
}
|
||||
|
||||
@ -102,12 +102,12 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest<DefaultBloom
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IndexProducer indexProducer) {
|
||||
public boolean contains(final IndexProducer indexProducer) {
|
||||
return indexProducer.forEachIndex((i) -> indices.contains(i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(BitMapProducer bitMapProducer) {
|
||||
public boolean contains(final BitMapProducer bitMapProducer) {
|
||||
return contains(IndexProducer.fromBitMapProducer(bitMapProducer));
|
||||
}
|
||||
|
||||
@ -126,8 +126,8 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest<DefaultBloom
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean merge(IndexProducer indexProducer) {
|
||||
boolean result = indexProducer.forEachIndex(x -> {
|
||||
public boolean merge(final IndexProducer indexProducer) {
|
||||
final boolean result = indexProducer.forEachIndex(x -> {
|
||||
indices.add(x);
|
||||
return true;
|
||||
});
|
||||
@ -136,7 +136,7 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest<DefaultBloom
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean merge(BitMapProducer bitMapProducer) {
|
||||
public boolean merge(final BitMapProducer bitMapProducer) {
|
||||
return merge(IndexProducer.fromBitMapProducer(bitMapProducer));
|
||||
}
|
||||
|
||||
@ -148,7 +148,7 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest<DefaultBloom
|
||||
|
||||
static class SparseDefaultBloomFilter extends AbstractDefaultBloomFilter {
|
||||
|
||||
SparseDefaultBloomFilter(Shape shape) {
|
||||
SparseDefaultBloomFilter(final Shape shape) {
|
||||
super(shape);
|
||||
}
|
||||
|
||||
@ -159,7 +159,7 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest<DefaultBloom
|
||||
|
||||
@Override
|
||||
public AbstractDefaultBloomFilter copy() {
|
||||
AbstractDefaultBloomFilter result = new SparseDefaultBloomFilter(getShape());
|
||||
final AbstractDefaultBloomFilter result = new SparseDefaultBloomFilter(getShape());
|
||||
result.indices.addAll(indices);
|
||||
return result;
|
||||
}
|
||||
@ -167,7 +167,7 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest<DefaultBloom
|
||||
|
||||
static class NonSparseDefaultBloomFilter extends AbstractDefaultBloomFilter {
|
||||
|
||||
NonSparseDefaultBloomFilter(Shape shape) {
|
||||
NonSparseDefaultBloomFilter(final Shape shape) {
|
||||
super(shape);
|
||||
}
|
||||
|
||||
@ -178,7 +178,7 @@ public class DefaultBloomFilterTest extends AbstractBloomFilterTest<DefaultBloom
|
||||
|
||||
@Override
|
||||
public AbstractDefaultBloomFilter copy() {
|
||||
AbstractDefaultBloomFilter result = new SparseDefaultBloomFilter(getShape());
|
||||
final AbstractDefaultBloomFilter result = new SparseDefaultBloomFilter(getShape());
|
||||
result.indices.addAll(indices);
|
||||
return result;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import org.junit.jupiter.api.Test;
|
||||
public class DefaultIndexProducerTest extends AbstractIndexProducerTest {
|
||||
|
||||
/** Make forEachIndex unordered and contain duplicates. */
|
||||
private int[] values = {10, 1, 10, 1};
|
||||
private final int[] values = {10, 1, 10, 1};
|
||||
|
||||
@Override
|
||||
protected int[] getExpectedIndices() {
|
||||
@ -40,9 +40,9 @@ public class DefaultIndexProducerTest extends AbstractIndexProducerTest {
|
||||
protected IndexProducer createProducer() {
|
||||
return new IndexProducer() {
|
||||
@Override
|
||||
public boolean forEachIndex(IntPredicate predicate) {
|
||||
public boolean forEachIndex(final IntPredicate predicate) {
|
||||
Objects.requireNonNull(predicate);
|
||||
for (int i : values) {
|
||||
for (final int i : values) {
|
||||
if (!predicate.test(i)) {
|
||||
return false;
|
||||
}
|
||||
@ -56,7 +56,7 @@ public class DefaultIndexProducerTest extends AbstractIndexProducerTest {
|
||||
protected IndexProducer createEmptyProducer() {
|
||||
return new IndexProducer() {
|
||||
@Override
|
||||
public boolean forEachIndex(IntPredicate predicate) {
|
||||
public boolean forEachIndex(final IntPredicate predicate) {
|
||||
Objects.requireNonNull(predicate);
|
||||
return true;
|
||||
}
|
||||
@ -81,7 +81,7 @@ public class DefaultIndexProducerTest extends AbstractIndexProducerTest {
|
||||
* @param bound the upper bound (exclusive) of the values in the array.
|
||||
* @return an array of int.
|
||||
*/
|
||||
public static int[] generateIntArray(int size, int bound) {
|
||||
public static int[] generateIntArray(final int size, final int bound) {
|
||||
return ThreadLocalRandom.current().ints(size, 0, bound).toArray();
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ public class DefaultIndexProducerTest extends AbstractIndexProducerTest {
|
||||
* @param ary the array
|
||||
* @return the set.
|
||||
*/
|
||||
public static BitSet uniqueSet(int[] ary) {
|
||||
public static BitSet uniqueSet(final int[] ary) {
|
||||
final BitSet bs = new BitSet();
|
||||
Arrays.stream(ary).forEach(bs::set);
|
||||
return bs;
|
||||
@ -101,19 +101,19 @@ public class DefaultIndexProducerTest extends AbstractIndexProducerTest {
|
||||
* @param ary the array to sort and make unique
|
||||
* @return the sorted unique array.
|
||||
*/
|
||||
public static int[] unique(int[] ary) {
|
||||
public static int[] unique(final int[] ary) {
|
||||
return Arrays.stream(ary).distinct().sorted().toArray();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromBitMapProducer() {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
int[] expected = generateIntArray(7, 256);
|
||||
long[] bits = new long[BitMap.numberOfBitMaps(256)];
|
||||
for (int bitIndex : expected) {
|
||||
final int[] expected = generateIntArray(7, 256);
|
||||
final long[] bits = new long[BitMap.numberOfBitMaps(256)];
|
||||
for (final int bitIndex : expected) {
|
||||
BitMap.set(bits, bitIndex);
|
||||
}
|
||||
IndexProducer ip = IndexProducer.fromBitMapProducer(BitMapProducer.fromBitMapArray(bits));
|
||||
final IndexProducer ip = IndexProducer.fromBitMapProducer(BitMapProducer.fromBitMapArray(bits));
|
||||
assertArrayEquals(unique(expected), ip.asIndexArray());
|
||||
}
|
||||
}
|
||||
@ -121,8 +121,8 @@ public class DefaultIndexProducerTest extends AbstractIndexProducerTest {
|
||||
@Test
|
||||
public void testFromIndexArray() {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
int[] expected = generateIntArray(10, 256);
|
||||
IndexProducer ip = IndexProducer.fromIndexArray(expected);
|
||||
final int[] expected = generateIntArray(10, 256);
|
||||
final IndexProducer ip = IndexProducer.fromIndexArray(expected);
|
||||
assertArrayEquals(expected, ip.asIndexArray());
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public class EnhancedDoubleHasherTest extends AbstractHasherTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getHasherSize(Hasher hasher) {
|
||||
protected int getHasherSize(final Hasher hasher) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -95,9 +95,9 @@ public class EnhancedDoubleHasherTest extends AbstractHasherTest {
|
||||
|
||||
@Test
|
||||
void testModEdgeCases() {
|
||||
for (long dividend : new long[] {-1, -2, -3, -6378683, -23567468136887892L, Long.MIN_VALUE, 345, 678686,
|
||||
for (final long dividend : new long[] {-1, -2, -3, -6378683, -23567468136887892L, Long.MIN_VALUE, 345, 678686,
|
||||
67868768686878924L, Long.MAX_VALUE}) {
|
||||
for (int divisor : new int[] {1, 2, 3, 5, 13, Integer.MAX_VALUE}) {
|
||||
for (final int divisor : new int[] {1, 2, 3, 5, 13, Integer.MAX_VALUE}) {
|
||||
assertEquals((int) Long.remainderUnsigned(dividend, divisor), EnhancedDoubleHasher.mod(dividend, divisor),
|
||||
() -> String.format("failure with dividend=%s and divisor=%s.", dividend, divisor));
|
||||
}
|
||||
|
@ -53,13 +53,13 @@ public class HasherCollectionTest extends AbstractHasherTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getHasherSize(Hasher hasher) {
|
||||
protected int getHasherSize(final Hasher hasher) {
|
||||
return ((HasherCollection) hasher).getHashers().size();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdd() {
|
||||
HasherCollection hasher = createHasher();
|
||||
final HasherCollection hasher = createHasher();
|
||||
hasher.add(new IncrementingHasher(2, 2));
|
||||
assertEquals(3, hasher.getHashers().size());
|
||||
|
||||
@ -69,15 +69,15 @@ public class HasherCollectionTest extends AbstractHasherTest {
|
||||
|
||||
@Test
|
||||
void testHasherCollection() {
|
||||
Hasher h1 = new IncrementingHasher(13, 4678);
|
||||
Hasher h2 = new IncrementingHasher(42, 987);
|
||||
Hasher h3 = new IncrementingHasher(454, 2342);
|
||||
final Hasher h1 = new IncrementingHasher(13, 4678);
|
||||
final Hasher h2 = new IncrementingHasher(42, 987);
|
||||
final Hasher h3 = new IncrementingHasher(454, 2342);
|
||||
|
||||
HasherCollection hc1 = new HasherCollection(Arrays.asList(h1, h1));
|
||||
HasherCollection hc2 = new HasherCollection(Arrays.asList(h2, h3));
|
||||
HasherCollection hc3 = new HasherCollection(Arrays.asList(hc1, hc2));
|
||||
final HasherCollection hc1 = new HasherCollection(Arrays.asList(h1, h1));
|
||||
final HasherCollection hc2 = new HasherCollection(Arrays.asList(h2, h3));
|
||||
final HasherCollection hc3 = new HasherCollection(Arrays.asList(hc1, hc2));
|
||||
|
||||
ArrayCountingBloomFilter bf = new ArrayCountingBloomFilter(Shape.fromKM(5, 10000));
|
||||
final ArrayCountingBloomFilter bf = new ArrayCountingBloomFilter(Shape.fromKM(5, 10000));
|
||||
|
||||
// Should add h1, h1, h2, h3
|
||||
Assertions.assertTrue(bf.merge(hc3));
|
||||
@ -90,11 +90,11 @@ public class HasherCollectionTest extends AbstractHasherTest {
|
||||
|
||||
@Test
|
||||
public void testAbsoluteUniqueIndices() {
|
||||
int[] actual = new HasherCollection(
|
||||
final int[] actual = new HasherCollection(
|
||||
new IncrementingHasher(1, 1),
|
||||
new IncrementingHasher(10, 1)
|
||||
).absoluteUniqueIndices(Shape.fromKM(5, 1000)).asIndexArray();
|
||||
int[] expected = IntStream.concat(
|
||||
final int[] expected = IntStream.concat(
|
||||
IntStream.range(1, 1 + 5),
|
||||
IntStream.range(10, 10 + 5)
|
||||
).toArray();
|
||||
|
@ -46,7 +46,7 @@ final class IncrementingHasher implements Hasher {
|
||||
* @param initial The initial value for the hasher.
|
||||
* @param increment The value to increment the hash by on each iteration.
|
||||
*/
|
||||
IncrementingHasher(long initial, long increment) {
|
||||
IncrementingHasher(final long initial, final long increment) {
|
||||
this.initial = initial;
|
||||
this.increment = increment;
|
||||
}
|
||||
@ -58,9 +58,9 @@ final class IncrementingHasher implements Hasher {
|
||||
return new IndexProducer() {
|
||||
|
||||
@Override
|
||||
public boolean forEachIndex(IntPredicate consumer) {
|
||||
public boolean forEachIndex(final IntPredicate consumer) {
|
||||
Objects.requireNonNull(consumer, "consumer");
|
||||
int bits = shape.getNumberOfBits();
|
||||
final int bits = shape.getNumberOfBits();
|
||||
|
||||
// Essentially this is computing a wrapped modulus from a start point and an
|
||||
// increment. So actually you only need two modulus operations before the loop.
|
||||
@ -68,7 +68,7 @@ final class IncrementingHasher implements Hasher {
|
||||
// to avoid overflow.
|
||||
|
||||
long index = EnhancedDoubleHasher.mod(initial, bits);
|
||||
int inc = EnhancedDoubleHasher.mod(increment, bits);
|
||||
final int inc = EnhancedDoubleHasher.mod(increment, bits);
|
||||
|
||||
for (int functionalCount = 0; functionalCount < shape.getNumberOfHashFunctions(); functionalCount++) {
|
||||
if (!consumer.test((int) index)) {
|
||||
@ -82,8 +82,8 @@ final class IncrementingHasher implements Hasher {
|
||||
|
||||
@Override
|
||||
public int[] asIndexArray() {
|
||||
int[] result = new int[shape.getNumberOfHashFunctions()];
|
||||
int[] idx = new int[1];
|
||||
final int[] result = new int[shape.getNumberOfHashFunctions()];
|
||||
final int[] idx = new int[1];
|
||||
|
||||
// This method needs to return duplicate indices
|
||||
|
||||
|
@ -39,9 +39,9 @@ public class IndexFilterTest {
|
||||
|
||||
@Test
|
||||
public void testFiltering() {
|
||||
Shape shape = Shape.fromKM(3, 12);
|
||||
List<Integer> consumer = new ArrayList<Integer>();
|
||||
IntPredicate filter = IndexFilter.create(shape, consumer::add);
|
||||
final Shape shape = Shape.fromKM(3, 12);
|
||||
final List<Integer> consumer = new ArrayList<>();
|
||||
final IntPredicate filter = IndexFilter.create(shape, consumer::add);
|
||||
|
||||
for (int i = 0; i < 12; i++) {
|
||||
assertTrue(filter.test(i));
|
||||
@ -62,21 +62,21 @@ public class IndexFilterTest {
|
||||
"7, 357",
|
||||
"7, 17",
|
||||
})
|
||||
void testFilter(int k, int m) {
|
||||
Shape shape = Shape.fromKM(k, m);
|
||||
BitSet used = new BitSet(m);
|
||||
void testFilter(final int k, final int m) {
|
||||
final Shape shape = Shape.fromKM(k, m);
|
||||
final BitSet used = new BitSet(m);
|
||||
for (int n = 0; n < 10; n++) {
|
||||
used.clear();
|
||||
List<Integer> consumer = new ArrayList<>();
|
||||
IntPredicate filter = IndexFilter.create(shape, consumer::add);
|
||||
final List<Integer> consumer = new ArrayList<>();
|
||||
final IntPredicate filter = IndexFilter.create(shape, consumer::add);
|
||||
|
||||
// Make random indices; these may be duplicates
|
||||
long seed = ThreadLocalRandom.current().nextLong();
|
||||
SplittableRandom rng = new SplittableRandom(seed);
|
||||
final long seed = ThreadLocalRandom.current().nextLong();
|
||||
final SplittableRandom rng = new SplittableRandom(seed);
|
||||
for (int i = Math.min(k, m / 2); i-- > 0;) {
|
||||
int bit = rng.nextInt(m);
|
||||
final int bit = rng.nextInt(m);
|
||||
// duplicates should not alter the list size
|
||||
int newSize = consumer.size() + (used.get(bit) ? 0 : 1);
|
||||
final int newSize = consumer.size() + (used.get(bit) ? 0 : 1);
|
||||
assertTrue(filter.test(bit));
|
||||
assertEquals(newSize, consumer.size(), () -> String.format("Bad filter. Seed=%d, bit=%d", seed, bit));
|
||||
used.set(bit);
|
||||
|
@ -28,7 +28,7 @@ public class IndexProducerFromBitmapProducerTest extends AbstractIndexProducerTe
|
||||
|
||||
@Override
|
||||
protected IndexProducer createEmptyProducer() {
|
||||
TestingBitMapProducer producer = new TestingBitMapProducer(new long[0]);
|
||||
final TestingBitMapProducer producer = new TestingBitMapProducer(new long[0]);
|
||||
return IndexProducer.fromBitMapProducer(producer);
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ public class IndexProducerFromBitmapProducerTest extends AbstractIndexProducerTe
|
||||
3L => ...0011
|
||||
@formatter:on
|
||||
*/
|
||||
TestingBitMapProducer producer = new TestingBitMapProducer(new long[] {1L, 2L, 3L});
|
||||
final TestingBitMapProducer producer = new TestingBitMapProducer(new long[] {1L, 2L, 3L});
|
||||
return IndexProducer.fromBitMapProducer(producer);
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ public class IndexProducerFromBitmapProducerTest extends AbstractIndexProducerTe
|
||||
assertEquals(Integer.valueOf(0 + 128), lst.get(2));
|
||||
assertEquals(Integer.valueOf(1 + 128), lst.get(3));
|
||||
|
||||
BitMapProducer producer = new TestingBitMapProducer(new long[] {0xFFFFFFFFFFFFFFFFL});
|
||||
final BitMapProducer producer = new TestingBitMapProducer(new long[] {0xFFFFFFFFFFFFFFFFL});
|
||||
underTest = IndexProducer.fromBitMapProducer(producer);
|
||||
lst = new ArrayList<>();
|
||||
|
||||
@ -87,13 +87,13 @@ public class IndexProducerFromBitmapProducerTest extends AbstractIndexProducerTe
|
||||
private class TestingBitMapProducer implements BitMapProducer {
|
||||
long[] values;
|
||||
|
||||
TestingBitMapProducer(long[] values) {
|
||||
TestingBitMapProducer(final long[] values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEachBitMap(LongPredicate consumer) {
|
||||
for (long l : values) {
|
||||
public boolean forEachBitMap(final LongPredicate consumer) {
|
||||
for (final long l : values) {
|
||||
if (!consumer.test(l)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -54,13 +54,13 @@ public class IndexProducerTest {
|
||||
private class TestingBitMapProducer implements BitMapProducer {
|
||||
long[] values;
|
||||
|
||||
TestingBitMapProducer(long[] values) {
|
||||
TestingBitMapProducer(final long[] values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEachBitMap(LongPredicate consumer) {
|
||||
for (long l : values) {
|
||||
public boolean forEachBitMap(final LongPredicate consumer) {
|
||||
for (final long l : values) {
|
||||
if (!consumer.test(l)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ final class NullHasher implements Hasher {
|
||||
|
||||
private static final IndexProducer PRODUCER = new IndexProducer() {
|
||||
@Override
|
||||
public boolean forEachIndex(IntPredicate consumer) {
|
||||
public boolean forEachIndex(final IntPredicate consumer) {
|
||||
Objects.requireNonNull(consumer, "consumer");
|
||||
return true;
|
||||
}
|
||||
@ -55,7 +55,7 @@ final class NullHasher implements Hasher {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IndexProducer uniqueIndices(Shape shape) {
|
||||
public IndexProducer uniqueIndices(final Shape shape) {
|
||||
Objects.requireNonNull(shape, "shape");
|
||||
return PRODUCER;
|
||||
}
|
||||
|
@ -36,26 +36,26 @@ public class SetOperationsTest {
|
||||
protected final long bigHashValue = 0xFFFFFFEL;
|
||||
private final Shape shape = Shape.fromKM(17, 72);
|
||||
|
||||
private static void assertSymmetricOperation(int expected, ToIntBiFunction<BloomFilter, BloomFilter> operation,
|
||||
BloomFilter filter1, BloomFilter filter2) {
|
||||
private static void assertSymmetricOperation(final int expected, final ToIntBiFunction<BloomFilter, BloomFilter> operation,
|
||||
final BloomFilter filter1, final BloomFilter filter2) {
|
||||
assertEquals(expected, operation.applyAsInt(filter1, filter2), "op(filter1, filter2)");
|
||||
assertEquals(expected, operation.applyAsInt(filter2, filter1), "op(filter2, filter1)");
|
||||
}
|
||||
|
||||
private static void assertSymmetricOperation(double expected, ToDoubleBiFunction<BloomFilter, BloomFilter> operation,
|
||||
BloomFilter filter1, BloomFilter filter2) {
|
||||
private static void assertSymmetricOperation(final double expected, final ToDoubleBiFunction<BloomFilter, BloomFilter> operation,
|
||||
final BloomFilter filter1, final BloomFilter filter2) {
|
||||
assertEquals(expected, operation.applyAsDouble(filter1, filter2), "op(filter1, filter2)");
|
||||
assertEquals(expected, operation.applyAsDouble(filter2, filter1), "op(filter2, filter1)");
|
||||
}
|
||||
|
||||
private BloomFilter createFilter(Shape shape, Hasher hasher) {
|
||||
BloomFilter bf = new SimpleBloomFilter(shape);
|
||||
private BloomFilter createFilter(final Shape shape, final Hasher hasher) {
|
||||
final BloomFilter bf = new SimpleBloomFilter(shape);
|
||||
bf.merge(hasher);
|
||||
return bf;
|
||||
}
|
||||
|
||||
private BloomFilter createFilter(Shape shape, IndexProducer producer) {
|
||||
BloomFilter bf = new SparseBloomFilter(shape);
|
||||
private BloomFilter createFilter(final Shape shape, final IndexProducer producer) {
|
||||
final BloomFilter bf = new SparseBloomFilter(shape);
|
||||
bf.merge(producer);
|
||||
return bf;
|
||||
}
|
||||
@ -73,7 +73,7 @@ public class SetOperationsTest {
|
||||
double expected = 0;
|
||||
assertSymmetricOperation(expected, SetOperations::cosineDistance, filter1, filter2);
|
||||
|
||||
Shape shape2 = Shape.fromKM(2, 72);
|
||||
final Shape shape2 = Shape.fromKM(2, 72);
|
||||
filter1 = createFilter(shape2, from1);
|
||||
filter2 = createFilter(shape2, new IncrementingHasher(2, 1));
|
||||
|
||||
@ -133,7 +133,7 @@ public class SetOperationsTest {
|
||||
filter1 = new SimpleBloomFilter(shape);
|
||||
filter2 = new SimpleBloomFilter(shape);
|
||||
// build a filter
|
||||
BloomFilter filter3 = createFilter(shape, from1);
|
||||
final BloomFilter filter3 = createFilter(shape, from1);
|
||||
assertSymmetricOperation(0.0, SetOperations::cosineSimilarity, filter1, filter2);
|
||||
assertSymmetricOperation(0.0, SetOperations::cosineSimilarity, filter1, filter3);
|
||||
}
|
||||
@ -166,15 +166,15 @@ public class SetOperationsTest {
|
||||
assertSymmetricOperation(0.0, SetOperations::jaccardDistance, filter1, filter2);
|
||||
|
||||
filter2 = createFilter(shape, from11);
|
||||
double intersection = /* [1..17] & [11..27] = [11..17] = */ 7.0;
|
||||
int union = /* [1..17] | [11..27] = [1..27] = */ 27;
|
||||
double expected = 1 - (intersection / union);
|
||||
final double intersection = /* [1..17] & [11..27] = [11..17] = */ 7.0;
|
||||
final int union = /* [1..17] | [11..27] = [1..27] = */ 27;
|
||||
final double expected = 1 - (intersection / union);
|
||||
assertSymmetricOperation(expected, SetOperations::jaccardDistance, filter1, filter2);
|
||||
|
||||
// test no values
|
||||
filter1 = new SimpleBloomFilter(shape);
|
||||
filter2 = new SimpleBloomFilter(shape);
|
||||
BloomFilter filter3 = createFilter(shape, from1);
|
||||
final BloomFilter filter3 = createFilter(shape, from1);
|
||||
|
||||
// 1 - jaccardSimilarity -- see jaccardSimilarityTest
|
||||
assertSymmetricOperation(1.0, SetOperations::jaccardDistance, filter1, filter2);
|
||||
@ -213,7 +213,7 @@ public class SetOperationsTest {
|
||||
|
||||
@Test
|
||||
public final void testOrCardinality() {
|
||||
Shape shape = Shape.fromKM(3, 128);
|
||||
final Shape shape = Shape.fromKM(3, 128);
|
||||
BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63, 64}));
|
||||
BloomFilter filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69}));
|
||||
assertSymmetricOperation(5, SetOperations::orCardinality, filter1, filter2);
|
||||
@ -229,8 +229,8 @@ public class SetOperationsTest {
|
||||
|
||||
@Test
|
||||
public final void testOrCardinalityWithDifferentLengthFilters() {
|
||||
Shape shape = Shape.fromKM(3, 128);
|
||||
Shape shape2 = Shape.fromKM(3, 192);
|
||||
final Shape shape = Shape.fromKM(3, 128);
|
||||
final Shape shape2 = Shape.fromKM(3, 192);
|
||||
BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63, 64}));
|
||||
BloomFilter filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169}));
|
||||
assertSymmetricOperation(5, SetOperations::orCardinality, filter1, filter2);
|
||||
@ -246,7 +246,7 @@ public class SetOperationsTest {
|
||||
|
||||
@Test
|
||||
public final void testAndCardinality() {
|
||||
Shape shape = Shape.fromKM(3, 128);
|
||||
final Shape shape = Shape.fromKM(3, 128);
|
||||
BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63, 64}));
|
||||
BloomFilter filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69}));
|
||||
assertSymmetricOperation(1, SetOperations::andCardinality, filter1, filter2);
|
||||
@ -262,8 +262,8 @@ public class SetOperationsTest {
|
||||
|
||||
@Test
|
||||
public final void testAndCardinalityWithDifferentLengthFilters() {
|
||||
Shape shape = Shape.fromKM(3, 128);
|
||||
Shape shape2 = Shape.fromKM(3, 192);
|
||||
final Shape shape = Shape.fromKM(3, 128);
|
||||
final Shape shape2 = Shape.fromKM(3, 192);
|
||||
BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63, 64}));
|
||||
BloomFilter filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169}));
|
||||
assertSymmetricOperation(1, SetOperations::andCardinality, filter1, filter2);
|
||||
@ -279,7 +279,7 @@ public class SetOperationsTest {
|
||||
|
||||
@Test
|
||||
public final void testXorCardinality() {
|
||||
Shape shape = Shape.fromKM(3, 128);
|
||||
final Shape shape = Shape.fromKM(3, 128);
|
||||
BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63, 64}));
|
||||
BloomFilter filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69}));
|
||||
assertSymmetricOperation(4, SetOperations::xorCardinality, filter1, filter2);
|
||||
@ -292,7 +292,7 @@ public class SetOperationsTest {
|
||||
filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 64, 69}));
|
||||
assertSymmetricOperation(3, SetOperations::xorCardinality, filter1, filter2);
|
||||
|
||||
Shape bigShape = Shape.fromKM(3, 192);
|
||||
final Shape bigShape = Shape.fromKM(3, 192);
|
||||
filter1 = createFilter(bigShape, IndexProducer.fromIndexArray(new int[] {1, 63, 185}));
|
||||
filter2 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {5, 63, 69}));
|
||||
assertSymmetricOperation(4, SetOperations::xorCardinality, filter1, filter2);
|
||||
@ -300,8 +300,8 @@ public class SetOperationsTest {
|
||||
|
||||
@Test
|
||||
public final void testXorCardinalityWithDifferentLengthFilters() {
|
||||
Shape shape = Shape.fromKM(3, 128);
|
||||
Shape shape2 = Shape.fromKM(3, 192);
|
||||
final Shape shape = Shape.fromKM(3, 128);
|
||||
final Shape shape2 = Shape.fromKM(3, 192);
|
||||
|
||||
BloomFilter filter1 = createFilter(shape, IndexProducer.fromIndexArray(new int[] {1, 63, 64}));
|
||||
BloomFilter filter2 = createFilter(shape2, IndexProducer.fromIndexArray(new int[] {5, 64, 169}));
|
||||
@ -318,8 +318,8 @@ public class SetOperationsTest {
|
||||
|
||||
@Test
|
||||
public final void testCommutativityOnMismatchedSizes() {
|
||||
BitMapProducer p1 = BitMapProducer.fromBitMapArray(new long[] {0x3L, 0x5L});
|
||||
BitMapProducer p2 = BitMapProducer.fromBitMapArray(new long[] {0x1L});
|
||||
final BitMapProducer p1 = BitMapProducer.fromBitMapArray(new long[] {0x3L, 0x5L});
|
||||
final BitMapProducer p2 = BitMapProducer.fromBitMapArray(new long[] {0x1L});
|
||||
|
||||
assertEquals(SetOperations.orCardinality(p1, p2), SetOperations.orCardinality(p2, p1));
|
||||
assertEquals(SetOperations.xorCardinality(p1, p2), SetOperations.xorCardinality(p2, p1));
|
||||
|
@ -58,8 +58,8 @@ public class ShapeTest {
|
||||
"13, 124",
|
||||
"13, 224",
|
||||
})
|
||||
public void testEqualsAndHashCode(int k, int m) {
|
||||
Shape shape1 = Shape.fromKM(k, m);
|
||||
public void testEqualsAndHashCode(final int k, final int m) {
|
||||
final Shape shape1 = Shape.fromKM(k, m);
|
||||
assertEquals(shape1, shape1);
|
||||
assertEquals(Arrays.hashCode(new int[] {m, k}), shape1.hashCode(),
|
||||
"Doesn't match Arrays.hashCode(new int[] {m, k})");
|
||||
@ -70,7 +70,7 @@ public class ShapeTest {
|
||||
assertNotEquals(shape1, Shape.fromKM(k + 1, m));
|
||||
|
||||
// Test this is reproducible
|
||||
Shape shape2 = Shape.fromKM(k, m);
|
||||
final Shape shape2 = Shape.fromKM(k, m);
|
||||
assertEquals(shape1, shape2);
|
||||
assertEquals(shape1.hashCode(), shape2.hashCode());
|
||||
}
|
||||
@ -78,8 +78,8 @@ public class ShapeTest {
|
||||
@Test
|
||||
public void testEstimateN() {
|
||||
for (int i = 0; i < 24; i++) {
|
||||
double c = i;
|
||||
double expected = -(24.0 / 3.0) * Math.log1p(-c / 24.0);
|
||||
final double c = i;
|
||||
final double expected = -(24.0 / 3.0) * Math.log1p(-c / 24.0);
|
||||
assertEquals(expected, shape.estimateN(i), "Error on " + i);
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ public class ShapeTest {
|
||||
@Test
|
||||
public void testGetProbability() {
|
||||
for (int i = 0; i <= 24; i++) {
|
||||
double expected = Math.pow(-Math.expm1(-3.0 * i / 24), 3);
|
||||
final double expected = Math.pow(-Math.expm1(-3.0 * i / 24), 3);
|
||||
assertEquals(expected, shape.getProbability(i), "error at " + i);
|
||||
}
|
||||
|
||||
@ -102,10 +102,10 @@ public class ShapeTest {
|
||||
|
||||
@Test
|
||||
public void testIsSparse() {
|
||||
int functions = 1; // Ignored
|
||||
final int functions = 1; // Ignored
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
int bits = i * Long.SIZE;
|
||||
Shape shape = Shape.fromKM(functions, bits);
|
||||
final int bits = i * Long.SIZE;
|
||||
final Shape shape = Shape.fromKM(functions, bits);
|
||||
for (int n = 0; n <= bits; n++) {
|
||||
final int c = n;
|
||||
// is sparse when number of bits stored as integers is less than 2 times the
|
||||
@ -187,7 +187,7 @@ public class ShapeTest {
|
||||
/*
|
||||
* values from https://hur.st/bloomfilter/?n=5&m=24&k=4
|
||||
*/
|
||||
Shape shape = Shape.fromNMK(5, 24, 4);
|
||||
final Shape shape = Shape.fromNMK(5, 24, 4);
|
||||
|
||||
assertEquals(24, shape.getNumberOfBits());
|
||||
assertEquals(4, shape.getNumberOfHashFunctions());
|
||||
@ -217,7 +217,7 @@ public class ShapeTest {
|
||||
/*
|
||||
* values from https://hur.st/bloomfilter/?n=5&m=24
|
||||
*/
|
||||
Shape shape = Shape.fromNM(5, 24);
|
||||
final Shape shape = Shape.fromNM(5, 24);
|
||||
|
||||
assertEquals(24, shape.getNumberOfBits());
|
||||
assertEquals(3, shape.getNumberOfHashFunctions());
|
||||
@ -232,7 +232,7 @@ public class ShapeTest {
|
||||
*/
|
||||
@Test
|
||||
public void testProbability() {
|
||||
Shape shape = Shape.fromNMK(5, 24, 3);
|
||||
final Shape shape = Shape.fromNMK(5, 24, 3);
|
||||
assertEquals(24, shape.getNumberOfBits());
|
||||
assertEquals(3, shape.getNumberOfHashFunctions());
|
||||
assertEquals(0.100375138, shape.getProbability(5), 0.000001);
|
||||
@ -273,7 +273,7 @@ public class ShapeTest {
|
||||
* values from https://hur.st/bloomfilter/?n=5&p=.1&m=24&k=3
|
||||
*/
|
||||
final double probability = 1.0 / 2000000;
|
||||
Shape shape = Shape.fromNP(10, probability);
|
||||
final Shape shape = Shape.fromNP(10, probability);
|
||||
|
||||
assertEquals(302, shape.getNumberOfBits());
|
||||
assertEquals(21, shape.getNumberOfHashFunctions());
|
||||
|
@ -37,7 +37,7 @@ public class SparseBloomFilterTest extends AbstractBloomFilterTest<SparseBloomFi
|
||||
BloomFilter bf = createFilter(getTestShape(), IndexProducer.fromIndexArray(values));
|
||||
|
||||
// verify exit early before bitmap boundary
|
||||
int[] passes = new int[1];
|
||||
final int[] passes = new int[1];
|
||||
assertFalse(bf.forEachBitMap(l -> {
|
||||
passes[0]++;
|
||||
return false;
|
||||
@ -48,7 +48,7 @@ public class SparseBloomFilterTest extends AbstractBloomFilterTest<SparseBloomFi
|
||||
bf = createFilter(getTestShape(), IndexProducer.fromIndexArray(values));
|
||||
passes[0] = 0;
|
||||
assertFalse(bf.forEachBitMap(l -> {
|
||||
boolean result = passes[0] == 0;
|
||||
final boolean result = passes[0] == 0;
|
||||
if (result) {
|
||||
passes[0]++;
|
||||
}
|
||||
@ -72,7 +72,7 @@ public class SparseBloomFilterTest extends AbstractBloomFilterTest<SparseBloomFi
|
||||
bf = createFilter(getTestShape(), IndexProducer.fromIndexArray(values));
|
||||
passes[0] = 0;
|
||||
assertFalse(bf.forEachBitMap(l -> {
|
||||
boolean result = passes[0] == 0;
|
||||
final boolean result = passes[0] == 0;
|
||||
if (result) {
|
||||
passes[0]++;
|
||||
}
|
||||
@ -83,8 +83,8 @@ public class SparseBloomFilterTest extends AbstractBloomFilterTest<SparseBloomFi
|
||||
|
||||
@Test
|
||||
public void testBloomFilterBasedMergeEdgeCases() {
|
||||
BloomFilter bf1 = createEmptyFilter(getTestShape());
|
||||
BloomFilter bf2 = new SimpleBloomFilter(getTestShape());
|
||||
final BloomFilter bf1 = createEmptyFilter(getTestShape());
|
||||
final BloomFilter bf2 = new SimpleBloomFilter(getTestShape());
|
||||
bf2.merge(from1);
|
||||
bf1.merge(bf2);
|
||||
assertTrue(bf2.forEachBitMapPair(bf1, (x, y) -> x == y));
|
||||
|
@ -754,7 +754,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
||||
resetEmpty();
|
||||
Iterator<E> it1 = getCollection().iterator();
|
||||
assertFalse("Iterator for empty Collection shouldn't have next.", it1.hasNext());
|
||||
Iterator<E> finalIt1 = it1;
|
||||
final Iterator<E> finalIt1 = it1;
|
||||
assertThrows(NoSuchElementException.class, () -> finalIt1.next(),
|
||||
"Iterator at end of Collection should throw NoSuchElementException when next is called.");
|
||||
// make sure nothing has changed after non-modification
|
||||
@ -776,7 +776,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
||||
getCollection().contains(next));
|
||||
list.add(next);
|
||||
}
|
||||
Iterator<E> finalIt2 = it1;
|
||||
final Iterator<E> finalIt2 = it1;
|
||||
assertThrows(NoSuchElementException.class, () -> finalIt2.next(),
|
||||
"iterator.next() should raise NoSuchElementException after it finishes");
|
||||
// make sure nothing has changed after non-modification
|
||||
@ -839,7 +839,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
||||
iter = getCollection().iterator();
|
||||
iter.next();
|
||||
iter.remove();
|
||||
Iterator<E> finalIter = iter;
|
||||
final Iterator<E> finalIter = iter;
|
||||
assertThrows(IllegalStateException.class, () -> finalIter.remove(),
|
||||
"Second iter.remove should raise IllegalState");
|
||||
}
|
||||
@ -1167,7 +1167,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
|
||||
* @param a2 Second array
|
||||
* @param msg Failure message prefix
|
||||
*/
|
||||
private static void assertUnorderedArrayEquals(Object[] a1, Object[] a2, String msg) {
|
||||
private static void assertUnorderedArrayEquals(final Object[] a1, final Object[] a2, final String msg) {
|
||||
Assertions.assertEquals(a1.length, a2.length, () -> msg + ": length");
|
||||
final int size = a1.length;
|
||||
// Track values that have been matched once (and only once)
|
||||
|
@ -157,7 +157,7 @@ public abstract class AbstractListIteratorTest<E> extends AbstractIteratorTest<E
|
||||
final E addValue = addSetValue();
|
||||
if (!supportsAdd()) {
|
||||
// check for UnsupportedOperationException if not supported
|
||||
ListIterator<E> finalIt0 = it;
|
||||
final ListIterator<E> finalIt0 = it;
|
||||
assertThrows(UnsupportedOperationException.class, () -> finalIt0.add(addValue),
|
||||
"UnsupportedOperationException must be thrown from add of " + it.getClass().getSimpleName());
|
||||
return;
|
||||
|
@ -48,6 +48,7 @@ public class BoundedIteratorTest<E> extends AbstractIteratorTest<E> {
|
||||
super(BoundedIteratorTest.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@BeforeEach
|
||||
public void setUp()
|
||||
|
@ -45,6 +45,7 @@ public class CollatingIteratorTest extends AbstractIteratorTest<Integer> {
|
||||
private ArrayList<Integer> odds = null;
|
||||
private ArrayList<Integer> fib = null;
|
||||
|
||||
@Override
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
@ -48,6 +48,7 @@ public class FilterIteratorTest<E> extends AbstractIteratorTest<E> {
|
||||
/**
|
||||
* Set up instance variables required by this test case.
|
||||
*/
|
||||
@Override
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
array = new String[] { "a", "b", "c" };
|
||||
|
@ -46,6 +46,7 @@ public class IteratorChainTest extends AbstractIteratorTest<String> {
|
||||
super(IteratorChainTest.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
list1 = new ArrayList<>();
|
||||
|
@ -46,6 +46,7 @@ public class LazyIteratorChainTest extends AbstractIteratorTest<String> {
|
||||
super(LazyIteratorChainTest.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
list1 = new ArrayList<>();
|
||||
|
@ -42,6 +42,7 @@ public class ListIteratorWrapper2Test<E> extends AbstractIteratorTest<E> {
|
||||
super(ListIteratorWrapper2Test.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@BeforeEach
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setUp() {
|
||||
|
@ -43,6 +43,7 @@ public class ListIteratorWrapperTest<E> extends AbstractIteratorTest<E> {
|
||||
super(ListIteratorWrapperTest.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@BeforeEach
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setUp() {
|
||||
|
@ -47,6 +47,7 @@ public class NodeListIteratorTest extends AbstractIteratorTest<Node> {
|
||||
super(NodeListIteratorTest.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@BeforeEach
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
@ -44,6 +44,7 @@ public class ObjectGraphIteratorTest extends AbstractIteratorTest<Object> {
|
||||
super(ObjectGraphIteratorTest.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
list1 = new ArrayList<>();
|
||||
|
@ -44,6 +44,7 @@ public class PeekingIteratorTest<E> extends AbstractIteratorTest<E> {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@BeforeEach
|
||||
protected void setUp() throws Exception {
|
||||
|
@ -44,6 +44,7 @@ public class PermutationIteratorTest extends AbstractIteratorTest<List<Character
|
||||
super(PermutationIteratorTest.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
testList = new ArrayList<>();
|
||||
|
@ -42,6 +42,7 @@ public class PushbackIteratorTest<E> extends AbstractIteratorTest<E> {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@BeforeEach
|
||||
protected void setUp() throws Exception {
|
||||
|
@ -44,6 +44,7 @@ public class SkippingIteratorTest<E> extends AbstractIteratorTest<E> {
|
||||
super(SkippingIteratorTest.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@BeforeEach
|
||||
public void setUp()
|
||||
|
@ -40,6 +40,7 @@ public class UniqueFilterIteratorTest<E> extends AbstractIteratorTest<E> {
|
||||
super(UniqueFilterIteratorTest.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@BeforeEach
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setUp() {
|
||||
|
@ -43,6 +43,7 @@ public class UnmodifiableIteratorTest<E> extends AbstractIteratorTest<E> {
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@BeforeEach
|
||||
protected void setUp() throws Exception {
|
||||
|
@ -43,6 +43,7 @@ public class UnmodifiableListIteratorTest<E> extends AbstractListIteratorTest<E>
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@BeforeEach
|
||||
protected void setUp() throws Exception {
|
||||
|
@ -41,6 +41,7 @@ public class ZippingIteratorTest extends AbstractIteratorTest<Integer> {
|
||||
private ArrayList<Integer> odds = null;
|
||||
private ArrayList<Integer> fib = null;
|
||||
|
||||
@Override
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
@ -182,19 +182,19 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
||||
|
||||
final E element = getOtherElements()[0];
|
||||
|
||||
List<E> finalList0 = makeObject();
|
||||
final List<E> finalList0 = makeObject();
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> finalList0.add(Integer.MIN_VALUE, element),
|
||||
"List.add should throw IndexOutOfBoundsException [Integer.MIN_VALUE]");
|
||||
|
||||
List<E> finalList1 = makeObject();
|
||||
final List<E> finalList1 = makeObject();
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> finalList1.add(-1, element),
|
||||
"List.add should throw IndexOutOfBoundsException [-1]");
|
||||
|
||||
List<E> finalList2 = makeObject();
|
||||
final List<E> finalList2 = makeObject();
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> finalList2.add(1, element),
|
||||
"List.add should throw IndexOutOfBoundsException [1]");
|
||||
|
||||
List<E> finalList3 = makeObject();
|
||||
final List<E> finalList3 = makeObject();
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> finalList3.add(Integer.MAX_VALUE, element),
|
||||
"List.add should throw IndexOutOfBoundsException [Integer.MAX_VALUE]");
|
||||
}
|
||||
@ -211,19 +211,19 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
||||
|
||||
final E element = getOtherElements()[0];
|
||||
|
||||
List<E> finalList0 = makeFullCollection();
|
||||
final List<E> finalList0 = makeFullCollection();
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> finalList0.add(Integer.MIN_VALUE, element),
|
||||
"List.add should throw IndexOutOfBoundsException [Integer.MIN_VALUE]");
|
||||
|
||||
List<E> finalList1 = makeFullCollection();
|
||||
final List<E> finalList1 = makeFullCollection();
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> finalList1.add(-1, element),
|
||||
"List.add should throw IndexOutOfBoundsException [-1]");
|
||||
|
||||
List<E> finalList2 = makeFullCollection();
|
||||
final List<E> finalList2 = makeFullCollection();
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> finalList2.add(finalList2.size() + 1, element),
|
||||
"List.add should throw IndexOutOfBoundsException [size + 1]");
|
||||
|
||||
List<E> finalList3 = makeFullCollection();
|
||||
final List<E> finalList3 = makeFullCollection();
|
||||
assertThrows(IndexOutOfBoundsException.class, () -> finalList3.add(Integer.MAX_VALUE, element),
|
||||
"List.add should throw IndexOutOfBoundsException [Integer.MAX_VALUE]");
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ public class CursorableLinkedListTest<E> extends AbstractLinkedListTest<E> {
|
||||
|
||||
private CursorableLinkedList<E> list;
|
||||
|
||||
@Override
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
list = new CursorableLinkedList<>();
|
||||
|
@ -18,6 +18,7 @@ package org.apache.commons.collections4.list;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
@ -113,9 +114,7 @@ public class TransformedListTest<E> extends AbstractListTest<E> {
|
||||
public void testTransformedList_decorateTransform() {
|
||||
final List<Object> originalList = new ArrayList<>();
|
||||
final Object[] els = {"1", "3", "5", "7", "2", "4", "6"};
|
||||
for (final Object el : els) {
|
||||
originalList.add(el);
|
||||
}
|
||||
Collections.addAll(originalList, els);
|
||||
final List<?> list = TransformedList.transformedList(originalList, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
|
||||
assertEquals(els.length, list.size());
|
||||
for (final Object el : els) {
|
||||
|
@ -68,14 +68,14 @@ public abstract class AbstractIterableMapTest<K, V> extends AbstractMapTest<K, V
|
||||
Iterator<Map.Entry<K, V>> it = getMap().entrySet().iterator();
|
||||
final Map.Entry<K, V> val = it.next();
|
||||
getMap().remove(val.getKey());
|
||||
Iterator<Map.Entry<K, V>> finalIt0 = it;
|
||||
final Iterator<Map.Entry<K, V>> finalIt0 = it;
|
||||
assertThrows(ConcurrentModificationException.class, () -> finalIt0.next());
|
||||
|
||||
resetFull();
|
||||
it = getMap().entrySet().iterator();
|
||||
it.next();
|
||||
getMap().clear();
|
||||
Iterator<Map.Entry<K, V>> finalIt1 = it;
|
||||
final Iterator<Map.Entry<K, V>> finalIt1 = it;
|
||||
assertThrows(ConcurrentModificationException.class, () -> finalIt1.next());
|
||||
}
|
||||
|
||||
@ -91,14 +91,14 @@ public abstract class AbstractIterableMapTest<K, V> extends AbstractMapTest<K, V
|
||||
Iterator<K> it = getMap().keySet().iterator();
|
||||
final K val = it.next();
|
||||
getMap().remove(val);
|
||||
Iterator<K> finalIt0 = it;
|
||||
final Iterator<K> finalIt0 = it;
|
||||
assertThrows(ConcurrentModificationException.class, () -> finalIt0.next());
|
||||
|
||||
resetFull();
|
||||
it = getMap().keySet().iterator();
|
||||
it.next();
|
||||
getMap().clear();
|
||||
Iterator<K> finalIt1 = it;
|
||||
final Iterator<K> finalIt1 = it;
|
||||
assertThrows(ConcurrentModificationException.class, () -> finalIt1.next());
|
||||
}
|
||||
|
||||
@ -114,14 +114,14 @@ public abstract class AbstractIterableMapTest<K, V> extends AbstractMapTest<K, V
|
||||
Iterator<V> it = getMap().values().iterator();
|
||||
it.next();
|
||||
getMap().remove(getMap().keySet().iterator().next());
|
||||
Iterator<V> finalIt0 = it;
|
||||
final Iterator<V> finalIt0 = it;
|
||||
assertThrows(ConcurrentModificationException.class, () -> finalIt0.next());
|
||||
|
||||
resetFull();
|
||||
it = getMap().values().iterator();
|
||||
it.next();
|
||||
getMap().clear();
|
||||
Iterator<V> finalIt1 = it;
|
||||
final Iterator<V> finalIt1 = it;
|
||||
assertThrows(ConcurrentModificationException.class, () -> finalIt1.next());
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ public abstract class AbstractOrderedMapTest<K, V> extends AbstractIterableMapTe
|
||||
public void testFirstKey() {
|
||||
resetEmpty();
|
||||
OrderedMap<K, V> ordered = getMap();
|
||||
OrderedMap<K, V> finalOrdered = ordered;
|
||||
final OrderedMap<K, V> finalOrdered = ordered;
|
||||
assertThrows(NoSuchElementException.class, () -> finalOrdered.firstKey());
|
||||
|
||||
resetFull();
|
||||
@ -101,7 +101,7 @@ public abstract class AbstractOrderedMapTest<K, V> extends AbstractIterableMapTe
|
||||
public void testLastKey() {
|
||||
resetEmpty();
|
||||
OrderedMap<K, V> ordered = getMap();
|
||||
OrderedMap<K, V> finalOrdered = ordered;
|
||||
final OrderedMap<K, V> finalOrdered = ordered;
|
||||
assertThrows(NoSuchElementException.class, () -> finalOrdered.lastKey());
|
||||
|
||||
resetFull();
|
||||
@ -138,7 +138,7 @@ public abstract class AbstractOrderedMapTest<K, V> extends AbstractIterableMapTe
|
||||
assertNull(ordered.nextKey(confirmedLast));
|
||||
|
||||
if (!isAllowNullKey()) {
|
||||
OrderedMap<K, V> finalOrdered = ordered;
|
||||
final OrderedMap<K, V> finalOrdered = ordered;
|
||||
assertThrows(NullPointerException.class, () -> finalOrdered.nextKey(null));
|
||||
} else {
|
||||
assertNull(ordered.nextKey(null));
|
||||
@ -172,7 +172,7 @@ public abstract class AbstractOrderedMapTest<K, V> extends AbstractIterableMapTe
|
||||
assertNull(ordered.previousKey(confirmedLast));
|
||||
|
||||
if (!isAllowNullKey()) {
|
||||
OrderedMap<K, V> finalOrdered = ordered;
|
||||
final OrderedMap<K, V> finalOrdered = ordered;
|
||||
assertThrows(NullPointerException.class, () -> finalOrdered.previousKey(null));
|
||||
} else {
|
||||
if (!isAllowNullKey()) {
|
||||
|
@ -40,6 +40,7 @@ public class CompositeMapTest<K, V> extends AbstractIterableMapTest<K, V> {
|
||||
super(CompositeMapTest.class.getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
@ -131,7 +131,7 @@ public class LazySortedMapTest<K, V> extends AbstractSortedMapTest<K, V> {
|
||||
@Test
|
||||
public void testTransformerDecorate() {
|
||||
final Transformer<Object, Integer> transformer = TransformerUtils.asTransformer(oneFactory);
|
||||
SortedMap<Integer, Number> map = lazySortedMap(new TreeMap<Integer, Number>(), transformer);
|
||||
final SortedMap<Integer, Number> map = lazySortedMap(new TreeMap<Integer, Number>(), transformer);
|
||||
assertTrue(map instanceof LazySortedMap);
|
||||
assertAll(
|
||||
() -> assertThrows(NullPointerException.class, () -> lazySortedMap(new TreeMap<Integer, Number>(), (Transformer<Integer, Number>) null),
|
||||
|
@ -197,7 +197,7 @@ public class ListOrderedMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
|
||||
resetEmpty();
|
||||
ListOrderedMap<K, V> lom = getMap();
|
||||
|
||||
ListOrderedMap<K, V> finalLom = lom;
|
||||
final ListOrderedMap<K, V> finalLom = lom;
|
||||
assertAll(
|
||||
() -> assertThrows(IndexOutOfBoundsException.class, () -> finalLom.put(1, (K) "testInsert1", (V) "testInsert1v"),
|
||||
"should not be able to insert at pos 1 in empty Map"),
|
||||
|
@ -93,7 +93,7 @@ public class PredicatedMapTest<K, V> extends AbstractIterableMapTest<K, V> {
|
||||
map.put((K) "E", (V) "e");
|
||||
Iterator<Map.Entry<K, V>> iterator = map.entrySet().iterator();
|
||||
Map.Entry<K, V> entry = iterator.next();
|
||||
Map.Entry<K, V> finalEntry = entry;
|
||||
final Map.Entry<K, V> finalEntry = entry;
|
||||
assertThrows(IllegalArgumentException.class, () -> finalEntry.setValue((V) Integer.valueOf(3)),
|
||||
"Illegal value should raise IllegalArgument");
|
||||
|
||||
|
@ -121,7 +121,7 @@ public class PredicatedSortedMapTest<K, V> extends AbstractSortedMapTest<K, V> {
|
||||
map.put((K) "E", (V) "e");
|
||||
Iterator<Map.Entry<K, V>> iterator = map.entrySet().iterator();
|
||||
Map.Entry<K, V> entry = iterator.next();
|
||||
Map.Entry<K, V> finalEntry = entry;
|
||||
final Map.Entry<K, V> finalEntry = entry;
|
||||
assertThrows(IllegalArgumentException.class, () -> finalEntry.setValue((V) Integer.valueOf(3)),
|
||||
"Illegal value should raise IllegalArgument");
|
||||
|
||||
|
@ -290,8 +290,8 @@ public class ReferenceIdentityMapTest<K, V> extends AbstractIterableMapTest<K, V
|
||||
assertFalse(getMap().containsValue(null));
|
||||
assertNull(getMap().remove(null));
|
||||
assertFalse(getMap().entrySet().contains(null));
|
||||
assertFalse(getMap().keySet().contains(null));
|
||||
assertFalse(getMap().values().contains(null));
|
||||
assertFalse(getMap().containsKey(null));
|
||||
assertFalse(getMap().containsValue(null));
|
||||
assertThrows(NullPointerException.class, () -> getMap().put(null, null));
|
||||
assertThrows(NullPointerException.class, () -> getMap().put((K) new Object(), null));
|
||||
assertThrows(NullPointerException.class, () -> getMap().put(null, (V) new Object()));
|
||||
|
@ -323,9 +323,9 @@ public class ReferenceMapTest<K, V> extends AbstractIterableMapTest<K, V> {
|
||||
*/
|
||||
@Test
|
||||
public void testIteratorLastEntryCanBeRemovedAfterHasNext() {
|
||||
ReferenceMap<Integer, Integer> map = new ReferenceMap<>();
|
||||
final ReferenceMap<Integer, Integer> map = new ReferenceMap<>();
|
||||
map.put(1, 2);
|
||||
Iterator<Map.Entry<Integer, Integer>> iter = map.entrySet().iterator();
|
||||
final Iterator<Map.Entry<Integer, Integer>> iter = map.entrySet().iterator();
|
||||
assertTrue(iter.hasNext());
|
||||
iter.next();
|
||||
// below line should not affect remove
|
||||
|
@ -79,14 +79,14 @@ public class TransformedSortedMapTest<K, V> extends AbstractSortedMapTest<K, V>
|
||||
map.put((K) els[i], (V) els[i]);
|
||||
assertEquals(i + 1, map.size());
|
||||
assertTrue(map.containsKey(Integer.valueOf((String) els[i])));
|
||||
SortedMap<K, V> finalMap1 = map;
|
||||
int finalI = i;
|
||||
final SortedMap<K, V> finalMap1 = map;
|
||||
final int finalI = i;
|
||||
assertThrows(ClassCastException.class, () -> finalMap1.containsKey(els[finalI]));
|
||||
assertTrue(map.containsValue(els[i]));
|
||||
assertEquals(els[i], map.get(Integer.valueOf((String) els[i])));
|
||||
}
|
||||
|
||||
SortedMap<K, V> finalMap = map;
|
||||
final SortedMap<K, V> finalMap = map;
|
||||
assertThrows(ClassCastException.class, () -> finalMap.remove(els[0]));
|
||||
assertEquals(els[0], map.remove(Integer.valueOf((String) els[0])));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user