Fix whitespace (Checkstyle WhitespaceAround)

This commit is contained in:
Gary Gregory 2024-05-12 09:47:14 -04:00
parent 765f381bb1
commit f4ecabd9ac
61 changed files with 509 additions and 613 deletions

View File

@ -59,6 +59,7 @@ limitations under the License.
<module name="RightCurly"/>
<module name="GenericWhitespace"/>
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround"/>
<module name="NoWhitespaceBefore"/>
<module name="Indentation">
<!-- Indentation style recommended by Oracle -->

View File

@ -263,5 +263,8 @@ public class BagUtils {
/**
* Don't allow instances.
*/
private BagUtils() {}
private BagUtils() {
// empty
}
}

View File

@ -370,6 +370,8 @@ public class ClosureUtils {
/**
* Don't allow instances.
*/
private ClosureUtils() {}
private ClosureUtils() {
// empty
}
}

View File

@ -2151,5 +2151,7 @@ public class CollectionUtils {
/**
* Don't allow instances.
*/
private CollectionUtils() {}
private CollectionUtils() {
// empty
}
}

View File

@ -238,6 +238,8 @@ public class ComparatorUtils {
/**
* Don't allow instances.
*/
private ComparatorUtils() {}
private ComparatorUtils() {
// empty
}
}

View File

@ -145,6 +145,8 @@ public class FactoryUtils {
/**
* Don't allow instances.
*/
private FactoryUtils() {}
private FactoryUtils() {
// empty
}
}

View File

@ -1438,6 +1438,8 @@ public class IteratorUtils {
/**
* Don't allow instances.
*/
private IteratorUtils() {}
private IteratorUtils() {
// empty
}
}

View File

@ -744,5 +744,8 @@ public class ListUtils {
/**
* Don't allow instances.
*/
private ListUtils() {}
private ListUtils() {
// empty
}
}

View File

@ -240,6 +240,8 @@ public class MultiMapUtils {
/**
* Don't allow instances.
*/
private MultiMapUtils() {}
private MultiMapUtils() {
// empty
}
}

View File

@ -112,6 +112,8 @@ public class MultiSetUtils {
/**
* Don't allow instances.
*/
private MultiSetUtils() {}
private MultiSetUtils() {
// empty
}
}

View File

@ -380,7 +380,7 @@ public class PredicateUtils {
* @throws NullPointerException if the predicate is null.
* @see NullIsExceptionPredicate
*/
public static <T> Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate){
public static <T> Predicate<T> nullIsExceptionPredicate(final Predicate<? super T> predicate) {
return NullIsExceptionPredicate.nullIsExceptionPredicate(predicate);
}
@ -395,7 +395,7 @@ public class PredicateUtils {
* @throws NullPointerException if the predicate is null.
* @see NullIsFalsePredicate
*/
public static <T> Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate){
public static <T> Predicate<T> nullIsFalsePredicate(final Predicate<? super T> predicate) {
return NullIsFalsePredicate.nullIsFalsePredicate(predicate);
}
@ -410,7 +410,7 @@ public class PredicateUtils {
* @throws NullPointerException if the predicate is null.
* @see NullIsTruePredicate
*/
public static <T> Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate){
public static <T> Predicate<T> nullIsTruePredicate(final Predicate<? super T> predicate) {
return NullIsTruePredicate.nullIsTruePredicate(predicate);
}
@ -486,8 +486,7 @@ public class PredicateUtils {
* @see TransformedPredicate
* @since 3.1
*/
public static <T> Predicate<T> transformedPredicate(
final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate) {
public static <T> Predicate<T> transformedPredicate(final Transformer<? super T, ? extends T> transformer, final Predicate<? super T> predicate) {
return TransformedPredicate.transformedPredicate(transformer, predicate);
}
@ -521,6 +520,8 @@ public class PredicateUtils {
/**
* Don't allow instances.
*/
private PredicateUtils() {}
private PredicateUtils() {
// empty
}
}

View File

@ -113,8 +113,7 @@ public class QueueUtils {
* @return a transformed queue backed by the given queue
* @throws NullPointerException if the queue or transformer is null
*/
public static <E> Queue<E> transformingQueue(final Queue<E> queue,
final Transformer<? super E, ? extends E> transformer) {
public static <E> Queue<E> transformingQueue(final Queue<E> queue, final Transformer<? super E, ? extends E> transformer) {
return TransformedQueue.transformingQueue(queue, transformer);
}
@ -133,5 +132,7 @@ public class QueueUtils {
/**
* Don't allow instances.
*/
private QueueUtils() {}
private QueueUtils() {
// empty
}
}

View File

@ -652,5 +652,8 @@ public class SetUtils {
/**
* Don't allow instances.
*/
private SetUtils() {}
private SetUtils() {
// empty
}
}

View File

@ -259,6 +259,8 @@ public class SplitMapUtils {
/**
* Don't allow instances.
*/
private SplitMapUtils() {}
private SplitMapUtils() {
// empty
}
}

View File

@ -480,6 +480,8 @@ public class TransformerUtils {
/**
* This class is not normally instantiated.
*/
private TransformerUtils() {}
private TransformerUtils() {
// empty
}
}

View File

@ -43,6 +43,8 @@ public class TrieUtils {
/**
* Don't allow instances.
*/
private TrieUtils() {}
private TrieUtils() {
// empty
}
}

View File

@ -1969,13 +1969,13 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>>
* @throws ClassNotFoundException if an object read from the stream can not be loaded
*/
@SuppressWarnings("unchecked") // This will fail at runtime if the stream is incorrect
private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException{
private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
rootNode = new Node[2];
final int size = stream.readInt();
for (int i = 0; i < size; i++){
final K k =(K) stream.readObject();
final V v =(V) stream.readObject();
for (int i = 0; i < size; i++) {
final K k = (K) stream.readObject();
final V v = (V) stream.readObject();
put(k, v);
}
}
@ -2224,7 +2224,7 @@ public class TreeBidiMap<K extends Comparable<K>, V extends Comparable<V>>
* @param stream the output stream
* @throws IOException if an error occurs while writing to the stream
*/
private void writeObject(final ObjectOutputStream stream) throws IOException{
private void writeObject(final ObjectOutputStream stream) throws IOException {
stream.defaultWriteObject();
stream.writeInt(this.size());
for (final Entry<K, V> entry : entrySet()) {

View File

@ -166,7 +166,7 @@ public interface BloomFilter extends IndexProducer, BitMapProducer {
estimate = Math.round(eThis + eOther - eUnion);
estimate = estimate < 0 ? 0 : estimate;
}
return estimate>Integer.MAX_VALUE?Integer.MAX_VALUE:(int) estimate;
return estimate > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) estimate;
}
/**

View File

@ -42,6 +42,10 @@ final class IndexUtils {
return array;
}
// do not instantiate
private IndexUtils() {}
/**
* Don't instantiate.
*/
private IndexUtils() {
// empty
}
}

View File

@ -125,8 +125,10 @@ public class LayerManager<T extends BloomFilter> implements BloomFilterProducer
* A Cleanup that never removes anything.
* @return A Consumer suitable for the LayerManager {@code cleanup} parameter.
*/
public static <T extends BloomFilter> Consumer<Deque<T>> noCleanup() {
return x -> {};
public static <T extends BloomFilter> Consumer<Deque<T>> noCleanup() {
return x -> {
// empty
};
}
/**

View File

@ -45,7 +45,7 @@ import java.util.Comparator;
public class ComparableComparator<E extends Comparable<? super E>> implements Comparator<E>, Serializable {
/** Serialization version. */
private static final long serialVersionUID=-291439688585137865L;
private static final long serialVersionUID = -291439688585137865L;
/** The singleton instance. */
@SuppressWarnings("rawtypes")

View File

@ -112,7 +112,7 @@ public class IfTransformer<I, O> implements Transformer<I, O>, Serializable {
*
* @return the predicate
*/
public Predicate<? super I> getPredicate(){
public Predicate<? super I> getPredicate() {
return iPredicate;
}
@ -133,7 +133,7 @@ public class IfTransformer<I, O> implements Transformer<I, O>, Serializable {
*/
@Override
public O transform(final I input) {
if (iPredicate.evaluate(input)){
if (iPredicate.evaluate(input)) {
return iTrueTransformer.transform(input);
}
return iFalseTransformer.transform(input);

View File

@ -93,7 +93,7 @@ public class SwitchClosure<E> implements Closure<E>, Serializable {
throw new IllegalArgumentException("The predicate and closure arrays must be the same size");
}
if (predicates.length == 0) {
return (Closure<E>) (defaultClosure == null ? NOPClosure.<E>nopClosure(): defaultClosure);
return (Closure<E>) (defaultClosure == null ? NOPClosure.<E>nopClosure() : defaultClosure);
}
return new SwitchClosure<>(predicates, closures, defaultClosure);
}

View File

@ -182,7 +182,7 @@ public class FilterListIterator<E> implements ListIterator<E> {
@Override
public int previousIndex() {
return nextIndex-1;
return nextIndex - 1;
}
/** Not supported. */

View File

@ -492,10 +492,8 @@ public class LRUMap<K, V>
reuseEntry(entry, hashIndex, hashCode, key, value);
addEntry(entry, hashIndex);
} catch (final NullPointerException ex) {
throw new IllegalStateException(
"NPE, entry=" + entry + " entryIsHeader=" + (entry==header) +
" key=" + key + " value=" + value + " size=" + size + " maxSize=" + maxSize +
" This should not occur if your keys are immutable, and you have used synchronization properly.");
throw new IllegalStateException("NPE, entry=" + entry + " entryIsHeader=" + (entry == header) + " key=" + key + " value=" + value + " size=" + size
+ " maxSize=" + maxSize + " This should not occur if your keys are immutable, and you have used synchronization properly.");
}
}

View File

@ -264,11 +264,11 @@ public class SequencesComparator<T> {
return null;
}
final int delta = m - n;
final int sum = n + m;
final int delta = m - n;
final int sum = n + m;
final int offset = (sum % 2 == 0 ? sum : sum + 1) / 2;
vDown[1+offset] = start1;
vUp[1+offset] = end1 + 1;
vDown[1 + offset] = start1;
vUp[1 + offset] = end1 + 1;
for (int d = 0; d <= offset; ++d) {
// Down
@ -276,10 +276,10 @@ public class SequencesComparator<T> {
// First step
final int i = k + offset;
if (k == -d || k != d && vDown[i-1] < vDown[i+1]) {
vDown[i] = vDown[i+1];
if (k == -d || k != d && vDown[i - 1] < vDown[i + 1]) {
vDown[i] = vDown[i + 1];
} else {
vDown[i] = vDown[i-1] + 1;
vDown[i] = vDown[i - 1] + 1;
}
int x = vDown[i];
@ -290,8 +290,8 @@ public class SequencesComparator<T> {
++y;
}
// Second step
if (delta % 2 != 0 && delta - d <= k && k <= delta + d && vUp[i-delta] <= vDown[i]) { // NOPMD
return buildSnake(vUp[i-delta], k + start1 - start2, end1, end2);
if (delta % 2 != 0 && delta - d <= k && k <= delta + d && vUp[i - delta] <= vDown[i]) { // NOPMD
return buildSnake(vUp[i - delta], k + start1 - start2, end1, end2);
}
}
@ -299,17 +299,15 @@ public class SequencesComparator<T> {
for (int k = delta - d; k <= delta + d; k += 2) {
// First step
final int i = k + offset - delta;
if (k == delta - d
|| k != delta + d && vUp[i+1] <= vUp[i-1]) {
vUp[i] = vUp[i+1] - 1;
if (k == delta - d || k != delta + d && vUp[i + 1] <= vUp[i - 1]) {
vUp[i] = vUp[i + 1] - 1;
} else {
vUp[i] = vUp[i-1];
vUp[i] = vUp[i - 1];
}
int x = vUp[i] - 1;
int y = x - start1 + start2 - k;
while (x >= start1 && y >= start2
&& equator.equate(sequence1.get(x), sequence2.get(y))) {
while (x >= start1 && y >= start2 && equator.equate(sequence1.get(x), sequence2.get(y))) {
vUp[i] = x--;
y--;
}

View File

@ -2061,11 +2061,11 @@ public abstract class AbstractPatriciaTrie<K, V> extends AbstractBitwiseTrie<K,
* Reads the content of the stream.
*/
@SuppressWarnings("unchecked") // This will fail at runtime if the stream is incorrect
private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException{
private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
root = new TrieEntry<>(null, null, -1);
final int size = stream.readInt();
for (int i = 0; i < size; i++){
for (int i = 0; i < size; i++) {
final K k = (K) stream.readObject();
final V v = (V) stream.readObject();
put(k, v);
@ -2434,7 +2434,7 @@ public abstract class AbstractPatriciaTrie<K, V> extends AbstractBitwiseTrie<K,
/**
* Writes the content to the stream for serialization.
*/
private void writeObject(final ObjectOutputStream stream) throws IOException{
private void writeObject(final ObjectOutputStream stream) throws IOException {
stream.defaultWriteObject();
stream.writeInt(this.size());
for (final Entry<K, V> entry : entrySet()) {

View File

@ -31,12 +31,10 @@ import org.junit.jupiter.api.Test;
/**
* Tests base {@link java.util.LinkedList} methods and contracts.
* <p>
* To use, simply extend this class, and implement
* the {@link #makeObject()} method.
* To use, simply extend this class, and implement the {@link #makeObject()} method.
* <p>
* If your {@link LinkedList} fails one of these tests by design,
* you may still use this base set of cases. Simply override the
* test case (method) your {@link List} fails.
* If your {@link LinkedList} fails one of these tests by design, you may still use this base set of cases. Simply override the test case (method) your
* {@link List} fails.
*/
public abstract class AbstractLinkedListTest<T> extends AbstractListTest<T> {
@ -45,9 +43,9 @@ public abstract class AbstractLinkedListTest<T> extends AbstractListTest<T> {
}
/**
* Returns the {@link #collection} field cast to a {@link LinkedList}.
* Returns the {@link #collection} field cast to a {@link LinkedList}.
*
* @return the collection field as a List
* @return the collection field as a List
*/
@Override
public LinkedList<T> getCollection() {
@ -55,16 +53,16 @@ public abstract class AbstractLinkedListTest<T> extends AbstractListTest<T> {
}
/**
* Returns the {@link #confirmed} field cast to a {@link LinkedList}.
* Returns the {@link #confirmed} field cast to a {@link LinkedList}.
*
* @return the confirmed field as a List
* @return the confirmed field as a List
*/
protected LinkedList<T> getConfirmedLinkedList() {
return (LinkedList<T>) getConfirmed();
}
/**
* Returns an empty {@link LinkedList}.
* Returns an empty {@link LinkedList}.
*/
@Override
public Collection<T> makeConfirmedCollection() {
@ -72,7 +70,7 @@ public abstract class AbstractLinkedListTest<T> extends AbstractListTest<T> {
}
/**
* Returns a full {@link LinkedList}.
* Returns a full {@link LinkedList}.
*/
@Override
public Collection<T> makeConfirmedFullCollection() {
@ -83,7 +81,7 @@ public abstract class AbstractLinkedListTest<T> extends AbstractListTest<T> {
public abstract LinkedList<T> makeObject();
/**
* Tests {@link LinkedList#addFirst(Object)}.
* Tests {@link LinkedList#addFirst(Object)}.
*/
@Test
@SuppressWarnings("unchecked")
@ -105,7 +103,7 @@ public abstract class AbstractLinkedListTest<T> extends AbstractListTest<T> {
}
/**
* Tests {@link LinkedList#addLast(Object)}.
* Tests {@link LinkedList#addLast(Object)}.
*/
@Test
@SuppressWarnings("unchecked")
@ -127,43 +125,39 @@ public abstract class AbstractLinkedListTest<T> extends AbstractListTest<T> {
}
/**
* Tests {@link LinkedList#getFirst()}.
* Tests {@link LinkedList#getFirst()}.
*/
@Test
public void testLinkedListGetFirst() {
resetEmpty();
assertThrows(NoSuchElementException.class, () -> getCollection().getFirst(),
"getFirst() should throw a NoSuchElementException for an empty list.");
assertThrows(NoSuchElementException.class, () -> getCollection().getFirst(), "getFirst() should throw a NoSuchElementException for an empty list.");
verify();
resetFull();
final Object first = getCollection().getFirst();
final Object confirmedFirst = getConfirmedLinkedList().getFirst();
assertEquals(confirmedFirst, first,
"Result returned by getFirst() was wrong.");
assertEquals(confirmedFirst, first, "Result returned by getFirst() was wrong.");
verify();
}
/**
* Tests {@link LinkedList#getLast()}.
* Tests {@link LinkedList#getLast()}.
*/
@Test
public void testLinkedListGetLast() {
resetEmpty();
assertThrows(NoSuchElementException.class, () -> getCollection().getLast(),
"getLast() should throw a NoSuchElementException for an empty list.");
assertThrows(NoSuchElementException.class, () -> getCollection().getLast(), "getLast() should throw a NoSuchElementException for an empty list.");
verify();
resetFull();
final Object last = getCollection().getLast();
final Object confirmedLast = getConfirmedLinkedList().getLast();
assertEquals(confirmedLast, last,
"Result returned by getLast() was wrong.");
assertEquals(confirmedLast, last, "Result returned by getLast() was wrong.");
verify();
}
/**
* Tests {@link LinkedList#removeFirst()}.
* Tests {@link LinkedList#removeFirst()}.
*/
@Test
public void testLinkedListRemoveFirst() {
@ -179,13 +173,12 @@ public abstract class AbstractLinkedListTest<T> extends AbstractListTest<T> {
resetFull();
final Object first = getCollection().removeFirst();
final Object confirmedFirst = getConfirmedLinkedList().removeFirst();
assertEquals(confirmedFirst, first,
"Result returned by removeFirst() was wrong.");
assertEquals(confirmedFirst, first, "Result returned by removeFirst() was wrong.");
verify();
}
/**
* Tests {@link LinkedList#removeLast()}.
* Tests {@link LinkedList#removeLast()}.
*/
@Test
public void testLinkedListRemoveLast() {
@ -194,15 +187,13 @@ public abstract class AbstractLinkedListTest<T> extends AbstractListTest<T> {
}
resetEmpty();
assertThrows(NoSuchElementException.class, () -> getCollection().removeLast(),
"removeLast() should throw a NoSuchElementException for an empty list.");
assertThrows(NoSuchElementException.class, () -> getCollection().removeLast(), "removeLast() should throw a NoSuchElementException for an empty list.");
verify();
resetFull();
final Object last = getCollection().removeLast();
final Object confirmedLast = getConfirmedLinkedList().removeLast();
assertEquals(confirmedLast, last,
"Result returned by removeLast() was wrong.");
assertEquals(confirmedLast, last, "Result returned by removeLast() was wrong.");
verify();
}

View File

@ -280,12 +280,12 @@ public class CollectionUtilsTest extends MockTestCase {
final Collection<String> strings = Arrays.asList("a", "b", "c");
final StringBuilder result = new StringBuilder();
result.append(CollectionUtils.forAllButLastDo(strings, (Closure<String>) input -> result.append(input+";")));
result.append(CollectionUtils.forAllButLastDo(strings, (Closure<String>) input -> result.append(input + ";")));
assertEquals("a;b;c", result.toString());
final Collection<String> oneString = Arrays.asList("a");
final StringBuilder resultOne = new StringBuilder();
resultOne.append(CollectionUtils.forAllButLastDo(oneString, (Closure<String>) input -> resultOne.append(input+";")));
resultOne.append(CollectionUtils.forAllButLastDo(oneString, (Closure<String>) input -> resultOne.append(input + ";")));
assertEquals("a", resultOne.toString());
assertNull(CollectionUtils.forAllButLastDo(strings, (Closure<String>) null)); // do not remove cast
assertNull(CollectionUtils.forAllButLastDo((Collection<String>) null, (Closure<String>) null)); // do not remove cast

View File

@ -247,7 +247,7 @@ public class MapUtilsTest {
final String INDENT = " ";
final Map<Object, Object> map = new HashMap<>();
final Map<Object, Object> map2= new HashMap<>();
final Map<Object, Object> map2 = new HashMap<>();
map.put(null, map2);
map2.put("2", "B");

View File

@ -76,5 +76,8 @@ public final class TestUtils {
}
}
private TestUtils() {}
private TestUtils() {
// empty
}
}

View File

@ -81,7 +81,7 @@ public abstract class AbstractBagTest<T> extends AbstractCollectionTest<T> {
}
@Override
protected int getIterationBehaviour(){
protected int getIterationBehaviour() {
return AbstractBagTest.this.getIterationBehaviour();
}

View File

@ -19,8 +19,7 @@ package org.apache.commons.collections4.bag;
import org.apache.commons.collections4.Bag;
/**
* Extension of {@link AbstractBagTest} for exercising the {@link SynchronizedBag}
* implementation.
* Extension of {@link AbstractBagTest} for exercising the {@link SynchronizedBag} implementation.
*/
public class SynchronizedBagTest<T> extends AbstractBagTest<T> {
@ -34,7 +33,7 @@ public class SynchronizedBagTest<T> extends AbstractBagTest<T> {
}
@Override
protected int getIterationBehaviour(){
protected int getIterationBehaviour() {
return UNORDERED;
}

View File

@ -149,7 +149,9 @@ public abstract class AbstractOrderedBidiMapTest<K, V> extends AbstractBidiMapTe
if (!isAllowNullKey()) {
try {
assertNull(bidi.nextKey(null)); // this is allowed too
} catch (final NullPointerException ex) {}
} catch (final NullPointerException ignore) {
// ignore
}
} else {
assertNull(bidi.nextKey(null));
}
@ -182,7 +184,9 @@ public abstract class AbstractOrderedBidiMapTest<K, V> extends AbstractBidiMapTe
if (!isAllowNullKey()) {
try {
assertNull(bidi.previousKey(null)); // this is allowed too
} catch (final NullPointerException ex) {}
} catch (final NullPointerException ignore) {
// ignore
}
} else {
assertNull(bidi.previousKey(null));
}

View File

@ -42,8 +42,9 @@ import org.junit.jupiter.api.Test;
@SuppressWarnings("boxing")
public class DualTreeBidiMap2Test<K extends Comparable<K>, V extends Comparable<V>> extends AbstractSortedBidiMapTest<K, V> {
private static final class IntegerComparator implements Comparator<Integer>, Serializable{
private static final class IntegerComparator implements Comparator<Integer>, Serializable {
private static final long serialVersionUID = 1L;
@Override
public int compare(final Integer o1, final Integer o2) {
return o1.compareTo(o2);

View File

@ -221,19 +221,17 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
BitMapProducer bitMapProducer = BitMapProducer.fromIndexProducer(new IncrementingHasher(1, 1).indices(getTestShape()),
getTestShape().getNumberOfBits());
assertTrue(bf2.contains(bitMapProducer), "BF2 Should contain this hasher");
bitMapProducer = BitMapProducer.fromIndexProducer(new IncrementingHasher(1, 3).indices(getTestShape()),
getTestShape().getNumberOfBits());
bitMapProducer = BitMapProducer.fromIndexProducer(new IncrementingHasher(1, 3).indices(getTestShape()), getTestShape().getNumberOfBits());
assertFalse(bf2.contains(bitMapProducer), "BF2 Should not contain this hasher");
// Test different lengths
bf1 = createFilter(getTestShape(), TestingHashers.FROM1);
final BloomFilter bf3 = createFilter(Shape.fromKM(getTestShape().getNumberOfHashFunctions(), Long.SIZE - 1),
TestingHashers.FROM1);
final BloomFilter bf3 = createFilter(Shape.fromKM(getTestShape().getNumberOfHashFunctions(), Long.SIZE - 1), TestingHashers.FROM1);
assertTrue(bf1.contains(bf3));
assertTrue(bf3.contains(bf1));
final BloomFilter bf4 = TestingHashers.populateRange(createEmptyFilter(Shape.fromKM(getTestShape().getNumberOfHashFunctions(), Long.SIZE - 1)),
1, 11+getTestShape().getNumberOfHashFunctions());
final BloomFilter bf4 = TestingHashers.populateRange(createEmptyFilter(Shape.fromKM(getTestShape().getNumberOfHashFunctions(), Long.SIZE - 1)), 1,
11 + getTestShape().getNumberOfHashFunctions());
assertFalse(bf1.contains(bf4));
assertTrue(bf4.contains(bf1));
@ -253,7 +251,6 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
*/
@Test
public final void testEstimateIntersection() {
final BloomFilter bf = createFilter(getTestShape(), TestingHashers.FROM1);
final BloomFilter bf2 = TestingHashers.populateFromHashersFrom1AndFrom11(createEmptyFilter(getTestShape()));
@ -272,7 +269,7 @@ public abstract class AbstractBloomFilterTest<T extends BloomFilter> {
final int midPoint = getTestShape().getNumberOfBits() / 2;
final BloomFilter bf5 = TestingHashers.populateRange(createEmptyFilter(getTestShape()), 0, midPoint);
final BloomFilter bf6 = TestingHashers.populateRange(createEmptyFilter(getTestShape()), midPoint+1, getTestShape().getNumberOfBits()-1);
final BloomFilter bf6 = TestingHashers.populateRange(createEmptyFilter(getTestShape()), midPoint + 1, getTestShape().getNumberOfBits() - 1);
assertThrows(IllegalArgumentException.class, () -> bf5.estimateIntersection(bf6));
// infinite with infinite

View File

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

View File

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

View File

@ -51,7 +51,7 @@ public class CountingPredicateTest {
final List<Pair<Integer, Integer>> result = new ArrayList<>();
expected.add(Pair.of(1, 3));
CountingPredicate<Integer> cp = new CountingPredicate<>(ary, makeFunc((x, y) -> x!=null, result));
CountingPredicate<Integer> cp = new CountingPredicate<>(ary, makeFunc((x, y) -> x != null, result));
assertTrue(cp.test(Integer.valueOf(3)));
assertEquals(expected, result);
expected.add(Pair.of(2, null));
@ -64,16 +64,16 @@ public class CountingPredicateTest {
expected.add(Pair.of(1, null));
expected.add(Pair.of(2, null));
result.clear();
cp = new CountingPredicate<>(ary, makeFunc((x, y) -> x!=null, result));
cp = new CountingPredicate<>(ary, makeFunc((x, y) -> x != null, result));
assertTrue(cp.forEachRemaining());
assertEquals( expected, result);
assertEquals(expected, result);
// If a test fails then the result should be false and the rest of the list should
// not be processed.
expected.clear();
expected.add(Pair.of(1, null));
result.clear();
cp = new CountingPredicate<>(ary, makeFunc((x, y) -> x == Integer.valueOf(1), result));
cp = new CountingPredicate<>(ary, makeFunc((x, y) -> x == Integer.valueOf(1), result));
assertFalse(cp.forEachRemaining());
assertEquals(expected, result);
}

View File

@ -35,11 +35,11 @@ public class IndexProducerFromSparseBloomFilterTest extends AbstractIndexProduce
@Override
protected int getAsIndexArrayBehaviour() {
return DISTINCT |ORDERED;
return DISTINCT | ORDERED;
}
@Override
protected int[] getExpectedIndices() {
return new int[] {2, 4, 9, 11, 16, 18, 23, 25, 30, 32, 37, 39, 44, 46, 53, 60, 67};
return new int[] { 2, 4, 9, 11, 16, 18, 23, 25, 30, 32, 37, 39, 44, 46, 53, 60, 67 };
}
}

View File

@ -78,7 +78,7 @@ public class LayerManagerTest {
while (layerManager.getTarget().getShape().estimateN(layerManager.getTarget().cardinality()) < maxN) {
assertFalse(underTest.test(layerManager));
layerManager.getTarget().merge(new IncrementingHasher(hashStart, shape.getNumberOfHashFunctions()));
hashStart+=shape.getNumberOfHashFunctions();
hashStart += shape.getNumberOfHashFunctions();
}
assertTrue(underTest.test(layerManager));
assertThrows(IllegalArgumentException.class, () -> LayerManager.ExtendCheck.advanceOnSaturation(0));

View File

@ -90,11 +90,14 @@ public class TestingHashers {
* Creates an EnhancedDoubleHasher hasher from 2 random longs.
*/
public static Hasher randomHasher() {
return new EnhancedDoubleHasher( ThreadLocalRandom.current().nextLong(), ThreadLocalRandom.current().nextLong() );
return new EnhancedDoubleHasher(ThreadLocalRandom.current().nextLong(), ThreadLocalRandom.current().nextLong());
}
/**
* Do not instantiate.
*/
private TestingHashers() {}
private TestingHashers() {
// empty
}
}

View File

@ -384,7 +384,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
* @return the iteration behavior
* @see #UNORDERED
*/
protected int getIterationBehaviour(){
protected int getIterationBehaviour() {
return 0;
}

View File

@ -137,20 +137,19 @@ public class FixedOrderComparatorTest extends AbstractComparatorTest<String> {
/** Shuffles the keys and asserts that the comparator sorts them back to
* their original order.
*/
private void assertComparatorYieldsOrder(final String[] orderedObjects,
final Comparator<String> comparator) {
private void assertComparatorYieldsOrder(final String[] orderedObjects, final Comparator<String> comparator) {
final String[] keys = orderedObjects.clone();
// shuffle until the order changes. It's extremely rare that
// shuffle until the order changes. It's extremely rare that
// this requires more than one shuffle.
boolean isInNewOrder = false;
final Random rand = new Random();
while (keys.length > 1 && !isInNewOrder) {
// shuffle:
for (int i = keys.length-1; i > 0; i--) {
for (int i = keys.length - 1; i > 0; i--) {
final String swap = keys[i];
final int j = rand.nextInt(i+1);
final int j = rand.nextInt(i + 1);
keys[i] = keys[j];
keys[j] = swap;
}
@ -164,7 +163,7 @@ public class FixedOrderComparatorTest extends AbstractComparatorTest<String> {
}
}
// The real test: sort and make sure they come out right.
// The real test: sort and make sure they come out right.
Arrays.sort(keys, comparator);

View File

@ -159,7 +159,8 @@ public abstract class AbstractIteratorTest<E> extends AbstractObjectTest {
// check for UnsupportedOperationException if not supported
try {
it.remove();
} catch (final UnsupportedOperationException ex) {}
} catch (final UnsupportedOperationException ex) {
}
return;
}

View File

@ -56,6 +56,7 @@ public class NodeListIteratorTest extends AbstractIteratorTest<Node> {
public int getLength() {
return 0;
}
@Override
public Node item(final int index) {
throw new IndexOutOfBoundsException();
@ -79,6 +80,7 @@ public class NodeListIteratorTest extends AbstractIteratorTest<Node> {
public int getLength() {
return nodes.length;
}
@Override
public Node item(final int index) {
return nodes[index];
@ -99,7 +101,7 @@ public class NodeListIteratorTest extends AbstractIteratorTest<Node> {
final Node node2 = createMock(Element.class);
final Node node3 = createMock(Text.class);
final Node node4 = createMock(Element.class);
nodes = new Node[] {node1, node2, node3, node4};
nodes = new Node[] { node1, node2, node3, node4 };
replay(node1);
replay(node2);
@ -116,7 +118,7 @@ public class NodeListIteratorTest extends AbstractIteratorTest<Node> {
* tests the convenience Constructor with parameter type org.w3c.Node
*/
@Test
public void testEmptyIteratorWithNodeConstructor(){
public void testEmptyIteratorWithNodeConstructor() {
createIteratorWithStandardConstr = false;
testEmptyIterator();
}
@ -125,7 +127,7 @@ public class NodeListIteratorTest extends AbstractIteratorTest<Node> {
* tests the convenience Constructor with parameter type org.w3c.Node
*/
@Test
public void testFullIteratorWithNodeConstructor(){
public void testFullIteratorWithNodeConstructor() {
createIteratorWithStandardConstr = false;
testFullIterator();
}

View File

@ -151,7 +151,7 @@ public class PermutationIteratorTest extends AbstractIteratorTest<List<Character
@SuppressWarnings("boxing") // OK in test code
public void testPermutationResultSize() {
int factorial = 1;
for (int i = 0; i < 8; i++, factorial*=i) {
for (int i = 0; i < 8; i++, factorial *= i) {
final List<Integer> list = new ArrayList<>();
for (int j = 0; j < i; j++) {
list.add(j);

View File

@ -87,7 +87,7 @@ public class MultiKeyTest {
}
private Object readResolve() {
hashCode=2; // simulate different hashCode after deserialization in another process
hashCode = 2; // simulate different hashCode after deserialization in another process
return this;
}
}

View File

@ -37,8 +37,7 @@ public abstract class AbstractLinkedListTest<E> extends AbstractListTest<E> {
for (int i = 0; i < list.size; i++) {
assertEquals(list.getNode(i, false).next, list.getNode(i + 1, true));
if (i < list.size - 1) {
assertEquals(list.getNode(i + 1, false).previous,
list.getNode(i, false));
assertEquals(list.getNode(i + 1, false).previous, list.getNode(i, false));
}
}
}
@ -59,7 +58,8 @@ public abstract class AbstractLinkedListTest<E> extends AbstractListTest<E> {
if (!isAddSupported()) {
try {
list.addFirst(null);
} catch (final UnsupportedOperationException ex) {}
} catch (final UnsupportedOperationException ex) {
}
}
list.addFirst((E) "value1");
@ -92,20 +92,16 @@ public abstract class AbstractLinkedListTest<E> extends AbstractListTest<E> {
final AbstractLinkedList<E> list = getCollection();
// get marker
assertEquals(list.getNode(0, true).previous, list.getNode(0, true).next);
assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(0, false),
"Expecting IndexOutOfBoundsException.");
list.addAll( Arrays.asList((E[]) new String[]{"value1", "value2"}));
assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(0, false), "Expecting IndexOutOfBoundsException.");
list.addAll(Arrays.asList((E[]) new String[] { "value1", "value2" }));
checkNodes();
list.addFirst((E) "value0");
checkNodes();
list.removeNode(list.getNode(1, false));
checkNodes();
assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(2, false),
"Expecting IndexOutOfBoundsException.");
assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(-1, false),
"Expecting IndexOutOfBoundsException.");
assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(3, true),
"Expecting IndexOutOfBoundsException.");
assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(2, false), "Expecting IndexOutOfBoundsException.");
assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(-1, false), "Expecting IndexOutOfBoundsException.");
assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(3, true), "Expecting IndexOutOfBoundsException.");
}
@Test
@ -116,7 +112,8 @@ public abstract class AbstractLinkedListTest<E> extends AbstractListTest<E> {
if (!isRemoveSupported()) {
try {
list.removeFirst();
} catch (final UnsupportedOperationException ex) {}
} catch (final UnsupportedOperationException ex) {
}
}
list.addAll(Arrays.asList((E[]) new String[] { "value1", "value2" }));
@ -141,7 +138,8 @@ public abstract class AbstractLinkedListTest<E> extends AbstractListTest<E> {
if (!isRemoveSupported()) {
try {
list.removeLast();
} catch (final UnsupportedOperationException ex) {}
} catch (final UnsupportedOperationException ex) {
}
}
list.addAll(Arrays.asList((E[]) new String[] { "value1", "value2" }));

View File

@ -817,11 +817,13 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
resetFull();
try {
getCollection().listIterator(-1);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
resetFull();
try {
getCollection().listIterator(getCollection().size() + 1);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
resetFull();
for (int i = 0; i <= getConfirmed().size(); i++) {
forwardTest(getCollection().listIterator(i), i);

View File

@ -57,8 +57,7 @@ public class DefaultAbstractLinkedListForJava21Test<E> extends AbstractListTest<
for (int i = 0; i < list.size; i++) {
assertEquals(list.getNode(i, false).next, list.getNode(i + 1, true));
if (i < list.size - 1) {
assertEquals(list.getNode(i + 1, false).previous,
list.getNode(i, false));
assertEquals(list.getNode(i + 1, false).previous, list.getNode(i, false));
}
}
}
@ -91,7 +90,8 @@ public class DefaultAbstractLinkedListForJava21Test<E> extends AbstractListTest<
if (!isAddSupported()) {
try {
list.addFirst(null);
} catch (final UnsupportedOperationException ex) {}
} catch (final UnsupportedOperationException ex) {
}
}
list.addFirst((E) "value1");
@ -124,20 +124,16 @@ public class DefaultAbstractLinkedListForJava21Test<E> extends AbstractListTest<
final AbstractLinkedListForJava21<E> list = getCollection();
// get marker
assertEquals(list.getNode(0, true).previous, list.getNode(0, true).next);
assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(0, false),
"Expecting IndexOutOfBoundsException.");
list.addAll( Arrays.asList((E[]) new String[]{"value1", "value2"}));
assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(0, false), "Expecting IndexOutOfBoundsException.");
list.addAll(Arrays.asList((E[]) new String[] { "value1", "value2" }));
checkNodes();
list.addFirst((E) "value0");
checkNodes();
list.removeNode(list.getNode(1, false));
checkNodes();
assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(2, false),
"Expecting IndexOutOfBoundsException.");
assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(-1, false),
"Expecting IndexOutOfBoundsException.");
assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(3, true),
"Expecting IndexOutOfBoundsException.");
assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(2, false), "Expecting IndexOutOfBoundsException.");
assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(-1, false), "Expecting IndexOutOfBoundsException.");
assertThrows(IndexOutOfBoundsException.class, () -> list.getNode(3, true), "Expecting IndexOutOfBoundsException.");
}
@Test
@ -148,7 +144,8 @@ public class DefaultAbstractLinkedListForJava21Test<E> extends AbstractListTest<
if (!isRemoveSupported()) {
try {
list.removeFirst();
} catch (final UnsupportedOperationException ex) {}
} catch (final UnsupportedOperationException ex) {
}
}
list.addAll(Arrays.asList((E[]) new String[] { "value1", "value2" }));
@ -173,7 +170,8 @@ public class DefaultAbstractLinkedListForJava21Test<E> extends AbstractListTest<
if (!isRemoveSupported()) {
try {
list.removeLast();
} catch (final UnsupportedOperationException ex) {}
} catch (final UnsupportedOperationException ex) {
}
}
list.addAll(Arrays.asList((E[]) new String[] { "value1", "value2" }));

View File

@ -95,7 +95,7 @@ public abstract class AbstractOrderedMapTest<K, V> extends AbstractIterableMapTe
/**
* JUnit constructor.
*
* @param testName the test name
* @param testName the test name
*/
public AbstractOrderedMapTest(final String testName) {
super(testName);
@ -114,8 +114,7 @@ public abstract class AbstractOrderedMapTest<K, V> extends AbstractIterableMapTe
}
/**
* The only confirmed collection we have that is ordered is the sorted one.
* Thus, sort the keys.
* The only confirmed collection we have that is ordered is the sorted one. Thus, sort the keys.
*/
@Override
@SuppressWarnings("unchecked")
@ -186,7 +185,8 @@ public abstract class AbstractOrderedMapTest<K, V> extends AbstractIterableMapTe
if (!isAllowNullKey()) {
try {
assertNull(ordered.nextKey(null)); // this is allowed too
} catch (final NullPointerException ex) {}
} catch (final NullPointerException ex) {
}
} else {
assertNull(ordered.nextKey(null));
}
@ -218,7 +218,8 @@ public abstract class AbstractOrderedMapTest<K, V> extends AbstractIterableMapTe
if (!isAllowNullKey()) {
try {
assertNull(ordered.previousKey(null)); // this is allowed too
} catch (final NullPointerException ex) {}
} catch (final NullPointerException ex) {
}
} else {
assertNull(ordered.previousKey(null));
}

View File

@ -57,22 +57,27 @@ public class LinkedMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
public boolean isNullSupported() {
return LinkedMapTest.this.isAllowNullKey();
}
@Override
public boolean isRemoveSupported() {
return false;
}
@Override
public boolean isSetSupported() {
return false;
}
@Override
public boolean isTestSerialization() {
return false;
}
@Override
public List<K> makeFullCollection() {
return LinkedMapTest.this.makeFullMap().asList();
}
@Override
public List<K> makeObject() {
return LinkedMapTest.this.makeObject().asList();
@ -129,19 +134,23 @@ public class LinkedMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
LinkedMap<K, V> lm = getMap();
try {
lm.get(0);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
try {
lm.get(-1);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
resetFull();
lm = getMap();
try {
lm.get(-1);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
try {
lm.get(lm.size());
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
int i = 0;
for (final MapIterator<K, V> it = lm.mapIterator(); it.hasNext(); i++) {
@ -155,19 +164,23 @@ public class LinkedMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
LinkedMap<K, V> lm = getMap();
try {
lm.getValue(0);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
try {
lm.getValue(-1);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
resetFull();
lm = getMap();
try {
lm.getValue(-1);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
try {
lm.getValue(lm.size());
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
int i = 0;
for (final MapIterator<K, V> it = lm.mapIterator(); it.hasNext(); i++) {
@ -263,19 +276,23 @@ public class LinkedMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
LinkedMap<K, V> lm = getMap();
try {
lm.remove(0);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
try {
lm.remove(-1);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
resetFull();
lm = getMap();
try {
lm.remove(-1);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
try {
lm.remove(lm.size());
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
final List<K> list = new ArrayList<>();
for (final MapIterator<K, V> it = lm.mapIterator(); it.hasNext();) {

View File

@ -29,8 +29,7 @@ import org.apache.commons.collections4.list.AbstractListTest;
import org.junit.jupiter.api.Test;
/**
* Extension of {@link AbstractOrderedMapTest} for exercising the {@link ListOrderedMap}
* implementation.
* Extension of {@link AbstractOrderedMapTest} for exercising the {@link ListOrderedMap} implementation.
*/
public class ListOrderedMap2Test<K, V> extends AbstractOrderedMapTest<K, V> {
@ -54,22 +53,27 @@ public class ListOrderedMap2Test<K, V> extends AbstractOrderedMapTest<K, V> {
public boolean isNullSupported() {
return ListOrderedMap2Test.this.isAllowNullKey();
}
@Override
public boolean isRemoveSupported() {
return false;
}
@Override
public boolean isSetSupported() {
return false;
}
@Override
public boolean isTestSerialization() {
return false;
}
@Override
public List<K> makeFullCollection() {
return ListOrderedMap2Test.this.makeFullMap().asList();
}
@Override
public List<K> makeObject() {
return ListOrderedMap2Test.this.makeObject().asList();
@ -116,19 +120,23 @@ public class ListOrderedMap2Test<K, V> extends AbstractOrderedMapTest<K, V> {
ListOrderedMap<K, V> lom = getMap();
try {
lom.get(0);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
try {
lom.get(-1);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
resetFull();
lom = getMap();
try {
lom.get(-1);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
try {
lom.get(lom.size());
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
int i = 0;
for (final MapIterator<K, V> it = lom.mapIterator(); it.hasNext(); i++) {
@ -142,19 +150,23 @@ public class ListOrderedMap2Test<K, V> extends AbstractOrderedMapTest<K, V> {
ListOrderedMap<K, V> lom = getMap();
try {
lom.getValue(0);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
try {
lom.getValue(-1);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
resetFull();
lom = getMap();
try {
lom.getValue(-1);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
try {
lom.getValue(lom.size());
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
int i = 0;
for (final MapIterator<K, V> it = lom.mapIterator(); it.hasNext(); i++) {
@ -197,19 +209,23 @@ public class ListOrderedMap2Test<K, V> extends AbstractOrderedMapTest<K, V> {
ListOrderedMap<K, V> lom = getMap();
try {
lom.remove(0);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
try {
lom.remove(-1);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
resetFull();
lom = getMap();
try {
lom.remove(-1);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
try {
lom.remove(lom.size());
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
final List<K> list = new ArrayList<>();
for (final MapIterator<K, V> it = lom.mapIterator(); it.hasNext();) {

View File

@ -35,8 +35,7 @@ import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
/**
* Extension of {@link AbstractOrderedMapTest} for exercising the {@link ListOrderedMap}
* implementation.
* Extension of {@link AbstractOrderedMapTest} for exercising the {@link ListOrderedMap} implementation.
*/
public class ListOrderedMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
@ -175,7 +174,7 @@ public class ListOrderedMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
}
@Test
public void testCOLLECTIONS_474_nonNullValues () {
public void testCOLLECTIONS_474_nonNullValues() {
final Object key1 = new Object();
final Object key2 = new Object();
final HashMap<Object, Object> hmap = new HashMap<>();
@ -190,7 +189,7 @@ public class ListOrderedMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
}
@Test
public void testCOLLECTIONS_474_nullValues () {
public void testCOLLECTIONS_474_nullValues() {
final Object key1 = new Object();
final Object key2 = new Object();
final HashMap<Object, Object> hmap = new HashMap<>();
@ -210,19 +209,23 @@ public class ListOrderedMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
ListOrderedMap<K, V> lom = getMap();
try {
lom.get(0);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
try {
lom.get(-1);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
resetFull();
lom = getMap();
try {
lom.get(-1);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
try {
lom.get(lom.size());
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
int i = 0;
for (final MapIterator<K, V> it = lom.mapIterator(); it.hasNext(); i++) {
@ -236,19 +239,23 @@ public class ListOrderedMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
ListOrderedMap<K, V> lom = getMap();
try {
lom.getValue(0);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
try {
lom.getValue(-1);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
resetFull();
lom = getMap();
try {
lom.getValue(-1);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
try {
lom.getValue(lom.size());
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
int i = 0;
for (final MapIterator<K, V> it = lom.mapIterator(); it.hasNext(); i++) {
@ -285,8 +292,7 @@ public class ListOrderedMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
() -> assertThrows(IndexOutOfBoundsException.class, () -> finalLom.put(1, (K) "testInsert1", (V) "testInsert1v"),
"should not be able to insert at pos 1 in empty Map"),
() -> assertThrows(IndexOutOfBoundsException.class, () -> finalLom.put(-1, (K) "testInsert-1", (V) "testInsert-1v"),
"should not be able to insert at pos -1 in empty Map")
);
"should not be able to insert at pos -1 in empty Map"));
// put where key doesn't exist
lom.put(0, (K) "testInsert1", (V) "testInsert1v");
@ -450,19 +456,23 @@ public class ListOrderedMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
ListOrderedMap<K, V> lom = getMap();
try {
lom.remove(0);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
try {
lom.remove(-1);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
resetFull();
lom = getMap();
try {
lom.remove(-1);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
try {
lom.remove(lom.size());
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
final List<K> list = new ArrayList<>();
for (final MapIterator<K, V> it = lom.mapIterator(); it.hasNext();) {
@ -484,19 +494,23 @@ public class ListOrderedMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
ListOrderedMap<K, V> lom = getMap();
try {
lom.setValue(0, (V) StringUtils.EMPTY);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
try {
lom.setValue(-1, (V) StringUtils.EMPTY);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
resetFull();
lom = getMap();
try {
lom.setValue(-1, (V) StringUtils.EMPTY);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
try {
lom.setValue(lom.size(), (V) StringUtils.EMPTY);
} catch (final IndexOutOfBoundsException ex) {}
} catch (final IndexOutOfBoundsException ex) {
}
for (int i = 0; i < lom.size(); i++) {
final V value = lom.getValue(i);

View File

@ -1337,7 +1337,7 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
}
@Test
public void testToString(){
public void testToString() {
assumeTrue(isAddSupported());
final MultiValuedMap<K, V> map = makeObject();
map.put((K) "A", (V) "X");
@ -1346,18 +1346,11 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
map.put((K) "B", (V) "U");
map.put((K) "B", (V) "V");
map.put((K) "B", (V) "W");
assertTrue(
"{A=[X, Y, Z], B=[U, V, W]}".equals(map.toString()) ||
"{B=[U, V, W], A=[X, Y, Z]}".equals(map.toString())
);
assertTrue("{A=[X, Y, Z], B=[U, V, W]}".equals(map.toString()) || "{B=[U, V, W], A=[X, Y, Z]}".equals(map.toString()));
final MultiValuedMap<K, V> originalNull = null;
assertThrows(NullPointerException.class, () -> map.putAll(originalNull),
"expecting NullPointerException");
assertTrue(
"{A=[X, Y, Z], B=[U, V, W]}".equals(map.toString()) ||
"{B=[U, V, W], A=[X, Y, Z]}".equals(map.toString())
);
assertThrows(NullPointerException.class, () -> map.putAll(originalNull), "expecting NullPointerException");
assertTrue("{A=[X, Y, Z], B=[U, V, W]}".equals(map.toString()) || "{B=[U, V, W], A=[X, Y, Z]}".equals(map.toString()));
map.remove("A");
map.remove("B");

View File

@ -176,7 +176,7 @@ public class ArrayListValuedHashMapTest<K, V> extends AbstractMultiValuedMapTest
}
@Test
public void testTrimToSize(){
public void testTrimToSize() {
final ArrayListValuedHashMap<K, V> listMap = new ArrayListValuedHashMap<>(4);
assertEquals("{}", listMap.toString());
@ -192,7 +192,7 @@ public class ArrayListValuedHashMapTest<K, V> extends AbstractMultiValuedMapTest
}
@Test
public void testValuesListIteratorMethods(){
public void testValuesListIteratorMethods() {
final ListValuedMap<K, V> listMap = makeObject();
final List<V> listA = listMap.get((K) "A");
final List<V> list = Arrays.asList((V) "W", (V) "X", (V) "F", (V) "Q", (V) "Q", (V) "F");

View File

@ -61,7 +61,7 @@ public class HashSetValuedHashMapTest<K, V> extends AbstractMultiValuedMapTest<K
}
@Test
public void testHashSetValuedHashMap_2(){
public void testHashSetValuedHashMap_2() {
final Map<K, V> map = new HashMap<>();
final SetValuedMap<K, V> map1;
final SetValuedMap<K, V> map2;

View File

@ -178,20 +178,18 @@ public class SequencesComparatorTest {
final Random random = new Random(4564634237452342L);
for (int nbCom = 0; nbCom <= 40; nbCom+=5) {
for (int nbCom = 0; nbCom <= 40; nbCom += 5) {
sentenceAfter.clear();
sentenceAfter.addAll(sentenceBefore);
for (int i = 0; i<nbCom; i++) {
for (int i = 0; i < nbCom; i++) {
if (random.nextInt(2) == 0) {
sentenceAfter.add(random.nextInt(sentenceAfter.size() + 1),
shadokAlph[random.nextInt(4)]);
sentenceAfter.add(random.nextInt(sentenceAfter.size() + 1), shadokAlph[random.nextInt(4)]);
} else {
sentenceAfter.remove(random.nextInt(sentenceAfter.size()));
}
}
final SequencesComparator<String> comparator =
new SequencesComparator<>(sentenceBefore, sentenceAfter);
final SequencesComparator<String> comparator = new SequencesComparator<>(sentenceBefore, sentenceAfter);
assertTrue(comparator.getScript().getModifications() <= nbCom);
}
}
@ -206,7 +204,7 @@ public class SequencesComparatorTest {
"MEU"
};
List<List<String>> shadokSentences = new ArrayList<>();
for (int lg=0; lg<lgMax; ++lg) {
for (int lg = 0; lg < lgMax; ++lg) {
final List<List<String>> newTab = new ArrayList<>();
newTab.add(new ArrayList<>());
for (final String element : shadokAlph) {

View File

@ -57,8 +57,7 @@ public class TransformedSplitMapTest extends BulkTest {
NOPTransformer.<String>nopTransformer(),
NOPTransformer.<String>nopTransformer() );
final ObjectInputStream in =
new ObjectInputStream( new FileInputStream( TEST_DATA_PATH+"/TransformedSplitMap.emptyCollection.version4.obj" ) );
final ObjectInputStream in = new ObjectInputStream(new FileInputStream(TEST_DATA_PATH + "/TransformedSplitMap.emptyCollection.version4.obj"));
final Object readObject = in.readObject();
in.close();
@ -78,14 +77,13 @@ public class TransformedSplitMapTest extends BulkTest {
map.put( "e", "f" );
map.put( "g", "h" );
final ObjectInputStream in =
new ObjectInputStream( new FileInputStream( TEST_DATA_PATH+"TransformedSplitMap.fullCollection.version4.obj" ) );
final ObjectInputStream in = new ObjectInputStream(new FileInputStream(TEST_DATA_PATH + "TransformedSplitMap.fullCollection.version4.obj"));
final Object readObject = in.readObject();
in.close();
final TransformedSplitMap<?, ?, ?, ?> readMap = (TransformedSplitMap<?, ?, ?, ?>) readObject;
assertFalse(readMap.isEmpty(), "Map should not be empty");
assertEquals( map.entrySet(), readMap.entrySet() );
assertEquals(map.entrySet(), readMap.entrySet());
}
@Test