Use final
This commit is contained in:
parent
b87d212629
commit
de059262b9
|
@ -42,7 +42,7 @@ public interface BloomFilterProducer {
|
|||
* @param filters The filters to be returned by the producer.
|
||||
* @return THe BloomFilterProducer containing the filters.
|
||||
*/
|
||||
static BloomFilterProducer fromBloomFilterArray(BloomFilter... filters) {
|
||||
static BloomFilterProducer fromBloomFilterArray(final BloomFilter... filters) {
|
||||
Objects.requireNonNull(filters, "filters");
|
||||
return new BloomFilterProducer() {
|
||||
/**
|
||||
|
@ -99,7 +99,7 @@ public interface BloomFilterProducer {
|
|||
* @return the merged bloom filter.
|
||||
*/
|
||||
default BloomFilter flatten() {
|
||||
BloomFilter[] bf = {null};
|
||||
final BloomFilter[] bf = {null};
|
||||
forEachBloomFilter( x -> {
|
||||
if (bf[0] == null) {
|
||||
bf[0] = new SimpleBloomFilter( x.getShape());
|
||||
|
|
|
@ -85,7 +85,7 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
|
|||
* dated or stale filters.
|
||||
* @return this
|
||||
*/
|
||||
public Builder<T> setCleanup(Consumer<Deque<T>> cleanup) {
|
||||
public Builder<T> setCleanup(final Consumer<Deque<T>> cleanup) {
|
||||
this.cleanup = cleanup;
|
||||
return this;
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
|
|||
* created.
|
||||
* @return this for chaining.
|
||||
*/
|
||||
public Builder<T> setExtendCheck(Predicate<LayerManager<T>> extendCheck) {
|
||||
public Builder<T> setExtendCheck(final Predicate<LayerManager<T>> extendCheck) {
|
||||
this.extendCheck = extendCheck;
|
||||
return this;
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
|
|||
* @param supplier The supplier of new Bloom filter instances.
|
||||
* @return this for chaining.
|
||||
*/
|
||||
public Builder<T> setSupplier(Supplier<T> supplier) {
|
||||
public Builder<T> setSupplier(final Supplier<T> supplier) {
|
||||
this.supplier = supplier;
|
||||
return this;
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
|
|||
* @return A Consumer suitable for the LayerManager {@code cleanup} parameter.
|
||||
* @throws IllegalArgumentException if {@code maxSize <= 0}.
|
||||
*/
|
||||
public static <T extends BloomFilter> Consumer<Deque<T>> onMaxSize(int maxSize) {
|
||||
public static <T extends BloomFilter> Consumer<Deque<T>> onMaxSize(final int maxSize) {
|
||||
if (maxSize <= 0) {
|
||||
throw new IllegalArgumentException("'maxSize' must be greater than 0");
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
|
|||
* @param test Predicate.
|
||||
* @return A Consumer suitable for the LayerManager {@code cleanup} parameter.
|
||||
*/
|
||||
public static <T extends BloomFilter> Consumer<Deque<T>> removeIf(Predicate<? super T> test) {
|
||||
public static <T extends BloomFilter> Consumer<Deque<T>> removeIf(final Predicate<? super T> test) {
|
||||
return x -> x.removeIf(test);
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
|
|||
* @return A Predicate suitable for the LayerManager {@code extendCheck} parameter.
|
||||
* @throws IllegalArgumentException if {@code breakAt <= 0}
|
||||
*/
|
||||
public static <T extends BloomFilter> Predicate<LayerManager<T>> advanceOnCount(int breakAt) {
|
||||
public static <T extends BloomFilter> Predicate<LayerManager<T>> advanceOnCount(final int breakAt) {
|
||||
if (breakAt <= 0) {
|
||||
throw new IllegalArgumentException("'breakAt' must be greater than 0");
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
|
|||
int count;
|
||||
|
||||
@Override
|
||||
public boolean test(LayerManager<T> filter) {
|
||||
public boolean test(final LayerManager<T> filter) {
|
||||
if (++count == breakAt) {
|
||||
count = 0;
|
||||
return true;
|
||||
|
@ -227,12 +227,12 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
|
|||
* @return A Predicate suitable for the LayerManager {@code extendCheck} parameter.
|
||||
* @throws IllegalArgumentException if {@code maxN <= 0}
|
||||
*/
|
||||
public static <T extends BloomFilter> Predicate<LayerManager<T>> advanceOnSaturation(double maxN) {
|
||||
public static <T extends BloomFilter> Predicate<LayerManager<T>> advanceOnSaturation(final double maxN) {
|
||||
if (maxN <= 0) {
|
||||
throw new IllegalArgumentException("'maxN' must be greater than 0");
|
||||
}
|
||||
return manager -> {
|
||||
BloomFilter bf = manager.last();
|
||||
final BloomFilter bf = manager.last();
|
||||
return maxN <= bf.getShape().estimateN(bf.cardinality());
|
||||
};
|
||||
}
|
||||
|
@ -278,8 +278,8 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
|
|||
* list.
|
||||
* @param initialize true if the filter list should be initialized.
|
||||
*/
|
||||
private LayerManager(Supplier<T> filterSupplier, Predicate<LayerManager<T>> extendCheck,
|
||||
Consumer<Deque<T>> filterCleanup, boolean initialize) {
|
||||
private LayerManager(final Supplier<T> filterSupplier, final Predicate<LayerManager<T>> extendCheck,
|
||||
final Consumer<Deque<T>> filterCleanup, final boolean initialize) {
|
||||
this.filterSupplier = filterSupplier;
|
||||
this.extendCheck = extendCheck;
|
||||
this.filterCleanup = filterCleanup;
|
||||
|
@ -292,7 +292,7 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
|
|||
* Adds a new Bloom filter to the list.
|
||||
*/
|
||||
private void addFilter() {
|
||||
T bf = filterSupplier.get();
|
||||
final T bf = filterSupplier.get();
|
||||
if (bf == null) {
|
||||
throw new NullPointerException("filterSupplier returned null.");
|
||||
}
|
||||
|
@ -330,8 +330,8 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
|
|||
* @return a copy of this layer Manager.
|
||||
*/
|
||||
public LayerManager<T> copy() {
|
||||
LayerManager<T> newMgr = new LayerManager<>(filterSupplier, extendCheck, filterCleanup, false);
|
||||
for (T bf : filters) {
|
||||
final LayerManager<T> newMgr = new LayerManager<>(filterSupplier, extendCheck, filterCleanup, false);
|
||||
for (final T bf : filters) {
|
||||
newMgr.filters.add(bf.copy());
|
||||
}
|
||||
return newMgr;
|
||||
|
@ -356,8 +356,8 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
|
|||
* {@code true} if all filters pass the test.
|
||||
*/
|
||||
@Override
|
||||
public boolean forEachBloomFilter(Predicate<BloomFilter> bloomFilterPredicate) {
|
||||
for (BloomFilter bf : filters) {
|
||||
public boolean forEachBloomFilter(final Predicate<BloomFilter> bloomFilterPredicate) {
|
||||
for (final BloomFilter bf : filters) {
|
||||
if (!bloomFilterPredicate.test(bf)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -374,7 +374,7 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
|
|||
* @throws NoSuchElementException if depth is not in the range
|
||||
* [0,filters.size())
|
||||
*/
|
||||
public final T get(int depth) {
|
||||
public final T get(final int depth) {
|
||||
if (depth < 0 || depth >= filters.size()) {
|
||||
throw new NoSuchElementException(String.format("Depth must be in the range [0,%s)", filters.size()));
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
|
|||
int resultIdx;
|
||||
BloomFilter bf;
|
||||
|
||||
Finder(BloomFilter bf) {
|
||||
Finder(final BloomFilter bf) {
|
||||
this.bf = bf;
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean test(BloomFilter x) {
|
||||
public boolean test(final BloomFilter x) {
|
||||
if (x.contains(bf)) {
|
||||
result[resultIdx++] = bfIdx;
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
|
|||
* @param shape the Shape of the enclosed Bloom filters
|
||||
* @param layerManager the LayerManager to manage the layers.
|
||||
*/
|
||||
public LayeredBloomFilter(Shape shape, LayerManager<T> layerManager) {
|
||||
public LayeredBloomFilter(final Shape shape, final LayerManager<T> layerManager) {
|
||||
this.shape = shape;
|
||||
this.layerManager = layerManager;
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
|
|||
* the {@code producer}.
|
||||
*/
|
||||
public boolean contains(final BloomFilterProducer producer) {
|
||||
boolean[] result = { true };
|
||||
final boolean[] result = { true };
|
||||
// return false when we have found a match to short circuit checks
|
||||
return producer.forEachBloomFilter(x -> {
|
||||
result[0] &= contains(x);
|
||||
|
@ -176,7 +176,7 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IndexProducer indexProducer) {
|
||||
public boolean contains(final IndexProducer indexProducer) {
|
||||
return contains(createFilter(indexProducer));
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
|
|||
* @return the BloomFilter.
|
||||
*/
|
||||
private BloomFilter createFilter(final BitMapProducer bitMapProducer) {
|
||||
SimpleBloomFilter bf = new SimpleBloomFilter(shape);
|
||||
final SimpleBloomFilter bf = new SimpleBloomFilter(shape);
|
||||
bf.merge(bitMapProducer);
|
||||
return bf;
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
|
|||
* @return the BloomFilter.
|
||||
*/
|
||||
private BloomFilter createFilter(final Hasher hasher) {
|
||||
SimpleBloomFilter bf = new SimpleBloomFilter(shape);
|
||||
final SimpleBloomFilter bf = new SimpleBloomFilter(shape);
|
||||
bf.merge(hasher);
|
||||
return bf;
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
|
|||
* @return the BloomFilter.
|
||||
*/
|
||||
private BloomFilter createFilter(final IndexProducer indexProducer) {
|
||||
SimpleBloomFilter bf = new SimpleBloomFilter(shape);
|
||||
final SimpleBloomFilter bf = new SimpleBloomFilter(shape);
|
||||
bf.merge(indexProducer);
|
||||
return bf;
|
||||
}
|
||||
|
@ -241,7 +241,7 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
|
|||
* @return an array of layer indices in which the Bloom filter is found.
|
||||
*/
|
||||
public int[] find(final BitMapProducer bitMapProducer) {
|
||||
SimpleBloomFilter bf = new SimpleBloomFilter(shape);
|
||||
final SimpleBloomFilter bf = new SimpleBloomFilter(shape);
|
||||
bf.merge(bitMapProducer);
|
||||
return find(bf);
|
||||
}
|
||||
|
@ -252,8 +252,8 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
|
|||
* @param bf the Bloom filter to search for.
|
||||
* @return an array of layer indices in which the Bloom filter is found.
|
||||
*/
|
||||
public int[] find(BloomFilter bf) {
|
||||
Finder finder = new Finder(bf);
|
||||
public int[] find(final BloomFilter bf) {
|
||||
final Finder finder = new Finder(bf);
|
||||
forEachBloomFilter(finder);
|
||||
return finder.getResult();
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
|
|||
* @return an array of layer indices in which the Bloom filter is found.
|
||||
*/
|
||||
public int[] find(final Hasher hasher) {
|
||||
SimpleBloomFilter bf = new SimpleBloomFilter(shape);
|
||||
final SimpleBloomFilter bf = new SimpleBloomFilter(shape);
|
||||
bf.merge(hasher);
|
||||
return find(bf);
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
|
|||
* @return an array of layer indices in which the Bloom filter is found.
|
||||
*/
|
||||
public int[] find(final IndexProducer indexProducer) {
|
||||
SimpleBloomFilter bf = new SimpleBloomFilter(shape);
|
||||
final SimpleBloomFilter bf = new SimpleBloomFilter(shape);
|
||||
bf.merge(indexProducer);
|
||||
return find(bf);
|
||||
}
|
||||
|
@ -290,13 +290,13 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
|
|||
*/
|
||||
@Override
|
||||
public BloomFilter flatten() {
|
||||
BloomFilter bf = new SimpleBloomFilter(shape);
|
||||
final BloomFilter bf = new SimpleBloomFilter(shape);
|
||||
forEachBloomFilter(bf::merge);
|
||||
return bf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEachBitMap(LongPredicate predicate) {
|
||||
public boolean forEachBitMap(final LongPredicate predicate) {
|
||||
return flatten().forEachBitMap(predicate);
|
||||
}
|
||||
|
||||
|
@ -310,12 +310,12 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
|
|||
* otherwise.
|
||||
*/
|
||||
@Override
|
||||
public final boolean forEachBloomFilter(Predicate<BloomFilter> bloomFilterPredicate) {
|
||||
public final boolean forEachBloomFilter(final Predicate<BloomFilter> bloomFilterPredicate) {
|
||||
return layerManager.forEachBloomFilter(bloomFilterPredicate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEachIndex(IntPredicate predicate) {
|
||||
public boolean forEachIndex(final IntPredicate predicate) {
|
||||
return forEachBloomFilter(bf -> bf.forEachIndex(predicate));
|
||||
}
|
||||
|
||||
|
@ -326,7 +326,7 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
|
|||
* @return the Bloom filter at the specified depth.
|
||||
* @throws NoSuchElementException if depth is not in the range [0,getDepth())
|
||||
*/
|
||||
public T get(int depth) {
|
||||
public T get(final int depth) {
|
||||
return layerManager.get(depth);
|
||||
}
|
||||
|
||||
|
@ -351,17 +351,17 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean merge(BitMapProducer bitMapProducer) {
|
||||
public boolean merge(final BitMapProducer bitMapProducer) {
|
||||
return layerManager.getTarget().merge(bitMapProducer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean merge(BloomFilter bf) {
|
||||
public boolean merge(final BloomFilter bf) {
|
||||
return layerManager.getTarget().merge(bf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean merge(IndexProducer indexProducer) {
|
||||
public boolean merge(final IndexProducer indexProducer) {
|
||||
return layerManager.getTarget().merge(indexProducer);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ public abstract class WrappedBloomFilter implements BloomFilter {
|
|||
* not a copy. Changes in one will be reflected in the other.
|
||||
* @param bf The Bloom filter.
|
||||
*/
|
||||
public WrappedBloomFilter(BloomFilter bf) {
|
||||
public WrappedBloomFilter(final BloomFilter bf) {
|
||||
this.wrapped = bf;
|
||||
}
|
||||
|
||||
|
@ -62,27 +62,27 @@ public abstract class WrappedBloomFilter implements BloomFilter {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(BitMapProducer bitMapProducer) {
|
||||
public boolean contains(final BitMapProducer bitMapProducer) {
|
||||
return wrapped.contains(bitMapProducer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(BloomFilter other) {
|
||||
public boolean contains(final BloomFilter other) {
|
||||
return wrapped.contains(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Hasher hasher) {
|
||||
public boolean contains(final Hasher hasher) {
|
||||
return wrapped.contains(hasher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(IndexProducer indexProducer) {
|
||||
public boolean contains(final IndexProducer indexProducer) {
|
||||
return wrapped.contains(indexProducer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int estimateIntersection(BloomFilter other) {
|
||||
public int estimateIntersection(final BloomFilter other) {
|
||||
return wrapped.estimateIntersection(other);
|
||||
}
|
||||
|
||||
|
@ -92,22 +92,22 @@ public abstract class WrappedBloomFilter implements BloomFilter {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int estimateUnion(BloomFilter other) {
|
||||
public int estimateUnion(final BloomFilter other) {
|
||||
return wrapped.estimateUnion(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEachBitMap(LongPredicate predicate) {
|
||||
public boolean forEachBitMap(final LongPredicate predicate) {
|
||||
return wrapped.forEachBitMap(predicate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEachBitMapPair(BitMapProducer other, LongBiPredicate func) {
|
||||
public boolean forEachBitMapPair(final BitMapProducer other, final LongBiPredicate func) {
|
||||
return wrapped.forEachBitMapPair(other, func);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEachIndex(IntPredicate predicate) {
|
||||
public boolean forEachIndex(final IntPredicate predicate) {
|
||||
return wrapped.forEachIndex(predicate);
|
||||
}
|
||||
|
||||
|
@ -126,22 +126,22 @@ public abstract class WrappedBloomFilter implements BloomFilter {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean merge(BitMapProducer bitMapProducer) {
|
||||
public boolean merge(final BitMapProducer bitMapProducer) {
|
||||
return wrapped.merge(bitMapProducer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean merge(BloomFilter other) {
|
||||
public boolean merge(final BloomFilter other) {
|
||||
return wrapped.merge(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean merge(Hasher hasher) {
|
||||
public boolean merge(final Hasher hasher) {
|
||||
return wrapped.merge(hasher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean merge(IndexProducer indexProducer) {
|
||||
public boolean merge(final IndexProducer indexProducer) {
|
||||
return wrapped.merge(indexProducer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -202,7 +202,7 @@ public class FixedOrderComparator<T> implements Comparator<T>, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ public class FixedOrderComparator<T> implements Comparator<T>, Serializable {
|
|||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
FixedOrderComparator<?> other = (FixedOrderComparator<?>) obj;
|
||||
final FixedOrderComparator<?> other = (FixedOrderComparator<?>) obj;
|
||||
return counter == other.counter && isLocked == other.isLocked && Objects.equals(map, other.map) && unknownObjectBehavior == other.unknownObjectBehavior;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import org.junit.jupiter.api.BeforeEach;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public abstract class AbstractBloomFilterProducerTest {
|
||||
private Shape shape = Shape.fromKM(17, 72);
|
||||
private final Shape shape = Shape.fromKM(17, 72);
|
||||
|
||||
BloomFilter one = new SimpleBloomFilter(shape);
|
||||
BloomFilter two = new SimpleBloomFilter(shape);
|
||||
|
@ -82,7 +82,7 @@ public abstract class AbstractBloomFilterProducerTest {
|
|||
|
||||
@Test
|
||||
public void testAsBloomFilterArray() {
|
||||
BloomFilter[] result = createUnderTest().asBloomFilterArray();
|
||||
final BloomFilter[] result = createUnderTest().asBloomFilterArray();
|
||||
assertEquals(2, result.length);
|
||||
assertEquals(1, result[0].cardinality());
|
||||
assertEquals(2, result[1].cardinality());
|
||||
|
@ -90,8 +90,8 @@ public abstract class AbstractBloomFilterProducerTest {
|
|||
|
||||
@Test
|
||||
public void testFlatten() {
|
||||
BloomFilter underTest = createUnderTest().flatten();
|
||||
BloomFilter expected = new SimpleBloomFilter(shape);
|
||||
final BloomFilter underTest = createUnderTest().flatten();
|
||||
final BloomFilter expected = new SimpleBloomFilter(shape);
|
||||
expected.merge(IndexProducer.fromIndexArray(1, 2, 3));
|
||||
assertArrayEquals(expected.asBitMapArray(), underTest.asBitMapArray());
|
||||
}
|
||||
|
|
|
@ -173,7 +173,7 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
|
|||
*
|
||||
* @param bf The Bloom filter to test.
|
||||
*/
|
||||
protected void testCardinalityAndIsEmpty(BloomFilter bf) {
|
||||
protected void testCardinalityAndIsEmpty(final BloomFilter bf) {
|
||||
assertTrue(bf.isEmpty());
|
||||
assertEquals(0, bf.cardinality());
|
||||
for (int i = 0; i < getTestShape().getNumberOfBits(); i++) {
|
||||
|
@ -243,7 +243,7 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
|
|||
public void testEmptyAfterMergeWithNothing() {
|
||||
// test the case where is empty after merge
|
||||
// in this case the internal cardinality == -1
|
||||
BloomFilter bf = createEmptyFilter(getTestShape());
|
||||
final BloomFilter bf = createEmptyFilter(getTestShape());
|
||||
bf.merge(IndexProducer.fromIndexArray());
|
||||
assertTrue(bf.isEmpty());
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public class BitMapProducerFromWrappedBloomFilterTest extends AbstractBitMapProd
|
|||
return new WrappedBloomFilter(new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape)) {
|
||||
@Override
|
||||
public BloomFilter copy() {
|
||||
BloomFilter result = new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape);
|
||||
final BloomFilter result = new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape);
|
||||
result.merge(getWrapped());
|
||||
return result;
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class BitMapProducerFromWrappedBloomFilterTest extends AbstractBitMapProd
|
|||
final BloomFilter bf = new WrappedBloomFilter(new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape)) {
|
||||
@Override
|
||||
public BloomFilter copy() {
|
||||
BloomFilter result = new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape);
|
||||
final BloomFilter result = new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape);
|
||||
result.merge(getWrapped());
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.apache.commons.collections4.bloomfilter;
|
|||
public class BloomFilterProducerFromBloomFilterArrayTest extends AbstractBloomFilterProducerTest{
|
||||
|
||||
@Override
|
||||
protected BloomFilterProducer createUnderTest(BloomFilter... filters) {
|
||||
protected BloomFilterProducer createUnderTest(final BloomFilter... filters) {
|
||||
return BloomFilterProducer.fromBloomFilterArray(filters);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,13 +19,13 @@ package org.apache.commons.collections4.bloomfilter;
|
|||
public class BloomFilterProducerFromLayeredBloomFilterTest extends AbstractBloomFilterProducerTest{
|
||||
|
||||
@Override
|
||||
protected BloomFilterProducer createUnderTest(BloomFilter... filters) {
|
||||
Shape shape = filters[0].getShape();
|
||||
LayerManager layerManager = LayerManager.builder().setSupplier( () -> new SimpleBloomFilter(shape) )
|
||||
protected BloomFilterProducer createUnderTest(final BloomFilter... filters) {
|
||||
final Shape shape = filters[0].getShape();
|
||||
final LayerManager layerManager = LayerManager.builder().setSupplier( () -> new SimpleBloomFilter(shape) )
|
||||
.setExtendCheck( LayerManager.ExtendCheck.advanceOnPopulated())
|
||||
.setCleanup(LayerManager.Cleanup.noCleanup()).build();
|
||||
LayeredBloomFilter underTest = new LayeredBloomFilter(shape, layerManager);
|
||||
for (BloomFilter bf : filters) {
|
||||
final LayeredBloomFilter underTest = new LayeredBloomFilter(shape, layerManager);
|
||||
for (final BloomFilter bf : filters) {
|
||||
underTest.merge(bf);
|
||||
}
|
||||
return underTest;
|
||||
|
|
|
@ -29,9 +29,9 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
public class CountingPredicateTest {
|
||||
|
||||
private Integer[] ary = {Integer.valueOf(1), Integer.valueOf(2)};
|
||||
private final Integer[] ary = {Integer.valueOf(1), Integer.valueOf(2)};
|
||||
|
||||
private BiPredicate<Integer, Integer> makeFunc(BiPredicate<Integer, Integer> inner, List<Pair<Integer, Integer>> result) {
|
||||
private BiPredicate<Integer, Integer> makeFunc(final BiPredicate<Integer, Integer> inner, final List<Pair<Integer, Integer>> result) {
|
||||
return (x, y) -> {
|
||||
if (inner.test(x, y)) {
|
||||
result.add(Pair.of(x, y));
|
||||
|
@ -47,8 +47,8 @@ public class CountingPredicateTest {
|
|||
*/
|
||||
@Test
|
||||
public void testPredicateLonger() {
|
||||
List<Pair<Integer, Integer>> expected = new ArrayList<>();
|
||||
List<Pair<Integer, Integer>> result = new ArrayList<>();
|
||||
final List<Pair<Integer, Integer>> expected = new ArrayList<>();
|
||||
final List<Pair<Integer, Integer>> result = new ArrayList<>();
|
||||
expected.add(Pair.of(1, 3));
|
||||
|
||||
CountingPredicate<Integer> cp = new CountingPredicate<>(ary, makeFunc((x, y) -> x!=null, result));
|
||||
|
@ -84,11 +84,11 @@ public class CountingPredicateTest {
|
|||
*/
|
||||
@Test
|
||||
public void testPredicateSameLength() {
|
||||
List<Pair<Integer, Integer>> expected = new ArrayList<>();
|
||||
List<Pair<Integer, Integer>> result = new ArrayList<>();
|
||||
final List<Pair<Integer, Integer>> expected = new ArrayList<>();
|
||||
final List<Pair<Integer, Integer>> result = new ArrayList<>();
|
||||
expected.add( Pair.of(1, 3));
|
||||
expected.add( Pair.of(2, 3));
|
||||
CountingPredicate<Integer> cp = new CountingPredicate<>(ary, makeFunc((x, y) -> true, result));
|
||||
final CountingPredicate<Integer> cp = new CountingPredicate<>(ary, makeFunc((x, y) -> true, result));
|
||||
assertTrue(cp.test(3));
|
||||
assertTrue(cp.test(3));
|
||||
assertEquals(expected, result);
|
||||
|
@ -102,13 +102,13 @@ public class CountingPredicateTest {
|
|||
*/
|
||||
@Test
|
||||
public void testPredicateShorter() {
|
||||
List<Pair<Integer, Integer>> expected = new ArrayList<>();
|
||||
List<Pair<Integer, Integer>> result = new ArrayList<>();
|
||||
Integer[] shortAry = {Integer.valueOf(3)};
|
||||
final List<Pair<Integer, Integer>> expected = new ArrayList<>();
|
||||
final List<Pair<Integer, Integer>> result = new ArrayList<>();
|
||||
final Integer[] shortAry = {Integer.valueOf(3)};
|
||||
expected.add(Pair.of(3, 1));
|
||||
expected.add(Pair.of(null, 2));
|
||||
CountingPredicate<Integer> cp = new CountingPredicate<>(shortAry, makeFunc((x, y) -> true, result));
|
||||
for (Integer i : ary) {
|
||||
final CountingPredicate<Integer> cp = new CountingPredicate<>(shortAry, makeFunc((x, y) -> true, result));
|
||||
for (final Integer i : ary) {
|
||||
assertTrue(cp.test(i));
|
||||
}
|
||||
assertEquals(expected, result);
|
||||
|
|
|
@ -44,9 +44,9 @@ public class LayerManagerTest {
|
|||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {4, 10, 2, 1})
|
||||
public void testAdvanceOnCount(int breakAt) {
|
||||
Predicate<LayerManager<BloomFilter>> underTest = LayerManager.ExtendCheck.advanceOnCount(breakAt);
|
||||
LayerManager<BloomFilter> layerManager = testingBuilder().build();
|
||||
public void testAdvanceOnCount(final int breakAt) {
|
||||
final Predicate<LayerManager<BloomFilter>> underTest = LayerManager.ExtendCheck.advanceOnCount(breakAt);
|
||||
final LayerManager<BloomFilter> layerManager = testingBuilder().build();
|
||||
for (int i = 0; i < breakAt - 1; i++) {
|
||||
assertFalse(underTest.test(layerManager), "at " + i);
|
||||
layerManager.getTarget().merge(TestingHashers.FROM1);
|
||||
|
@ -62,8 +62,8 @@ public class LayerManagerTest {
|
|||
|
||||
@Test
|
||||
public void testAdvanceOnPopulated() {
|
||||
Predicate<LayerManager<BloomFilter>> underTest = LayerManager.ExtendCheck.advanceOnPopulated();
|
||||
LayerManager<BloomFilter> layerManager = testingBuilder().build();
|
||||
final Predicate<LayerManager<BloomFilter>> underTest = LayerManager.ExtendCheck.advanceOnPopulated();
|
||||
final LayerManager<BloomFilter> layerManager = testingBuilder().build();
|
||||
assertFalse(underTest.test(layerManager));
|
||||
layerManager.getTarget().merge(TestingHashers.FROM1);
|
||||
assertTrue(underTest.test(layerManager));
|
||||
|
@ -71,10 +71,10 @@ public class LayerManagerTest {
|
|||
|
||||
@Test
|
||||
public void testAdvanceOnSaturation() {
|
||||
double maxN = shape.estimateMaxN();
|
||||
final double maxN = shape.estimateMaxN();
|
||||
int hashStart = 0;
|
||||
Predicate<LayerManager<BloomFilter>> underTest = LayerManager.ExtendCheck.advanceOnSaturation(maxN);
|
||||
LayerManager<BloomFilter> layerManager = testingBuilder().build();
|
||||
final Predicate<LayerManager<BloomFilter>> underTest = LayerManager.ExtendCheck.advanceOnSaturation(maxN);
|
||||
final LayerManager<BloomFilter> layerManager = testingBuilder().build();
|
||||
while (layerManager.getTarget().getShape().estimateN(layerManager.getTarget().cardinality()) < maxN) {
|
||||
assertFalse(underTest.test(layerManager));
|
||||
layerManager.getTarget().merge(new IncrementingHasher(hashStart, shape.getNumberOfHashFunctions()));
|
||||
|
@ -87,7 +87,7 @@ public class LayerManagerTest {
|
|||
|
||||
@Test
|
||||
public void testBuilder() {
|
||||
LayerManager.Builder<BloomFilter> underTest = LayerManager.builder();
|
||||
final LayerManager.Builder<BloomFilter> underTest = LayerManager.builder();
|
||||
NullPointerException npe = assertThrows(NullPointerException.class, underTest::build);
|
||||
assertTrue(npe.getMessage().contains("Supplier must not be null"));
|
||||
underTest.setSupplier(() -> null).setCleanup(null);
|
||||
|
@ -105,7 +105,7 @@ public class LayerManagerTest {
|
|||
|
||||
@Test
|
||||
public void testClear() {
|
||||
LayerManager<BloomFilter> underTest = LayerManager.builder().setSupplier(() -> new SimpleBloomFilter(shape)).build();
|
||||
final LayerManager<BloomFilter> underTest = LayerManager.builder().setSupplier(() -> new SimpleBloomFilter(shape)).build();
|
||||
underTest.getTarget().merge(TestingHashers.randomHasher());
|
||||
underTest.next();
|
||||
underTest.getTarget().merge(TestingHashers.randomHasher());
|
||||
|
@ -119,7 +119,7 @@ public class LayerManagerTest {
|
|||
|
||||
@Test
|
||||
public void testCopy() {
|
||||
LayerManager<BloomFilter> underTest = LayerManager.builder().setSupplier(() -> new SimpleBloomFilter(shape)).build();
|
||||
final LayerManager<BloomFilter> underTest = LayerManager.builder().setSupplier(() -> new SimpleBloomFilter(shape)).build();
|
||||
underTest.getTarget().merge(TestingHashers.randomHasher());
|
||||
underTest.next();
|
||||
underTest.getTarget().merge(TestingHashers.randomHasher());
|
||||
|
@ -127,7 +127,7 @@ public class LayerManagerTest {
|
|||
underTest.getTarget().merge(TestingHashers.randomHasher());
|
||||
assertEquals(3, underTest.getDepth());
|
||||
|
||||
LayerManager<BloomFilter> copy = underTest.copy();
|
||||
final LayerManager<BloomFilter> copy = underTest.copy();
|
||||
assertNotSame(underTest, copy);
|
||||
// object equals not implemented
|
||||
assertNotEquals(underTest, copy);
|
||||
|
@ -139,17 +139,17 @@ public class LayerManagerTest {
|
|||
|
||||
@Test
|
||||
public void testForEachBloomFilter() {
|
||||
LayerManager<BloomFilter> underTest = LayerManager.builder().setSupplier(() -> new SimpleBloomFilter(shape))
|
||||
final LayerManager<BloomFilter> underTest = LayerManager.builder().setSupplier(() -> new SimpleBloomFilter(shape))
|
||||
.setExtendCheck(LayerManager.ExtendCheck.advanceOnPopulated()).build();
|
||||
|
||||
List<BloomFilter> lst = new ArrayList<>();
|
||||
final List<BloomFilter> lst = new ArrayList<>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
BloomFilter bf = new SimpleBloomFilter(shape);
|
||||
final BloomFilter bf = new SimpleBloomFilter(shape);
|
||||
bf.merge(TestingHashers.randomHasher());
|
||||
lst.add(bf);
|
||||
underTest.getTarget().merge(bf);
|
||||
}
|
||||
List<BloomFilter> lst2 = new ArrayList<>();
|
||||
final List<BloomFilter> lst2 = new ArrayList<>();
|
||||
underTest.forEachBloomFilter(lst2::add);
|
||||
assertEquals(10, lst.size());
|
||||
assertEquals(10, lst2.size());
|
||||
|
@ -160,8 +160,8 @@ public class LayerManagerTest {
|
|||
|
||||
@Test
|
||||
public void testGet() {
|
||||
SimpleBloomFilter f = new SimpleBloomFilter(shape);
|
||||
LayerManager<BloomFilter> underTest = LayerManager.builder().setSupplier(() -> f).build();
|
||||
final SimpleBloomFilter f = new SimpleBloomFilter(shape);
|
||||
final LayerManager<BloomFilter> underTest = LayerManager.builder().setSupplier(() -> f).build();
|
||||
assertEquals(1, underTest.getDepth());
|
||||
assertSame(f, underTest.get(0));
|
||||
assertThrows(NoSuchElementException.class, () -> underTest.get(-1));
|
||||
|
@ -174,8 +174,8 @@ public class LayerManagerTest {
|
|||
|
||||
@Test
|
||||
public void testNeverAdvance() {
|
||||
Predicate<LayerManager<BloomFilter>> underTest = LayerManager.ExtendCheck.neverAdvance();
|
||||
LayerManager<BloomFilter> layerManager = testingBuilder().build();
|
||||
final Predicate<LayerManager<BloomFilter>> underTest = LayerManager.ExtendCheck.neverAdvance();
|
||||
final LayerManager<BloomFilter> layerManager = testingBuilder().build();
|
||||
assertFalse(underTest.test(layerManager));
|
||||
for (int i = 0; i < 10; i++) {
|
||||
layerManager.getTarget().merge(TestingHashers.randomHasher());
|
||||
|
@ -185,7 +185,7 @@ public class LayerManagerTest {
|
|||
|
||||
@Test
|
||||
public void testNextAndGetDepth() {
|
||||
LayerManager<BloomFilter> underTest = LayerManager.builder().setSupplier(() -> new SimpleBloomFilter(shape)).build();
|
||||
final LayerManager<BloomFilter> underTest = LayerManager.builder().setSupplier(() -> new SimpleBloomFilter(shape)).build();
|
||||
assertEquals(1, underTest.getDepth());
|
||||
underTest.getTarget().merge(TestingHashers.randomHasher());
|
||||
assertEquals(1, underTest.getDepth());
|
||||
|
@ -195,8 +195,8 @@ public class LayerManagerTest {
|
|||
|
||||
@Test
|
||||
public void testNoCleanup() {
|
||||
Consumer<Deque<BloomFilter>> underTest = LayerManager.Cleanup.noCleanup();
|
||||
Deque<BloomFilter> list = new LinkedList<>();
|
||||
final Consumer<Deque<BloomFilter>> underTest = LayerManager.Cleanup.noCleanup();
|
||||
final Deque<BloomFilter> list = new LinkedList<>();
|
||||
for (int i = 0; i < 20; i++) {
|
||||
assertEquals(i, list.size());
|
||||
list.add(new SimpleBloomFilter(shape));
|
||||
|
@ -206,9 +206,9 @@ public class LayerManagerTest {
|
|||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {5, 100, 2, 1})
|
||||
public void testOnMaxSize(int maxSize) {
|
||||
Consumer<Deque<BloomFilter>> underTest = LayerManager.Cleanup.onMaxSize(maxSize);
|
||||
LinkedList<BloomFilter> list = new LinkedList<>();
|
||||
public void testOnMaxSize(final int maxSize) {
|
||||
final Consumer<Deque<BloomFilter>> underTest = LayerManager.Cleanup.onMaxSize(maxSize);
|
||||
final LinkedList<BloomFilter> list = new LinkedList<>();
|
||||
for (int i = 0; i < maxSize; i++) {
|
||||
assertEquals(i, list.size());
|
||||
list.add(new SimpleBloomFilter(shape));
|
||||
|
@ -231,11 +231,11 @@ public class LayerManagerTest {
|
|||
|
||||
@Test
|
||||
public void testRemoveEmptyTarget() {
|
||||
Consumer<Deque<BloomFilter>> underTest = LayerManager.Cleanup.removeEmptyTarget();
|
||||
LinkedList<BloomFilter> list = new LinkedList<>();
|
||||
final Consumer<Deque<BloomFilter>> underTest = LayerManager.Cleanup.removeEmptyTarget();
|
||||
final LinkedList<BloomFilter> list = new LinkedList<>();
|
||||
|
||||
// removes an empty filter
|
||||
BloomFilter bf = new SimpleBloomFilter(shape);
|
||||
final BloomFilter bf = new SimpleBloomFilter(shape);
|
||||
list.add(bf);
|
||||
assertEquals(bf, list.get(0));
|
||||
underTest.accept(list);
|
||||
|
@ -270,10 +270,10 @@ public class LayerManagerTest {
|
|||
|
||||
@Test
|
||||
public void testTarget() {
|
||||
boolean[] extendCheckCalled = { false };
|
||||
boolean[] cleanupCalled = { false };
|
||||
int[] supplierCount = { 0 };
|
||||
LayerManager<BloomFilter> underTest = LayerManager.builder().setSupplier(() -> {
|
||||
final boolean[] extendCheckCalled = { false };
|
||||
final boolean[] cleanupCalled = { false };
|
||||
final int[] supplierCount = { 0 };
|
||||
final LayerManager<BloomFilter> underTest = LayerManager.builder().setSupplier(() -> {
|
||||
supplierCount[0]++;
|
||||
return new SimpleBloomFilter(shape);
|
||||
}).setExtendCheck(lm -> {
|
||||
|
|
|
@ -42,12 +42,12 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
|
|||
static class AdvanceOnTimeQuanta implements Predicate<LayerManager<TimestampedBloomFilter>> {
|
||||
long quanta;
|
||||
|
||||
AdvanceOnTimeQuanta(long quanta, TimeUnit unit) {
|
||||
AdvanceOnTimeQuanta(final long quanta, final TimeUnit unit) {
|
||||
this.quanta = unit.toMillis(quanta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(LayerManager<TimestampedBloomFilter> lm) {
|
||||
public boolean test(final LayerManager<TimestampedBloomFilter> lm) {
|
||||
// can not use getTarget() as it causes recursion.
|
||||
return lm.last().timestamp + quanta < System.currentTimeMillis();
|
||||
}
|
||||
|
@ -60,23 +60,22 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
|
|||
static class CleanByTime<T extends TimestampedBloomFilter> implements Consumer<List<T>> {
|
||||
long elapsedTime;
|
||||
|
||||
CleanByTime(long duration, TimeUnit unit) {
|
||||
CleanByTime(final long duration, final TimeUnit unit) {
|
||||
elapsedTime = unit.toMillis(duration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(List<T> t) {
|
||||
long min = System.currentTimeMillis() - elapsedTime;
|
||||
Iterator<T> iter = t.iterator();
|
||||
public void accept(final List<T> t) {
|
||||
final long min = System.currentTimeMillis() - elapsedTime;
|
||||
final Iterator<T> iter = t.iterator();
|
||||
while (iter.hasNext()) {
|
||||
TimestampedBloomFilter bf = iter.next();
|
||||
if (bf.getTimestamp() < min) {
|
||||
dbgInstrument.add(String.format("Removing old entry: T:%s (Aged: %s) \n", bf.getTimestamp(),
|
||||
(min - bf.getTimestamp())));
|
||||
iter.remove();
|
||||
} else {
|
||||
final TimestampedBloomFilter bf = iter.next();
|
||||
if (bf.getTimestamp() >= min) {
|
||||
return;
|
||||
}
|
||||
dbgInstrument.add(String.format("Removing old entry: T:%s (Aged: %s) \n", bf.getTimestamp(),
|
||||
min - bf.getTimestamp()));
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +83,7 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
|
|||
static class NumberedBloomFilter extends WrappedBloomFilter {
|
||||
int value;
|
||||
int sequence;
|
||||
NumberedBloomFilter(Shape shape, int value, int sequence) {
|
||||
NumberedBloomFilter(final Shape shape, final int value, final int sequence) {
|
||||
super(new SimpleBloomFilter(shape));
|
||||
this.value = value;
|
||||
this.sequence = sequence;
|
||||
|
@ -102,12 +101,12 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
|
|||
public static class TimestampedBloomFilter extends WrappedBloomFilter {
|
||||
final long timestamp;
|
||||
|
||||
TimestampedBloomFilter(BloomFilter bf) {
|
||||
TimestampedBloomFilter(final BloomFilter bf) {
|
||||
super(bf);
|
||||
this.timestamp = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
TimestampedBloomFilter(BloomFilter bf, long timestamp) {
|
||||
TimestampedBloomFilter(final BloomFilter bf, final long timestamp) {
|
||||
super(bf);
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
@ -138,11 +137,11 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
|
|||
* @param qUnit the unit of time to apply to quanta.
|
||||
* @return LayeredBloomFilter with the above properties.
|
||||
*/
|
||||
static LayeredBloomFilter<TimestampedBloomFilter> createTimedLayeredFilter(Shape shape, long duration, TimeUnit dUnit, long quanta,
|
||||
TimeUnit qUnit) {
|
||||
LayerManager.Builder<TimestampedBloomFilter> builder = LayerManager.builder();
|
||||
Consumer<Deque<TimestampedBloomFilter>> cleanup = Cleanup.removeEmptyTarget().andThen(new CleanByTime(duration, dUnit));
|
||||
LayerManager<TimestampedBloomFilter> layerManager = builder
|
||||
static LayeredBloomFilter<TimestampedBloomFilter> createTimedLayeredFilter(final Shape shape, final long duration, final TimeUnit dUnit, final long quanta,
|
||||
final TimeUnit qUnit) {
|
||||
final LayerManager.Builder<TimestampedBloomFilter> builder = LayerManager.builder();
|
||||
final Consumer<Deque<TimestampedBloomFilter>> cleanup = Cleanup.removeEmptyTarget().andThen(new CleanByTime(duration, dUnit));
|
||||
final LayerManager<TimestampedBloomFilter> layerManager = builder
|
||||
.setSupplier(() -> new TimestampedBloomFilter(new SimpleBloomFilter(shape)))
|
||||
.setCleanup(cleanup)
|
||||
.setExtendCheck(new AdvanceOnTimeQuanta(quanta, qUnit)
|
||||
|
@ -160,7 +159,7 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
|
|||
* @param maxDepth The maximum depth of layers.
|
||||
* @return An empty layered Bloom filter of the specified shape and depth.
|
||||
*/
|
||||
public static LayeredBloomFilter<BloomFilter> fixed(final Shape shape, int maxDepth) {
|
||||
public static LayeredBloomFilter<BloomFilter> fixed(final Shape shape, final int maxDepth) {
|
||||
return fixed(shape, maxDepth, () -> new SimpleBloomFilter(shape));
|
||||
}
|
||||
|
||||
|
@ -174,17 +173,17 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
|
|||
* @param supplier A supplier of the Bloom filters to create layers with.
|
||||
* @return An empty layered Bloom filter of the specified shape and depth.
|
||||
*/
|
||||
public static <T extends BloomFilter> LayeredBloomFilter<T> fixed(final Shape shape, int maxDepth, Supplier<T> supplier) {
|
||||
LayerManager.Builder<T> builder = LayerManager.builder();
|
||||
public static <T extends BloomFilter> LayeredBloomFilter<T> fixed(final Shape shape, final int maxDepth, final Supplier<T> supplier) {
|
||||
final LayerManager.Builder<T> builder = LayerManager.builder();
|
||||
builder.setExtendCheck(LayerManager.ExtendCheck.advanceOnPopulated())
|
||||
.setCleanup(LayerManager.Cleanup.onMaxSize(maxDepth)).setSupplier(supplier);
|
||||
return new LayeredBloomFilter<>(shape, builder.build());
|
||||
}
|
||||
|
||||
// instrumentation to record timestamps in dbgInstrument list
|
||||
private final Predicate<BloomFilter> dbg = (bf) -> {
|
||||
TimestampedBloomFilter tbf = (TimestampedBloomFilter) bf;
|
||||
long ts = System.currentTimeMillis();
|
||||
private final Predicate<BloomFilter> dbg = bf -> {
|
||||
final TimestampedBloomFilter tbf = (TimestampedBloomFilter) bf;
|
||||
final long ts = System.currentTimeMillis();
|
||||
dbgInstrument.add(String.format("T:%s (Elapsed:%s)- EstN:%s (Card:%s)\n", tbf.timestamp, ts - tbf.timestamp,
|
||||
tbf.estimateN(), tbf.cardinality()));
|
||||
return true;
|
||||
|
@ -192,28 +191,28 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
|
|||
// *** end of instrumentation ***
|
||||
|
||||
@Override
|
||||
protected LayeredBloomFilter<BloomFilter> createEmptyFilter(Shape shape) {
|
||||
protected LayeredBloomFilter<BloomFilter> createEmptyFilter(final Shape shape) {
|
||||
return LayeredBloomFilterTest.fixed(shape, 10);
|
||||
}
|
||||
|
||||
protected BloomFilter makeFilter(Hasher h) {
|
||||
BloomFilter bf = new SparseBloomFilter(getTestShape());
|
||||
protected BloomFilter makeFilter(final Hasher h) {
|
||||
final BloomFilter bf = new SparseBloomFilter(getTestShape());
|
||||
bf.merge(h);
|
||||
return bf;
|
||||
}
|
||||
|
||||
protected BloomFilter makeFilter(IndexProducer p) {
|
||||
BloomFilter bf = new SparseBloomFilter(getTestShape());
|
||||
protected BloomFilter makeFilter(final IndexProducer p) {
|
||||
final BloomFilter bf = new SparseBloomFilter(getTestShape());
|
||||
bf.merge(p);
|
||||
return bf;
|
||||
}
|
||||
|
||||
protected BloomFilter makeFilter(int... values) {
|
||||
protected BloomFilter makeFilter(final int... values) {
|
||||
return makeFilter(IndexProducer.fromIndexArray(values));
|
||||
}
|
||||
|
||||
private LayeredBloomFilter<BloomFilter> setupFindTest() {
|
||||
LayeredBloomFilter<BloomFilter> filter = LayeredBloomFilterTest.fixed(getTestShape(), 10);
|
||||
final LayeredBloomFilter<BloomFilter> filter = LayeredBloomFilterTest.fixed(getTestShape(), 10);
|
||||
filter.merge(TestingHashers.FROM1);
|
||||
filter.merge(TestingHashers.FROM11);
|
||||
filter.merge(new IncrementingHasher(11, 2));
|
||||
|
@ -224,7 +223,7 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
|
|||
@Override
|
||||
@Test
|
||||
public void testCardinalityAndIsEmpty() {
|
||||
LayerManager<BloomFilter> layerManager = LayerManager.builder().setExtendCheck(ExtendCheck.neverAdvance())
|
||||
final LayerManager<BloomFilter> layerManager = LayerManager.builder().setExtendCheck(ExtendCheck.neverAdvance())
|
||||
.setSupplier(() -> new SimpleBloomFilter(getTestShape())).build();
|
||||
testCardinalityAndIsEmpty(new LayeredBloomFilter<>(getTestShape(), layerManager));
|
||||
}
|
||||
|
@ -233,12 +232,12 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
|
|||
|
||||
@Test
|
||||
public void testCleanup() {
|
||||
int[] sequence = {1};
|
||||
LayerManager layerManager = LayerManager.builder()
|
||||
final int[] sequence = {1};
|
||||
final LayerManager layerManager = LayerManager.builder()
|
||||
.setSupplier(() -> new NumberedBloomFilter(getTestShape(), 3, sequence[0]++))
|
||||
.setExtendCheck(ExtendCheck.neverAdvance())
|
||||
.setCleanup(ll -> ll.removeIf( f -> (((NumberedBloomFilter) f).value-- == 0))).build();
|
||||
LayeredBloomFilter underTest = new LayeredBloomFilter(getTestShape(), layerManager );
|
||||
final LayeredBloomFilter underTest = new LayeredBloomFilter(getTestShape(), layerManager );
|
||||
assertEquals(1, underTest.getDepth());
|
||||
underTest.merge(TestingHashers.randomHasher());
|
||||
underTest.cleanup(); // first count == 2
|
||||
|
@ -281,12 +280,12 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
|
|||
// purposes.
|
||||
|
||||
// list of timestamps that are expected to be expired.
|
||||
List<Long> lst = new ArrayList<>();
|
||||
Shape shape = Shape.fromNM(4, 64);
|
||||
final List<Long> lst = new ArrayList<>();
|
||||
final Shape shape = Shape.fromNM(4, 64);
|
||||
|
||||
// create a filter that removes filters that are 4 seconds old
|
||||
// and quantises time to 1 second intervals.
|
||||
LayeredBloomFilter<TimestampedBloomFilter> underTest = createTimedLayeredFilter(shape, 600, TimeUnit.MILLISECONDS, 150,
|
||||
final LayeredBloomFilter<TimestampedBloomFilter> underTest = createTimedLayeredFilter(shape, 600, TimeUnit.MILLISECONDS, 150,
|
||||
TimeUnit.MILLISECONDS);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
|
@ -319,7 +318,7 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
|
|||
|
||||
@Test
|
||||
public void testFindBitMapProducer() {
|
||||
LayeredBloomFilter<BloomFilter> filter = setupFindTest();
|
||||
final LayeredBloomFilter<BloomFilter> filter = setupFindTest();
|
||||
|
||||
IndexProducer idxProducer = TestingHashers.FROM1.indices(getTestShape());
|
||||
BitMapProducer producer = BitMapProducer.fromIndexProducer(idxProducer, getTestShape().getNumberOfBits());
|
||||
|
@ -337,7 +336,7 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
|
|||
|
||||
@Test
|
||||
public void testFindBloomFilter() {
|
||||
LayeredBloomFilter<BloomFilter> filter = setupFindTest();
|
||||
final LayeredBloomFilter<BloomFilter> filter = setupFindTest();
|
||||
int[] expected = {0, 3};
|
||||
int[] result = filter.find(TestingHashers.FROM1);
|
||||
assertArrayEquals(expected, result);
|
||||
|
@ -349,7 +348,7 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
|
|||
@Test
|
||||
public void testFindIndexProducer() {
|
||||
IndexProducer producer = TestingHashers.FROM1.indices(getTestShape());
|
||||
LayeredBloomFilter<BloomFilter> filter = setupFindTest();
|
||||
final LayeredBloomFilter<BloomFilter> filter = setupFindTest();
|
||||
|
||||
int[] expected = {0, 3};
|
||||
int[] result = filter.find(producer);
|
||||
|
@ -363,9 +362,9 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
|
|||
|
||||
@Test
|
||||
public final void testGetLayer() {
|
||||
BloomFilter bf = new SimpleBloomFilter(getTestShape());
|
||||
final BloomFilter bf = new SimpleBloomFilter(getTestShape());
|
||||
bf.merge(TestingHashers.FROM11);
|
||||
LayeredBloomFilter<BloomFilter> filter = LayeredBloomFilterTest.fixed(getTestShape(), 10);
|
||||
final LayeredBloomFilter<BloomFilter> filter = LayeredBloomFilterTest.fixed(getTestShape(), 10);
|
||||
filter.merge(TestingHashers.FROM1);
|
||||
filter.merge(TestingHashers.FROM11);
|
||||
filter.merge(new IncrementingHasher(11, 2));
|
||||
|
@ -375,13 +374,13 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
|
|||
|
||||
@Test
|
||||
public void testMultipleFilters() {
|
||||
LayeredBloomFilter<BloomFilter> filter = LayeredBloomFilterTest.fixed(getTestShape(), 10);
|
||||
final LayeredBloomFilter<BloomFilter> filter = LayeredBloomFilterTest.fixed(getTestShape(), 10);
|
||||
filter.merge(TestingHashers.FROM1);
|
||||
filter.merge(TestingHashers.FROM11);
|
||||
assertEquals(2, filter.getDepth());
|
||||
assertTrue(filter.contains(makeFilter(TestingHashers.FROM1)));
|
||||
assertTrue(filter.contains(makeFilter(TestingHashers.FROM11)));
|
||||
BloomFilter t1 = makeFilter(6, 7, 17, 18, 19);
|
||||
final BloomFilter t1 = makeFilter(6, 7, 17, 18, 19);
|
||||
assertFalse(filter.contains(t1));
|
||||
assertFalse(filter.copy().contains(t1));
|
||||
assertTrue(filter.flatten().contains(t1));
|
||||
|
@ -389,10 +388,10 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
|
|||
|
||||
@Test
|
||||
public final void testNext() {
|
||||
LayerManager<BloomFilter> layerManager = LayerManager.builder().setSupplier(() -> new SimpleBloomFilter(getTestShape()))
|
||||
final LayerManager<BloomFilter> layerManager = LayerManager.builder().setSupplier(() -> new SimpleBloomFilter(getTestShape()))
|
||||
.build();
|
||||
|
||||
LayeredBloomFilter<BloomFilter> filter = new LayeredBloomFilter<>(getTestShape(), layerManager);
|
||||
final LayeredBloomFilter<BloomFilter> filter = new LayeredBloomFilter<>(getTestShape(), layerManager);
|
||||
filter.merge(TestingHashers.FROM1);
|
||||
filter.merge(TestingHashers.FROM11);
|
||||
assertEquals(1, filter.getDepth());
|
||||
|
|
|
@ -24,11 +24,11 @@ import org.junit.jupiter.params.provider.ValueSource;
|
|||
public class WrappedBloomFilterTest extends AbstractBloomFilterTest<WrappedBloomFilter> {
|
||||
|
||||
@Override
|
||||
protected WrappedBloomFilter createEmptyFilter(Shape shape) {
|
||||
protected WrappedBloomFilter createEmptyFilter(final Shape shape) {
|
||||
return new WrappedBloomFilter(new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape)) {
|
||||
@Override
|
||||
public BloomFilter copy() {
|
||||
BloomFilter result = new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape);
|
||||
final BloomFilter result = new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape);
|
||||
result.merge(this.getWrapped());
|
||||
return result;
|
||||
}
|
||||
|
@ -37,18 +37,18 @@ public class WrappedBloomFilterTest extends AbstractBloomFilterTest<WrappedBloom
|
|||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {0, 1, 34})
|
||||
public void testCharacteristics(int characteristics) {
|
||||
Shape shape = getTestShape();
|
||||
BloomFilter inner = new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape) {
|
||||
public void testCharacteristics(final int characteristics) {
|
||||
final Shape shape = getTestShape();
|
||||
final BloomFilter inner = new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape) {
|
||||
@Override
|
||||
public int characteristics() {
|
||||
return characteristics;
|
||||
}
|
||||
};
|
||||
WrappedBloomFilter underTest = new WrappedBloomFilter(inner) {
|
||||
final WrappedBloomFilter underTest = new WrappedBloomFilter(inner) {
|
||||
@Override
|
||||
public BloomFilter copy() {
|
||||
BloomFilter result = new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape);
|
||||
final BloomFilter result = new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape);
|
||||
result.merge(this.getWrapped());
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -41,52 +41,52 @@ public class FixedOrderComparatorTest extends AbstractComparatorTest<String> {
|
|||
|
||||
@Test
|
||||
void expectFalseWhenBothComparatorsWithDifferentItems() {
|
||||
FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>(1, 2, 3);
|
||||
FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>(2, 3, 4);
|
||||
final FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>(1, 2, 3);
|
||||
final FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>(2, 3, 4);
|
||||
assertFalse(comparator1.equals(comparator2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void expectFalseWhenBothComparatorsWithDifferentUnknownObjectBehavior() {
|
||||
FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>();
|
||||
final FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>();
|
||||
comparator1.setUnknownObjectBehavior(FixedOrderComparator.UnknownObjectBehavior.BEFORE);
|
||||
FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>();
|
||||
final FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>();
|
||||
comparator2.setUnknownObjectBehavior(FixedOrderComparator.UnknownObjectBehavior.AFTER);
|
||||
assertFalse(comparator1.equals(comparator2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void expectFalseWhenFixedOrderComparatorIsComparedWithNull() {
|
||||
FixedOrderComparator<Integer> comparator = new FixedOrderComparator<>();
|
||||
final FixedOrderComparator<Integer> comparator = new FixedOrderComparator<>();
|
||||
assertFalse(comparator.equals(null));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void expectFalseWhenFixedOrderComparatorIsComparedWithOtherObject() {
|
||||
FixedOrderComparator<Integer> comparator = new FixedOrderComparator<>();
|
||||
final FixedOrderComparator<Integer> comparator = new FixedOrderComparator<>();
|
||||
assertFalse(comparator.equals(new Object()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void expectFalseWhenOneComparatorIsLocked() {
|
||||
FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>(1, 2, 3);
|
||||
FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>(1, 2, 3);
|
||||
final FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>(1, 2, 3);
|
||||
final FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>(1, 2, 3);
|
||||
comparator2.compare(1, 2);
|
||||
assertFalse(comparator1.equals(comparator2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void expectFalseWhenOneComparatorsWithDuplicateItems() {
|
||||
FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>(1, 2, 3);
|
||||
FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>(1, 2, 3, 3);
|
||||
final FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>(1, 2, 3);
|
||||
final FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>(1, 2, 3, 3);
|
||||
assertFalse(comparator1.equals(comparator2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void expectTrueWhenBothComparatorsAreLocked() {
|
||||
FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>(1, 2, 3);
|
||||
FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>(1, 2, 3);
|
||||
final FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>(1, 2, 3);
|
||||
final FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>(1, 2, 3);
|
||||
comparator1.compare(1, 2);
|
||||
comparator2.compare(1, 2);
|
||||
assertTrue(comparator1.equals(comparator2));
|
||||
|
@ -94,14 +94,14 @@ public class FixedOrderComparatorTest extends AbstractComparatorTest<String> {
|
|||
|
||||
@Test
|
||||
void expectTrueWhenBothComparatorsWithoutAnyItems() {
|
||||
FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>();
|
||||
FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>();
|
||||
final FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>();
|
||||
final FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>();
|
||||
assertTrue(comparator1.equals(comparator2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void expectTrueWhenBothObjectsAreSame() {
|
||||
FixedOrderComparator<Integer> comparator = new FixedOrderComparator<>();
|
||||
final FixedOrderComparator<Integer> comparator = new FixedOrderComparator<>();
|
||||
assertTrue(comparator.equals(comparator));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -217,7 +217,7 @@ public class DefaultAbstractLinkedListForJava21Test<E> extends AbstractListTest<
|
|||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testSubList() {
|
||||
List<E> list = makeObject();
|
||||
final List<E> list = makeObject();
|
||||
list.add((E) "A");
|
||||
list.add((E) "B");
|
||||
list.add((E) "C");
|
||||
|
@ -236,7 +236,7 @@ public class DefaultAbstractLinkedListForJava21Test<E> extends AbstractListTest<
|
|||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testSubListAddBegin() {
|
||||
List<E> list = makeObject();
|
||||
final List<E> list = makeObject();
|
||||
list.add((E) "A");
|
||||
list.add((E) "B");
|
||||
list.add((E) "C");
|
||||
|
@ -255,7 +255,7 @@ public class DefaultAbstractLinkedListForJava21Test<E> extends AbstractListTest<
|
|||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testSubListAddEnd() {
|
||||
List<E> list = makeObject();
|
||||
final List<E> list = makeObject();
|
||||
list.add((E) "A");
|
||||
list.add((E) "B");
|
||||
list.add((E) "C");
|
||||
|
@ -274,7 +274,7 @@ public class DefaultAbstractLinkedListForJava21Test<E> extends AbstractListTest<
|
|||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testSubListAddMiddle() {
|
||||
List<E> list = makeObject();
|
||||
final List<E> list = makeObject();
|
||||
list.add((E) "A");
|
||||
list.add((E) "B");
|
||||
list.add((E) "C");
|
||||
|
@ -293,7 +293,7 @@ public class DefaultAbstractLinkedListForJava21Test<E> extends AbstractListTest<
|
|||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testSubListRemove() {
|
||||
List<E> list = makeObject();
|
||||
final List<E> list = makeObject();
|
||||
list.add((E) "A");
|
||||
list.add((E) "B");
|
||||
list.add((E) "C");
|
||||
|
|
|
@ -98,7 +98,7 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||
final int cpk = getSampleCountPerKey();
|
||||
final Collection<V>[] colArr = new Collection[maxK];
|
||||
for (int i = 0; i < maxK; i++) {
|
||||
List<V> coll = new ArrayList<>(cpk);
|
||||
final List<V> coll = new ArrayList<>(cpk);
|
||||
for (int j = 0; j < cpk; j++) {
|
||||
coll.add(sampleValues[i * cpk + j]);
|
||||
}
|
||||
|
@ -934,9 +934,7 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||
public void testKeysBagIterator() {
|
||||
final MultiValuedMap<K, V> map = makeFullMap();
|
||||
final Collection<K> col = new ArrayList<>();
|
||||
for (K element : map.keys()) {
|
||||
col.add(element);
|
||||
}
|
||||
col.addAll(map.keys());
|
||||
final Bag<K> bag = new HashBag<>(col);
|
||||
final int maxK = getSampleKeySize();
|
||||
for (int k = 0; k < maxK; k++) {
|
||||
|
|
Loading…
Reference in New Issue