From 1a193e4f211dd529a280471033a410c177548515 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 26 Jan 2020 17:35:27 -0500 Subject: [PATCH] Use final. --- .../commons/collections4/CollectionUtils.java | 4 +- .../collections4/bag/UnmodifiableBag.java | 2 +- .../bag/UnmodifiableSortedBag.java | 2 +- .../bidimap/AbstractDualBidiMap.java | 2 +- .../bloomfilter/AbstractBloomFilter.java | 50 ++-- .../bloomfilter/BitSetBloomFilter.java | 20 +- .../bloomfilter/CountingBloomFilter.java | 40 ++-- .../bloomfilter/HasherBloomFilter.java | 28 +-- .../bloomfilter/SetOperations.java | 30 +-- .../bloomfilter/hasher/DynamicHasher.java | 14 +- .../hasher/HashFunctionIdentity.java | 8 +- .../hasher/HashFunctionIdentityImpl.java | 6 +- .../bloomfilter/hasher/Shape.java | 14 +- .../bloomfilter/hasher/StaticHasher.java | 12 +- .../hasher/function/MD5Cyclic.java | 6 +- .../hasher/function/Murmur128x86Cyclic.java | 2 +- .../hasher/function/Murmur32x86Iterative.java | 2 +- .../hasher/function/ObjectsHashIterative.java | 4 +- .../collection/CompositeCollection.java | 2 +- .../collections4/list/FixedSizeList.java | 2 +- .../collections4/list/SetUniqueList.java | 4 +- .../collections4/list/UnmodifiableList.java | 2 +- .../map/AbstractReferenceMap.java | 2 +- .../map/UnmodifiableEntrySet.java | 2 +- .../multiset/UnmodifiableMultiSet.java | 2 +- .../collections4/queue/UnmodifiableQueue.java | 2 +- .../collections4/set/CompositeSet.java | 2 +- .../collections4/set/MapBackedSet.java | 2 +- .../set/UnmodifiableNavigableSet.java | 2 +- .../collections4/set/UnmodifiableSet.java | 2 +- .../set/UnmodifiableSortedSet.java | 2 +- .../collections4/CollectionUtilsTest.java | 40 ++-- .../collections4/EnumerationUtilsTest.java | 2 +- .../collections4/IteratorUtilsTest.java | 76 +++--- .../commons/collections4/ListUtilsTest.java | 2 +- .../commons/collections4/SetUtilsTest.java | 24 +- .../bloomfilter/AbstractBloomFilterTest.java | 222 +++++++++--------- .../bloomfilter/BitSetBloomFilterTest.java | 24 +- .../bloomfilter/CountingBloomFilterTest.java | 126 +++++----- .../DefaultBloomFilterMethodsTest.java | 14 +- .../bloomfilter/HasherBloomFilterTest.java | 12 +- .../bloomfilter/SetOperationsTest.java | 92 ++++---- .../hasher/CommonComparatorTest.java | 30 +-- .../hasher/DeepComparatorTest.java | 30 +-- .../hasher/DynamicHasherBuilderTest.java | 24 +- .../bloomfilter/hasher/DynamicHasherTest.java | 18 +- .../hasher/HashFunctionIdentityImplTest.java | 6 +- .../bloomfilter/hasher/ShapeTest.java | 58 ++--- .../bloomfilter/hasher/StaticHasherTest.java | 86 +++---- .../hasher/function/MD5CyclicTest.java | 14 +- .../function/Murmur128x86CyclicTest.java | 14 +- .../function/Murmur32x86IterativeTest.java | 10 +- .../function/ObjectsHashIterativeTest.java | 12 +- .../collection/CompositeCollectionTest.java | 12 +- .../collections4/list/FixedSizeListTest.java | 32 +-- .../collections4/list/LazyListTest.java | 14 +- .../collections4/map/DefaultedMapTest.java | 10 +- .../collections4/map/Flat3MapTest.java | 8 +- .../collections4/map/LazySortedMapTest.java | 2 +- .../map/PredicatedSortedMapTest.java | 2 +- .../collections4/map/ReferenceMapTest.java | 4 +- .../multimap/ArrayListValuedHashMapTest.java | 22 +- .../multimap/HashSetValuedHashMapTest.java | 2 +- .../queue/UnmodifiableQueueTest.java | 6 +- 64 files changed, 662 insertions(+), 662 deletions(-) diff --git a/src/main/java/org/apache/commons/collections4/CollectionUtils.java b/src/main/java/org/apache/commons/collections4/CollectionUtils.java index 5b11291fc..c32838f8e 100644 --- a/src/main/java/org/apache/commons/collections4/CollectionUtils.java +++ b/src/main/java/org/apache/commons/collections4/CollectionUtils.java @@ -1829,8 +1829,8 @@ public class CollectionUtils { "The sum of start index and count can't be greater than the size of collection."); } - Collection result = new ArrayList<>(count); - Iterator iterator = input.iterator(); + final Collection result = new ArrayList<>(count); + final Iterator iterator = input.iterator(); while (count > 0) { if (startIndex > 0) { startIndex = startIndex - 1; diff --git a/src/main/java/org/apache/commons/collections4/bag/UnmodifiableBag.java b/src/main/java/org/apache/commons/collections4/bag/UnmodifiableBag.java index f2b900adc..e3aa3165d 100644 --- a/src/main/java/org/apache/commons/collections4/bag/UnmodifiableBag.java +++ b/src/main/java/org/apache/commons/collections4/bag/UnmodifiableBag.java @@ -135,7 +135,7 @@ public final class UnmodifiableBag * @since 4.4 */ @Override - public boolean removeIf(Predicate filter) { + public boolean removeIf(final Predicate filter) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/org/apache/commons/collections4/bag/UnmodifiableSortedBag.java b/src/main/java/org/apache/commons/collections4/bag/UnmodifiableSortedBag.java index 8103973a1..1e3ecb4fb 100644 --- a/src/main/java/org/apache/commons/collections4/bag/UnmodifiableSortedBag.java +++ b/src/main/java/org/apache/commons/collections4/bag/UnmodifiableSortedBag.java @@ -132,7 +132,7 @@ public final class UnmodifiableSortedBag * @since 4.4 */ @Override - public boolean removeIf(Predicate filter) { + public boolean removeIf(final Predicate filter) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/org/apache/commons/collections4/bidimap/AbstractDualBidiMap.java b/src/main/java/org/apache/commons/collections4/bidimap/AbstractDualBidiMap.java index ddef8f268..c8c91ad8d 100644 --- a/src/main/java/org/apache/commons/collections4/bidimap/AbstractDualBidiMap.java +++ b/src/main/java/org/apache/commons/collections4/bidimap/AbstractDualBidiMap.java @@ -377,7 +377,7 @@ public abstract class AbstractDualBidiMap implements BidiMap { * @since 4.4 */ @Override - public boolean removeIf(Predicate filter) { + public boolean removeIf(final Predicate filter) { if (parent.isEmpty() || Objects.isNull(filter)) { return false; } diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilter.java b/src/main/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilter.java index 6949f9731..5eca78d8d 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilter.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilter.java @@ -76,7 +76,7 @@ public abstract class AbstractBloomFilter implements BloomFilter { * * @param shape The shape. */ - protected AbstractBloomFilter(Shape shape) { + protected AbstractBloomFilter(final Shape shape) { this.shape = shape; } @@ -86,7 +86,7 @@ public abstract class AbstractBloomFilter implements BloomFilter { * @param other the other filter to check. * @throws IllegalArgumentException if the shapes are not the same. */ - protected void verifyShape(BloomFilter other) { + protected void verifyShape(final BloomFilter other) { verifyShape(other.getShape()); } @@ -96,7 +96,7 @@ public abstract class AbstractBloomFilter implements BloomFilter { * @param shape the other shape to check. * @throws IllegalArgumentException if the shapes are not the same. */ - protected void verifyShape(Shape shape) { + protected void verifyShape(final Shape shape) { if (!this.shape.equals(shape)) { throw new IllegalArgumentException(String.format("Shape %s is not the same as %s", shape, this.shape)); } @@ -107,7 +107,7 @@ public abstract class AbstractBloomFilter implements BloomFilter { * * @param hasher the Hasher to check */ - protected void verifyHasher(Hasher hasher) { + protected void verifyHasher(final Hasher hasher) { if (shape.getHashFunctionIdentity().getSignature() != hasher.getHashFunctionIdentity().getSignature()) { throw new IllegalArgumentException( String.format("Hasher (%s) is not the hasher for shape (%s)", @@ -163,12 +163,12 @@ public abstract class AbstractBloomFilter implements BloomFilter { * @return the cardinality of the result of {@code ( this AND other )}. */ @Override - public int andCardinality(BloomFilter other) { + public int andCardinality(final BloomFilter other) { verifyShape(other); - long[] mine = getBits(); - long[] theirs = other.getBits(); - int limit = Integer.min(mine.length, theirs.length); - long[] result = new long[limit]; + final long[] mine = getBits(); + final long[] theirs = other.getBits(); + final int limit = Integer.min(mine.length, theirs.length); + final long[] result = new long[limit]; for (int i = 0; i < limit; i++) { result[i] = mine[i] & theirs[i]; } @@ -176,10 +176,10 @@ public abstract class AbstractBloomFilter implements BloomFilter { } @Override - public int orCardinality(BloomFilter other) { + public int orCardinality(final BloomFilter other) { verifyShape(other); - long[] mine = getBits(); - long[] theirs = other.getBits(); + final long[] mine = getBits(); + final long[] theirs = other.getBits(); long[] remainder = null; long[] result = null; if (mine.length > theirs.length) { @@ -190,7 +190,7 @@ public abstract class AbstractBloomFilter implements BloomFilter { remainder = theirs; } - int limit = Integer.min(mine.length, theirs.length); + final int limit = Integer.min(mine.length, theirs.length); for (int i = 0; i < limit; i++) { result[i] = mine[i] | theirs[i]; } @@ -209,10 +209,10 @@ public abstract class AbstractBloomFilter implements BloomFilter { * @return the cardinality of the result of {@code( this XOR other )} */ @Override - public int xorCardinality(BloomFilter other) { + public int xorCardinality(final BloomFilter other) { verifyShape(other); - long[] mine = getBits(); - long[] theirs = other.getBits(); + final long[] mine = getBits(); + final long[] theirs = other.getBits(); long[] remainder = null; long[] result = null; if (mine.length > theirs.length) { @@ -223,7 +223,7 @@ public abstract class AbstractBloomFilter implements BloomFilter { remainder = theirs; } - int limit = Integer.min(mine.length, theirs.length); + final int limit = Integer.min(mine.length, theirs.length); for (int i = 0; i < limit; i++) { result[i] = mine[i] ^ theirs[i]; } @@ -241,7 +241,7 @@ public abstract class AbstractBloomFilter implements BloomFilter { * @return true if this filter matches the other. */ @Override - public boolean contains(BloomFilter other) { + public boolean contains(final BloomFilter other) { verifyShape(other); return other.cardinality() == andCardinality(other); } @@ -257,16 +257,16 @@ public abstract class AbstractBloomFilter implements BloomFilter { * this filter, or if the hasher is not the specified one */ @Override - public boolean contains(Hasher hasher) { + public boolean contains(final Hasher hasher) { verifyHasher( hasher ); - long[] buff = getBits(); + final long[] buff = getBits(); - OfInt iter = hasher.getBits(shape); + final OfInt iter = hasher.getBits(shape); while (iter.hasNext()) { - int idx = iter.nextInt(); - int buffIdx = idx / Long.SIZE; - int pwr = Math.floorMod(idx, Long.SIZE); - long buffOffset = 1L << pwr; + final int idx = iter.nextInt(); + final int buffIdx = idx / Long.SIZE; + final int pwr = Math.floorMod(idx, Long.SIZE); + final long buffOffset = 1L << pwr; if ((buff[buffIdx] & buffOffset) == 0) { return false; } diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/BitSetBloomFilter.java b/src/main/java/org/apache/commons/collections4/bloomfilter/BitSetBloomFilter.java index 63edfeeb2..a85f11ee3 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/BitSetBloomFilter.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/BitSetBloomFilter.java @@ -43,7 +43,7 @@ public class BitSetBloomFilter extends AbstractBloomFilter { * @param hasher the Hasher to use. * @param shape the desired shape of the filter. */ - public BitSetBloomFilter(Hasher hasher, Shape shape) { + public BitSetBloomFilter(final Hasher hasher, final Shape shape) { this(shape); verifyHasher(hasher); hasher.getBits(shape).forEachRemaining((IntConsumer) bitSet::set); @@ -54,7 +54,7 @@ public class BitSetBloomFilter extends AbstractBloomFilter { * * @param shape the desired shape of the filter. */ - public BitSetBloomFilter(Shape shape) { + public BitSetBloomFilter(final Shape shape) { super(shape); this.bitSet = new BitSet(); } @@ -70,7 +70,7 @@ public class BitSetBloomFilter extends AbstractBloomFilter { } @Override - public void merge(BloomFilter other) { + public void merge(final BloomFilter other) { verifyShape(other); if (other instanceof BitSetBloomFilter) { bitSet.or(((BitSetBloomFilter)other).bitSet); @@ -80,9 +80,9 @@ public class BitSetBloomFilter extends AbstractBloomFilter { } @Override - public boolean contains(Hasher hasher) { + public boolean contains(final Hasher hasher) { verifyHasher(hasher); - OfInt iter = hasher.getBits(getShape()); + final OfInt iter = hasher.getBits(getShape()); while (iter.hasNext()) { if (!bitSet.get(iter.nextInt())) { return false; @@ -103,7 +103,7 @@ public class BitSetBloomFilter extends AbstractBloomFilter { @Override - public void merge(Hasher hasher) { + public void merge(final Hasher hasher) { verifyHasher(hasher); hasher.getBits(getShape()).forEachRemaining((IntConsumer) bitSet::set); } @@ -117,10 +117,10 @@ public class BitSetBloomFilter extends AbstractBloomFilter { * @see #andCardinality(BloomFilter) */ @Override - public int andCardinality(BloomFilter other) { + public int andCardinality(final BloomFilter other) { if (other instanceof BitSetBloomFilter) { verifyShape(other); - BitSet result = (BitSet) bitSet.clone(); + final BitSet result = (BitSet) bitSet.clone(); result.and(((BitSetBloomFilter)other).bitSet); return result.cardinality(); } @@ -129,10 +129,10 @@ public class BitSetBloomFilter extends AbstractBloomFilter { @Override - public int xorCardinality(BloomFilter other) { + public int xorCardinality(final BloomFilter other) { if (other instanceof BitSetBloomFilter) { verifyShape(other); - BitSet result = (BitSet) bitSet.clone(); + final BitSet result = (BitSet) bitSet.clone(); result.xor(((BitSetBloomFilter)other).bitSet); return result.cardinality(); } diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilter.java b/src/main/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilter.java index c4dceb11f..644b6a8eb 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilter.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilter.java @@ -58,11 +58,11 @@ public class CountingBloomFilter extends AbstractBloomFilter { * @param hasher The hasher to build the filter from. * @param shape The shape of the resulting filter. */ - public CountingBloomFilter(Hasher hasher, Shape shape) { + public CountingBloomFilter(final Hasher hasher, final Shape shape) { super(shape); verifyHasher(hasher); counts = new TreeMap<>(); - Set idxs = new HashSet<>(); + final Set idxs = new HashSet<>(); hasher.getBits(shape).forEachRemaining((IntConsumer) idxs::add); idxs.stream().forEach(idx -> counts.put(idx, 1)); } @@ -72,7 +72,7 @@ public class CountingBloomFilter extends AbstractBloomFilter { * * @param shape The shape of the resulting filter. */ - public CountingBloomFilter(Shape shape) { + public CountingBloomFilter(final Shape shape) { super(shape); this.counts = new TreeMap<>(); } @@ -83,7 +83,7 @@ public class CountingBloomFilter extends AbstractBloomFilter { * @param counts A map of data counts. * @param shape The shape of the resulting filter. */ - public CountingBloomFilter(Map counts, Shape shape) { + public CountingBloomFilter(final Map counts, final Shape shape) { this(shape); counts.entrySet().stream().forEach( e -> { if (e.getKey() >= shape.getNumberOfBits()) @@ -116,8 +116,8 @@ public class CountingBloomFilter extends AbstractBloomFilter { @Override public String toString() { - StringBuilder sb = new StringBuilder("{ "); - for (Map.Entry e : counts.entrySet()) { + final StringBuilder sb = new StringBuilder("{ "); + for (final Map.Entry e : counts.entrySet()) { sb.append(String.format("(%s,%s) ", e.getKey(), e.getValue())); } return sb.append("}").toString(); @@ -135,7 +135,7 @@ public class CountingBloomFilter extends AbstractBloomFilter { * @param other the other filter. */ @Override - public void merge(BloomFilter other) { + public void merge(final BloomFilter other) { verifyShape(other); if (other instanceof CountingBloomFilter) { @@ -146,7 +146,7 @@ public class CountingBloomFilter extends AbstractBloomFilter { } @Override - public void merge(Hasher hasher) { + public void merge(final Hasher hasher) { verifyHasher( hasher ); merge( hasher.getBits(getShape()) ); } @@ -155,9 +155,9 @@ public class CountingBloomFilter extends AbstractBloomFilter { * Merge an iterator of set bits into this filter. * @param iter the iterator of bits to set. */ - private void merge(Iterator iter) { + private void merge(final Iterator iter) { iter.forEachRemaining(idx -> { - Integer val = counts.get(idx); + final Integer val = counts.get(idx); if (val == null) { counts.put(idx, 1 ); } else if (val == Integer.MAX_VALUE) { @@ -178,7 +178,7 @@ public class CountingBloomFilter extends AbstractBloomFilter { * * @param other the other filter. */ - public void remove(BloomFilter other) { + public void remove(final BloomFilter other) { verifyShape(other); if (other instanceof CountingBloomFilter) { @@ -198,9 +198,9 @@ public class CountingBloomFilter extends AbstractBloomFilter { * * @param hasher the hasher to generate bits. */ - public void remove(Hasher hasher) { + public void remove(final Hasher hasher) { verifyHasher( hasher ); - Set lst = new HashSet<>(); + final Set lst = new HashSet<>(); hasher.getBits(getShape()).forEachRemaining( (Consumer)lst::add ); remove(lst.stream()); } @@ -210,9 +210,9 @@ public class CountingBloomFilter extends AbstractBloomFilter { * * @param idxStream The stream of bit counts to decrement. */ - private void remove(Stream idxStream) { + private void remove(final Stream idxStream) { idxStream.forEach(idx -> { - Integer val = counts.get(idx); + final Integer val = counts.get(idx); if (val != null) { if (val - 1 == 0) { counts.remove(idx); @@ -232,7 +232,7 @@ public class CountingBloomFilter extends AbstractBloomFilter { @Override public long[] getBits() { - BitSet bs = new BitSet(); + final BitSet bs = new BitSet(); counts.keySet().stream().forEach(bs::set); return bs.toLongArray(); } @@ -243,9 +243,9 @@ public class CountingBloomFilter extends AbstractBloomFilter { } @Override - public boolean contains(Hasher hasher) { + public boolean contains(final Hasher hasher) { verifyHasher(hasher); - OfInt iter = hasher.getBits(getShape()); + final OfInt iter = hasher.getBits(getShape()); while (iter.hasNext()) { if (counts.get(iter.nextInt()) == null) { return false; @@ -260,9 +260,9 @@ public class CountingBloomFilter extends AbstractBloomFilter { } @Override - public int andCardinality(BloomFilter other) { + public int andCardinality(final BloomFilter other) { if (other instanceof CountingBloomFilter) { - Set result = new HashSet<>( counts.keySet()); + final Set result = new HashSet<>( counts.keySet()); result.retainAll( ((CountingBloomFilter)other).counts.keySet() ); return result.size(); } diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/HasherBloomFilter.java b/src/main/java/org/apache/commons/collections4/bloomfilter/HasherBloomFilter.java index 3c0fb8c31..e78b13e3a 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/HasherBloomFilter.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/HasherBloomFilter.java @@ -49,7 +49,7 @@ public class HasherBloomFilter extends AbstractBloomFilter { * @param hasher the hasher to use. * @param shape the shape of the Bloom filter. */ - public HasherBloomFilter(Hasher hasher, Shape shape) { + public HasherBloomFilter(final Hasher hasher, final Shape shape) { super(shape); verifyHasher(hasher); if (hasher instanceof StaticHasher) { @@ -65,7 +65,7 @@ public class HasherBloomFilter extends AbstractBloomFilter { * * @param shape the shape of the Bloom filter. */ - public HasherBloomFilter(Shape shape) { + public HasherBloomFilter(final Shape shape) { super(shape); this.hasher = new StaticHasher(EmptyIterator.emptyIterator(), shape); } @@ -75,13 +75,13 @@ public class HasherBloomFilter extends AbstractBloomFilter { if (hasher.size() == 0) { return new long[0]; } - int n = (int) Math.ceil(hasher.getShape().getNumberOfBits() * 1.0 / Long.SIZE); - long[] result = new long[n]; - OfInt iter = hasher.getBits(hasher.getShape()); + final int n = (int) Math.ceil(hasher.getShape().getNumberOfBits() * 1.0 / Long.SIZE); + final long[] result = new long[n]; + final OfInt iter = hasher.getBits(hasher.getShape()); iter.forEachRemaining((IntConsumer) idx -> { long buff = result[idx / Long.SIZE]; - long pwr = Math.floorMod(idx, Long.SIZE); - long buffOffset = 1L << pwr; + final long pwr = Math.floorMod(idx, Long.SIZE); + final long buffOffset = 1L << pwr; buff |= buffOffset; result[idx / Long.SIZE] = buff; }); @@ -105,14 +105,14 @@ public class HasherBloomFilter extends AbstractBloomFilter { } @Override - public void merge(BloomFilter other) { + public void merge(final BloomFilter other) { merge(other.getHasher()); } @Override - public void merge(Hasher hasher) { + public void merge(final Hasher hasher) { verifyHasher(hasher); - IteratorChain iter = new IteratorChain<>(this.hasher.getBits(getShape()), + final IteratorChain iter = new IteratorChain<>(this.hasher.getBits(getShape()), hasher.getBits(getShape())); this.hasher = new StaticHasher(iter, getShape()); } @@ -123,15 +123,15 @@ public class HasherBloomFilter extends AbstractBloomFilter { } @Override - public boolean contains(Hasher hasher) { + public boolean contains(final Hasher hasher) { verifyHasher(hasher); - Set set = new TreeSet<>(); + final Set set = new TreeSet<>(); hasher.getBits(getShape()).forEachRemaining((IntConsumer) idx -> { set.add(idx); }); - OfInt iter = this.hasher.getBits(getShape()); + final OfInt iter = this.hasher.getBits(getShape()); while (iter.hasNext()) { - int idx = iter.nextInt(); + final int idx = iter.nextInt(); set.remove(idx); if (set.isEmpty()) { return true; diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/SetOperations.java b/src/main/java/org/apache/commons/collections4/bloomfilter/SetOperations.java index a31bbb16f..d823a931e 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/SetOperations.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/SetOperations.java @@ -37,7 +37,7 @@ public final class SetOperations { * @param second the second filter to check. * @throws IllegalArgumentException if the shapes are not the same. */ - private static void verifyShape(BloomFilter first, BloomFilter second) { + private static void verifyShape(final BloomFilter first, final BloomFilter second) { if (!first.getShape().equals(second.getShape())) { throw new IllegalArgumentException(String.format("Shape %s is not the same as %s", first.getShape(), second.getShape())); @@ -51,7 +51,7 @@ public final class SetOperations { * @param second the second Bloom filter. * @return the Hamming distance. */ - public static int hammingDistance(BloomFilter first, BloomFilter second) { + public static int hammingDistance(final BloomFilter first, final BloomFilter second) { verifyShape(first,second); return first.xorCardinality(second); } @@ -66,9 +66,9 @@ public final class SetOperations { * @param second the second Bloom filter. * @return the Jaccard similarity. */ - public static double jaccardSimilarity(BloomFilter first, BloomFilter second) { + public static double jaccardSimilarity(final BloomFilter first, final BloomFilter second) { verifyShape(first,second); - int orCard = first.orCardinality(second); + final int orCard = first.orCardinality(second); // if the orCard is zero then the hamming distance will also be zero. return orCard==0?0:hammingDistance(first,second) / (double) orCard; } @@ -82,7 +82,7 @@ public final class SetOperations { * @param second the second Bloom filter. * @return the Jaccard distance. */ - public static double jaccardDistance(BloomFilter first, BloomFilter second) { + public static double jaccardDistance(final BloomFilter first, final BloomFilter second) { return 1.0 - jaccardSimilarity(first,second); } @@ -97,9 +97,9 @@ public final class SetOperations { * @param second the second Bloom filter. * @return the Cosine similarity. */ - public static double cosineSimilarity(BloomFilter first, BloomFilter second) { + public static double cosineSimilarity(final BloomFilter first, final BloomFilter second) { verifyShape(first,second); - int numerator = first.andCardinality(second); + final int numerator = first.andCardinality(second); return numerator==0?0:numerator / (Math.sqrt(first.cardinality()) * Math.sqrt(second.cardinality())); } @@ -113,7 +113,7 @@ public final class SetOperations { * @param second the second Bloom filter. * @return the jaccard distance. */ - public static double cosineDistance(BloomFilter first, BloomFilter second) { + public static double cosineDistance(final BloomFilter first, final BloomFilter second) { return 1.0 - cosineSimilarity(first,second); } @@ -124,9 +124,9 @@ public final class SetOperations { * @param filter the Bloom filter to estimate size for. * @return an estimate of the number of items that were placed in the Bloom filter. */ - public static long estimateSize(BloomFilter filter) { - Shape shape = filter.getShape(); - double estimate = -(shape.getNumberOfBits() * + public static long estimateSize(final BloomFilter filter) { + final Shape shape = filter.getShape(); + final double estimate = -(shape.getNumberOfBits() * Math.log(1.0 - filter.cardinality() * 1.0 / shape.getNumberOfBits())) / shape.getNumberOfHashFunctions(); return Math.round(estimate); @@ -140,10 +140,10 @@ public final class SetOperations { * @param second the second Bloom filter. * @return an estimate of the size of the union between the two filters. */ - public static long estimateUnionSize(BloomFilter first, BloomFilter second) { + public static long estimateUnionSize(final BloomFilter first, final BloomFilter second) { verifyShape(first,second); - Shape shape = first.getShape(); - double estimate = -(shape.getNumberOfBits() * + final Shape shape = first.getShape(); + final double estimate = -(shape.getNumberOfBits() * Math.log(1.0 - first.orCardinality(second) * 1.0 / shape.getNumberOfBits())) / shape.getNumberOfHashFunctions(); return Math.round(estimate); @@ -157,7 +157,7 @@ public final class SetOperations { * @param second the second Bloom filter. * @return an estimate of the size of the intersection between the two filters. */ - public static long estimateIntersectionSize(BloomFilter first, BloomFilter second) { + public static long estimateIntersectionSize(final BloomFilter first, final BloomFilter second) { verifyShape(first,second); // do subtraction early to avoid Long overflow. return estimateSize(first) - estimateUnionSize(first,second) + estimateSize(second); diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/DynamicHasher.java b/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/DynamicHasher.java index 7c08978a8..a4f943cda 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/DynamicHasher.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/DynamicHasher.java @@ -45,7 +45,7 @@ public class DynamicHasher implements Hasher { * @param function the function to use. * @param buffers the byte buffers that will be hashed. */ - public DynamicHasher(HashFunction function, List buffers) { + public DynamicHasher(final HashFunction function, final List buffers) { this.buffers = new ArrayList<>(buffers); this.function = function; } @@ -71,7 +71,7 @@ public class DynamicHasher implements Hasher { * {@code getName()} */ @Override - public PrimitiveIterator.OfInt getBits(Shape shape) { + public PrimitiveIterator.OfInt getBits(final Shape shape) { if (HashFunctionIdentity.COMMON_COMPARATOR.compare(getHashFunctionIdentity(), shape.getHashFunctionIdentity()) != 0) { throw new IllegalArgumentException( @@ -95,7 +95,7 @@ public class DynamicHasher implements Hasher { * * @param shape */ - private Iterator(Shape shape) { + private Iterator(final Shape shape) { this.shape = shape; } @@ -141,7 +141,7 @@ public class DynamicHasher implements Hasher { * * @param function the function implementation. */ - public Builder(HashFunction function) { + public Builder(final HashFunction function) { this.function = function; this.buffers = new ArrayList<>(); @@ -158,18 +158,18 @@ public class DynamicHasher implements Hasher { } @Override - public final Builder with(byte property) { + public final Builder with(final byte property) { return with(new byte[] {property}); } @Override - public final Builder with(byte[] property) { + public final Builder with(final byte[] property) { buffers.add(property); return this; } @Override - public final Builder with(String property) { + public final Builder with(final String property) { return with(property.getBytes(StandardCharsets.UTF_8)); } diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/HashFunctionIdentity.java b/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/HashFunctionIdentity.java index 4a2035f63..84e5d1a0a 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/HashFunctionIdentity.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/HashFunctionIdentity.java @@ -35,7 +35,7 @@ public interface HashFunctionIdentity { Comparator COMMON_COMPARATOR = new Comparator() { @Override - public int compare(HashFunctionIdentity identity1, HashFunctionIdentity identity2) { + public int compare(final HashFunctionIdentity identity1, final HashFunctionIdentity identity2) { int result = identity1.getName().compareToIgnoreCase(identity2.getName()); if (result == 0) { result = identity1.getSignedness().compareTo(identity2.getSignedness()); @@ -54,7 +54,7 @@ public interface HashFunctionIdentity { Comparator DEEP_COMPARATOR = new Comparator() { @Override - public int compare(HashFunctionIdentity identity1, HashFunctionIdentity identity2) { + public int compare(final HashFunctionIdentity identity1, final HashFunctionIdentity identity2) { int result = COMMON_COMPARATOR.compare(identity1, identity2); if (result == 0) { result = identity1.getProvider().compareToIgnoreCase(identity2.getProvider()); @@ -69,7 +69,7 @@ public interface HashFunctionIdentity { * @param identity the identity to format. * @return the String representing the identity. */ - static String asCommonString(HashFunctionIdentity identity) { + static String asCommonString(final HashFunctionIdentity identity) { return String.format("%s-%s-%s", identity.getName(), identity.getSignedness(), identity.getProcessType()); } @@ -85,7 +85,7 @@ public interface HashFunctionIdentity { * @param identity The HashFunctionIdentity to create the buffer for. * @return the signature buffer for the identity */ - static byte[] prepareSignatureBuffer(HashFunctionIdentity identity) { + static byte[] prepareSignatureBuffer(final HashFunctionIdentity identity) { return String.format( "%s-%s-%s", identity.getName().toUpperCase(Locale.ROOT), identity.getSignedness(), diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/HashFunctionIdentityImpl.java b/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/HashFunctionIdentityImpl.java index 1d2124b7e..17e9ab2c3 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/HashFunctionIdentityImpl.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/HashFunctionIdentityImpl.java @@ -35,7 +35,7 @@ public final class HashFunctionIdentityImpl implements HashFunctionIdentity { * Creates a copy of the HashFunctionIdentity. * @param identity the identity to copy. */ - public HashFunctionIdentityImpl( HashFunctionIdentity identity) { + public HashFunctionIdentityImpl( final HashFunctionIdentity identity) { this.name = identity.getName(); this.provider = identity.getProvider(); this.signedness = identity.getSignedness(); @@ -51,8 +51,8 @@ public final class HashFunctionIdentityImpl implements HashFunctionIdentity { * @param process the processes of the hash function. * @param signature the signature for the hash function. */ - public HashFunctionIdentityImpl( String provider, String name, Signedness signedness, ProcessType process, - long signature) { + public HashFunctionIdentityImpl( final String provider, final String name, final Signedness signedness, final ProcessType process, + final long signature) { this.name = name; this.provider = provider; this.signedness = signedness; diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/Shape.java b/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/Shape.java index 041078ed8..a4968f464 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/Shape.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/Shape.java @@ -89,7 +89,7 @@ public class Shape { * @param probability The desired probability of duplicates. Must be in the range * (0.0,1.0). */ - public Shape(HashFunctionIdentity hashFunctionIdentity, final int numberOfItems, final double probability) { + public Shape(final HashFunctionIdentity hashFunctionIdentity, final int numberOfItems, final double probability) { if (hashFunctionIdentity == null) { throw new IllegalArgumentException("Hash function identity may not be null"); } @@ -213,7 +213,7 @@ public class Shape { this.numberOfHashFunctions = numberOfHashFunctions; // n = ceil(m / (-k / log(1 - exp(log(p) / k)))) - double n = Math.ceil(numberOfBits / + final double n = Math.ceil(numberOfBits / (-numberOfHashFunctions / Math.log(1 - Math.exp(Math.log(probability) / numberOfHashFunctions)))); // log of probability is always < 0 @@ -251,12 +251,12 @@ public class Shape { * @param numberOfBits the number of bits in the filter. * @return the optimal number of hash functions. */ - private int calculateNumberOfHashFunctions(int numberOfItems, int numberOfBits) { + private int calculateNumberOfHashFunctions(final int numberOfItems, final int numberOfBits) { /* * k = round((m / n) * log(2)) We change order so that we use real math rather * than integer math. */ - long k = Math.round(LOG_OF_2 * numberOfBits / numberOfItems); + final long k = Math.round(LOG_OF_2 * numberOfBits / numberOfItems); if (k < 1) { throw new IllegalArgumentException( String.format("Filter to small: Calculated number of hash functions (%s) was less than 1", k)); @@ -279,7 +279,7 @@ public class Shape { */ public final double getProbability() { // (1 - exp(-kn/m))^k - double p = Math.pow(1.0 - Math.exp(-1.0 * numberOfHashFunctions * numberOfItems / numberOfBits), + final double p = Math.pow(1.0 - Math.exp(-1.0 * numberOfHashFunctions * numberOfItems / numberOfBits), numberOfHashFunctions); /* * We do not need to check for p < = since we only allow positive values for @@ -331,9 +331,9 @@ public class Shape { } @Override - public boolean equals(Object o) { + public boolean equals(final Object o) { if (o instanceof Shape) { - Shape other = (Shape) o; + final Shape other = (Shape) o; return other.getNumberOfBits() == getNumberOfBits() && other.getNumberOfHashFunctions() == getNumberOfHashFunctions() && diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/StaticHasher.java b/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/StaticHasher.java index b14cf4095..50bd3b80a 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/StaticHasher.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/StaticHasher.java @@ -45,7 +45,7 @@ public final class StaticHasher implements Hasher { * @param shape the Shape for the resulting values. * @throws IllegalArgumentException if the shape of the hasher and the shape parameter are not the same. */ - public StaticHasher(StaticHasher hasher, Shape shape) { + public StaticHasher(final StaticHasher hasher, final Shape shape) { if (!hasher.shape.equals(shape)) { throw new IllegalArgumentException(String.format("Hasher shape (%s) is not the same as shape (%s)", hasher.getShape().toString(), shape.toString())); @@ -60,7 +60,7 @@ public final class StaticHasher implements Hasher { * @param shape the Shape for the resulting values. * @throws IllegalArgumentException if the hasher function and the shape function are not the same. */ - public StaticHasher(Hasher hasher, Shape shape) { + public StaticHasher(final Hasher hasher, final Shape shape) { this( hasher.getBits(shape), shape); if ( HashFunctionIdentity.COMMON_COMPARATOR.compare( @@ -77,9 +77,9 @@ public final class StaticHasher implements Hasher { * @param shape the Shape that the integers were generated for. * @throws IllegalArgumentException if any Integer is outside the range [0,shape.getNumberOfBits()) */ - public StaticHasher(Iterator iter, Shape shape) { + public StaticHasher(final Iterator iter, final Shape shape) { this.shape = shape; - Set workingValues = new TreeSet<>(); + final Set workingValues = new TreeSet<>(); iter.forEachRemaining( idx -> { if (idx >= this.shape.getNumberOfBits()) { @@ -92,7 +92,7 @@ public final class StaticHasher implements Hasher { }); this.values = new int[workingValues.size()]; int i=0; - for (Integer value : workingValues) + for (final Integer value : workingValues) { values[i++] = value.intValue(); } @@ -136,7 +136,7 @@ public final class StaticHasher implements Hasher { * equal {@code getName()} */ @Override - public OfInt getBits(Shape shape) { + public OfInt getBits(final Shape shape) { if (!this.shape.equals(shape)) { throw new IllegalArgumentException( String.format("shape (%s) does not match internal shape (%s)", shape, this.shape)); diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/function/MD5Cyclic.java b/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/function/MD5Cyclic.java index 58ca68eb3..5a390a496 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/function/MD5Cyclic.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/function/MD5Cyclic.java @@ -58,14 +58,14 @@ public final class MD5Cyclic implements HashFunction { public MD5Cyclic() { try { messageDigest = MessageDigest.getInstance(NAME); - } catch (NoSuchAlgorithmException e) { + } catch (final NoSuchAlgorithmException e) { throw new IllegalStateException( e.getMessage() ); } signature = apply( HashFunctionIdentity.prepareSignatureBuffer(this), 0); } @Override - public long apply(byte[] buffer, int seed) { + public long apply(final byte[] buffer, final int seed) { if (seed == 0) { byte[] hash; @@ -75,7 +75,7 @@ public final class MD5Cyclic implements HashFunction { messageDigest.reset(); } - LongBuffer lb = ByteBuffer.wrap(hash).asLongBuffer(); + final LongBuffer lb = ByteBuffer.wrap(hash).asLongBuffer(); result[0] = lb.get(0); result[1] = lb.get(1); } else { diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/function/Murmur128x86Cyclic.java b/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/function/Murmur128x86Cyclic.java index 300ba4869..d922afac6 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/function/Murmur128x86Cyclic.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/function/Murmur128x86Cyclic.java @@ -54,7 +54,7 @@ public final class Murmur128x86Cyclic implements HashFunction { @Override - public long apply(byte[] buffer, int seed) { + public long apply(final byte[] buffer, final int seed) { if (parts == null || seed == 0) { parts = MurmurHash3.hash128x64(buffer, 0, buffer.length, 0); } else { diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/function/Murmur32x86Iterative.java b/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/function/Murmur32x86Iterative.java index 886fd0850..868d4eaae 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/function/Murmur32x86Iterative.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/function/Murmur32x86Iterative.java @@ -49,7 +49,7 @@ public final class Murmur32x86Iterative implements HashFunction { } @Override - public long apply(byte[] buffer, int seed) { + public long apply(final byte[] buffer, final int seed) { return MurmurHash3.hash32x86(buffer, 0, buffer.length, seed); } diff --git a/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/function/ObjectsHashIterative.java b/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/function/ObjectsHashIterative.java index fe756ee4d..788c32a42 100644 --- a/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/function/ObjectsHashIterative.java +++ b/src/main/java/org/apache/commons/collections4/bloomfilter/hasher/function/ObjectsHashIterative.java @@ -57,11 +57,11 @@ public final class ObjectsHashIterative implements HashFunction { } @Override - public long apply(byte[] buffer, int seed) { + public long apply(final byte[] buffer, final int seed) { if (seed == 0) { last = 0; } - long result = Arrays.deepHashCode( new Object[] {last, buffer}); + final long result = Arrays.deepHashCode( new Object[] {last, buffer}); last += result; return result; } diff --git a/src/main/java/org/apache/commons/collections4/collection/CompositeCollection.java b/src/main/java/org/apache/commons/collections4/collection/CompositeCollection.java index 4e6b5759b..cd6d4feea 100644 --- a/src/main/java/org/apache/commons/collections4/collection/CompositeCollection.java +++ b/src/main/java/org/apache/commons/collections4/collection/CompositeCollection.java @@ -415,7 +415,7 @@ public class CompositeCollection implements Collection, Serializable { * @param compositeCollections the Collections to be appended to the composite */ public void addComposited(final Collection... compositeCollections) { - for (Collection compositeCollection : compositeCollections) { + for (final Collection compositeCollection : compositeCollections) { if (compositeCollection != null) { all.add(compositeCollection); } diff --git a/src/main/java/org/apache/commons/collections4/list/FixedSizeList.java b/src/main/java/org/apache/commons/collections4/list/FixedSizeList.java index 9a87de889..6a8170b48 100644 --- a/src/main/java/org/apache/commons/collections4/list/FixedSizeList.java +++ b/src/main/java/org/apache/commons/collections4/list/FixedSizeList.java @@ -146,7 +146,7 @@ public class FixedSizeList * @since 4.4 */ @Override - public boolean removeIf(Predicate filter) { + public boolean removeIf(final Predicate filter) { throw unsupportedOperationException(); } diff --git a/src/main/java/org/apache/commons/collections4/list/SetUniqueList.java b/src/main/java/org/apache/commons/collections4/list/SetUniqueList.java index ac5a2777f..2af4ac34d 100644 --- a/src/main/java/org/apache/commons/collections4/list/SetUniqueList.java +++ b/src/main/java/org/apache/commons/collections4/list/SetUniqueList.java @@ -246,8 +246,8 @@ public class SetUniqueList extends AbstractSerializableListDecorator { * @since 4.4 */ @Override - public boolean removeIf(Predicate filter) { - boolean result = super.removeIf(filter); + public boolean removeIf(final Predicate filter) { + final boolean result = super.removeIf(filter); set.removeIf(filter); return result; } diff --git a/src/main/java/org/apache/commons/collections4/list/UnmodifiableList.java b/src/main/java/org/apache/commons/collections4/list/UnmodifiableList.java index 09695eaf2..b1fadb61f 100644 --- a/src/main/java/org/apache/commons/collections4/list/UnmodifiableList.java +++ b/src/main/java/org/apache/commons/collections4/list/UnmodifiableList.java @@ -104,7 +104,7 @@ public final class UnmodifiableList * @since 4.4 */ @Override - public boolean removeIf(Predicate filter) { + public boolean removeIf(final Predicate filter) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/org/apache/commons/collections4/map/AbstractReferenceMap.java b/src/main/java/org/apache/commons/collections4/map/AbstractReferenceMap.java index 794c535cc..e422756de 100644 --- a/src/main/java/org/apache/commons/collections4/map/AbstractReferenceMap.java +++ b/src/main/java/org/apache/commons/collections4/map/AbstractReferenceMap.java @@ -405,7 +405,7 @@ public abstract class AbstractReferenceMap extends AbstractHashedMap HashEntry previous = null; HashEntry entry = data[index]; while (entry != null) { - ReferenceEntry refEntry = (ReferenceEntry) entry; + final ReferenceEntry refEntry = (ReferenceEntry) entry; if (refEntry.purge(ref)) { if (previous == null) { data[index] = entry.next; diff --git a/src/main/java/org/apache/commons/collections4/map/UnmodifiableEntrySet.java b/src/main/java/org/apache/commons/collections4/map/UnmodifiableEntrySet.java index 99966a8a7..54cc77055 100644 --- a/src/main/java/org/apache/commons/collections4/map/UnmodifiableEntrySet.java +++ b/src/main/java/org/apache/commons/collections4/map/UnmodifiableEntrySet.java @@ -98,7 +98,7 @@ public final class UnmodifiableEntrySet * @since 4.4 */ @Override - public boolean removeIf(Predicate> filter) { + public boolean removeIf(final Predicate> filter) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/org/apache/commons/collections4/multiset/UnmodifiableMultiSet.java b/src/main/java/org/apache/commons/collections4/multiset/UnmodifiableMultiSet.java index 04f2cb097..2376c3ceb 100644 --- a/src/main/java/org/apache/commons/collections4/multiset/UnmodifiableMultiSet.java +++ b/src/main/java/org/apache/commons/collections4/multiset/UnmodifiableMultiSet.java @@ -131,7 +131,7 @@ public final class UnmodifiableMultiSet * @since 4.4 */ @Override - public boolean removeIf(Predicate filter) { + public boolean removeIf(final Predicate filter) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/org/apache/commons/collections4/queue/UnmodifiableQueue.java b/src/main/java/org/apache/commons/collections4/queue/UnmodifiableQueue.java index 82a3fbe01..52e8ae008 100644 --- a/src/main/java/org/apache/commons/collections4/queue/UnmodifiableQueue.java +++ b/src/main/java/org/apache/commons/collections4/queue/UnmodifiableQueue.java @@ -129,7 +129,7 @@ public final class UnmodifiableQueue * @since 4.4 */ @Override - public boolean removeIf(Predicate filter) { + public boolean removeIf(final Predicate filter) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/org/apache/commons/collections4/set/CompositeSet.java b/src/main/java/org/apache/commons/collections4/set/CompositeSet.java index ebed42272..93975edf1 100644 --- a/src/main/java/org/apache/commons/collections4/set/CompositeSet.java +++ b/src/main/java/org/apache/commons/collections4/set/CompositeSet.java @@ -291,7 +291,7 @@ public class CompositeSet implements Set, Serializable { * @since 4.4 */ @Override - public boolean removeIf(Predicate filter) { + public boolean removeIf(final Predicate filter) { if (Objects.isNull(filter)) { return false; } diff --git a/src/main/java/org/apache/commons/collections4/set/MapBackedSet.java b/src/main/java/org/apache/commons/collections4/set/MapBackedSet.java index 748df14be..6533dfde9 100644 --- a/src/main/java/org/apache/commons/collections4/set/MapBackedSet.java +++ b/src/main/java/org/apache/commons/collections4/set/MapBackedSet.java @@ -147,7 +147,7 @@ public final class MapBackedSet implements Set, Serializable { * @since 4.4 */ @Override - public boolean removeIf(Predicate filter) { + public boolean removeIf(final Predicate filter) { return map.keySet().removeIf(filter); } diff --git a/src/main/java/org/apache/commons/collections4/set/UnmodifiableNavigableSet.java b/src/main/java/org/apache/commons/collections4/set/UnmodifiableNavigableSet.java index 1441f2606..0fbda3080 100644 --- a/src/main/java/org/apache/commons/collections4/set/UnmodifiableNavigableSet.java +++ b/src/main/java/org/apache/commons/collections4/set/UnmodifiableNavigableSet.java @@ -100,7 +100,7 @@ public final class UnmodifiableNavigableSet * @since 4.4 */ @Override - public boolean removeIf(Predicate filter) { + public boolean removeIf(final Predicate filter) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/org/apache/commons/collections4/set/UnmodifiableSet.java b/src/main/java/org/apache/commons/collections4/set/UnmodifiableSet.java index 1a04b5f5a..59c8da413 100644 --- a/src/main/java/org/apache/commons/collections4/set/UnmodifiableSet.java +++ b/src/main/java/org/apache/commons/collections4/set/UnmodifiableSet.java @@ -103,7 +103,7 @@ public final class UnmodifiableSet * @since 4.4 */ @Override - public boolean removeIf(Predicate filter) { + public boolean removeIf(final Predicate filter) { throw new UnsupportedOperationException(); } diff --git a/src/main/java/org/apache/commons/collections4/set/UnmodifiableSortedSet.java b/src/main/java/org/apache/commons/collections4/set/UnmodifiableSortedSet.java index daf310782..37b774f5a 100644 --- a/src/main/java/org/apache/commons/collections4/set/UnmodifiableSortedSet.java +++ b/src/main/java/org/apache/commons/collections4/set/UnmodifiableSortedSet.java @@ -103,7 +103,7 @@ public final class UnmodifiableSortedSet * @since 4.4 */ @Override - public boolean removeIf(Predicate filter) { + public boolean removeIf(final Predicate filter) { throw new UnsupportedOperationException(); } diff --git a/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java b/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java index fca9f3069..bc37d7dce 100644 --- a/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java @@ -1474,7 +1474,7 @@ public class CollectionUtilsTest extends MockTestCase { @Test public void testRemoveRange() { - List list = new ArrayList<>(); + final List list = new ArrayList<>(); list.add(1); Collection result = CollectionUtils.removeRange(list, 0, 0); assertEquals(1, list.size()); @@ -1492,42 +1492,42 @@ public class CollectionUtilsTest extends MockTestCase { @Test(expected=IllegalArgumentException.class) public void testRemoveRangeNull() { - Collection list = null; - Collection result = CollectionUtils.removeRange(list, 0, 0); + final Collection list = null; + final Collection result = CollectionUtils.removeRange(list, 0, 0); } @Test(expected=IndexOutOfBoundsException.class) public void testRemoveRangeStartIndexNegative() { - Collection list = new ArrayList<>(); + final Collection list = new ArrayList<>(); list.add(1); - Collection result = CollectionUtils.removeRange(list, -1, 1); + final Collection result = CollectionUtils.removeRange(list, -1, 1); } @Test(expected=IllegalArgumentException.class) public void testRemoveRangeEndIndexNegative() { - Collection list = new ArrayList<>(); + final Collection list = new ArrayList<>(); list.add(1); - Collection result = CollectionUtils.removeRange(list, 0, -1); + final Collection result = CollectionUtils.removeRange(list, 0, -1); } @Test(expected=IllegalArgumentException.class) public void testRemoveRangeEndLowStart() { - Collection list = new ArrayList<>(); + final Collection list = new ArrayList<>(); list.add(1); list.add(2); - Collection result = CollectionUtils.removeRange(list, 1, 0); + final Collection result = CollectionUtils.removeRange(list, 1, 0); } @Test(expected=IndexOutOfBoundsException.class) public void testRemoveRangeWrongEndIndex() { - Collection list = new ArrayList<>(); + final Collection list = new ArrayList<>(); list.add(1); - Collection result = CollectionUtils.removeRange(list, 0, 2); + final Collection result = CollectionUtils.removeRange(list, 0, 2); } @Test public void testRemoveCount() { - List list = new ArrayList<>(); + final List list = new ArrayList<>(); list.add(1); list.add(2); list.add(3); @@ -1558,27 +1558,27 @@ public class CollectionUtilsTest extends MockTestCase { @Test(expected=IllegalArgumentException.class) public void testRemoveCountWithNull() { - Collection list = null; - Collection result = CollectionUtils.removeCount(list, 0, 1); + final Collection list = null; + final Collection result = CollectionUtils.removeCount(list, 0, 1); } @Test(expected=IndexOutOfBoundsException.class) public void testRemoveCountStartNegative() { - Collection list = new ArrayList<>(); - Collection result = CollectionUtils.removeCount(list, -1, 1); + final Collection list = new ArrayList<>(); + final Collection result = CollectionUtils.removeCount(list, -1, 1); } @Test(expected=IndexOutOfBoundsException.class) public void testRemoveCountNegative() { - Collection list = new ArrayList<>(); - Collection result = CollectionUtils.removeCount(list, 0, -1); + final Collection list = new ArrayList<>(); + final Collection result = CollectionUtils.removeCount(list, 0, -1); } @Test(expected=IndexOutOfBoundsException.class) public void testRemoveCountWrongCount() { - Collection list = new ArrayList<>(); + final Collection list = new ArrayList<>(); list.add(1); - Collection result = CollectionUtils.removeCount(list, 0, 2); + final Collection result = CollectionUtils.removeCount(list, 0, 2); } @Test diff --git a/src/test/java/org/apache/commons/collections4/EnumerationUtilsTest.java b/src/test/java/org/apache/commons/collections4/EnumerationUtilsTest.java index d4e0577ef..9445493e7 100644 --- a/src/test/java/org/apache/commons/collections4/EnumerationUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/EnumerationUtilsTest.java @@ -65,7 +65,7 @@ public class EnumerationUtilsTest { final Vector vector = new Vector<>(); vector.addElement("zero"); vector.addElement("one"); - Enumeration en = vector.elements(); + final Enumeration en = vector.elements(); final Iterator iterator = EnumerationUtils.asIterable(en).iterator(); assertTrue(iterator.hasNext()); assertEquals("zero", iterator.next()); diff --git a/src/test/java/org/apache/commons/collections4/IteratorUtilsTest.java b/src/test/java/org/apache/commons/collections4/IteratorUtilsTest.java index a1d1a1b55..ad1eba66b 100644 --- a/src/test/java/org/apache/commons/collections4/IteratorUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/IteratorUtilsTest.java @@ -477,28 +477,28 @@ public class IteratorUtilsTest { final Vector vector = new Vector<>(); vector.addElement("zero"); vector.addElement("one"); - Enumeration en = vector.elements(); + final Enumeration en = vector.elements(); assertTrue("create instance fail", IteratorUtils.asIterator(en) instanceof Iterator); IteratorUtils.asIterator(null); } @Test public void testAsIteratorNull() { - Collection coll = new ArrayList(); + final Collection coll = new ArrayList(); coll.add("test"); final Vector vector = new Vector<>(); vector.addElement("test"); vector.addElement("one"); - Enumeration en = vector.elements(); + final Enumeration en = vector.elements(); assertTrue("create instance fail", IteratorUtils.asIterator(en, coll) instanceof Iterator); try { IteratorUtils.asIterator(null, coll); - } catch (NullPointerException npe) { + } catch (final NullPointerException npe) { // } try { IteratorUtils.asIterator(en, null); - } catch (NullPointerException npe) { + } catch (final NullPointerException npe) { // } } @@ -542,8 +542,8 @@ public class IteratorUtilsTest { @Test public void testChainedIterator() { - ArrayList arrayList = new ArrayList(); - Iterator ie = arrayList.iterator(); + final ArrayList arrayList = new ArrayList(); + final Iterator ie = arrayList.iterator(); assertTrue("create instance fail", IteratorUtils.chainedIterator(ie) instanceof Iterator); final Collection> coll = new ArrayList(); assertTrue("create instance fail", IteratorUtils.chainedIterator(coll) instanceof Iterator); @@ -601,18 +601,18 @@ public class IteratorUtilsTest { @Test(expected = NullPointerException.class) public void testCollatedIteratorCollectionNull() { - Collection> coll = new ArrayList<>(); + final Collection> coll = new ArrayList<>(); coll.add(collectionOdd.iterator()); // natural ordering - Iterator it = IteratorUtils.collatedIterator(null, coll); - List result = IteratorUtils.toList(it); + final Iterator it = IteratorUtils.collatedIterator(null, coll); + final List result = IteratorUtils.toList(it); assertEquals(6, result.size()); IteratorUtils.collatedIterator(null, (Collection>) null); } @Test(expected = NullPointerException.class) public void testCollatedIteratorNull() { - ArrayList arrayList = new ArrayList(); + final ArrayList arrayList = new ArrayList(); // natural ordering Iterator it = IteratorUtils.collatedIterator(null, collectionOdd.iterator(), collectionOdd.iterator(), collectionOdd.iterator()); @@ -842,35 +842,35 @@ public class IteratorUtilsTest { @Test public void testFilteredIterator() { - ArrayList arrayList = new ArrayList(); - Iterator ie = arrayList.iterator(); + final ArrayList arrayList = new ArrayList(); + final Iterator ie = arrayList.iterator(); try { IteratorUtils.filteredIterator(ie, null); - } catch (NullPointerException npe) { + } catch (final NullPointerException npe) { // } try { IteratorUtils.filteredIterator(null, null); - } catch (NullPointerException npe) { + } catch (final NullPointerException npe) { // } } @Test public void testFilteredListIterator() { - List arrayList = new ArrayList(); + final List arrayList = new ArrayList(); arrayList.add("test"); - Predicate predicate = INSTANCE; + final Predicate predicate = INSTANCE; assertTrue("create instance fail", IteratorUtils.filteredListIterator(arrayList.listIterator(), predicate) instanceof ListIterator); try { IteratorUtils.filteredListIterator(null, predicate); - } catch (NullPointerException npe) { + } catch (final NullPointerException npe) { // } try { IteratorUtils.filteredListIterator(arrayList.listIterator(), null); - } catch (NullPointerException npe) { + } catch (final NullPointerException npe) { // } } @@ -996,13 +996,13 @@ public class IteratorUtilsTest { IteratorUtils.getIterator(nodeList) instanceof NodeListIterator); assertTrue("returns EnumerationIterator when Enumeration passed", IteratorUtils.getIterator(new Vector().elements()) instanceof EnumerationIterator); - Node node1 = createMock(Node.class); + final Node node1 = createMock(Node.class); assertTrue("returns NodeListIterator when nodeList passed", IteratorUtils.getIterator(node1) instanceof NodeListIterator); - Dictionary dic = createMock(Dictionary.class); + final Dictionary dic = createMock(Dictionary.class); assertTrue("returns EnumerationIterator when Dictionary passed", IteratorUtils.getIterator(dic) instanceof EnumerationIterator); - int[] arr = new int[8]; + final int[] arr = new int[8]; assertTrue("returns ArrayIterator when array passed", IteratorUtils.getIterator(arr) instanceof ArrayIterator); } @@ -1025,20 +1025,20 @@ public class IteratorUtilsTest { @Test(expected = NullPointerException.class) public void testLoopingIterator() { - ArrayList arrayList = new ArrayList(); + final ArrayList arrayList = new ArrayList(); arrayList.add("test"); - Collection coll = new ArrayList(); + final Collection coll = new ArrayList(); coll.add("test"); - Iterator ie = arrayList.iterator(); + final Iterator ie = arrayList.iterator(); assertTrue("create instance fail", IteratorUtils.loopingIterator(coll) instanceof ResettableIterator); IteratorUtils.loopingIterator(null); } @Test(expected = NullPointerException.class) public void testLoopingListIterator() { - ArrayList arrayList = new ArrayList(); + final ArrayList arrayList = new ArrayList(); arrayList.add("test"); - Iterator ie = arrayList.iterator(); + final Iterator ie = arrayList.iterator(); assertTrue("create instance fail", IteratorUtils.loopingListIterator(arrayList) instanceof ResettableIterator); IteratorUtils.loopingListIterator(null); } @@ -1111,8 +1111,8 @@ public class IteratorUtilsTest { @Test(expected = NullPointerException.class) public void testPeekingIterator() { - ArrayList arrayList = new ArrayList(); - Iterator ie = arrayList.iterator(); + final ArrayList arrayList = new ArrayList(); + final Iterator ie = arrayList.iterator(); assertTrue("create instance fail", IteratorUtils.peekingIterator(ie) instanceof Iterator); IteratorUtils.peekingIterator(null); @@ -1120,8 +1120,8 @@ public class IteratorUtilsTest { @Test(expected = NullPointerException.class) public void testPushBackIterator() { - ArrayList arrayList = new ArrayList(); - Iterator ie = arrayList.iterator(); + final ArrayList arrayList = new ArrayList(); + final Iterator ie = arrayList.iterator(); assertTrue("create instance fail", IteratorUtils.pushbackIterator(ie) instanceof Iterator); IteratorUtils.pushbackIterator(null); } @@ -1230,16 +1230,16 @@ public class IteratorUtilsTest { @Test public void testTransformedIterator() { - ArrayList arrayList = new ArrayList(); - Iterator ie = arrayList.iterator(); + final ArrayList arrayList = new ArrayList(); + final Iterator ie = arrayList.iterator(); try { IteratorUtils.transformedIterator(ie, null); - } catch (NullPointerException npe) { + } catch (final NullPointerException npe) { // } try { IteratorUtils.transformedIterator(null, null); - } catch (NullPointerException npe) { + } catch (final NullPointerException npe) { // } } @@ -1409,7 +1409,7 @@ public class IteratorUtilsTest { @Test(expected = NullPointerException.class) public void testUnmodifiableMapIterator() { - Set set = new LinkedHashSet<>(); + final Set set = new LinkedHashSet<>(); final MapIterator ie = new EntrySetToMapIteratorAdapter(set); assertTrue("create instance fail", IteratorUtils.unmodifiableMapIterator(ie) instanceof MapIterator); IteratorUtils.unmodifiableMapIterator(null); @@ -1418,8 +1418,8 @@ public class IteratorUtilsTest { @Test public void testZippingIterator() { - ArrayList arrayList = new ArrayList(); - Iterator ie = arrayList.iterator(); + final ArrayList arrayList = new ArrayList(); + final Iterator ie = arrayList.iterator(); assertTrue("create instance fail", IteratorUtils.zippingIterator(ie, ie, ie) instanceof ZippingIterator); assertTrue("create instance fail", IteratorUtils.zippingIterator(ie, ie) instanceof ZippingIterator); } diff --git a/src/test/java/org/apache/commons/collections4/ListUtilsTest.java b/src/test/java/org/apache/commons/collections4/ListUtilsTest.java index b46575d78..11b09cfdf 100644 --- a/src/test/java/org/apache/commons/collections4/ListUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/ListUtilsTest.java @@ -167,7 +167,7 @@ public class ListUtilsTest { private int index; @Override - public Integer transform(Integer input) { + public Integer transform(final Integer input) { return offsets.get(input) + index++; } diff --git a/src/test/java/org/apache/commons/collections4/SetUtilsTest.java b/src/test/java/org/apache/commons/collections4/SetUtilsTest.java index c44b3ffe6..6cf0cc2ef 100644 --- a/src/test/java/org/apache/commons/collections4/SetUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/SetUtilsTest.java @@ -189,26 +189,26 @@ public class SetUtilsTest { @Test public void testHashSet() { - Set set1 = SetUtils.unmodifiableSet(); + final Set set1 = SetUtils.unmodifiableSet(); assertTrue("set is empty", set1.isEmpty()); - Set set2 = SetUtils.hashSet(1, 2, 2, 3); + final Set set2 = SetUtils.hashSet(1, 2, 2, 3); assertEquals("set has 3 elements", 3, set2.size()); assertTrue("set contains 1", set2.contains(1)); assertTrue("set contains 2", set2.contains(2)); assertTrue("set contains 3", set2.contains(3)); - Set set3 = SetUtils.hashSet("1", "2", "2", "3"); + final Set set3 = SetUtils.hashSet("1", "2", "2", "3"); assertEquals("set has 3 elements", 3, set3.size()); assertTrue("set contains 1", set3.contains("1")); assertTrue("set contains 2", set3.contains("2")); assertTrue("set contains 3", set3.contains("3")); - Set set4 = SetUtils.hashSet(null, null); + final Set set4 = SetUtils.hashSet(null, null); assertEquals("set has 1 element", 1, set4.size()); assertTrue("set contains null", set4.contains(null)); - Set set5 = SetUtils.hashSet((Object[]) null); + final Set set5 = SetUtils.hashSet((Object[]) null); assertEquals("set is null", null, set5); } @@ -251,34 +251,34 @@ public class SetUtilsTest { @Test public void testUnmodifiableSet() { - Set set1 = SetUtils.unmodifiableSet(); + final Set set1 = SetUtils.unmodifiableSet(); assertTrue("set is empty", set1.isEmpty()); - Set set2 = SetUtils.unmodifiableSet(1, 2, 2, 3); + final Set set2 = SetUtils.unmodifiableSet(1, 2, 2, 3); assertEquals("set has 3 elements", 3, set2.size()); assertTrue("set contains 1", set2.contains(1)); assertTrue("set contains 2", set2.contains(2)); assertTrue("set contains 3", set2.contains(3)); - Set set3 = SetUtils.unmodifiableSet("1", "2", "2", "3"); + final Set set3 = SetUtils.unmodifiableSet("1", "2", "2", "3"); assertEquals("set has 3 elements", 3, set3.size()); assertTrue("set contains 1", set3.contains("1")); assertTrue("set contains 2", set3.contains("2")); assertTrue("set contains 3", set3.contains("3")); - Set set4 = SetUtils.unmodifiableSet(null, null); + final Set set4 = SetUtils.unmodifiableSet(null, null); assertEquals("set has 1 element", 1, set4.size()); assertTrue("set contains null", set4.contains(null)); - Set set5 = SetUtils.unmodifiableSet((Object[]) null); + final Set set5 = SetUtils.unmodifiableSet((Object[]) null); assertEquals("set is null", null, set5); } @Test public void testUnmodifiableSetWrap() { - Set set1 = SetUtils.unmodifiableSet(1, 2, 2, 3); - Set set2 = SetUtils.unmodifiableSet(set1); + final Set set1 = SetUtils.unmodifiableSet(1, 2, 2, 3); + final Set set2 = SetUtils.unmodifiableSet(set1); assertSame(set1, set2); } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilterTest.java index 8d2935d12..e66c3bdc2 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilterTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/AbstractBloomFilterTest.java @@ -127,11 +127,11 @@ public abstract class AbstractBloomFilterTest { */ @Test public final void constructorTest_Hasher() { - List lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); - Hasher hasher = new StaticHasher(lst.iterator(), shape); + final List lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter bf = createFilter(hasher, shape); - long[] lb = bf.getBits(); + final BloomFilter bf = createFilter(hasher, shape); + final long[] lb = bf.getBits(); assertEquals(0x1FFFF, lb[0]); assertEquals(1, lb.length); } @@ -142,8 +142,8 @@ public abstract class AbstractBloomFilterTest { @Test public final void constructorTest_Empty() { - BloomFilter bf = createEmptyFilter(shape); - long[] lb = bf.getBits(); + final BloomFilter bf = createEmptyFilter(shape); + final long[] lb = bf.getBits(); assertEquals(0, lb.length); } @@ -153,14 +153,14 @@ public abstract class AbstractBloomFilterTest { */ @Test public final void constructorTest_WrongShape() { - Shape anotherShape = new Shape(testFunctionX, 3, 72, 17); + final Shape anotherShape = new Shape(testFunctionX, 3, 72, 17); - List lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); - Hasher hasher = new StaticHasher(lst.iterator(), anotherShape); + final List lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + final Hasher hasher = new StaticHasher(lst.iterator(), anotherShape); try { createFilter(hasher, shape); fail("Should throw IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + } catch (final IllegalArgumentException expected) { // do nothing. } } @@ -171,10 +171,10 @@ public abstract class AbstractBloomFilterTest { @Test public final void cardinalityTest() { - List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); - Hasher hasher = new StaticHasher(lst.iterator(), shape); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter bf = createFilter(hasher, shape); + final BloomFilter bf = createFilter(hasher, shape); assertEquals(17, bf.cardinality()); } @@ -183,15 +183,15 @@ public abstract class AbstractBloomFilterTest { */ @Test public final void orCardinalityTest() { - List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); - Hasher hasher = new StaticHasher(lst.iterator(), shape); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); - AbstractBloomFilter bf = createFilter(hasher, shape); + final AbstractBloomFilter bf = createFilter(hasher, shape); - List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); - Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); + final List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); + final Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); - BloomFilter bf2 = createFilter(hasher2, shape); + final BloomFilter bf2 = createFilter(hasher2, shape); assertEquals(27, bf.orCardinality(bf2)); } @@ -201,15 +201,15 @@ public abstract class AbstractBloomFilterTest { */ @Test public final void orCardinalityTest_ExtraLongs() { - List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); - Hasher hasher = new StaticHasher(lst.iterator(), shape); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); - AbstractBloomFilter bf = createFilter(hasher, shape); + final AbstractBloomFilter bf = createFilter(hasher, shape); - List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69); - Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); + final List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69); + final Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); - AbstractBloomFilter bf2 = createFilter(hasher2, shape); + final AbstractBloomFilter bf2 = createFilter(hasher2, shape); assertEquals(27, bf.orCardinality(bf2)); assertEquals(27, bf2.orCardinality(bf)); @@ -220,15 +220,15 @@ public abstract class AbstractBloomFilterTest { */ @Test public final void andCardinalityTest() { - List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); - Hasher hasher = new StaticHasher(lst.iterator(), shape); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter bf = createFilter(hasher, shape); + final BloomFilter bf = createFilter(hasher, shape); - List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); - Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); + final List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); + final Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); - BloomFilter bf2 = createFilter(hasher2, shape); + final BloomFilter bf2 = createFilter(hasher2, shape); assertEquals(7, bf.andCardinality(bf2)); } @@ -238,15 +238,15 @@ public abstract class AbstractBloomFilterTest { */ @Test public final void andCardinalityTest_ExtraLongs() { - List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); - Hasher hasher = new StaticHasher(lst.iterator(), shape); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter bf = createFilter(hasher, shape); + final BloomFilter bf = createFilter(hasher, shape); - List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69); - Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); + final List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69); + final Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); - BloomFilter bf2 = createFilter(hasher2, shape); + final BloomFilter bf2 = createFilter(hasher2, shape); assertEquals(7, bf.andCardinality(bf2)); assertEquals(7, bf2.andCardinality(bf)); @@ -257,14 +257,14 @@ public abstract class AbstractBloomFilterTest { */ @Test public final void xorCardinalityTest() { - List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); - Hasher hasher = new StaticHasher(lst.iterator(), shape); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter bf = createFilter(hasher, shape); + final BloomFilter bf = createFilter(hasher, shape); - List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); - Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); - BloomFilter bf2 = createFilter(hasher2, shape); + final List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); + final Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); + final BloomFilter bf2 = createFilter(hasher2, shape); assertEquals(20, bf.xorCardinality(bf2)); } @@ -274,14 +274,14 @@ public abstract class AbstractBloomFilterTest { */ @Test public final void xorCardinalityTest_ExtraLongs() { - List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); - Hasher hasher = new StaticHasher(lst.iterator(), shape); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter bf = createFilter(hasher, shape); + final BloomFilter bf = createFilter(hasher, shape); - List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69); - Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); - BloomFilter bf2 = createFilter(hasher2, shape); + final List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69); + final Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); + final BloomFilter bf2 = createFilter(hasher2, shape); assertEquals(20, bf.xorCardinality(bf2)); assertEquals(20, bf2.xorCardinality(bf)); @@ -292,14 +292,14 @@ public abstract class AbstractBloomFilterTest { */ @Test public final void mergeTest_BloomFilter() { - List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); - Hasher hasher = new StaticHasher(lst.iterator(), shape); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter bf = createFilter(hasher, shape); + final BloomFilter bf = createFilter(hasher, shape); - List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); - Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); - BloomFilter bf2 = createFilter(hasher2, shape); + final List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); + final Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); + final BloomFilter bf2 = createFilter(hasher2, shape); bf.merge(bf2); assertEquals(27, bf.cardinality()); @@ -310,20 +310,20 @@ public abstract class AbstractBloomFilterTest { */ @Test public final void mergeTest_BloomFilter_WrongShape() { - List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); - Hasher hasher = new StaticHasher(lst.iterator(), shape); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter bf = createFilter(hasher, shape); + final BloomFilter bf = createFilter(hasher, shape); - Shape anotherShape = new Shape(testFunctionX, 3, 72, 17); - List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); - Hasher hasher2 = new StaticHasher(lst2.iterator(), anotherShape); - BloomFilter bf2 = createFilter(hasher2, anotherShape); + final Shape anotherShape = new Shape(testFunctionX, 3, 72, 17); + final List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); + final Hasher hasher2 = new StaticHasher(lst2.iterator(), anotherShape); + final BloomFilter bf2 = createFilter(hasher2, anotherShape); try { bf.merge(bf2); fail("Should throw IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + } catch (final IllegalArgumentException expected) { // do nothing. } } @@ -333,13 +333,13 @@ public abstract class AbstractBloomFilterTest { */ @Test public final void mergeTest_Hasher() { - List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); - Hasher hasher = new StaticHasher(lst.iterator(), shape); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter bf = createFilter(hasher, shape); + final BloomFilter bf = createFilter(hasher, shape); - List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); - Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); + final List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); + final Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); bf.merge(hasher2); assertEquals(27, bf.cardinality()); @@ -350,19 +350,19 @@ public abstract class AbstractBloomFilterTest { */ @Test public final void mergeTest_Hasher_WrongShape() { - List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); - Hasher hasher = new StaticHasher(lst.iterator(), shape); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter bf = createFilter(hasher, shape); + final BloomFilter bf = createFilter(hasher, shape); - Shape anotherShape = new Shape(testFunctionX, 3, 72, 17); - List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); - Hasher hasher2 = new StaticHasher(lst2.iterator(), anotherShape); + final Shape anotherShape = new Shape(testFunctionX, 3, 72, 17); + final List lst2 = Arrays.asList(11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27); + final Hasher hasher2 = new StaticHasher(lst2.iterator(), anotherShape); try { bf.merge(hasher2); fail("Should throw IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + } catch (final IllegalArgumentException expected) { // do nothing. } } @@ -377,7 +377,7 @@ public abstract class AbstractBloomFilterTest { AbstractBloomFilter filter = createEmptyFilter(shape); assertFalse(filter.isFull()); - List values = new ArrayList<>(shape.getNumberOfBits()); + final List values = new ArrayList<>(shape.getNumberOfBits()); for (int i = 0; i < shape.getNumberOfBits(); i++) { values.add(i); } @@ -387,7 +387,7 @@ public abstract class AbstractBloomFilterTest { assertTrue(filter.isFull()); - int mid = shape.getNumberOfBits() / 2; + final int mid = shape.getNumberOfBits() / 2; values.remove(Integer.valueOf(mid)); hasher2 = new StaticHasher(values.iterator(), shape); filter = createFilter(hasher2, shape); @@ -400,17 +400,17 @@ public abstract class AbstractBloomFilterTest { */ @Test public final void containsTest_BloomFilter_WrongShape() { - List lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); - Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter bf = createFilter(hasher, shape); + final List lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); + final BloomFilter bf = createFilter(hasher, shape); - Shape anotherShape = new Shape(testFunctionX, 3, 72, 17); - Hasher hasher2 = new StaticHasher(lst.iterator(), anotherShape); - BloomFilter bf2 = createFilter(hasher2, anotherShape); + final Shape anotherShape = new Shape(testFunctionX, 3, 72, 17); + final Hasher hasher2 = new StaticHasher(lst.iterator(), anotherShape); + final BloomFilter bf2 = createFilter(hasher2, anotherShape); try { bf.contains(bf2); fail("Should throw IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + } catch (final IllegalArgumentException expected) { // do nothing. } } @@ -420,13 +420,13 @@ public abstract class AbstractBloomFilterTest { */ @Test public final void containsTest_BloomFilter() { - List lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); - Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter bf = createFilter(hasher, shape); + final List lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); + final BloomFilter bf = createFilter(hasher, shape); - List lst2 = Arrays.asList(4, 5, 6, 7, 8, 9, 10); - Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); - BloomFilter bf2 = createFilter(hasher2, shape); + final List lst2 = Arrays.asList(4, 5, 6, 7, 8, 9, 10); + final Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); + final BloomFilter bf2 = createFilter(hasher2, shape); assertTrue(bf.contains(bf2)); assertFalse(bf2.contains(bf)); } @@ -436,9 +436,9 @@ public abstract class AbstractBloomFilterTest { */ @Test public final void containsTest_Hasher() { - List lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); - Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter bf = createFilter(hasher, shape); + final List lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); + final BloomFilter bf = createFilter(hasher, shape); List lst2 = Arrays.asList(4, 5, 6, 7, 8, 9, 10); Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); @@ -458,18 +458,18 @@ public abstract class AbstractBloomFilterTest { */ @Test public final void containsTest_Hasher_WrongShape() { - List lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); - Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter bf = createFilter(hasher, shape); + final List lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); + final BloomFilter bf = createFilter(hasher, shape); - Shape anotherShape = new Shape(testFunctionX, 3, 72, 17); + final Shape anotherShape = new Shape(testFunctionX, 3, 72, 17); - List lst2 = Arrays.asList(4, 5, 6, 7, 8, 9, 10); - Hasher hasher2 = new StaticHasher(lst2.iterator(), anotherShape); + final List lst2 = Arrays.asList(4, 5, 6, 7, 8, 9, 10); + final Hasher hasher2 = new StaticHasher(lst2.iterator(), anotherShape); try { bf.contains(hasher2); fail("Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + } catch (final IllegalArgumentException expected) { // do nothing } } @@ -480,9 +480,9 @@ public abstract class AbstractBloomFilterTest { * @param hasher1 the first static hasher. * @param hasher2 the second static hasher. */ - private void assertSameBits(StaticHasher hasher1, StaticHasher hasher2) { - OfInt iter1 = hasher1.getBits(shape); - OfInt iter2 = hasher2.getBits(shape); + private void assertSameBits(final StaticHasher hasher1, final StaticHasher hasher2) { + final OfInt iter1 = hasher1.getBits(shape); + final OfInt iter2 = hasher2.getBits(shape); while (iter1.hasNext()) { assertTrue("Not enough data in second hasher", iter2.hasNext()); @@ -496,11 +496,11 @@ public abstract class AbstractBloomFilterTest { */ @Test public final void getHasherTest() { - List lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); - StaticHasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter bf = createFilter(hasher, shape); + final List lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + final StaticHasher hasher = new StaticHasher(lst.iterator(), shape); + final BloomFilter bf = createFilter(hasher, shape); - StaticHasher hasher2 = bf.getHasher(); + final StaticHasher hasher2 = bf.getHasher(); assertEquals(shape, hasher2.getShape()); assertSameBits(hasher, hasher2); @@ -511,10 +511,10 @@ public abstract class AbstractBloomFilterTest { */ @Test public final void getBitsTest_SpanLong() { - List lst = Arrays.asList(63, 64); - StaticHasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter bf = createFilter(hasher, shape); - long[] lb = bf.getBits(); + final List lst = Arrays.asList(63, 64); + final StaticHasher hasher = new StaticHasher(lst.iterator(), shape); + final BloomFilter bf = createFilter(hasher, shape); + final long[] lb = bf.getBits(); assertEquals(2, lb.length); assertEquals(0x8000000000000000L, lb[0]); assertEquals(0x1, lb[1]); diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/BitSetBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/BitSetBloomFilterTest.java index fd5f15f57..8939d8860 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/BitSetBloomFilterTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/BitSetBloomFilterTest.java @@ -33,12 +33,12 @@ import org.junit.Test; public class BitSetBloomFilterTest extends AbstractBloomFilterTest { @Override - protected BitSetBloomFilter createFilter(Hasher hasher, Shape shape) { + protected BitSetBloomFilter createFilter(final Hasher hasher, final Shape shape) { return new BitSetBloomFilter( hasher, shape ); } @Override - protected BitSetBloomFilter createEmptyFilter(Shape shape) { + protected BitSetBloomFilter createEmptyFilter(final Shape shape) { return new BitSetBloomFilter( shape ); } @@ -47,9 +47,9 @@ public class BitSetBloomFilterTest extends AbstractBloomFilterTest { */ @Test public void andCardinalityTest_BitSetBloomFilter() { - Hasher hasher = new StaticHasher( Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ).iterator(), shape ); + final Hasher hasher = new StaticHasher( Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ).iterator(), shape ); - BitSetBloomFilter bf = createFilter(hasher, shape); + final BitSetBloomFilter bf = createFilter(hasher, shape); Hasher hasher2 = new StaticHasher( Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ).iterator(), shape ); BitSetBloomFilter bf2 = createFilter(hasher2, shape); @@ -76,9 +76,9 @@ public class BitSetBloomFilterTest extends AbstractBloomFilterTest { */ @Test public void xorCardinalityTest_BitSetBloomFilter() { - Hasher hasher = new StaticHasher( Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ).iterator(), shape ); + final Hasher hasher = new StaticHasher( Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ).iterator(), shape ); - BitSetBloomFilter bf = createFilter(hasher, shape); + final BitSetBloomFilter bf = createFilter(hasher, shape); Hasher hasher2 = new StaticHasher( Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ).iterator(), shape ); BitSetBloomFilter bf2 = createFilter(hasher2, shape); @@ -106,14 +106,14 @@ public class BitSetBloomFilterTest extends AbstractBloomFilterTest { @Test public void mergeTest_BitSetBloomFilter() { - List lst = Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17 ); - Hasher hasher = new StaticHasher( lst.iterator(), shape ); + final List lst = Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17 ); + final Hasher hasher = new StaticHasher( lst.iterator(), shape ); - BitSetBloomFilter bf = createFilter(hasher, shape); + final BitSetBloomFilter bf = createFilter(hasher, shape); - List lst2 = Arrays.asList( 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ,26 ,27 ); - Hasher hasher2 = new StaticHasher( lst2.iterator(), shape ); - BloomFilter bf2 = new BitSetBloomFilter(hasher2, shape); + final List lst2 = Arrays.asList( 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ,26 ,27 ); + final Hasher hasher2 = new StaticHasher( lst2.iterator(), shape ); + final BloomFilter bf2 = new BitSetBloomFilter(hasher2, shape); bf.merge(bf2); diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilterTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilterTest.java index 527acf403..ec6640499 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilterTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/CountingBloomFilterTest.java @@ -39,12 +39,12 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { @Override - protected CountingBloomFilter createFilter(Hasher hasher, Shape shape) { + protected CountingBloomFilter createFilter(final Hasher hasher, final Shape shape) { return new CountingBloomFilter( hasher, shape ); } @Override - protected CountingBloomFilter createEmptyFilter(Shape shape) { + protected CountingBloomFilter createEmptyFilter(final Shape shape) { return new CountingBloomFilter( shape ); } @@ -53,11 +53,11 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { */ @Test public void ConstructorTest_HasherValues_CountsTest() { - List lst = Arrays.asList( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ); - Hasher hasher = new StaticHasher( lst.iterator(), shape ); + final List lst = Arrays.asList( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 ); + final Hasher hasher = new StaticHasher( lst.iterator(), shape ); - CountingBloomFilter bf = createFilter(hasher, shape); - long[] lb = bf.getBits(); + final CountingBloomFilter bf = createFilter(hasher, shape); + final long[] lb = bf.getBits(); assertEquals(0x1FFFF, lb[0]); assertEquals(1, lb.length); @@ -72,7 +72,7 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { */ @Test public void ConstructorTest_Map_CountsTest() { - Map map = new HashMap<>(); + final Map map = new HashMap<>(); for (int i =0;i<17;i++) { map.put( i, 1 ); @@ -85,7 +85,7 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { try { bf = new CountingBloomFilter( map, shape); fail( "Should have thrown IllegalArgumentExceptionW"); - } catch (IllegalArgumentException exprected) + } catch (final IllegalArgumentException exprected) { // expected } @@ -95,7 +95,7 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { try { bf = new CountingBloomFilter( map, shape); fail( "Should have thrown IllegalArgumentExceptionW"); - } catch (IllegalArgumentException exprected) + } catch (final IllegalArgumentException exprected) { // expected } @@ -105,7 +105,7 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { try { bf = new CountingBloomFilter( map, shape); fail( "Should have thrown IllegalArgumentExceptionW"); - } catch (IllegalArgumentException exprected) + } catch (final IllegalArgumentException exprected) { // expected } @@ -117,19 +117,19 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { */ @Test public void mergeTest_Counts() { - int[] expected = { + final int[] expected = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 }; - List lst = Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17 ); - Hasher hasher = new StaticHasher( lst.iterator(), shape ); + final List lst = Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17 ); + final Hasher hasher = new StaticHasher( lst.iterator(), shape ); - CountingBloomFilter bf = createFilter(hasher, shape); + final CountingBloomFilter bf = createFilter(hasher, shape); - List lst2 = Arrays.asList( 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ,26 ,27 ); - Hasher hasher2 = new StaticHasher( lst2.iterator(), shape ); - BloomFilter bf2 = createFilter(hasher2, shape); + final List lst2 = Arrays.asList( 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ,26 ,27 ); + final Hasher hasher2 = new StaticHasher( lst2.iterator(), shape ); + final BloomFilter bf2 = createFilter(hasher2, shape); bf.merge(bf2); @@ -137,7 +137,7 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { assertEquals(Integer.valueOf(2), bf.getCounts().map(Map.Entry::getValue).max(Integer::compare).get()); assertEquals(Integer.valueOf(1), bf.getCounts().map(Map.Entry::getValue).min(Integer::compare).get()); - Map m = new HashMap<>(); + final Map m = new HashMap<>(); bf.getCounts().forEach(e -> m.put(e.getKey(), e.getValue())); for (int i=0;i<29;i++) { @@ -157,19 +157,19 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { */ @Test public void mergeTest_Counts_BitSetFilter() { - int[] expected = { + final int[] expected = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 }; - List lst = Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17 ); - Hasher hasher = new StaticHasher( lst.iterator(), shape ); + final List lst = Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17 ); + final Hasher hasher = new StaticHasher( lst.iterator(), shape ); - CountingBloomFilter bf = createFilter(hasher, shape); + final CountingBloomFilter bf = createFilter(hasher, shape); - List lst2 = Arrays.asList( 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ,26 ,27 ); - Hasher hasher2 = new StaticHasher( lst2.iterator(), shape ); - BloomFilter bf2 = new BitSetBloomFilter(hasher2, shape); + final List lst2 = Arrays.asList( 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ,26 ,27 ); + final Hasher hasher2 = new StaticHasher( lst2.iterator(), shape ); + final BloomFilter bf2 = new BitSetBloomFilter(hasher2, shape); bf.merge(bf2); @@ -177,7 +177,7 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { assertEquals(Integer.valueOf(2), bf.getCounts().map(Map.Entry::getValue).max(Integer::compare).get()); assertEquals(Integer.valueOf(1), bf.getCounts().map(Map.Entry::getValue).min(Integer::compare).get()); - Map m = new HashMap<>(); + final Map m = new HashMap<>(); bf.getCounts().forEach(e -> m.put(e.getKey(), e.getValue())); for (int i=0;i<29;i++) { @@ -197,19 +197,19 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { */ @Test public void mergeTest_Shape_Hasher_Count() { - int[] expected = { + final int[] expected = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 }; - List lst = Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17 ); - Hasher hasher = new StaticHasher( lst.iterator(), shape ); + final List lst = Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17 ); + final Hasher hasher = new StaticHasher( lst.iterator(), shape ); - CountingBloomFilter bf = createFilter(hasher, shape); + final CountingBloomFilter bf = createFilter(hasher, shape); - List lst2 = Arrays.asList( 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ,26 ,27 ); - Hasher hasher2 = new StaticHasher( lst2.iterator(), shape ); + final List lst2 = Arrays.asList( 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 ,26 ,27 ); + final Hasher hasher2 = new StaticHasher( lst2.iterator(), shape ); bf.merge(hasher2); @@ -217,7 +217,7 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { assertEquals(Integer.valueOf(2), bf.getCounts().map(Map.Entry::getValue).max(Integer::compare).get()); assertEquals(Integer.valueOf(1), bf.getCounts().map(Map.Entry::getValue).min(Integer::compare).get()); - Map m = new HashMap<>(); + final Map m = new HashMap<>(); bf.getCounts().forEach(e -> m.put(e.getKey(), e.getValue())); for (int i=0;i<29;i++) { @@ -237,13 +237,13 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { @Test public void mergeTest_Overflow() { - List lst = Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17 ); - Hasher hasher = new StaticHasher( lst.iterator(), shape ); + final List lst = Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17 ); + final Hasher hasher = new StaticHasher( lst.iterator(), shape ); CountingBloomFilter bf = createFilter(hasher, shape); - Map map = new HashMap<>(); + final Map map = new HashMap<>(); bf.getCounts().forEach( e -> map.put( e.getKey(), e.getValue())); map.put(1, Integer.MAX_VALUE ); @@ -260,7 +260,7 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { bf.merge(bf2); fail( "Should have thrown IllegalStateException"); } - catch (IllegalStateException expected) + catch (final IllegalStateException expected) { // do nothing } @@ -271,26 +271,26 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { */ @Test public void removeTest_Standard() { - int[] values = { + final int[] values = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; - Map map = new HashMap<>(); + final Map map = new HashMap<>(); for (int i=1;i lst = Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17 ); - Hasher hasher = new StaticHasher( lst.iterator(), shape ); - BitSetBloomFilter bf2 = new BitSetBloomFilter( hasher, shape ); + final List lst = Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17 ); + final Hasher hasher = new StaticHasher( lst.iterator(), shape ); + final BitSetBloomFilter bf2 = new BitSetBloomFilter( hasher, shape ); bf.remove( bf2 ); assertEquals( 17, bf.cardinality() ); - Map map2 = new HashMap<>(); + final Map map2 = new HashMap<>(); bf.getCounts().forEach( e -> map2.put( e.getKey(), e.getValue())); for (int i = 11; i map = new HashMap<>(); + final Map map = new HashMap<>(); for (int i=1;i lst = Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17 ); - Hasher hasher = new StaticHasher( lst.iterator(), shape ); - BloomFilter bf2 = new CountingBloomFilter( hasher, shape ); + final List lst = Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17 ); + final Hasher hasher = new StaticHasher( lst.iterator(), shape ); + final BloomFilter bf2 = new CountingBloomFilter( hasher, shape ); bf.remove( bf2 ); assertEquals( 17, bf.cardinality() ); - Map map2 = new HashMap<>(); + final Map map2 = new HashMap<>(); bf.getCounts().forEach( e -> map2.put( e.getKey(), e.getValue())); for (int i = 11; i lst = Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17 ); - Hasher hasher = new StaticHasher( lst.iterator(), shape ); + final List lst = Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17 ); + final Hasher hasher = new StaticHasher( lst.iterator(), shape ); CountingBloomFilter bf = createFilter(hasher, shape); - Map map = new HashMap<>(); + final Map map = new HashMap<>(); bf.getCounts().forEach( e -> map.put( e.getKey(), e.getValue())); map.remove(1); @@ -365,7 +365,7 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { bf.remove(bf2); fail( "Should have thrown IllegalStateException"); } - catch (IllegalStateException expected) + catch (final IllegalStateException expected) { // do nothing } @@ -376,26 +376,26 @@ public class CountingBloomFilterTest extends AbstractBloomFilterTest { */ @Test public void removeTest_Hasher() { - int[] values = { + final int[] values = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; - Map map = new HashMap<>(); + final Map map = new HashMap<>(); for (int i=1;i lst = Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17 ); - Hasher hasher = new StaticHasher( lst.iterator(), shape ); + final List lst = Arrays.asList( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ,16 ,17 ); + final Hasher hasher = new StaticHasher( lst.iterator(), shape ); bf.remove( hasher ); assertEquals( 17, bf.cardinality() ); - Map map2 = new HashMap<>(); + final Map map2 = new HashMap<>(); bf.getCounts().forEach( e -> map2.put( e.getKey(), e.getValue())); for (int i = 11; i lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); - Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter filter1 = new HasherBloomFilter(hasher, shape); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); + final BloomFilter filter1 = new HasherBloomFilter(hasher, shape); lst = Arrays.asList(17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40); - Hasher hasher2 = new StaticHasher(lst.iterator(), shape); - BloomFilter filter2 = new HasherBloomFilter(hasher2, shape); + final Hasher hasher2 = new StaticHasher(lst.iterator(), shape); + final BloomFilter filter2 = new HasherBloomFilter(hasher2, shape); - long estimate = SetOperations.estimateUnionSize(filter1, filter2); + final long estimate = SetOperations.estimateUnionSize(filter1, filter2); assertEquals(3, estimate); } @@ -116,15 +116,15 @@ public class SetOperationsTest { public final void estimateIntersectionSizeTest() { // build a filter List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); - Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter filter1 = new HasherBloomFilter(hasher, shape); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); + final BloomFilter filter1 = new HasherBloomFilter(hasher, shape); lst = Arrays.asList(8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40); - Hasher hasher2 = new StaticHasher(lst.iterator(), shape); - BloomFilter filter2 = new HasherBloomFilter(hasher2, shape); + final Hasher hasher2 = new StaticHasher(lst.iterator(), shape); + final BloomFilter filter2 = new HasherBloomFilter(hasher2, shape); - long estimate = SetOperations.estimateIntersectionSize(filter1, filter2); + final long estimate = SetOperations.estimateIntersectionSize(filter1, filter2); assertEquals(1, estimate); } @@ -134,9 +134,9 @@ public class SetOperationsTest { */ @Test public final void hammingDistanceTest() { - List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); - Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter filter1 = new HasherBloomFilter(hasher, shape); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); + final BloomFilter filter1 = new HasherBloomFilter(hasher, shape); List lst2 = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); @@ -159,9 +159,9 @@ public class SetOperationsTest { */ @Test public final void jaccardSimilarityTest() { - List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); - Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter filter1 = new HasherBloomFilter(hasher, shape); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); + final BloomFilter filter1 = new HasherBloomFilter(hasher, shape); List lst2 = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); @@ -184,12 +184,12 @@ public class SetOperationsTest { */ @Test public final void jaccardSimilarityTest_NoValues() { - BloomFilter filter1 = new HasherBloomFilter(shape); - BloomFilter filter2 = new HasherBloomFilter(shape); + final BloomFilter filter1 = new HasherBloomFilter(shape); + final BloomFilter filter2 = new HasherBloomFilter(shape); // build a filter - List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); - Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter filter3 = new HasherBloomFilter( hasher, shape ); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); + final BloomFilter filter3 = new HasherBloomFilter( hasher, shape ); assertEquals(0.0, SetOperations.jaccardSimilarity(filter1, filter2), 0.0001); assertEquals(0.0, SetOperations.jaccardSimilarity(filter2, filter1), 0.0001); @@ -204,9 +204,9 @@ public class SetOperationsTest { */ @Test public final void jaccardDistanceTest() { - List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); - Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter filter1 = new HasherBloomFilter(hasher, shape); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); + final BloomFilter filter1 = new HasherBloomFilter(hasher, shape); List lst2 = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); @@ -230,12 +230,12 @@ public class SetOperationsTest { */ @Test public final void jaccardDistanceTest_NoValues() { - BloomFilter filter1 = new HasherBloomFilter(shape); - BloomFilter filter2 = new HasherBloomFilter(shape); + final BloomFilter filter1 = new HasherBloomFilter(shape); + final BloomFilter filter2 = new HasherBloomFilter(shape); // build a filter - List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); - Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter filter3 = new HasherBloomFilter( hasher, shape ); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); + final BloomFilter filter3 = new HasherBloomFilter( hasher, shape ); assertEquals(1.0, SetOperations.jaccardDistance(filter1, filter2), 0.0001); assertEquals(1.0, SetOperations.jaccardDistance(filter2, filter1), 0.0001); @@ -250,9 +250,9 @@ public class SetOperationsTest { */ @Test public final void cosineSimilarityTest() { - List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); - Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter filter1 = new HasherBloomFilter(hasher, shape); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); + final BloomFilter filter1 = new HasherBloomFilter(hasher, shape); List lst2 = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); Hasher hasher2 = new StaticHasher(lst2.iterator(), shape); @@ -276,12 +276,12 @@ public class SetOperationsTest { */ @Test public final void cosineSimilarityTest_NoValues() { - BloomFilter filter1 = new HasherBloomFilter(shape); - BloomFilter filter2 = new HasherBloomFilter(shape); + final BloomFilter filter1 = new HasherBloomFilter(shape); + final BloomFilter filter2 = new HasherBloomFilter(shape); // build a filter - List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); - Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter filter3 = new HasherBloomFilter( hasher, shape ); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); + final BloomFilter filter3 = new HasherBloomFilter( hasher, shape ); assertEquals(0.0, SetOperations.cosineSimilarity(filter1, filter2), 0.0001); assertEquals(0.0, SetOperations.cosineSimilarity(filter2, filter1), 0.0001); @@ -332,12 +332,12 @@ public class SetOperationsTest { */ @Test public final void cosineDistanceTest_NoValues() { - BloomFilter filter1 = new HasherBloomFilter(shape); - BloomFilter filter2 = new HasherBloomFilter(shape); + final BloomFilter filter1 = new HasherBloomFilter(shape); + final BloomFilter filter2 = new HasherBloomFilter(shape); // build a filter - List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); - Hasher hasher = new StaticHasher(lst.iterator(), shape); - BloomFilter filter3 = new HasherBloomFilter( hasher, shape ); + final List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17); + final Hasher hasher = new StaticHasher(lst.iterator(), shape); + final BloomFilter filter3 = new HasherBloomFilter( hasher, shape ); assertEquals(1.0, SetOperations.cosineDistance(filter1, filter2), 0.0001); assertEquals(1.0, SetOperations.cosineDistance(filter2, filter1), 0.0001); diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/CommonComparatorTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/CommonComparatorTest.java index e0cee3794..4a703f7b8 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/CommonComparatorTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/CommonComparatorTest.java @@ -35,11 +35,11 @@ import org.junit.Test; */ public class CommonComparatorTest { - private void assertBefore(HashFunctionIdentity identity1, HashFunctionIdentity identity2) { + private void assertBefore(final HashFunctionIdentity identity1, final HashFunctionIdentity identity2) { assertTrue(0 > HashFunctionIdentity.COMMON_COMPARATOR.compare(identity1, identity2)); } - private void assertAfter(HashFunctionIdentity identity1, HashFunctionIdentity identity2) { + private void assertAfter(final HashFunctionIdentity identity1, final HashFunctionIdentity identity2) { assertTrue(0 < HashFunctionIdentity.COMMON_COMPARATOR.compare(identity1, identity2)); } @@ -48,9 +48,9 @@ public class CommonComparatorTest { */ @Test public void nameOrderTestDifferentNames() { - HashFunctionIdentityImpl impl1 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, + final HashFunctionIdentityImpl impl1 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, ProcessType.CYCLIC, 300L); - HashFunctionIdentityImpl impl2 = new HashFunctionIdentityImpl("Testing Suite", "impl2", Signedness.SIGNED, + final HashFunctionIdentityImpl impl2 = new HashFunctionIdentityImpl("Testing Suite", "impl2", Signedness.SIGNED, ProcessType.CYCLIC, 300L); assertBefore(impl1, impl2); @@ -64,9 +64,9 @@ public class CommonComparatorTest { */ @Test public void nameOrderTestDifferentCapitalization() { - HashFunctionIdentityImpl impl1 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, + final HashFunctionIdentityImpl impl1 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, ProcessType.CYCLIC, 300L); - HashFunctionIdentityImpl impl2 = new HashFunctionIdentityImpl("Testing Suite", "IMPL1", Signedness.SIGNED, + final HashFunctionIdentityImpl impl2 = new HashFunctionIdentityImpl("Testing Suite", "IMPL1", Signedness.SIGNED, ProcessType.CYCLIC, 300L); assertEquals(0, HashFunctionIdentity.COMMON_COMPARATOR.compare(impl1, impl2)); @@ -78,9 +78,9 @@ public class CommonComparatorTest { */ @Test public void signednessOrder() { - HashFunctionIdentityImpl impl1 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, + final HashFunctionIdentityImpl impl1 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, ProcessType.CYCLIC, 300L); - HashFunctionIdentityImpl impl2 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.UNSIGNED, + final HashFunctionIdentityImpl impl2 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.UNSIGNED, ProcessType.CYCLIC, 300L); assertBefore(impl1, impl2); @@ -94,9 +94,9 @@ public class CommonComparatorTest { */ @Test public void processTypeOrder() { - HashFunctionIdentityImpl impl1 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, + final HashFunctionIdentityImpl impl1 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, ProcessType.CYCLIC, 300L); - HashFunctionIdentityImpl impl2 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, + final HashFunctionIdentityImpl impl2 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, ProcessType.ITERATIVE, 300L); assertBefore(impl1, impl2); @@ -110,9 +110,9 @@ public class CommonComparatorTest { */ @Test public void producerDoesNotChangeOrder() { - HashFunctionIdentityImpl impl1 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, + final HashFunctionIdentityImpl impl1 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, ProcessType.CYCLIC, 300L); - HashFunctionIdentityImpl impl2 = new HashFunctionIdentityImpl("Testing Suite2", "impl1", Signedness.SIGNED, + final HashFunctionIdentityImpl impl2 = new HashFunctionIdentityImpl("Testing Suite2", "impl1", Signedness.SIGNED, ProcessType.CYCLIC, 300L); assertEquals(0, HashFunctionIdentity.COMMON_COMPARATOR.compare(impl1, impl2)); @@ -124,9 +124,9 @@ public class CommonComparatorTest { @Test public void testSortOrder() { // in this test the signature is the position in the final collection for the ID - TreeSet result = new TreeSet<>( + final TreeSet result = new TreeSet<>( HashFunctionIdentity.COMMON_COMPARATOR); - List collection = new ArrayList<>(); + final List collection = new ArrayList<>(); collection .add(new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, ProcessType.CYCLIC, 0)); @@ -156,7 +156,7 @@ public class CommonComparatorTest { result.addAll(collection); long idx = 0; - for (HashFunctionIdentity id : result) { + for (final HashFunctionIdentity id : result) { assertEquals("Unexpected order for " + HashFunctionIdentity.asCommonString(id), idx++, id.getSignature()); } } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/DeepComparatorTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/DeepComparatorTest.java index f1534e28b..1394c7b4c 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/DeepComparatorTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/DeepComparatorTest.java @@ -35,11 +35,11 @@ import org.junit.Test; */ public class DeepComparatorTest { - private void assertBefore(HashFunctionIdentity identity1, HashFunctionIdentity identity2) { + private void assertBefore(final HashFunctionIdentity identity1, final HashFunctionIdentity identity2) { assertTrue(0 > HashFunctionIdentity.DEEP_COMPARATOR.compare(identity1, identity2)); } - private void assertAfter(HashFunctionIdentity identity1, HashFunctionIdentity identity2) { + private void assertAfter(final HashFunctionIdentity identity1, final HashFunctionIdentity identity2) { assertTrue(0 < HashFunctionIdentity.DEEP_COMPARATOR.compare(identity1, identity2)); } @@ -48,9 +48,9 @@ public class DeepComparatorTest { */ @Test public void nameOrderTestDifferentNames() { - HashFunctionIdentityImpl impl1 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, + final HashFunctionIdentityImpl impl1 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, ProcessType.CYCLIC, 300L); - HashFunctionIdentityImpl impl2 = new HashFunctionIdentityImpl("Testing Suite", "impl2", Signedness.SIGNED, + final HashFunctionIdentityImpl impl2 = new HashFunctionIdentityImpl("Testing Suite", "impl2", Signedness.SIGNED, ProcessType.CYCLIC, 300L); assertBefore(impl1, impl2); @@ -64,9 +64,9 @@ public class DeepComparatorTest { */ @Test public void nameOrderTestDifferentCapitalization() { - HashFunctionIdentityImpl impl1 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, + final HashFunctionIdentityImpl impl1 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, ProcessType.CYCLIC, 300L); - HashFunctionIdentityImpl impl2 = new HashFunctionIdentityImpl("Testing Suite", "IMPL1", Signedness.SIGNED, + final HashFunctionIdentityImpl impl2 = new HashFunctionIdentityImpl("Testing Suite", "IMPL1", Signedness.SIGNED, ProcessType.CYCLIC, 300L); assertEquals(0, HashFunctionIdentity.DEEP_COMPARATOR.compare(impl1, impl2)); @@ -78,9 +78,9 @@ public class DeepComparatorTest { */ @Test public void signednessOrder() { - HashFunctionIdentityImpl impl1 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, + final HashFunctionIdentityImpl impl1 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, ProcessType.CYCLIC, 300L); - HashFunctionIdentityImpl impl2 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.UNSIGNED, + final HashFunctionIdentityImpl impl2 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.UNSIGNED, ProcessType.CYCLIC, 300L); assertBefore(impl1, impl2); @@ -94,9 +94,9 @@ public class DeepComparatorTest { */ @Test public void processTypeOrder() { - HashFunctionIdentityImpl impl1 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, + final HashFunctionIdentityImpl impl1 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, ProcessType.CYCLIC, 300L); - HashFunctionIdentityImpl impl2 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, + final HashFunctionIdentityImpl impl2 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, ProcessType.ITERATIVE, 300L); assertBefore(impl1, impl2); @@ -110,9 +110,9 @@ public class DeepComparatorTest { */ @Test public void producerOrder() { - HashFunctionIdentityImpl impl1 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, + final HashFunctionIdentityImpl impl1 = new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, ProcessType.CYCLIC, 300L); - HashFunctionIdentityImpl impl2 = new HashFunctionIdentityImpl("Testing Suite2", "impl1", Signedness.SIGNED, + final HashFunctionIdentityImpl impl2 = new HashFunctionIdentityImpl("Testing Suite2", "impl1", Signedness.SIGNED, ProcessType.CYCLIC, 300L); assertBefore(impl1, impl2); @@ -127,8 +127,8 @@ public class DeepComparatorTest { @Test public void testSortOrder() { // in this test the signature is the position in the final collection for the ID - TreeSet result = new TreeSet<>(HashFunctionIdentity.DEEP_COMPARATOR); - List collection = new ArrayList<>(); + final TreeSet result = new TreeSet<>(HashFunctionIdentity.DEEP_COMPARATOR); + final List collection = new ArrayList<>(); collection .add(new HashFunctionIdentityImpl("Testing Suite", "impl1", Signedness.SIGNED, ProcessType.CYCLIC, 0)); @@ -182,7 +182,7 @@ public class DeepComparatorTest { result.addAll(collection); long idx = 0; - for (HashFunctionIdentity id : result) { + for (final HashFunctionIdentity id : result) { assertEquals("Unexpected order for " + id.getProvider() + ":" + HashFunctionIdentity.asCommonString(id), idx++, id.getSignature()); } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/DynamicHasherBuilderTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/DynamicHasherBuilderTest.java index 148e79246..0c7132e75 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/DynamicHasherBuilderTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/DynamicHasherBuilderTest.java @@ -35,7 +35,7 @@ import org.junit.Test; public class DynamicHasherBuilderTest { private DynamicHasher.Builder builder; - private Shape shape = new Shape( new MD5Cyclic(), 1, Integer.MAX_VALUE, 1 ); + private final Shape shape = new Shape( new MD5Cyclic(), 1, Integer.MAX_VALUE, 1 ); /** * Sets up the builder for testing. @@ -52,11 +52,11 @@ public class DynamicHasherBuilderTest { */ @Test public void buildTest_byte() { - DynamicHasher hasher = builder.with((byte) 0x1).build(); + final DynamicHasher hasher = builder.with((byte) 0x1).build(); - int expected = 1483089307; + final int expected = 1483089307; - OfInt iter = hasher.getBits(shape); + final OfInt iter = hasher.getBits(shape); assertTrue(iter.hasNext()); assertEquals( expected, iter.nextInt() ); @@ -68,10 +68,10 @@ public class DynamicHasherBuilderTest { */ @Test public void buildTest_byteArray() { - DynamicHasher hasher = builder.with("Hello".getBytes()).build(); - int expected = 1519797563; + final DynamicHasher hasher = builder.with("Hello".getBytes()).build(); + final int expected = 1519797563; - OfInt iter = hasher.getBits(shape); + final OfInt iter = hasher.getBits(shape); assertTrue(iter.hasNext()); assertEquals( expected, iter.nextInt() ); @@ -84,10 +84,10 @@ public class DynamicHasherBuilderTest { */ @Test public void buildTest_String() { - DynamicHasher hasher = builder.with("Hello").build(); - int expected = 1519797563; + final DynamicHasher hasher = builder.with("Hello").build(); + final int expected = 1519797563; - OfInt iter = hasher.getBits(shape); + final OfInt iter = hasher.getBits(shape); assertTrue(iter.hasNext()); assertEquals( expected, iter.nextInt() ); @@ -99,9 +99,9 @@ public class DynamicHasherBuilderTest { */ @Test public void buildTest_Empty() { - DynamicHasher hasher = builder.build(); + final DynamicHasher hasher = builder.build(); - OfInt iter = hasher.getBits(shape); + final OfInt iter = hasher.getBits(shape); assertFalse(iter.hasNext()); } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/DynamicHasherTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/DynamicHasherTest.java index 19cdc1d8c..117dc052b 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/DynamicHasherTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/DynamicHasherTest.java @@ -37,7 +37,7 @@ public class DynamicHasherTest { private DynamicHasher.Builder builder; private Shape shape; - private HashFunctionIdentity testFunction = new HashFunctionIdentity() { + private final HashFunctionIdentity testFunction = new HashFunctionIdentity() { @Override public String getName() { @@ -82,11 +82,11 @@ public class DynamicHasherTest { @Test public void testGetBits() { - int[] expected = {6, 69, 44, 19, 10, 57, 48, 23, 70, 61, 36, 11, 2, 49, 24, 15, 62}; + final int[] expected = {6, 69, 44, 19, 10, 57, 48, 23, 70, 61, 36, 11, 2, 49, 24, 15, 62}; - Hasher hasher = builder.with("Hello").build(); + final Hasher hasher = builder.with("Hello").build(); - OfInt iter = hasher.getBits(shape); + final OfInt iter = hasher.getBits(shape); for (int i = 0; i < expected.length; i++) { assertTrue(iter.hasNext()); @@ -101,12 +101,12 @@ public class DynamicHasherTest { */ @Test public void testGetBits_MultipleHashes() { - int[] expected = {6, 69, 44, 19, 10, 57, 48, 23, 70, 61, 36, 11, 2, 49, 24, 15, 62, 1, 63, 53, 43, 17, 7, 69, + final int[] expected = {6, 69, 44, 19, 10, 57, 48, 23, 70, 61, 36, 11, 2, 49, 24, 15, 62, 1, 63, 53, 43, 17, 7, 69, 59, 49, 39, 13, 3, 65, 55, 45, 35, 25}; - Hasher hasher = builder.with("Hello").with("World").build(); + final Hasher hasher = builder.with("Hello").with("World").build(); - OfInt iter = hasher.getBits(shape); + final OfInt iter = hasher.getBits(shape); for (int i = 0; i < expected.length; i++) { assertTrue(iter.hasNext()); @@ -122,12 +122,12 @@ public class DynamicHasherTest { @Test public void testGetBits_WongShape() { - Hasher hasher = builder.with("Hello").build(); + final Hasher hasher = builder.with("Hello").build(); try { hasher.getBits(new Shape(testFunction, 3, 72, 17)); fail("Should have thown IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + } catch (final IllegalArgumentException expected) { // do nothing } } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/HashFunctionIdentityImplTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/HashFunctionIdentityImplTest.java index 365c73527..254339bc2 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/HashFunctionIdentityImplTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/HashFunctionIdentityImplTest.java @@ -34,7 +34,7 @@ public class HashFunctionIdentityImplTest { */ @Test public void copyConstructorTest() { - HashFunctionIdentity identity = new HashFunctionIdentity() { + final HashFunctionIdentity identity = new HashFunctionIdentity() { @Override public String getName() { @@ -62,7 +62,7 @@ public class HashFunctionIdentityImplTest { } }; - HashFunctionIdentityImpl impl = new HashFunctionIdentityImpl( identity ); + final HashFunctionIdentityImpl impl = new HashFunctionIdentityImpl( identity ); assertEquals( "NAME", impl.getName()); assertEquals( "Provider", impl.getProvider()); assertEquals( Signedness.SIGNED, impl.getSignedness()); @@ -80,7 +80,7 @@ public class HashFunctionIdentityImplTest { */ @Test public void valuesConstructorTest() { - HashFunctionIdentityImpl impl = new HashFunctionIdentityImpl( "Provider", "NAME", + final HashFunctionIdentityImpl impl = new HashFunctionIdentityImpl( "Provider", "NAME", Signedness.UNSIGNED, ProcessType.ITERATIVE, -2l); assertEquals( "NAME", impl.getName()); assertEquals( "Provider", impl.getProvider()); diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/ShapeTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/ShapeTest.java index 6ed068e2d..8d863d48c 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/ShapeTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/ShapeTest.java @@ -34,7 +34,7 @@ import org.junit.Test; public class ShapeTest { - private HashFunctionIdentity testFunction = new HashFunctionIdentity() { + private final HashFunctionIdentity testFunction = new HashFunctionIdentity() { @Override public String getName() { @@ -74,7 +74,7 @@ public class ShapeTest { */ - private Shape shape = new Shape(testFunction, 5, 0.1); + private final Shape shape = new Shape(testFunction, 5, 0.1); /** * Tests that the constructor with a null name, number of items, and probability fails. @@ -86,7 +86,7 @@ public class ShapeTest { new Shape(null, 5, 0.1); fail( "Should throw IllegalArgumentException"); } - catch (IllegalArgumentException expected) + catch (final IllegalArgumentException expected) { // do nothing } @@ -102,7 +102,7 @@ public class ShapeTest { new Shape(null, 5, 72); fail( "Should throw IllegalArgumentException"); } - catch (IllegalArgumentException expected) + catch (final IllegalArgumentException expected) { // do nothing } @@ -119,7 +119,7 @@ public class ShapeTest { new Shape(null, 5, 72, 17); fail( "Should throw IllegalArgumentException"); } - catch (IllegalArgumentException expected) + catch (final IllegalArgumentException expected) { // do nothing } @@ -136,7 +136,7 @@ public class ShapeTest { new Shape(null, 0.1, 72, 17); fail( "Should throw IllegalArgumentException"); } - catch (IllegalArgumentException expected) + catch (final IllegalArgumentException expected) { // do nothing } @@ -165,7 +165,7 @@ public class ShapeTest { try { new Shape( testFunction, Integer.MAX_VALUE, 1.0 / 10); fail("Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + } catch (final IllegalArgumentException expected) { // do nothing. } } @@ -179,7 +179,7 @@ public class ShapeTest { try { new Shape( testFunction, 0, 1.0 / 10); fail("Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + } catch (final IllegalArgumentException expected) { // do nothing. } } @@ -193,14 +193,14 @@ public class ShapeTest { try { new Shape(testFunction, 10, 0.0); fail("Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + } catch (final IllegalArgumentException expected) { // do nothing. } try { new Shape(testFunction, 10, 1.0); fail("Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + } catch (final IllegalArgumentException expected) { // do nothing. } } @@ -214,7 +214,7 @@ public class ShapeTest { /* * values from https://hur.st/bloomfilter/?n=5&m=24 */ - Shape filterConfig = new Shape(testFunction, 5, 24); + final Shape filterConfig = new Shape(testFunction, 5, 24); assertEquals(24, filterConfig.getNumberOfBits()); assertEquals(3, filterConfig.getNumberOfBytes()); @@ -233,7 +233,7 @@ public class ShapeTest { try { new Shape(testFunction, 0, 24); fail( "Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) + } catch (final IllegalArgumentException expected) { //expected } @@ -248,7 +248,7 @@ public class ShapeTest { try { new Shape(testFunction, 5, 6); fail( "Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) + } catch (final IllegalArgumentException expected) { //expected } @@ -262,7 +262,7 @@ public class ShapeTest { try { new Shape(testFunction, 16,8); fail( "Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) + } catch (final IllegalArgumentException expected) { //expected } @@ -277,7 +277,7 @@ public class ShapeTest { /* * values from https://hur.st/bloomfilter/?n=5&m=24&k=4 */ - Shape filterConfig = new Shape(testFunction, 5, 24, 4); + final Shape filterConfig = new Shape(testFunction, 5, 24, 4); assertEquals(24, filterConfig.getNumberOfBits()); assertEquals(3, filterConfig.getNumberOfBytes()); @@ -295,7 +295,7 @@ public class ShapeTest { try { new Shape(testFunction, 0, 24, 1); fail( "Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) + } catch (final IllegalArgumentException expected) { //expected } @@ -309,7 +309,7 @@ public class ShapeTest { try { new Shape(testFunction, 5, 6, 1); fail( "Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) + } catch (final IllegalArgumentException expected) { //expected } @@ -324,7 +324,7 @@ public class ShapeTest { try { new Shape(testFunction, 5, 24, 0); fail( "Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) + } catch (final IllegalArgumentException expected) { //expected } @@ -339,7 +339,7 @@ public class ShapeTest { try { new Shape(testFunction, 4000,8,1); fail( "Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) + } catch (final IllegalArgumentException expected) { //expected } @@ -354,7 +354,7 @@ public class ShapeTest { /* * values from https://hur.st/bloomfilter/?n=5&p=.1&m=&k= */ - Shape filterConfig = new Shape(testFunction, 0.1, 24, 3); + final Shape filterConfig = new Shape(testFunction, 0.1, 24, 3); assertEquals(24, filterConfig.getNumberOfBits()); assertEquals(3, filterConfig.getNumberOfBytes()); @@ -373,7 +373,7 @@ public class ShapeTest { try { new Shape(testFunction, 0.0, 24, 1); fail( "Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) + } catch (final IllegalArgumentException expected) { //expected } @@ -382,7 +382,7 @@ public class ShapeTest { try { new Shape(testFunction, -1.0, 24, 1); fail( "Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) + } catch (final IllegalArgumentException expected) { //expected } @@ -391,7 +391,7 @@ public class ShapeTest { try { new Shape(testFunction, -1.5, 24, 1); fail( "Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) + } catch (final IllegalArgumentException expected) { //expected } @@ -400,7 +400,7 @@ public class ShapeTest { try { new Shape(testFunction, 1.0, 24, 1); fail( "Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) + } catch (final IllegalArgumentException expected) { //expected } @@ -409,7 +409,7 @@ public class ShapeTest { try { new Shape(testFunction, 2.0, 24, 1); fail( "Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) + } catch (final IllegalArgumentException expected) { //expected } @@ -423,7 +423,7 @@ public class ShapeTest { try { new Shape(testFunction, 0.5, 6, 1); fail( "Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) + } catch (final IllegalArgumentException expected) { //expected } @@ -437,7 +437,7 @@ public class ShapeTest { try { new Shape(testFunction, 0.5, 24, 0); fail( "Should have thrown IllegalArgumentException"); - } catch (IllegalArgumentException expected) + } catch (final IllegalArgumentException expected) { //expected } @@ -453,7 +453,7 @@ public class ShapeTest { assertNotEquals(new Shape(testFunction, 5, 1.0 / 11), shape); assertNotEquals(new Shape(testFunction, 4, 1.0 / 10), shape); - HashFunctionIdentity testFunction2 = new HashFunctionIdentity() { + final HashFunctionIdentity testFunction2 = new HashFunctionIdentity() { @Override public String getName() { @@ -489,7 +489,7 @@ public class ShapeTest { */ @Test public void hashCodeTest() { - int hashCode = Objects.hash(testFunction, 24, 3 ); + final int hashCode = Objects.hash(testFunction, 24, 3 ); assertEquals(hashCode, shape.hashCode()); } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/StaticHasherTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/StaticHasherTest.java index 034bf8aeb..937340b99 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/StaticHasherTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/StaticHasherTest.java @@ -35,7 +35,7 @@ import org.junit.Test; */ public class StaticHasherTest { - private HashFunctionIdentity testFunction = new HashFunctionIdentity() { + private final HashFunctionIdentity testFunction = new HashFunctionIdentity() { @Override public String getName() { @@ -63,7 +63,7 @@ public class StaticHasherTest { } }; - private HashFunctionIdentity testFunctionX = new HashFunctionIdentity() { + private final HashFunctionIdentity testFunctionX = new HashFunctionIdentity() { @Override public String getName() { @@ -91,18 +91,18 @@ public class StaticHasherTest { } }; - private Shape shape = new Shape(testFunction, 3, 72, 17); + private final Shape shape = new Shape(testFunction, 3, 72, 17); /** * Tests that getBits returns the proper values. */ @Test public void testGetBits() { - List lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + final List lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); - StaticHasher hasher = new StaticHasher(lst.iterator(), shape); + final StaticHasher hasher = new StaticHasher(lst.iterator(), shape); assertEquals(17, hasher.size()); - OfInt iter = hasher.getBits(shape); + final OfInt iter = hasher.getBits(shape); for (int i = 0; i < 17; i++) { assertTrue(iter.hasNext()); assertEquals(i, iter.nextInt()); @@ -116,14 +116,14 @@ public class StaticHasherTest { */ @Test public void testGetBits_DuplicateValues() { - int[] input = {6, 69, 44, 19, 10, 57, 48, 23, 70, 61, 36, 11, 2, 49, 24, 15, 62, 1, 63, 53, 43, 17, 7, 69, 59, + final int[] input = {6, 69, 44, 19, 10, 57, 48, 23, 70, 61, 36, 11, 2, 49, 24, 15, 62, 1, 63, 53, 43, 17, 7, 69, 59, 49, 39, 13, 3, 65, 55, 45, 35, 25}; - int[] expected = {1, 2, 3, 6, 7, 10, 11, 13, 15, 17, 19, 23, 24, 25, 35, 36, 39, 43, 44, 45, 48, 49, 53, 55, 57, + final int[] expected = {1, 2, 3, 6, 7, 10, 11, 13, 15, 17, 19, 23, 24, 25, 35, 36, 39, 43, 44, 45, 48, 49, 53, 55, 57, 59, 61, 62, 63, 65, 69, 70}; - StaticHasher hasher = new StaticHasher(Arrays.stream(input).iterator(), shape); + final StaticHasher hasher = new StaticHasher(Arrays.stream(input).iterator(), shape); - OfInt iter = hasher.getBits(shape); + final OfInt iter = hasher.getBits(shape); for (int i = 0; i < expected.length; i++) { assertTrue(iter.hasNext()); assertEquals(expected[i], iter.nextInt()); @@ -136,13 +136,13 @@ public class StaticHasherTest { */ @Test public void testGetBits_WrongShape() { - List lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); - StaticHasher hasher = new StaticHasher(lst.iterator(), shape); + final List lst = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + final StaticHasher hasher = new StaticHasher(lst.iterator(), shape); try { hasher.getBits(new Shape(testFunctionX, 3, 72, 17)); fail("Should have thown IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + } catch (final IllegalArgumentException expected) { // do nothing } @@ -154,9 +154,9 @@ public class StaticHasherTest { @Test public void testConstructor_Iterator() { - int[] values = {1, 3, 5, 7, 9, 3, 5, 1}; + final int[] values = {1, 3, 5, 7, 9, 3, 5, 1}; Iterator iter = Arrays.stream(values).iterator(); - StaticHasher hasher = new StaticHasher(iter, shape); + final StaticHasher hasher = new StaticHasher(iter, shape); assertEquals(5, hasher.size()); assertEquals(shape, hasher.getShape()); @@ -178,12 +178,12 @@ public class StaticHasherTest { @Test public void testConstructor_Iterator_ValueTooBig() { - int[] values = {shape.getNumberOfBits(), 3, 5, 7, 9, 3, 5, 1}; - Iterator iter = Arrays.stream(values).iterator(); + final int[] values = {shape.getNumberOfBits(), 3, 5, 7, 9, 3, 5, 1}; + final Iterator iter = Arrays.stream(values).iterator(); try { new StaticHasher(iter, shape); fail("Should have thown IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + } catch (final IllegalArgumentException expected) { // do nothing } } @@ -195,12 +195,12 @@ public class StaticHasherTest { @Test public void testConstructor_Iterator_ValueTooSmall() { - int[] values = {-1, 3, 5, 7, 9, 3, 5, 1}; - Iterator iter = Arrays.stream(values).iterator(); + final int[] values = {-1, 3, 5, 7, 9, 3, 5, 1}; + final Iterator iter = Arrays.stream(values).iterator(); try { new StaticHasher(iter, shape); fail("Should have thown IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + } catch (final IllegalArgumentException expected) { // do nothing } } @@ -211,9 +211,9 @@ public class StaticHasherTest { * @param hasher1 the first static hasher. * @param hasher2 the second static hasher. */ - private void assertSameBits(StaticHasher hasher1, StaticHasher hasher2) { - OfInt iter1 = hasher1.getBits(shape); - OfInt iter2 = hasher2.getBits(shape); + private void assertSameBits(final StaticHasher hasher1, final StaticHasher hasher2) { + final OfInt iter1 = hasher1.getBits(shape); + final OfInt iter2 = hasher2.getBits(shape); while (iter1.hasNext()) { assertTrue("Not enough data in second hasher", iter2.hasNext()); @@ -227,11 +227,11 @@ public class StaticHasherTest { */ @Test public void testConstructor_StaticHasher() { - int[] values = {1, 3, 5, 7, 9, 3, 5, 1}; - Iterator iter = Arrays.stream(values).iterator(); - StaticHasher hasher = new StaticHasher(iter, shape); + final int[] values = {1, 3, 5, 7, 9, 3, 5, 1}; + final Iterator iter = Arrays.stream(values).iterator(); + final StaticHasher hasher = new StaticHasher(iter, shape); - StaticHasher hasher2 = new StaticHasher(hasher, shape); + final StaticHasher hasher2 = new StaticHasher(hasher, shape); assertEquals(shape, hasher2.getShape()); assertSameBits(hasher, hasher2); @@ -243,14 +243,14 @@ public class StaticHasherTest { */ @Test public void testConstructor_StaticHasher_WrongShape() { - int[] values = {1, 3, 5, 7, 9, 3, 5, 1}; - Iterator iter = Arrays.stream(values).iterator(); - StaticHasher hasher = new StaticHasher(iter, new Shape(testFunctionX, 3, 72, 17)); + final int[] values = {1, 3, 5, 7, 9, 3, 5, 1}; + final Iterator iter = Arrays.stream(values).iterator(); + final StaticHasher hasher = new StaticHasher(iter, new Shape(testFunctionX, 3, 72, 17)); try { new StaticHasher(hasher, shape); fail("Should have thown IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + } catch (final IllegalArgumentException expected) { // do nothing } } @@ -261,9 +261,9 @@ public class StaticHasherTest { */ @Test public void testConstructor_Hasher() { - int[] expected = {1, 3, 5, 7, 9}; + final int[] expected = {1, 3, 5, 7, 9}; - Hasher testHasher = new Hasher() { + final Hasher testHasher = new Hasher() { @Override public boolean isEmpty() { return false; } @@ -274,14 +274,14 @@ public class StaticHasherTest { } @Override - public OfInt getBits(Shape shape) { - int[] values = {1, 3, 5, 7, 9, 3, 5, 1}; + public OfInt getBits(final Shape shape) { + final int[] values = {1, 3, 5, 7, 9, 3, 5, 1}; return Arrays.stream(values).iterator(); } }; - StaticHasher hasher = new StaticHasher(testHasher, shape); - OfInt iter = hasher.getBits(shape); + final StaticHasher hasher = new StaticHasher(testHasher, shape); + final OfInt iter = hasher.getBits(shape); for (int i = 0; i < expected.length; i++) { assertTrue(iter.hasNext()); assertEquals(expected[i], iter.nextInt()); @@ -295,7 +295,7 @@ public class StaticHasherTest { */ @Test public void testConstructor_Hasher_WrongShape() { - Hasher testHasher = new Hasher() { + final Hasher testHasher = new Hasher() { @Override public boolean isEmpty() { return false; } @@ -306,8 +306,8 @@ public class StaticHasherTest { } @Override - public OfInt getBits(Shape shape) { - int[] values = {1, 3, 5, 7, 9, 3, 5, 1}; + public OfInt getBits(final Shape shape) { + final int[] values = {1, 3, 5, 7, 9, 3, 5, 1}; return Arrays.stream(values).iterator(); } }; @@ -315,7 +315,7 @@ public class StaticHasherTest { try { new StaticHasher(testHasher, shape); fail("Should have thown IllegalArgumentException"); - } catch (IllegalArgumentException expected) { + } catch (final IllegalArgumentException expected) { // do nothing } } @@ -325,7 +325,7 @@ public class StaticHasherTest { */ @Test public void testIsEmpty() { - List lst = new ArrayList<>(); + final List lst = new ArrayList<>(); StaticHasher hasher = new StaticHasher(lst.iterator(), shape); diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/function/MD5CyclicTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/function/MD5CyclicTest.java index 348fc3b20..16c59f4b0 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/function/MD5CyclicTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/function/MD5CyclicTest.java @@ -36,10 +36,10 @@ public class MD5CyclicTest { */ @Test public void applyTest() { - MD5Cyclic md5 = new MD5Cyclic(); - long l1 = 0x8b1a9953c4611296L; - long l2 = 0xa827abf8c47804d7L; - byte[] buffer = "Hello".getBytes(); + final MD5Cyclic md5 = new MD5Cyclic(); + final long l1 = 0x8b1a9953c4611296L; + final long l2 = 0xa827abf8c47804d7L; + final byte[] buffer = "Hello".getBytes(); long l = md5.apply(buffer, 0); assertEquals(l1, l); @@ -54,10 +54,10 @@ public class MD5CyclicTest { */ @Test public void signatureTest() { - MD5Cyclic md5 = new MD5Cyclic(); - String arg = String.format("%s-%s-%s", md5.getName().toUpperCase(Locale.ROOT), md5.getSignedness(), + final MD5Cyclic md5 = new MD5Cyclic(); + final String arg = String.format("%s-%s-%s", md5.getName().toUpperCase(Locale.ROOT), md5.getSignedness(), md5.getProcessType()); - long expected = md5.apply(arg.getBytes(StandardCharsets.UTF_8), 0); + final long expected = md5.apply(arg.getBytes(StandardCharsets.UTF_8), 0); assertEquals(expected, md5.getSignature()); } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/function/Murmur128x86CyclicTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/function/Murmur128x86CyclicTest.java index b3de2d1b6..61f3a485b 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/function/Murmur128x86CyclicTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/function/Murmur128x86CyclicTest.java @@ -36,11 +36,11 @@ public class Murmur128x86CyclicTest { */ @Test public void applyTest() { - Murmur128x86Cyclic murmur = new Murmur128x86Cyclic(); + final Murmur128x86Cyclic murmur = new Murmur128x86Cyclic(); - long l1 = 0xe7eb60dabb386407L; - long l2 = 0xc3ca49f691f73056L; - byte[] buffer = "Now is the time for all good men to come to the aid of their country" + final long l1 = 0xe7eb60dabb386407L; + final long l2 = 0xc3ca49f691f73056L; + final byte[] buffer = "Now is the time for all good men to come to the aid of their country" .getBytes(StandardCharsets.UTF_8); long l = murmur.apply(buffer, 0); @@ -56,10 +56,10 @@ public class Murmur128x86CyclicTest { */ @Test public void signatureTest() { - Murmur128x86Cyclic murmur = new Murmur128x86Cyclic(); - String arg = String.format("%s-%s-%s", murmur.getName().toUpperCase(Locale.ROOT), murmur.getSignedness(), + final Murmur128x86Cyclic murmur = new Murmur128x86Cyclic(); + final String arg = String.format("%s-%s-%s", murmur.getName().toUpperCase(Locale.ROOT), murmur.getSignedness(), murmur.getProcessType()); - long expected = murmur.apply(arg.getBytes(StandardCharsets.UTF_8), 0); + final long expected = murmur.apply(arg.getBytes(StandardCharsets.UTF_8), 0); assertEquals(expected, murmur.getSignature()); } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/function/Murmur32x86IterativeTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/function/Murmur32x86IterativeTest.java index a12a743e1..d15eb5af5 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/function/Murmur32x86IterativeTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/function/Murmur32x86IterativeTest.java @@ -36,9 +36,9 @@ public class Murmur32x86IterativeTest { */ @Test public void applyTest() { - Murmur32x86Iterative murmur = new Murmur32x86Iterative(); + final Murmur32x86Iterative murmur = new Murmur32x86Iterative(); - byte[] buffer = "Now is the time for all good men to come to the aid of their country" + final byte[] buffer = "Now is the time for all good men to come to the aid of their country" .getBytes(StandardCharsets.UTF_8); long l = murmur.apply(buffer, 0); @@ -54,10 +54,10 @@ public class Murmur32x86IterativeTest { */ @Test public void signatureTest() { - Murmur32x86Iterative murmur = new Murmur32x86Iterative(); - String arg = String.format("%s-%s-%s", murmur.getName().toUpperCase(Locale.ROOT), murmur.getSignedness(), + final Murmur32x86Iterative murmur = new Murmur32x86Iterative(); + final String arg = String.format("%s-%s-%s", murmur.getName().toUpperCase(Locale.ROOT), murmur.getSignedness(), murmur.getProcessType()); - long expected = murmur.apply(arg.getBytes(StandardCharsets.UTF_8), 0); + final long expected = murmur.apply(arg.getBytes(StandardCharsets.UTF_8), 0); assertEquals(expected, murmur.getSignature()); } diff --git a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/function/ObjectsHashIterativeTest.java b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/function/ObjectsHashIterativeTest.java index fec1f4160..9387346ef 100644 --- a/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/function/ObjectsHashIterativeTest.java +++ b/src/test/java/org/apache/commons/collections4/bloomfilter/hasher/function/ObjectsHashIterativeTest.java @@ -36,9 +36,9 @@ public class ObjectsHashIterativeTest { */ @Test public void applyTest() { - ObjectsHashIterative obj = new ObjectsHashIterative(); + final ObjectsHashIterative obj = new ObjectsHashIterative(); - byte[] buffer = "Now is the time for all good men to come to the aid of their country" + final byte[] buffer = "Now is the time for all good men to come to the aid of their country" .getBytes(StandardCharsets.UTF_8); long l = obj.apply(buffer, 0); @@ -57,11 +57,11 @@ public class ObjectsHashIterativeTest { */ @Test public void signatureTest() { - ObjectsHashIterative obj = new ObjectsHashIterative(); - String arg = String.format("%s-%s-%s", obj.getName().toUpperCase(Locale.ROOT), obj.getSignedness(), + final ObjectsHashIterative obj = new ObjectsHashIterative(); + final String arg = String.format("%s-%s-%s", obj.getName().toUpperCase(Locale.ROOT), obj.getSignedness(), obj.getProcessType()); - long expected = obj.apply(arg.getBytes(StandardCharsets.UTF_8), 0); - long expected2 = obj.apply(arg.getBytes(StandardCharsets.UTF_8), 0); + final long expected = obj.apply(arg.getBytes(StandardCharsets.UTF_8), 0); + final long expected2 = obj.apply(arg.getBytes(StandardCharsets.UTF_8), 0); assertEquals(expected, expected2); assertEquals(expected, obj.getSignature()); } diff --git a/src/test/java/org/apache/commons/collections4/collection/CompositeCollectionTest.java b/src/test/java/org/apache/commons/collections4/collection/CompositeCollectionTest.java index f169a1c2a..12093fffc 100644 --- a/src/test/java/org/apache/commons/collections4/collection/CompositeCollectionTest.java +++ b/src/test/java/org/apache/commons/collections4/collection/CompositeCollectionTest.java @@ -253,22 +253,22 @@ public class CompositeCollectionTest extends AbstractCollectionTest { } public void testAddNullList() { - ArrayList nullList = null; - CompositeCollection cc = new CompositeCollection<>(); + final ArrayList nullList = null; + final CompositeCollection cc = new CompositeCollection<>(); cc.addComposited(nullList); Assert.assertEquals(0, cc.size()); } public void testAddNullLists2Args() { - ArrayList nullList = null; - CompositeCollection cc = new CompositeCollection<>(); + final ArrayList nullList = null; + final CompositeCollection cc = new CompositeCollection<>(); cc.addComposited(nullList, nullList); Assert.assertEquals(0, cc.size()); } public void testAddNullListsVarArgs() { - ArrayList nullList = null; - CompositeCollection cc = new CompositeCollection<>(); + final ArrayList nullList = null; + final CompositeCollection cc = new CompositeCollection<>(); cc.addComposited(nullList, nullList, nullList); Assert.assertEquals(0, cc.size()); } diff --git a/src/test/java/org/apache/commons/collections4/list/FixedSizeListTest.java b/src/test/java/org/apache/commons/collections4/list/FixedSizeListTest.java index 2eda80f73..a3cbcd08a 100644 --- a/src/test/java/org/apache/commons/collections4/list/FixedSizeListTest.java +++ b/src/test/java/org/apache/commons/collections4/list/FixedSizeListTest.java @@ -70,14 +70,14 @@ public class FixedSizeListTest extends AbstractListTest { public void testListAllowsMutationOfUnderlyingCollection() { - List decoratedList = new ArrayList<>(); + final List decoratedList = new ArrayList<>(); decoratedList.add("item 1"); decoratedList.add("item 2"); // - FixedSizeList fixedSizeList = FixedSizeList.fixedSizeList(decoratedList); - int sizeBefore = fixedSizeList.size(); + final FixedSizeList fixedSizeList = FixedSizeList.fixedSizeList(decoratedList); + final int sizeBefore = fixedSizeList.size(); // - boolean changed = decoratedList.add("New Value"); + final boolean changed = decoratedList.add("New Value"); Assert.assertTrue(changed); // Assert.assertEquals("Modifying an the underlying list is allowed", @@ -85,7 +85,7 @@ public class FixedSizeListTest extends AbstractListTest { } private FixedSizeList initFixedSizeList() { - List decoratedList = new ArrayList<>(); + final List decoratedList = new ArrayList<>(); decoratedList.add("item 1"); decoratedList.add("item 2"); // @@ -93,53 +93,53 @@ public class FixedSizeListTest extends AbstractListTest { } public void testAdd() { - FixedSizeList fixedSizeList = initFixedSizeList(); + final FixedSizeList fixedSizeList = initFixedSizeList(); try { fixedSizeList.add(2,"New Value"); fail(); - } catch (UnsupportedOperationException ex) {} + } catch (final UnsupportedOperationException ex) {} } public void testAddAll() { - FixedSizeList fixedSizeList = initFixedSizeList(); + final FixedSizeList fixedSizeList = initFixedSizeList(); - List addList = new ArrayList<>(); + final List addList = new ArrayList<>(); addList.add("item 3"); addList.add("item 4"); try { fixedSizeList.addAll(2, addList); fail(); - } catch (UnsupportedOperationException ex) {} + } catch (final UnsupportedOperationException ex) {} } public void testRemove() { - FixedSizeList fixedSizeList = initFixedSizeList(); + final FixedSizeList fixedSizeList = initFixedSizeList(); try { fixedSizeList.remove(1); fail(); - } catch (UnsupportedOperationException ex) {} + } catch (final UnsupportedOperationException ex) {} } public void testSubList() { - FixedSizeList fixedSizeList = initFixedSizeList(); + final FixedSizeList fixedSizeList = initFixedSizeList(); - List subFixedSizeList = fixedSizeList.subList(1, 1); + final List subFixedSizeList = fixedSizeList.subList(1, 1); Assert.assertNotNull(subFixedSizeList); Assert.assertEquals(0, subFixedSizeList.size()); } public void testIsFull() { - FixedSizeList fixedSizeList = initFixedSizeList(); + final FixedSizeList fixedSizeList = initFixedSizeList(); Assert.assertTrue(fixedSizeList.isFull()); } public void testMaxSize() { - FixedSizeList fixedSizeList = initFixedSizeList(); + final FixedSizeList fixedSizeList = initFixedSizeList(); Assert.assertEquals(2, fixedSizeList.maxSize()); } diff --git a/src/test/java/org/apache/commons/collections4/list/LazyListTest.java b/src/test/java/org/apache/commons/collections4/list/LazyListTest.java index 1403901f6..8765267de 100644 --- a/src/test/java/org/apache/commons/collections4/list/LazyListTest.java +++ b/src/test/java/org/apache/commons/collections4/list/LazyListTest.java @@ -27,7 +27,7 @@ import java.util.List; public class LazyListTest extends AbstractObjectTest { - public LazyListTest(String testName) { + public LazyListTest(final String testName) { super(testName); } @@ -101,7 +101,7 @@ public class LazyListTest extends AbstractObjectTest { public void testGetWithNull() { final List hours = Arrays.asList(7, 5, 8, 2); final Transformer transformer = input -> LocalDateTime.now().withHour(hours.get(input)); - List list = new LazyList<>(new ArrayList<>(), transformer); + final List list = new LazyList<>(new ArrayList<>(), transformer); LocalDateTime fourthElement = list.get(3); assertFalse(list.isEmpty()); assertNotNull(fourthElement); @@ -113,8 +113,8 @@ public class LazyListTest extends AbstractObjectTest { public void testSubListWitheFactory() { final Factory dateFactory = LocalDateTime::now; - List list = new LazyList<>(new ArrayList<>(), dateFactory); - LocalDateTime fourthElement = list.get(3); + final List list = new LazyList<>(new ArrayList<>(), dateFactory); + final LocalDateTime fourthElement = list.get(3); assertFalse(list.isEmpty()); assertNotNull(fourthElement); testSubList(list); @@ -123,14 +123,14 @@ public class LazyListTest extends AbstractObjectTest { public void testSubListWithTransformer() { final List hours = Arrays.asList(7, 5, 8, 2); final Transformer transformer = input -> LocalDateTime.now().withHour(hours.get(input)); - List list = new LazyList<>(new ArrayList<>(), transformer); - LocalDateTime fourthElement = list.get(3); + final List list = new LazyList<>(new ArrayList<>(), transformer); + final LocalDateTime fourthElement = list.get(3); assertFalse(list.isEmpty()); assertNotNull(fourthElement); testSubList(list); } - private void testSubList(List list) { + private void testSubList(final List list) { List subList = list.subList(1, 3); assertFalse(subList.isEmpty()); assertNotNull(subList); diff --git a/src/test/java/org/apache/commons/collections4/map/DefaultedMapTest.java b/src/test/java/org/apache/commons/collections4/map/DefaultedMapTest.java index f047f2d7f..2a9fd37d8 100644 --- a/src/test/java/org/apache/commons/collections4/map/DefaultedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/DefaultedMapTest.java @@ -135,35 +135,35 @@ public class DefaultedMapTest extends AbstractIterableMapTest { try { DefaultedMap.defaultedMap(null, (V) "DEFAULT_VALUE"); fail("Expecting NullPointerException"); - } catch (NullPointerException e) { + } catch (final NullPointerException e) { // Expected } try { DefaultedMap.defaultedMap((Map) null, nullFactory); fail("Expecting NullPointerException"); - } catch (NullPointerException e) { + } catch (final NullPointerException e) { // Expected } try { DefaultedMap.defaultedMap(base, (Factory) null); fail("Expecting NullPointerException"); - } catch (NullPointerException e) { + } catch (final NullPointerException e) { // Expected } try { DefaultedMap.defaultedMap((Map) null, nullTransformer); fail("Expecting NullPointerException"); - } catch (NullPointerException e) { + } catch (final NullPointerException e) { // Expected } try { DefaultedMap.defaultedMap(base, (Transformer) null); fail("Expecting NullPointerException"); - } catch (NullPointerException e) { + } catch (final NullPointerException e) { // Expected } } diff --git a/src/test/java/org/apache/commons/collections4/map/Flat3MapTest.java b/src/test/java/org/apache/commons/collections4/map/Flat3MapTest.java index 8b748cae0..76fc059af 100644 --- a/src/test/java/org/apache/commons/collections4/map/Flat3MapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/Flat3MapTest.java @@ -347,11 +347,11 @@ public class Flat3MapTest extends AbstractIterableMapTest { map.put((K) "A", (V) "one"); map.put((K) "B", (V) "two"); map.put((K) "C", (V) "three"); - Iterator> it = map.entrySet().iterator(); + final Iterator> it = map.entrySet().iterator(); - Map.Entry mapEntry1 = it.next(); - Map.Entry mapEntry2 = it.next(); - Map.Entry mapEntry3 = it.next(); + final Map.Entry mapEntry1 = it.next(); + final Map.Entry mapEntry2 = it.next(); + final Map.Entry mapEntry3 = it.next(); it.remove(); assertEquals(2, map.size()); assertEquals("one", map.get("A")); diff --git a/src/test/java/org/apache/commons/collections4/map/LazySortedMapTest.java b/src/test/java/org/apache/commons/collections4/map/LazySortedMapTest.java index 8b0d275d1..0b0917b89 100644 --- a/src/test/java/org/apache/commons/collections4/map/LazySortedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/LazySortedMapTest.java @@ -41,7 +41,7 @@ public class LazySortedMapTest extends AbstractSortedMapTest { private class ReverseStringComparator implements Comparator { @Override - public int compare(String arg0, String arg1) { + public int compare(final String arg0, final String arg1) { return arg1.compareTo(arg0); } } diff --git a/src/test/java/org/apache/commons/collections4/map/PredicatedSortedMapTest.java b/src/test/java/org/apache/commons/collections4/map/PredicatedSortedMapTest.java index 730b27a8b..55870f69c 100644 --- a/src/test/java/org/apache/commons/collections4/map/PredicatedSortedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/PredicatedSortedMapTest.java @@ -37,7 +37,7 @@ public class PredicatedSortedMapTest extends AbstractSortedMapTest { private class ReverseStringComparator implements Comparator { @Override - public int compare(K arg0, K arg1) { + public int compare(final K arg0, final K arg1) { return ((String) arg1).compareTo((String)arg0); } } diff --git a/src/test/java/org/apache/commons/collections4/map/ReferenceMapTest.java b/src/test/java/org/apache/commons/collections4/map/ReferenceMapTest.java index 35699e0a6..ed0eb0566 100644 --- a/src/test/java/org/apache/commons/collections4/map/ReferenceMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/ReferenceMapTest.java @@ -261,14 +261,14 @@ public class ReferenceMapTest extends AbstractIterableMapTest { } public void testCustomPurge() { - List expiredValues = new ArrayList<>(); + final List expiredValues = new ArrayList<>(); @SuppressWarnings("unchecked") final Consumer consumer = (Consumer & Serializable) v -> expiredValues.add(v); final Map map = new ReferenceMap(ReferenceStrength.WEAK, ReferenceStrength.HARD, false) { private static final long serialVersionUID = 1L; @Override - protected ReferenceEntry createEntry(HashEntry next, int hashCode, Integer key, Integer value) { + protected ReferenceEntry createEntry(final HashEntry next, final int hashCode, final Integer key, final Integer value) { return new AccessibleEntry<>(this, next, hashCode, key, value, consumer); } }; diff --git a/src/test/java/org/apache/commons/collections4/multimap/ArrayListValuedHashMapTest.java b/src/test/java/org/apache/commons/collections4/multimap/ArrayListValuedHashMapTest.java index be9ce42c1..03f6fc933 100644 --- a/src/test/java/org/apache/commons/collections4/multimap/ArrayListValuedHashMapTest.java +++ b/src/test/java/org/apache/commons/collections4/multimap/ArrayListValuedHashMapTest.java @@ -152,8 +152,8 @@ public class ArrayListValuedHashMapTest extends AbstractMultiValuedMapTest public void testArrayListValuedHashMap() { ListValuedMap listMap = null; ListValuedMap listMap1 = null; - Map map = new HashMap<>(); - Map map1 = new HashMap<>(); + final Map map = new HashMap<>(); + final Map map1 = new HashMap<>(); map.put((K) "A", (V) "W"); map.put((K) "B", (V) "X"); map.put((K) "C", (V) "F"); @@ -184,7 +184,7 @@ public class ArrayListValuedHashMapTest extends AbstractMultiValuedMapTest public void testWrappedListAdd() { final ListValuedMap listMap = makeObject(); - List listA = listMap.get((K) "A"); + final List listA = listMap.get((K) "A"); listA.add(0, (V) "W"); listA.add(1, (V) "X"); listA.add(2, (V) "F"); @@ -195,12 +195,12 @@ public class ArrayListValuedHashMapTest extends AbstractMultiValuedMapTest public void testWrappedListAddAll() { final ListValuedMap listMap = makeObject(); - List listA = listMap.get((K) "A"); - List list = Arrays.asList((V) "W", (V) "X", (V) "F"); + final List listA = listMap.get((K) "A"); + final List list = Arrays.asList((V) "W", (V) "X", (V) "F"); listA.addAll(0, list); assertEquals("{A=[W, X, F]}", listMap.toString()); - List list1 = Arrays.asList((V) "Q", (V) "Q", (V) "L"); + final List list1 = Arrays.asList((V) "Q", (V) "Q", (V) "L"); listA.addAll(3, list1); assertEquals("{A=[W, X, F, Q, Q, L]}", listMap.toString()); assertEquals("W", listMap.get((K) "A").get(0)); @@ -216,20 +216,20 @@ public class ArrayListValuedHashMapTest extends AbstractMultiValuedMapTest assertEquals(4, listMap.get((K) "A").lastIndexOf("Q")); assertEquals(-1, listMap.get((K) "A").lastIndexOf("A")); - List list2 = new ArrayList<>(); + final List list2 = new ArrayList<>(); listMap.get((K) "B").addAll(0, list2); assertEquals("{A=[W, X, F, Q, Q, L]}", listMap.toString()); - List list3 = listMap.get((K) "A").subList(1, 4); + final List list3 = listMap.get((K) "A").subList(1, 4); assertEquals(3, list3.size()); assertEquals("Q", list3.get(2)); } public void testValuesListIteratorMethods(){ final ListValuedMap listMap = makeObject(); - List listA = listMap.get((K) "A"); - List list = Arrays.asList((V) "W", (V) "X", (V) "F", (V) "Q", (V) "Q", (V)"F"); + final List listA = listMap.get((K) "A"); + final List list = Arrays.asList((V) "W", (V) "X", (V) "F", (V) "Q", (V) "Q", (V)"F"); listA.addAll(0, list); - ListIterator it = listMap.get((K) "A").listIterator(1); + final ListIterator it = listMap.get((K) "A").listIterator(1); assertTrue(it.hasNext()); assertEquals("X", it.next()); assertEquals("F", it.next()); diff --git a/src/test/java/org/apache/commons/collections4/multimap/HashSetValuedHashMapTest.java b/src/test/java/org/apache/commons/collections4/multimap/HashSetValuedHashMapTest.java index 846488e64..c20453fcb 100644 --- a/src/test/java/org/apache/commons/collections4/multimap/HashSetValuedHashMapTest.java +++ b/src/test/java/org/apache/commons/collections4/multimap/HashSetValuedHashMapTest.java @@ -146,7 +146,7 @@ public class HashSetValuedHashMapTest extends AbstractMultiValuedMapTest map = new ArrayListValuedHashMap<>(); SetValuedMap map1 = null; - SetValuedMap map2 = makeObject(); + final SetValuedMap map2 = makeObject(); SetValuedMap map3 = null; map.put((K) "A", (V) "W"); diff --git a/src/test/java/org/apache/commons/collections4/queue/UnmodifiableQueueTest.java b/src/test/java/org/apache/commons/collections4/queue/UnmodifiableQueueTest.java index d769c2970..579dc1a87 100644 --- a/src/test/java/org/apache/commons/collections4/queue/UnmodifiableQueueTest.java +++ b/src/test/java/org/apache/commons/collections4/queue/UnmodifiableQueueTest.java @@ -107,8 +107,8 @@ public class UnmodifiableQueueTest extends AbstractQueueTest { } public void testOffer() { - Queue queue = makeFullCollection(); - E e = null; + final Queue queue = makeFullCollection(); + final E e = null; try { queue.offer(e); fail(); @@ -116,7 +116,7 @@ public class UnmodifiableQueueTest extends AbstractQueueTest { } public void testPoll() { - Queue queue = makeFullCollection(); + final Queue queue = makeFullCollection(); try { queue.poll(); fail();