Use final

This commit is contained in:
Gary Gregory 2024-05-12 08:54:09 -04:00
parent b87d212629
commit de059262b9
17 changed files with 192 additions and 195 deletions

View File

@ -42,7 +42,7 @@ public interface BloomFilterProducer {
* @param filters The filters to be returned by the producer. * @param filters The filters to be returned by the producer.
* @return THe BloomFilterProducer containing the filters. * @return THe BloomFilterProducer containing the filters.
*/ */
static BloomFilterProducer fromBloomFilterArray(BloomFilter... filters) { static BloomFilterProducer fromBloomFilterArray(final BloomFilter... filters) {
Objects.requireNonNull(filters, "filters"); Objects.requireNonNull(filters, "filters");
return new BloomFilterProducer() { return new BloomFilterProducer() {
/** /**
@ -99,7 +99,7 @@ public interface BloomFilterProducer {
* @return the merged bloom filter. * @return the merged bloom filter.
*/ */
default BloomFilter flatten() { default BloomFilter flatten() {
BloomFilter[] bf = {null}; final BloomFilter[] bf = {null};
forEachBloomFilter( x -> { forEachBloomFilter( x -> {
if (bf[0] == null) { if (bf[0] == null) {
bf[0] = new SimpleBloomFilter( x.getShape()); bf[0] = new SimpleBloomFilter( x.getShape());

View File

@ -85,7 +85,7 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
* dated or stale filters. * dated or stale filters.
* @return this * @return this
*/ */
public Builder<T> setCleanup(Consumer<Deque<T>> cleanup) { public Builder<T> setCleanup(final Consumer<Deque<T>> cleanup) {
this.cleanup = cleanup; this.cleanup = cleanup;
return this; return this;
} }
@ -98,7 +98,7 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
* created. * created.
* @return this for chaining. * @return this for chaining.
*/ */
public Builder<T> setExtendCheck(Predicate<LayerManager<T>> extendCheck) { public Builder<T> setExtendCheck(final Predicate<LayerManager<T>> extendCheck) {
this.extendCheck = extendCheck; this.extendCheck = extendCheck;
return this; return this;
} }
@ -110,7 +110,7 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
* @param supplier The supplier of new Bloom filter instances. * @param supplier The supplier of new Bloom filter instances.
* @return this for chaining. * @return this for chaining.
*/ */
public Builder<T> setSupplier(Supplier<T> supplier) { public Builder<T> setSupplier(final Supplier<T> supplier) {
this.supplier = supplier; this.supplier = supplier;
return this; return this;
} }
@ -138,7 +138,7 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
* @return A Consumer suitable for the LayerManager {@code cleanup} parameter. * @return A Consumer suitable for the LayerManager {@code cleanup} parameter.
* @throws IllegalArgumentException if {@code maxSize <= 0}. * @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) { if (maxSize <= 0) {
throw new IllegalArgumentException("'maxSize' must be greater than 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. * @param test Predicate.
* @return A Consumer suitable for the LayerManager {@code cleanup} parameter. * @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); 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. * @return A Predicate suitable for the LayerManager {@code extendCheck} parameter.
* @throws IllegalArgumentException if {@code breakAt <= 0} * @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) { if (breakAt <= 0) {
throw new IllegalArgumentException("'breakAt' must be greater than 0"); throw new IllegalArgumentException("'breakAt' must be greater than 0");
} }
@ -198,7 +198,7 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
int count; int count;
@Override @Override
public boolean test(LayerManager<T> filter) { public boolean test(final LayerManager<T> filter) {
if (++count == breakAt) { if (++count == breakAt) {
count = 0; count = 0;
return true; return true;
@ -227,12 +227,12 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
* @return A Predicate suitable for the LayerManager {@code extendCheck} parameter. * @return A Predicate suitable for the LayerManager {@code extendCheck} parameter.
* @throws IllegalArgumentException if {@code maxN <= 0} * @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) { if (maxN <= 0) {
throw new IllegalArgumentException("'maxN' must be greater than 0"); throw new IllegalArgumentException("'maxN' must be greater than 0");
} }
return manager -> { return manager -> {
BloomFilter bf = manager.last(); final BloomFilter bf = manager.last();
return maxN <= bf.getShape().estimateN(bf.cardinality()); return maxN <= bf.getShape().estimateN(bf.cardinality());
}; };
} }
@ -278,8 +278,8 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
* list. * list.
* @param initialize true if the filter list should be initialized. * @param initialize true if the filter list should be initialized.
*/ */
private LayerManager(Supplier<T> filterSupplier, Predicate<LayerManager<T>> extendCheck, private LayerManager(final Supplier<T> filterSupplier, final Predicate<LayerManager<T>> extendCheck,
Consumer<Deque<T>> filterCleanup, boolean initialize) { final Consumer<Deque<T>> filterCleanup, final boolean initialize) {
this.filterSupplier = filterSupplier; this.filterSupplier = filterSupplier;
this.extendCheck = extendCheck; this.extendCheck = extendCheck;
this.filterCleanup = filterCleanup; this.filterCleanup = filterCleanup;
@ -292,7 +292,7 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
* Adds a new Bloom filter to the list. * Adds a new Bloom filter to the list.
*/ */
private void addFilter() { private void addFilter() {
T bf = filterSupplier.get(); final T bf = filterSupplier.get();
if (bf == null) { if (bf == null) {
throw new NullPointerException("filterSupplier returned 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. * @return a copy of this layer Manager.
*/ */
public LayerManager<T> copy() { public LayerManager<T> copy() {
LayerManager<T> newMgr = new LayerManager<>(filterSupplier, extendCheck, filterCleanup, false); final LayerManager<T> newMgr = new LayerManager<>(filterSupplier, extendCheck, filterCleanup, false);
for (T bf : filters) { for (final T bf : filters) {
newMgr.filters.add(bf.copy()); newMgr.filters.add(bf.copy());
} }
return newMgr; return newMgr;
@ -356,8 +356,8 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
* {@code true} if all filters pass the test. * {@code true} if all filters pass the test.
*/ */
@Override @Override
public boolean forEachBloomFilter(Predicate<BloomFilter> bloomFilterPredicate) { public boolean forEachBloomFilter(final Predicate<BloomFilter> bloomFilterPredicate) {
for (BloomFilter bf : filters) { for (final BloomFilter bf : filters) {
if (!bloomFilterPredicate.test(bf)) { if (!bloomFilterPredicate.test(bf)) {
return false; return false;
} }
@ -374,7 +374,7 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
* @throws NoSuchElementException if depth is not in the range * @throws NoSuchElementException if depth is not in the range
* [0,filters.size()) * [0,filters.size())
*/ */
public final T get(int depth) { public final T get(final int depth) {
if (depth < 0 || depth >= filters.size()) { if (depth < 0 || depth >= filters.size()) {
throw new NoSuchElementException(String.format("Depth must be in the range [0,%s)", filters.size())); throw new NoSuchElementException(String.format("Depth must be in the range [0,%s)", filters.size()));
} }

View File

@ -72,7 +72,7 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
int resultIdx; int resultIdx;
BloomFilter bf; BloomFilter bf;
Finder(BloomFilter bf) { Finder(final BloomFilter bf) {
this.bf = bf; this.bf = bf;
} }
@ -81,7 +81,7 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
} }
@Override @Override
public boolean test(BloomFilter x) { public boolean test(final BloomFilter x) {
if (x.contains(bf)) { if (x.contains(bf)) {
result[resultIdx++] = bfIdx; 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 shape the Shape of the enclosed Bloom filters
* @param layerManager the LayerManager to manage the layers. * @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.shape = shape;
this.layerManager = layerManager; this.layerManager = layerManager;
} }
@ -162,7 +162,7 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
* the {@code producer}. * the {@code producer}.
*/ */
public boolean contains(final BloomFilterProducer 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 false when we have found a match to short circuit checks
return producer.forEachBloomFilter(x -> { return producer.forEachBloomFilter(x -> {
result[0] &= contains(x); result[0] &= contains(x);
@ -176,7 +176,7 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
} }
@Override @Override
public boolean contains(IndexProducer indexProducer) { public boolean contains(final IndexProducer indexProducer) {
return contains(createFilter(indexProducer)); return contains(createFilter(indexProducer));
} }
@ -192,7 +192,7 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
* @return the BloomFilter. * @return the BloomFilter.
*/ */
private BloomFilter createFilter(final BitMapProducer bitMapProducer) { private BloomFilter createFilter(final BitMapProducer bitMapProducer) {
SimpleBloomFilter bf = new SimpleBloomFilter(shape); final SimpleBloomFilter bf = new SimpleBloomFilter(shape);
bf.merge(bitMapProducer); bf.merge(bitMapProducer);
return bf; return bf;
} }
@ -204,7 +204,7 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
* @return the BloomFilter. * @return the BloomFilter.
*/ */
private BloomFilter createFilter(final Hasher hasher) { private BloomFilter createFilter(final Hasher hasher) {
SimpleBloomFilter bf = new SimpleBloomFilter(shape); final SimpleBloomFilter bf = new SimpleBloomFilter(shape);
bf.merge(hasher); bf.merge(hasher);
return bf; return bf;
} }
@ -216,7 +216,7 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
* @return the BloomFilter. * @return the BloomFilter.
*/ */
private BloomFilter createFilter(final IndexProducer indexProducer) { private BloomFilter createFilter(final IndexProducer indexProducer) {
SimpleBloomFilter bf = new SimpleBloomFilter(shape); final SimpleBloomFilter bf = new SimpleBloomFilter(shape);
bf.merge(indexProducer); bf.merge(indexProducer);
return bf; 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. * @return an array of layer indices in which the Bloom filter is found.
*/ */
public int[] find(final BitMapProducer bitMapProducer) { public int[] find(final BitMapProducer bitMapProducer) {
SimpleBloomFilter bf = new SimpleBloomFilter(shape); final SimpleBloomFilter bf = new SimpleBloomFilter(shape);
bf.merge(bitMapProducer); bf.merge(bitMapProducer);
return find(bf); return find(bf);
} }
@ -252,8 +252,8 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
* @param bf the Bloom filter to search for. * @param bf the Bloom filter to search for.
* @return an array of layer indices in which the Bloom filter is found. * @return an array of layer indices in which the Bloom filter is found.
*/ */
public int[] find(BloomFilter bf) { public int[] find(final BloomFilter bf) {
Finder finder = new Finder(bf); final Finder finder = new Finder(bf);
forEachBloomFilter(finder); forEachBloomFilter(finder);
return finder.getResult(); 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. * @return an array of layer indices in which the Bloom filter is found.
*/ */
public int[] find(final Hasher hasher) { public int[] find(final Hasher hasher) {
SimpleBloomFilter bf = new SimpleBloomFilter(shape); final SimpleBloomFilter bf = new SimpleBloomFilter(shape);
bf.merge(hasher); bf.merge(hasher);
return find(bf); 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. * @return an array of layer indices in which the Bloom filter is found.
*/ */
public int[] find(final IndexProducer indexProducer) { public int[] find(final IndexProducer indexProducer) {
SimpleBloomFilter bf = new SimpleBloomFilter(shape); final SimpleBloomFilter bf = new SimpleBloomFilter(shape);
bf.merge(indexProducer); bf.merge(indexProducer);
return find(bf); return find(bf);
} }
@ -290,13 +290,13 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
*/ */
@Override @Override
public BloomFilter flatten() { public BloomFilter flatten() {
BloomFilter bf = new SimpleBloomFilter(shape); final BloomFilter bf = new SimpleBloomFilter(shape);
forEachBloomFilter(bf::merge); forEachBloomFilter(bf::merge);
return bf; return bf;
} }
@Override @Override
public boolean forEachBitMap(LongPredicate predicate) { public boolean forEachBitMap(final LongPredicate predicate) {
return flatten().forEachBitMap(predicate); return flatten().forEachBitMap(predicate);
} }
@ -310,12 +310,12 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
* otherwise. * otherwise.
*/ */
@Override @Override
public final boolean forEachBloomFilter(Predicate<BloomFilter> bloomFilterPredicate) { public final boolean forEachBloomFilter(final Predicate<BloomFilter> bloomFilterPredicate) {
return layerManager.forEachBloomFilter(bloomFilterPredicate); return layerManager.forEachBloomFilter(bloomFilterPredicate);
} }
@Override @Override
public boolean forEachIndex(IntPredicate predicate) { public boolean forEachIndex(final IntPredicate predicate) {
return forEachBloomFilter(bf -> bf.forEachIndex(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. * @return the Bloom filter at the specified depth.
* @throws NoSuchElementException if depth is not in the range [0,getDepth()) * @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); return layerManager.get(depth);
} }
@ -351,17 +351,17 @@ public class LayeredBloomFilter<T extends BloomFilter> implements BloomFilter, B
} }
@Override @Override
public boolean merge(BitMapProducer bitMapProducer) { public boolean merge(final BitMapProducer bitMapProducer) {
return layerManager.getTarget().merge(bitMapProducer); return layerManager.getTarget().merge(bitMapProducer);
} }
@Override @Override
public boolean merge(BloomFilter bf) { public boolean merge(final BloomFilter bf) {
return layerManager.getTarget().merge(bf); return layerManager.getTarget().merge(bf);
} }
@Override @Override
public boolean merge(IndexProducer indexProducer) { public boolean merge(final IndexProducer indexProducer) {
return layerManager.getTarget().merge(indexProducer); return layerManager.getTarget().merge(indexProducer);
} }

View File

@ -32,7 +32,7 @@ public abstract class WrappedBloomFilter implements BloomFilter {
* not a copy. Changes in one will be reflected in the other. * not a copy. Changes in one will be reflected in the other.
* @param bf The Bloom filter. * @param bf The Bloom filter.
*/ */
public WrappedBloomFilter(BloomFilter bf) { public WrappedBloomFilter(final BloomFilter bf) {
this.wrapped = bf; this.wrapped = bf;
} }
@ -62,27 +62,27 @@ public abstract class WrappedBloomFilter implements BloomFilter {
} }
@Override @Override
public boolean contains(BitMapProducer bitMapProducer) { public boolean contains(final BitMapProducer bitMapProducer) {
return wrapped.contains(bitMapProducer); return wrapped.contains(bitMapProducer);
} }
@Override @Override
public boolean contains(BloomFilter other) { public boolean contains(final BloomFilter other) {
return wrapped.contains(other); return wrapped.contains(other);
} }
@Override @Override
public boolean contains(Hasher hasher) { public boolean contains(final Hasher hasher) {
return wrapped.contains(hasher); return wrapped.contains(hasher);
} }
@Override @Override
public boolean contains(IndexProducer indexProducer) { public boolean contains(final IndexProducer indexProducer) {
return wrapped.contains(indexProducer); return wrapped.contains(indexProducer);
} }
@Override @Override
public int estimateIntersection(BloomFilter other) { public int estimateIntersection(final BloomFilter other) {
return wrapped.estimateIntersection(other); return wrapped.estimateIntersection(other);
} }
@ -92,22 +92,22 @@ public abstract class WrappedBloomFilter implements BloomFilter {
} }
@Override @Override
public int estimateUnion(BloomFilter other) { public int estimateUnion(final BloomFilter other) {
return wrapped.estimateUnion(other); return wrapped.estimateUnion(other);
} }
@Override @Override
public boolean forEachBitMap(LongPredicate predicate) { public boolean forEachBitMap(final LongPredicate predicate) {
return wrapped.forEachBitMap(predicate); return wrapped.forEachBitMap(predicate);
} }
@Override @Override
public boolean forEachBitMapPair(BitMapProducer other, LongBiPredicate func) { public boolean forEachBitMapPair(final BitMapProducer other, final LongBiPredicate func) {
return wrapped.forEachBitMapPair(other, func); return wrapped.forEachBitMapPair(other, func);
} }
@Override @Override
public boolean forEachIndex(IntPredicate predicate) { public boolean forEachIndex(final IntPredicate predicate) {
return wrapped.forEachIndex(predicate); return wrapped.forEachIndex(predicate);
} }
@ -126,22 +126,22 @@ public abstract class WrappedBloomFilter implements BloomFilter {
} }
@Override @Override
public boolean merge(BitMapProducer bitMapProducer) { public boolean merge(final BitMapProducer bitMapProducer) {
return wrapped.merge(bitMapProducer); return wrapped.merge(bitMapProducer);
} }
@Override @Override
public boolean merge(BloomFilter other) { public boolean merge(final BloomFilter other) {
return wrapped.merge(other); return wrapped.merge(other);
} }
@Override @Override
public boolean merge(Hasher hasher) { public boolean merge(final Hasher hasher) {
return wrapped.merge(hasher); return wrapped.merge(hasher);
} }
@Override @Override
public boolean merge(IndexProducer indexProducer) { public boolean merge(final IndexProducer indexProducer) {
return wrapped.merge(indexProducer); return wrapped.merge(indexProducer);
} }
} }

View File

@ -202,7 +202,7 @@ public class FixedOrderComparator<T> implements Comparator<T>, Serializable {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(final Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@ -212,7 +212,7 @@ public class FixedOrderComparator<T> implements Comparator<T>, Serializable {
if (getClass() != obj.getClass()) { if (getClass() != obj.getClass()) {
return false; 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; return counter == other.counter && isLocked == other.isLocked && Objects.equals(map, other.map) && unknownObjectBehavior == other.unknownObjectBehavior;
} }

View File

@ -27,7 +27,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
public abstract class AbstractBloomFilterProducerTest { 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 one = new SimpleBloomFilter(shape);
BloomFilter two = new SimpleBloomFilter(shape); BloomFilter two = new SimpleBloomFilter(shape);
@ -82,7 +82,7 @@ public abstract class AbstractBloomFilterProducerTest {
@Test @Test
public void testAsBloomFilterArray() { public void testAsBloomFilterArray() {
BloomFilter[] result = createUnderTest().asBloomFilterArray(); final BloomFilter[] result = createUnderTest().asBloomFilterArray();
assertEquals(2, result.length); assertEquals(2, result.length);
assertEquals(1, result[0].cardinality()); assertEquals(1, result[0].cardinality());
assertEquals(2, result[1].cardinality()); assertEquals(2, result[1].cardinality());
@ -90,8 +90,8 @@ public abstract class AbstractBloomFilterProducerTest {
@Test @Test
public void testFlatten() { public void testFlatten() {
BloomFilter underTest = createUnderTest().flatten(); final BloomFilter underTest = createUnderTest().flatten();
BloomFilter expected = new SimpleBloomFilter(shape); final BloomFilter expected = new SimpleBloomFilter(shape);
expected.merge(IndexProducer.fromIndexArray(1, 2, 3)); expected.merge(IndexProducer.fromIndexArray(1, 2, 3));
assertArrayEquals(expected.asBitMapArray(), underTest.asBitMapArray()); assertArrayEquals(expected.asBitMapArray(), underTest.asBitMapArray());
} }

View File

@ -173,7 +173,7 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
* *
* @param bf The Bloom filter to test. * @param bf The Bloom filter to test.
*/ */
protected void testCardinalityAndIsEmpty(BloomFilter bf) { protected void testCardinalityAndIsEmpty(final BloomFilter bf) {
assertTrue(bf.isEmpty()); assertTrue(bf.isEmpty());
assertEquals(0, bf.cardinality()); assertEquals(0, bf.cardinality());
for (int i = 0; i < getTestShape().getNumberOfBits(); i++) { for (int i = 0; i < getTestShape().getNumberOfBits(); i++) {
@ -243,7 +243,7 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
public void testEmptyAfterMergeWithNothing() { public void testEmptyAfterMergeWithNothing() {
// test the case where is empty after merge // test the case where is empty after merge
// in this case the internal cardinality == -1 // in this case the internal cardinality == -1
BloomFilter bf = createEmptyFilter(getTestShape()); final BloomFilter bf = createEmptyFilter(getTestShape());
bf.merge(IndexProducer.fromIndexArray()); bf.merge(IndexProducer.fromIndexArray());
assertTrue(bf.isEmpty()); assertTrue(bf.isEmpty());
} }

View File

@ -25,7 +25,7 @@ public class BitMapProducerFromWrappedBloomFilterTest extends AbstractBitMapProd
return new WrappedBloomFilter(new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape)) { return new WrappedBloomFilter(new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape)) {
@Override @Override
public BloomFilter copy() { public BloomFilter copy() {
BloomFilter result = new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape); final BloomFilter result = new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape);
result.merge(getWrapped()); result.merge(getWrapped());
return result; return result;
} }
@ -38,7 +38,7 @@ public class BitMapProducerFromWrappedBloomFilterTest extends AbstractBitMapProd
final BloomFilter bf = new WrappedBloomFilter(new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape)) { final BloomFilter bf = new WrappedBloomFilter(new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape)) {
@Override @Override
public BloomFilter copy() { public BloomFilter copy() {
BloomFilter result = new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape); final BloomFilter result = new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape);
result.merge(getWrapped()); result.merge(getWrapped());
return result; return result;
} }

View File

@ -19,7 +19,7 @@ package org.apache.commons.collections4.bloomfilter;
public class BloomFilterProducerFromBloomFilterArrayTest extends AbstractBloomFilterProducerTest{ public class BloomFilterProducerFromBloomFilterArrayTest extends AbstractBloomFilterProducerTest{
@Override @Override
protected BloomFilterProducer createUnderTest(BloomFilter... filters) { protected BloomFilterProducer createUnderTest(final BloomFilter... filters) {
return BloomFilterProducer.fromBloomFilterArray(filters); return BloomFilterProducer.fromBloomFilterArray(filters);
} }
} }

View File

@ -19,13 +19,13 @@ package org.apache.commons.collections4.bloomfilter;
public class BloomFilterProducerFromLayeredBloomFilterTest extends AbstractBloomFilterProducerTest{ public class BloomFilterProducerFromLayeredBloomFilterTest extends AbstractBloomFilterProducerTest{
@Override @Override
protected BloomFilterProducer createUnderTest(BloomFilter... filters) { protected BloomFilterProducer createUnderTest(final BloomFilter... filters) {
Shape shape = filters[0].getShape(); final Shape shape = filters[0].getShape();
LayerManager layerManager = LayerManager.builder().setSupplier( () -> new SimpleBloomFilter(shape) ) final LayerManager layerManager = LayerManager.builder().setSupplier( () -> new SimpleBloomFilter(shape) )
.setExtendCheck( LayerManager.ExtendCheck.advanceOnPopulated()) .setExtendCheck( LayerManager.ExtendCheck.advanceOnPopulated())
.setCleanup(LayerManager.Cleanup.noCleanup()).build(); .setCleanup(LayerManager.Cleanup.noCleanup()).build();
LayeredBloomFilter underTest = new LayeredBloomFilter(shape, layerManager); final LayeredBloomFilter underTest = new LayeredBloomFilter(shape, layerManager);
for (BloomFilter bf : filters) { for (final BloomFilter bf : filters) {
underTest.merge(bf); underTest.merge(bf);
} }
return underTest; return underTest;

View File

@ -29,9 +29,9 @@ import org.junit.jupiter.api.Test;
public class CountingPredicateTest { 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) -> { return (x, y) -> {
if (inner.test(x, y)) { if (inner.test(x, y)) {
result.add(Pair.of(x, y)); result.add(Pair.of(x, y));
@ -47,8 +47,8 @@ public class CountingPredicateTest {
*/ */
@Test @Test
public void testPredicateLonger() { public void testPredicateLonger() {
List<Pair<Integer, Integer>> expected = new ArrayList<>(); final List<Pair<Integer, Integer>> expected = new ArrayList<>();
List<Pair<Integer, Integer>> result = new ArrayList<>(); final List<Pair<Integer, Integer>> result = new ArrayList<>();
expected.add(Pair.of(1, 3)); expected.add(Pair.of(1, 3));
CountingPredicate<Integer> cp = new CountingPredicate<>(ary, makeFunc((x, y) -> x!=null, result)); CountingPredicate<Integer> cp = new CountingPredicate<>(ary, makeFunc((x, y) -> x!=null, result));
@ -84,11 +84,11 @@ public class CountingPredicateTest {
*/ */
@Test @Test
public void testPredicateSameLength() { public void testPredicateSameLength() {
List<Pair<Integer, Integer>> expected = new ArrayList<>(); final List<Pair<Integer, Integer>> expected = new ArrayList<>();
List<Pair<Integer, Integer>> result = new ArrayList<>(); final List<Pair<Integer, Integer>> result = new ArrayList<>();
expected.add( Pair.of(1, 3)); expected.add( Pair.of(1, 3));
expected.add( Pair.of(2, 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));
assertTrue(cp.test(3)); assertTrue(cp.test(3));
assertEquals(expected, result); assertEquals(expected, result);
@ -102,13 +102,13 @@ public class CountingPredicateTest {
*/ */
@Test @Test
public void testPredicateShorter() { public void testPredicateShorter() {
List<Pair<Integer, Integer>> expected = new ArrayList<>(); final List<Pair<Integer, Integer>> expected = new ArrayList<>();
List<Pair<Integer, Integer>> result = new ArrayList<>(); final List<Pair<Integer, Integer>> result = new ArrayList<>();
Integer[] shortAry = {Integer.valueOf(3)}; final Integer[] shortAry = {Integer.valueOf(3)};
expected.add(Pair.of(3, 1)); expected.add(Pair.of(3, 1));
expected.add(Pair.of(null, 2)); expected.add(Pair.of(null, 2));
CountingPredicate<Integer> cp = new CountingPredicate<>(shortAry, makeFunc((x, y) -> true, result)); final CountingPredicate<Integer> cp = new CountingPredicate<>(shortAry, makeFunc((x, y) -> true, result));
for (Integer i : ary) { for (final Integer i : ary) {
assertTrue(cp.test(i)); assertTrue(cp.test(i));
} }
assertEquals(expected, result); assertEquals(expected, result);

View File

@ -44,9 +44,9 @@ public class LayerManagerTest {
@ParameterizedTest @ParameterizedTest
@ValueSource(ints = {4, 10, 2, 1}) @ValueSource(ints = {4, 10, 2, 1})
public void testAdvanceOnCount(int breakAt) { public void testAdvanceOnCount(final int breakAt) {
Predicate<LayerManager<BloomFilter>> underTest = LayerManager.ExtendCheck.advanceOnCount(breakAt); final Predicate<LayerManager<BloomFilter>> underTest = LayerManager.ExtendCheck.advanceOnCount(breakAt);
LayerManager<BloomFilter> layerManager = testingBuilder().build(); final LayerManager<BloomFilter> layerManager = testingBuilder().build();
for (int i = 0; i < breakAt - 1; i++) { for (int i = 0; i < breakAt - 1; i++) {
assertFalse(underTest.test(layerManager), "at " + i); assertFalse(underTest.test(layerManager), "at " + i);
layerManager.getTarget().merge(TestingHashers.FROM1); layerManager.getTarget().merge(TestingHashers.FROM1);
@ -62,8 +62,8 @@ public class LayerManagerTest {
@Test @Test
public void testAdvanceOnPopulated() { public void testAdvanceOnPopulated() {
Predicate<LayerManager<BloomFilter>> underTest = LayerManager.ExtendCheck.advanceOnPopulated(); final Predicate<LayerManager<BloomFilter>> underTest = LayerManager.ExtendCheck.advanceOnPopulated();
LayerManager<BloomFilter> layerManager = testingBuilder().build(); final LayerManager<BloomFilter> layerManager = testingBuilder().build();
assertFalse(underTest.test(layerManager)); assertFalse(underTest.test(layerManager));
layerManager.getTarget().merge(TestingHashers.FROM1); layerManager.getTarget().merge(TestingHashers.FROM1);
assertTrue(underTest.test(layerManager)); assertTrue(underTest.test(layerManager));
@ -71,10 +71,10 @@ public class LayerManagerTest {
@Test @Test
public void testAdvanceOnSaturation() { public void testAdvanceOnSaturation() {
double maxN = shape.estimateMaxN(); final double maxN = shape.estimateMaxN();
int hashStart = 0; int hashStart = 0;
Predicate<LayerManager<BloomFilter>> underTest = LayerManager.ExtendCheck.advanceOnSaturation(maxN); final Predicate<LayerManager<BloomFilter>> underTest = LayerManager.ExtendCheck.advanceOnSaturation(maxN);
LayerManager<BloomFilter> layerManager = testingBuilder().build(); final LayerManager<BloomFilter> layerManager = testingBuilder().build();
while (layerManager.getTarget().getShape().estimateN(layerManager.getTarget().cardinality()) < maxN) { while (layerManager.getTarget().getShape().estimateN(layerManager.getTarget().cardinality()) < maxN) {
assertFalse(underTest.test(layerManager)); assertFalse(underTest.test(layerManager));
layerManager.getTarget().merge(new IncrementingHasher(hashStart, shape.getNumberOfHashFunctions())); layerManager.getTarget().merge(new IncrementingHasher(hashStart, shape.getNumberOfHashFunctions()));
@ -87,7 +87,7 @@ public class LayerManagerTest {
@Test @Test
public void testBuilder() { public void testBuilder() {
LayerManager.Builder<BloomFilter> underTest = LayerManager.builder(); final LayerManager.Builder<BloomFilter> underTest = LayerManager.builder();
NullPointerException npe = assertThrows(NullPointerException.class, underTest::build); NullPointerException npe = assertThrows(NullPointerException.class, underTest::build);
assertTrue(npe.getMessage().contains("Supplier must not be null")); assertTrue(npe.getMessage().contains("Supplier must not be null"));
underTest.setSupplier(() -> null).setCleanup(null); underTest.setSupplier(() -> null).setCleanup(null);
@ -105,7 +105,7 @@ public class LayerManagerTest {
@Test @Test
public void testClear() { 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.getTarget().merge(TestingHashers.randomHasher());
underTest.next(); underTest.next();
underTest.getTarget().merge(TestingHashers.randomHasher()); underTest.getTarget().merge(TestingHashers.randomHasher());
@ -119,7 +119,7 @@ public class LayerManagerTest {
@Test @Test
public void testCopy() { 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.getTarget().merge(TestingHashers.randomHasher());
underTest.next(); underTest.next();
underTest.getTarget().merge(TestingHashers.randomHasher()); underTest.getTarget().merge(TestingHashers.randomHasher());
@ -127,7 +127,7 @@ public class LayerManagerTest {
underTest.getTarget().merge(TestingHashers.randomHasher()); underTest.getTarget().merge(TestingHashers.randomHasher());
assertEquals(3, underTest.getDepth()); assertEquals(3, underTest.getDepth());
LayerManager<BloomFilter> copy = underTest.copy(); final LayerManager<BloomFilter> copy = underTest.copy();
assertNotSame(underTest, copy); assertNotSame(underTest, copy);
// object equals not implemented // object equals not implemented
assertNotEquals(underTest, copy); assertNotEquals(underTest, copy);
@ -139,17 +139,17 @@ public class LayerManagerTest {
@Test @Test
public void testForEachBloomFilter() { 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(); .setExtendCheck(LayerManager.ExtendCheck.advanceOnPopulated()).build();
List<BloomFilter> lst = new ArrayList<>(); final List<BloomFilter> lst = new ArrayList<>();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
BloomFilter bf = new SimpleBloomFilter(shape); final BloomFilter bf = new SimpleBloomFilter(shape);
bf.merge(TestingHashers.randomHasher()); bf.merge(TestingHashers.randomHasher());
lst.add(bf); lst.add(bf);
underTest.getTarget().merge(bf); underTest.getTarget().merge(bf);
} }
List<BloomFilter> lst2 = new ArrayList<>(); final List<BloomFilter> lst2 = new ArrayList<>();
underTest.forEachBloomFilter(lst2::add); underTest.forEachBloomFilter(lst2::add);
assertEquals(10, lst.size()); assertEquals(10, lst.size());
assertEquals(10, lst2.size()); assertEquals(10, lst2.size());
@ -160,8 +160,8 @@ public class LayerManagerTest {
@Test @Test
public void testGet() { public void testGet() {
SimpleBloomFilter f = new SimpleBloomFilter(shape); final SimpleBloomFilter f = new SimpleBloomFilter(shape);
LayerManager<BloomFilter> underTest = LayerManager.builder().setSupplier(() -> f).build(); final LayerManager<BloomFilter> underTest = LayerManager.builder().setSupplier(() -> f).build();
assertEquals(1, underTest.getDepth()); assertEquals(1, underTest.getDepth());
assertSame(f, underTest.get(0)); assertSame(f, underTest.get(0));
assertThrows(NoSuchElementException.class, () -> underTest.get(-1)); assertThrows(NoSuchElementException.class, () -> underTest.get(-1));
@ -174,8 +174,8 @@ public class LayerManagerTest {
@Test @Test
public void testNeverAdvance() { public void testNeverAdvance() {
Predicate<LayerManager<BloomFilter>> underTest = LayerManager.ExtendCheck.neverAdvance(); final Predicate<LayerManager<BloomFilter>> underTest = LayerManager.ExtendCheck.neverAdvance();
LayerManager<BloomFilter> layerManager = testingBuilder().build(); final LayerManager<BloomFilter> layerManager = testingBuilder().build();
assertFalse(underTest.test(layerManager)); assertFalse(underTest.test(layerManager));
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
layerManager.getTarget().merge(TestingHashers.randomHasher()); layerManager.getTarget().merge(TestingHashers.randomHasher());
@ -185,7 +185,7 @@ public class LayerManagerTest {
@Test @Test
public void testNextAndGetDepth() { 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()); assertEquals(1, underTest.getDepth());
underTest.getTarget().merge(TestingHashers.randomHasher()); underTest.getTarget().merge(TestingHashers.randomHasher());
assertEquals(1, underTest.getDepth()); assertEquals(1, underTest.getDepth());
@ -195,8 +195,8 @@ public class LayerManagerTest {
@Test @Test
public void testNoCleanup() { public void testNoCleanup() {
Consumer<Deque<BloomFilter>> underTest = LayerManager.Cleanup.noCleanup(); final Consumer<Deque<BloomFilter>> underTest = LayerManager.Cleanup.noCleanup();
Deque<BloomFilter> list = new LinkedList<>(); final Deque<BloomFilter> list = new LinkedList<>();
for (int i = 0; i < 20; i++) { for (int i = 0; i < 20; i++) {
assertEquals(i, list.size()); assertEquals(i, list.size());
list.add(new SimpleBloomFilter(shape)); list.add(new SimpleBloomFilter(shape));
@ -206,9 +206,9 @@ public class LayerManagerTest {
@ParameterizedTest @ParameterizedTest
@ValueSource(ints = {5, 100, 2, 1}) @ValueSource(ints = {5, 100, 2, 1})
public void testOnMaxSize(int maxSize) { public void testOnMaxSize(final int maxSize) {
Consumer<Deque<BloomFilter>> underTest = LayerManager.Cleanup.onMaxSize(maxSize); final Consumer<Deque<BloomFilter>> underTest = LayerManager.Cleanup.onMaxSize(maxSize);
LinkedList<BloomFilter> list = new LinkedList<>(); final LinkedList<BloomFilter> list = new LinkedList<>();
for (int i = 0; i < maxSize; i++) { for (int i = 0; i < maxSize; i++) {
assertEquals(i, list.size()); assertEquals(i, list.size());
list.add(new SimpleBloomFilter(shape)); list.add(new SimpleBloomFilter(shape));
@ -231,11 +231,11 @@ public class LayerManagerTest {
@Test @Test
public void testRemoveEmptyTarget() { public void testRemoveEmptyTarget() {
Consumer<Deque<BloomFilter>> underTest = LayerManager.Cleanup.removeEmptyTarget(); final Consumer<Deque<BloomFilter>> underTest = LayerManager.Cleanup.removeEmptyTarget();
LinkedList<BloomFilter> list = new LinkedList<>(); final LinkedList<BloomFilter> list = new LinkedList<>();
// removes an empty filter // removes an empty filter
BloomFilter bf = new SimpleBloomFilter(shape); final BloomFilter bf = new SimpleBloomFilter(shape);
list.add(bf); list.add(bf);
assertEquals(bf, list.get(0)); assertEquals(bf, list.get(0));
underTest.accept(list); underTest.accept(list);
@ -270,10 +270,10 @@ public class LayerManagerTest {
@Test @Test
public void testTarget() { public void testTarget() {
boolean[] extendCheckCalled = { false }; final boolean[] extendCheckCalled = { false };
boolean[] cleanupCalled = { false }; final boolean[] cleanupCalled = { false };
int[] supplierCount = { 0 }; final int[] supplierCount = { 0 };
LayerManager<BloomFilter> underTest = LayerManager.builder().setSupplier(() -> { final LayerManager<BloomFilter> underTest = LayerManager.builder().setSupplier(() -> {
supplierCount[0]++; supplierCount[0]++;
return new SimpleBloomFilter(shape); return new SimpleBloomFilter(shape);
}).setExtendCheck(lm -> { }).setExtendCheck(lm -> {

View File

@ -42,12 +42,12 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
static class AdvanceOnTimeQuanta implements Predicate<LayerManager<TimestampedBloomFilter>> { static class AdvanceOnTimeQuanta implements Predicate<LayerManager<TimestampedBloomFilter>> {
long quanta; long quanta;
AdvanceOnTimeQuanta(long quanta, TimeUnit unit) { AdvanceOnTimeQuanta(final long quanta, final TimeUnit unit) {
this.quanta = unit.toMillis(quanta); this.quanta = unit.toMillis(quanta);
} }
@Override @Override
public boolean test(LayerManager<TimestampedBloomFilter> lm) { public boolean test(final LayerManager<TimestampedBloomFilter> lm) {
// can not use getTarget() as it causes recursion. // can not use getTarget() as it causes recursion.
return lm.last().timestamp + quanta < System.currentTimeMillis(); 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>> { static class CleanByTime<T extends TimestampedBloomFilter> implements Consumer<List<T>> {
long elapsedTime; long elapsedTime;
CleanByTime(long duration, TimeUnit unit) { CleanByTime(final long duration, final TimeUnit unit) {
elapsedTime = unit.toMillis(duration); elapsedTime = unit.toMillis(duration);
} }
@Override @Override
public void accept(List<T> t) { public void accept(final List<T> t) {
long min = System.currentTimeMillis() - elapsedTime; final long min = System.currentTimeMillis() - elapsedTime;
Iterator<T> iter = t.iterator(); final Iterator<T> iter = t.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
TimestampedBloomFilter bf = iter.next(); final TimestampedBloomFilter bf = iter.next();
if (bf.getTimestamp() < min) { if (bf.getTimestamp() >= min) {
dbgInstrument.add(String.format("Removing old entry: T:%s (Aged: %s) \n", bf.getTimestamp(),
(min - bf.getTimestamp())));
iter.remove();
} else {
return; 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 { static class NumberedBloomFilter extends WrappedBloomFilter {
int value; int value;
int sequence; int sequence;
NumberedBloomFilter(Shape shape, int value, int sequence) { NumberedBloomFilter(final Shape shape, final int value, final int sequence) {
super(new SimpleBloomFilter(shape)); super(new SimpleBloomFilter(shape));
this.value = value; this.value = value;
this.sequence = sequence; this.sequence = sequence;
@ -102,12 +101,12 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
public static class TimestampedBloomFilter extends WrappedBloomFilter { public static class TimestampedBloomFilter extends WrappedBloomFilter {
final long timestamp; final long timestamp;
TimestampedBloomFilter(BloomFilter bf) { TimestampedBloomFilter(final BloomFilter bf) {
super(bf); super(bf);
this.timestamp = System.currentTimeMillis(); this.timestamp = System.currentTimeMillis();
} }
TimestampedBloomFilter(BloomFilter bf, long timestamp) { TimestampedBloomFilter(final BloomFilter bf, final long timestamp) {
super(bf); super(bf);
this.timestamp = timestamp; this.timestamp = timestamp;
} }
@ -138,11 +137,11 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
* @param qUnit the unit of time to apply to quanta. * @param qUnit the unit of time to apply to quanta.
* @return LayeredBloomFilter with the above properties. * @return LayeredBloomFilter with the above properties.
*/ */
static LayeredBloomFilter<TimestampedBloomFilter> createTimedLayeredFilter(Shape shape, long duration, TimeUnit dUnit, long quanta, static LayeredBloomFilter<TimestampedBloomFilter> createTimedLayeredFilter(final Shape shape, final long duration, final TimeUnit dUnit, final long quanta,
TimeUnit qUnit) { final TimeUnit qUnit) {
LayerManager.Builder<TimestampedBloomFilter> builder = LayerManager.builder(); final LayerManager.Builder<TimestampedBloomFilter> builder = LayerManager.builder();
Consumer<Deque<TimestampedBloomFilter>> cleanup = Cleanup.removeEmptyTarget().andThen(new CleanByTime(duration, dUnit)); final Consumer<Deque<TimestampedBloomFilter>> cleanup = Cleanup.removeEmptyTarget().andThen(new CleanByTime(duration, dUnit));
LayerManager<TimestampedBloomFilter> layerManager = builder final LayerManager<TimestampedBloomFilter> layerManager = builder
.setSupplier(() -> new TimestampedBloomFilter(new SimpleBloomFilter(shape))) .setSupplier(() -> new TimestampedBloomFilter(new SimpleBloomFilter(shape)))
.setCleanup(cleanup) .setCleanup(cleanup)
.setExtendCheck(new AdvanceOnTimeQuanta(quanta, qUnit) .setExtendCheck(new AdvanceOnTimeQuanta(quanta, qUnit)
@ -160,7 +159,7 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
* @param maxDepth The maximum depth of layers. * @param maxDepth The maximum depth of layers.
* @return An empty layered Bloom filter of the specified shape and depth. * @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)); 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. * @param supplier A supplier of the Bloom filters to create layers with.
* @return An empty layered Bloom filter of the specified shape and depth. * @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) { public static <T extends BloomFilter> LayeredBloomFilter<T> fixed(final Shape shape, final int maxDepth, final Supplier<T> supplier) {
LayerManager.Builder<T> builder = LayerManager.builder(); final LayerManager.Builder<T> builder = LayerManager.builder();
builder.setExtendCheck(LayerManager.ExtendCheck.advanceOnPopulated()) builder.setExtendCheck(LayerManager.ExtendCheck.advanceOnPopulated())
.setCleanup(LayerManager.Cleanup.onMaxSize(maxDepth)).setSupplier(supplier); .setCleanup(LayerManager.Cleanup.onMaxSize(maxDepth)).setSupplier(supplier);
return new LayeredBloomFilter<>(shape, builder.build()); return new LayeredBloomFilter<>(shape, builder.build());
} }
// instrumentation to record timestamps in dbgInstrument list // instrumentation to record timestamps in dbgInstrument list
private final Predicate<BloomFilter> dbg = (bf) -> { private final Predicate<BloomFilter> dbg = bf -> {
TimestampedBloomFilter tbf = (TimestampedBloomFilter) bf; final TimestampedBloomFilter tbf = (TimestampedBloomFilter) bf;
long ts = System.currentTimeMillis(); final long ts = System.currentTimeMillis();
dbgInstrument.add(String.format("T:%s (Elapsed:%s)- EstN:%s (Card:%s)\n", tbf.timestamp, ts - tbf.timestamp, dbgInstrument.add(String.format("T:%s (Elapsed:%s)- EstN:%s (Card:%s)\n", tbf.timestamp, ts - tbf.timestamp,
tbf.estimateN(), tbf.cardinality())); tbf.estimateN(), tbf.cardinality()));
return true; return true;
@ -192,28 +191,28 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
// *** end of instrumentation *** // *** end of instrumentation ***
@Override @Override
protected LayeredBloomFilter<BloomFilter> createEmptyFilter(Shape shape) { protected LayeredBloomFilter<BloomFilter> createEmptyFilter(final Shape shape) {
return LayeredBloomFilterTest.fixed(shape, 10); return LayeredBloomFilterTest.fixed(shape, 10);
} }
protected BloomFilter makeFilter(Hasher h) { protected BloomFilter makeFilter(final Hasher h) {
BloomFilter bf = new SparseBloomFilter(getTestShape()); final BloomFilter bf = new SparseBloomFilter(getTestShape());
bf.merge(h); bf.merge(h);
return bf; return bf;
} }
protected BloomFilter makeFilter(IndexProducer p) { protected BloomFilter makeFilter(final IndexProducer p) {
BloomFilter bf = new SparseBloomFilter(getTestShape()); final BloomFilter bf = new SparseBloomFilter(getTestShape());
bf.merge(p); bf.merge(p);
return bf; return bf;
} }
protected BloomFilter makeFilter(int... values) { protected BloomFilter makeFilter(final int... values) {
return makeFilter(IndexProducer.fromIndexArray(values)); return makeFilter(IndexProducer.fromIndexArray(values));
} }
private LayeredBloomFilter<BloomFilter> setupFindTest() { 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.FROM1);
filter.merge(TestingHashers.FROM11); filter.merge(TestingHashers.FROM11);
filter.merge(new IncrementingHasher(11, 2)); filter.merge(new IncrementingHasher(11, 2));
@ -224,7 +223,7 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
@Override @Override
@Test @Test
public void testCardinalityAndIsEmpty() { 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(); .setSupplier(() -> new SimpleBloomFilter(getTestShape())).build();
testCardinalityAndIsEmpty(new LayeredBloomFilter<>(getTestShape(), layerManager)); testCardinalityAndIsEmpty(new LayeredBloomFilter<>(getTestShape(), layerManager));
} }
@ -233,12 +232,12 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
@Test @Test
public void testCleanup() { public void testCleanup() {
int[] sequence = {1}; final int[] sequence = {1};
LayerManager layerManager = LayerManager.builder() final LayerManager layerManager = LayerManager.builder()
.setSupplier(() -> new NumberedBloomFilter(getTestShape(), 3, sequence[0]++)) .setSupplier(() -> new NumberedBloomFilter(getTestShape(), 3, sequence[0]++))
.setExtendCheck(ExtendCheck.neverAdvance()) .setExtendCheck(ExtendCheck.neverAdvance())
.setCleanup(ll -> ll.removeIf( f -> (((NumberedBloomFilter) f).value-- == 0))).build(); .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()); assertEquals(1, underTest.getDepth());
underTest.merge(TestingHashers.randomHasher()); underTest.merge(TestingHashers.randomHasher());
underTest.cleanup(); // first count == 2 underTest.cleanup(); // first count == 2
@ -281,12 +280,12 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
// purposes. // purposes.
// list of timestamps that are expected to be expired. // list of timestamps that are expected to be expired.
List<Long> lst = new ArrayList<>(); final List<Long> lst = new ArrayList<>();
Shape shape = Shape.fromNM(4, 64); final Shape shape = Shape.fromNM(4, 64);
// create a filter that removes filters that are 4 seconds old // create a filter that removes filters that are 4 seconds old
// and quantises time to 1 second intervals. // 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); TimeUnit.MILLISECONDS);
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
@ -319,7 +318,7 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
@Test @Test
public void testFindBitMapProducer() { public void testFindBitMapProducer() {
LayeredBloomFilter<BloomFilter> filter = setupFindTest(); final LayeredBloomFilter<BloomFilter> filter = setupFindTest();
IndexProducer idxProducer = TestingHashers.FROM1.indices(getTestShape()); IndexProducer idxProducer = TestingHashers.FROM1.indices(getTestShape());
BitMapProducer producer = BitMapProducer.fromIndexProducer(idxProducer, getTestShape().getNumberOfBits()); BitMapProducer producer = BitMapProducer.fromIndexProducer(idxProducer, getTestShape().getNumberOfBits());
@ -337,7 +336,7 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
@Test @Test
public void testFindBloomFilter() { public void testFindBloomFilter() {
LayeredBloomFilter<BloomFilter> filter = setupFindTest(); final LayeredBloomFilter<BloomFilter> filter = setupFindTest();
int[] expected = {0, 3}; int[] expected = {0, 3};
int[] result = filter.find(TestingHashers.FROM1); int[] result = filter.find(TestingHashers.FROM1);
assertArrayEquals(expected, result); assertArrayEquals(expected, result);
@ -349,7 +348,7 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
@Test @Test
public void testFindIndexProducer() { public void testFindIndexProducer() {
IndexProducer producer = TestingHashers.FROM1.indices(getTestShape()); IndexProducer producer = TestingHashers.FROM1.indices(getTestShape());
LayeredBloomFilter<BloomFilter> filter = setupFindTest(); final LayeredBloomFilter<BloomFilter> filter = setupFindTest();
int[] expected = {0, 3}; int[] expected = {0, 3};
int[] result = filter.find(producer); int[] result = filter.find(producer);
@ -363,9 +362,9 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
@Test @Test
public final void testGetLayer() { public final void testGetLayer() {
BloomFilter bf = new SimpleBloomFilter(getTestShape()); final BloomFilter bf = new SimpleBloomFilter(getTestShape());
bf.merge(TestingHashers.FROM11); 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.FROM1);
filter.merge(TestingHashers.FROM11); filter.merge(TestingHashers.FROM11);
filter.merge(new IncrementingHasher(11, 2)); filter.merge(new IncrementingHasher(11, 2));
@ -375,13 +374,13 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
@Test @Test
public void testMultipleFilters() { 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.FROM1);
filter.merge(TestingHashers.FROM11); filter.merge(TestingHashers.FROM11);
assertEquals(2, filter.getDepth()); assertEquals(2, filter.getDepth());
assertTrue(filter.contains(makeFilter(TestingHashers.FROM1))); assertTrue(filter.contains(makeFilter(TestingHashers.FROM1)));
assertTrue(filter.contains(makeFilter(TestingHashers.FROM11))); 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.contains(t1));
assertFalse(filter.copy().contains(t1)); assertFalse(filter.copy().contains(t1));
assertTrue(filter.flatten().contains(t1)); assertTrue(filter.flatten().contains(t1));
@ -389,10 +388,10 @@ public class LayeredBloomFilterTest extends AbstractBloomFilterTest<LayeredBloom
@Test @Test
public final void testNext() { public final void testNext() {
LayerManager<BloomFilter> layerManager = LayerManager.builder().setSupplier(() -> new SimpleBloomFilter(getTestShape())) final LayerManager<BloomFilter> layerManager = LayerManager.builder().setSupplier(() -> new SimpleBloomFilter(getTestShape()))
.build(); .build();
LayeredBloomFilter<BloomFilter> filter = new LayeredBloomFilter<>(getTestShape(), layerManager); final LayeredBloomFilter<BloomFilter> filter = new LayeredBloomFilter<>(getTestShape(), layerManager);
filter.merge(TestingHashers.FROM1); filter.merge(TestingHashers.FROM1);
filter.merge(TestingHashers.FROM11); filter.merge(TestingHashers.FROM11);
assertEquals(1, filter.getDepth()); assertEquals(1, filter.getDepth());

View File

@ -24,11 +24,11 @@ import org.junit.jupiter.params.provider.ValueSource;
public class WrappedBloomFilterTest extends AbstractBloomFilterTest<WrappedBloomFilter> { public class WrappedBloomFilterTest extends AbstractBloomFilterTest<WrappedBloomFilter> {
@Override @Override
protected WrappedBloomFilter createEmptyFilter(Shape shape) { protected WrappedBloomFilter createEmptyFilter(final Shape shape) {
return new WrappedBloomFilter(new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape)) { return new WrappedBloomFilter(new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape)) {
@Override @Override
public BloomFilter copy() { public BloomFilter copy() {
BloomFilter result = new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape); final BloomFilter result = new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape);
result.merge(this.getWrapped()); result.merge(this.getWrapped());
return result; return result;
} }
@ -37,18 +37,18 @@ public class WrappedBloomFilterTest extends AbstractBloomFilterTest<WrappedBloom
@ParameterizedTest @ParameterizedTest
@ValueSource(ints = {0, 1, 34}) @ValueSource(ints = {0, 1, 34})
public void testCharacteristics(int characteristics) { public void testCharacteristics(final int characteristics) {
Shape shape = getTestShape(); final Shape shape = getTestShape();
BloomFilter inner = new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape) { final BloomFilter inner = new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape) {
@Override @Override
public int characteristics() { public int characteristics() {
return characteristics; return characteristics;
} }
}; };
WrappedBloomFilter underTest = new WrappedBloomFilter(inner) { final WrappedBloomFilter underTest = new WrappedBloomFilter(inner) {
@Override @Override
public BloomFilter copy() { public BloomFilter copy() {
BloomFilter result = new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape); final BloomFilter result = new DefaultBloomFilterTest.SparseDefaultBloomFilter(shape);
result.merge(this.getWrapped()); result.merge(this.getWrapped());
return result; return result;
} }

View File

@ -41,52 +41,52 @@ public class FixedOrderComparatorTest extends AbstractComparatorTest<String> {
@Test @Test
void expectFalseWhenBothComparatorsWithDifferentItems() { void expectFalseWhenBothComparatorsWithDifferentItems() {
FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>(1, 2, 3); final FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>(1, 2, 3);
FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>(2, 3, 4); final FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>(2, 3, 4);
assertFalse(comparator1.equals(comparator2)); assertFalse(comparator1.equals(comparator2));
} }
@Test @Test
void expectFalseWhenBothComparatorsWithDifferentUnknownObjectBehavior() { void expectFalseWhenBothComparatorsWithDifferentUnknownObjectBehavior() {
FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>(); final FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>();
comparator1.setUnknownObjectBehavior(FixedOrderComparator.UnknownObjectBehavior.BEFORE); comparator1.setUnknownObjectBehavior(FixedOrderComparator.UnknownObjectBehavior.BEFORE);
FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>(); final FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>();
comparator2.setUnknownObjectBehavior(FixedOrderComparator.UnknownObjectBehavior.AFTER); comparator2.setUnknownObjectBehavior(FixedOrderComparator.UnknownObjectBehavior.AFTER);
assertFalse(comparator1.equals(comparator2)); assertFalse(comparator1.equals(comparator2));
} }
@Test @Test
void expectFalseWhenFixedOrderComparatorIsComparedWithNull() { void expectFalseWhenFixedOrderComparatorIsComparedWithNull() {
FixedOrderComparator<Integer> comparator = new FixedOrderComparator<>(); final FixedOrderComparator<Integer> comparator = new FixedOrderComparator<>();
assertFalse(comparator.equals(null)); assertFalse(comparator.equals(null));
} }
@Test @Test
void expectFalseWhenFixedOrderComparatorIsComparedWithOtherObject() { void expectFalseWhenFixedOrderComparatorIsComparedWithOtherObject() {
FixedOrderComparator<Integer> comparator = new FixedOrderComparator<>(); final FixedOrderComparator<Integer> comparator = new FixedOrderComparator<>();
assertFalse(comparator.equals(new Object())); assertFalse(comparator.equals(new Object()));
} }
@Test @Test
void expectFalseWhenOneComparatorIsLocked() { void expectFalseWhenOneComparatorIsLocked() {
FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>(1, 2, 3); final FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>(1, 2, 3);
FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>(1, 2, 3); final FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>(1, 2, 3);
comparator2.compare(1, 2); comparator2.compare(1, 2);
assertFalse(comparator1.equals(comparator2)); assertFalse(comparator1.equals(comparator2));
} }
@Test @Test
void expectFalseWhenOneComparatorsWithDuplicateItems() { void expectFalseWhenOneComparatorsWithDuplicateItems() {
FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>(1, 2, 3); final FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>(1, 2, 3);
FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>(1, 2, 3, 3); final FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>(1, 2, 3, 3);
assertFalse(comparator1.equals(comparator2)); assertFalse(comparator1.equals(comparator2));
} }
@Test @Test
void expectTrueWhenBothComparatorsAreLocked() { void expectTrueWhenBothComparatorsAreLocked() {
FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>(1, 2, 3); final FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>(1, 2, 3);
FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>(1, 2, 3); final FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>(1, 2, 3);
comparator1.compare(1, 2); comparator1.compare(1, 2);
comparator2.compare(1, 2); comparator2.compare(1, 2);
assertTrue(comparator1.equals(comparator2)); assertTrue(comparator1.equals(comparator2));
@ -94,14 +94,14 @@ public class FixedOrderComparatorTest extends AbstractComparatorTest<String> {
@Test @Test
void expectTrueWhenBothComparatorsWithoutAnyItems() { void expectTrueWhenBothComparatorsWithoutAnyItems() {
FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>(); final FixedOrderComparator<Integer> comparator1 = new FixedOrderComparator<>();
FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>(); final FixedOrderComparator<Integer> comparator2 = new FixedOrderComparator<>();
assertTrue(comparator1.equals(comparator2)); assertTrue(comparator1.equals(comparator2));
} }
@Test @Test
void expectTrueWhenBothObjectsAreSame() { void expectTrueWhenBothObjectsAreSame() {
FixedOrderComparator<Integer> comparator = new FixedOrderComparator<>(); final FixedOrderComparator<Integer> comparator = new FixedOrderComparator<>();
assertTrue(comparator.equals(comparator)); assertTrue(comparator.equals(comparator));
} }
} }

View File

@ -217,7 +217,7 @@ public class DefaultAbstractLinkedListForJava21Test<E> extends AbstractListTest<
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testSubList() { public void testSubList() {
List<E> list = makeObject(); final List<E> list = makeObject();
list.add((E) "A"); list.add((E) "A");
list.add((E) "B"); list.add((E) "B");
list.add((E) "C"); list.add((E) "C");
@ -236,7 +236,7 @@ public class DefaultAbstractLinkedListForJava21Test<E> extends AbstractListTest<
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testSubListAddBegin() { public void testSubListAddBegin() {
List<E> list = makeObject(); final List<E> list = makeObject();
list.add((E) "A"); list.add((E) "A");
list.add((E) "B"); list.add((E) "B");
list.add((E) "C"); list.add((E) "C");
@ -255,7 +255,7 @@ public class DefaultAbstractLinkedListForJava21Test<E> extends AbstractListTest<
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testSubListAddEnd() { public void testSubListAddEnd() {
List<E> list = makeObject(); final List<E> list = makeObject();
list.add((E) "A"); list.add((E) "A");
list.add((E) "B"); list.add((E) "B");
list.add((E) "C"); list.add((E) "C");
@ -274,7 +274,7 @@ public class DefaultAbstractLinkedListForJava21Test<E> extends AbstractListTest<
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testSubListAddMiddle() { public void testSubListAddMiddle() {
List<E> list = makeObject(); final List<E> list = makeObject();
list.add((E) "A"); list.add((E) "A");
list.add((E) "B"); list.add((E) "B");
list.add((E) "C"); list.add((E) "C");
@ -293,7 +293,7 @@ public class DefaultAbstractLinkedListForJava21Test<E> extends AbstractListTest<
@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testSubListRemove() { public void testSubListRemove() {
List<E> list = makeObject(); final List<E> list = makeObject();
list.add((E) "A"); list.add((E) "A");
list.add((E) "B"); list.add((E) "B");
list.add((E) "C"); list.add((E) "C");

View File

@ -98,7 +98,7 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
final int cpk = getSampleCountPerKey(); final int cpk = getSampleCountPerKey();
final Collection<V>[] colArr = new Collection[maxK]; final Collection<V>[] colArr = new Collection[maxK];
for (int i = 0; i < maxK; i++) { 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++) { for (int j = 0; j < cpk; j++) {
coll.add(sampleValues[i * cpk + j]); coll.add(sampleValues[i * cpk + j]);
} }
@ -934,9 +934,7 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
public void testKeysBagIterator() { public void testKeysBagIterator() {
final MultiValuedMap<K, V> map = makeFullMap(); final MultiValuedMap<K, V> map = makeFullMap();
final Collection<K> col = new ArrayList<>(); final Collection<K> col = new ArrayList<>();
for (K element : map.keys()) { col.addAll(map.keys());
col.add(element);
}
final Bag<K> bag = new HashBag<>(col); final Bag<K> bag = new HashBag<>(col);
final int maxK = getSampleKeySize(); final int maxK = getSampleKeySize();
for (int k = 0; k < maxK; k++) { for (int k = 0; k < maxK; k++) {