From 0f5b35aa8d60b03f1974f1ebb784fc85054c67f3 Mon Sep 17 00:00:00 2001 From: Emmanuel Bourg Date: Mon, 11 Nov 2013 21:58:27 +0000 Subject: [PATCH] Code simplification git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1540860 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/commons/collections4/BulkTest.java | 2 +- .../collections4/CollectionUtilsTest.java | 10 +++--- .../commons/collections4/ListUtilsTest.java | 4 +-- .../commons/collections4/SetUtilsTest.java | 4 +-- .../collections4/bag/AbstractBagTest.java | 2 +- .../bidimap/AbstractBidiMapTest.java | 28 ++++++++--------- .../bidimap/AbstractOrderedBidiMapTest.java | 8 ++--- .../bidimap/AbstractSortedBidiMapTest.java | 18 +++++------ .../collection/AbstractCollectionTest.java | 24 ++++++-------- .../collection/TransformedCollectionTest.java | 31 +++++++++---------- .../comparators/FixedOrderComparatorTest.java | 2 +- .../iterators/AbstractIteratorTest.java | 6 ++-- .../iterators/AbstractListIteratorTest.java | 6 ++-- .../iterators/AbstractMapIteratorTest.java | 20 ++++++------ .../AbstractOrderedMapIteratorTest.java | 10 +++--- .../iterators/LoopingIteratorTest.java | 16 +++++----- .../iterators/LoopingListIteratorTest.java | 22 ++++++------- .../collections4/keyvalue/MultiKeyTest.java | 10 +++--- .../list/AbstractLinkedListTest.java | 8 ++--- .../collections4/list/AbstractListTest.java | 14 ++++----- .../list/NodeCachingLinkedListTest.java | 2 +- .../collections4/list/SetUniqueListTest.java | 4 +-- .../map/AbstractIterableMapTest.java | 12 +++---- .../collections4/map/AbstractMapTest.java | 12 +++---- .../map/AbstractOrderedMapTest.java | 8 ++--- .../map/AbstractSortedMapTest.java | 11 +++---- .../commons/collections4/map/IdentityMap.java | 2 +- .../commons/collections4/map/LRUMapTest.java | 8 ++--- .../collections4/map/LinkedMapTest.java | 2 +- .../collections4/map/MultiValueMapTest.java | 6 ++-- .../collections4/queue/AbstractQueueTest.java | 5 ++- .../queue/CircularFifoQueueTest.java | 5 ++- .../queue/TransformedQueueTest.java | 29 +++++++++-------- .../sequence/SequencesComparatorTest.java | 18 +++++------ .../collections4/set/AbstractSetTest.java | 5 ++- .../collections4/set/TransformedSetTest.java | 5 ++- .../set/TransformedSortedSetTest.java | 5 ++- 37 files changed, 184 insertions(+), 200 deletions(-) diff --git a/src/test/java/org/apache/commons/collections4/BulkTest.java b/src/test/java/org/apache/commons/collections4/BulkTest.java index 04f69af50..174622748 100644 --- a/src/test/java/org/apache/commons/collections4/BulkTest.java +++ b/src/test/java/org/apache/commons/collections4/BulkTest.java @@ -426,7 +426,7 @@ class BulkTestSuiteMaker { private static BulkTest makeTestCase(final Class c, final Method m) { final Constructor con = getTestCaseConstructor(c); try { - return con.newInstance(new Object[] { m.getName() }); + return con.newInstance(m.getName()); } catch (final InvocationTargetException e) { e.printStackTrace(); throw new RuntimeException(); // FIXME; diff --git a/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java b/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java index cad7b001e..b47c35199 100644 --- a/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java @@ -673,7 +673,7 @@ public class CollectionUtilsTest extends MockTestCase { lastElement = CollectionUtils.forAllButLastDo(col, testClosure); assertNull(lastElement); - Collection strings = Arrays.asList(new String[]{"a", "b", "c"}); + Collection strings = Arrays.asList("a", "b", "c"); final StringBuffer result = new StringBuffer(); result.append(CollectionUtils.forAllButLastDo(strings, new Closure() { public void execute(String input) { @@ -682,7 +682,7 @@ public class CollectionUtilsTest extends MockTestCase { })); assertEquals("a;b;c", result.toString()); - Collection oneString = Arrays.asList(new String[]{"a"}); + Collection oneString = Arrays.asList("a"); final StringBuffer resultOne = new StringBuffer(); resultOne.append(CollectionUtils.forAllButLastDo(oneString, new Closure() { public void execute(String input) { @@ -690,8 +690,8 @@ public class CollectionUtilsTest extends MockTestCase { } })); assertEquals("a", resultOne.toString()); - assertNull(CollectionUtils.forAllButLastDo(strings, (Closure) null)); - assertNull(CollectionUtils.forAllButLastDo((Collection) null, (Closure) null)); + assertNull(CollectionUtils.forAllButLastDo(strings, null)); + assertNull(CollectionUtils.forAllButLastDo((Collection) null, null)); } @Test @@ -705,7 +705,7 @@ public class CollectionUtilsTest extends MockTestCase { assertTrue(collectionA.isEmpty() && !collectionB.isEmpty()); assertNull(CollectionUtils.forAllButLastDo(col.iterator(), (Closure>) null)); - assertNull(CollectionUtils.forAllButLastDo((Iterator) null, (Closure) null)); + assertNull(CollectionUtils.forAllButLastDo((Iterator) null, null)); } @Test diff --git a/src/test/java/org/apache/commons/collections4/ListUtilsTest.java b/src/test/java/org/apache/commons/collections4/ListUtilsTest.java index 8869ad3b8..908dc941b 100644 --- a/src/test/java/org/apache/commons/collections4/ListUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/ListUtilsTest.java @@ -179,7 +179,7 @@ public class ListUtilsTest extends BulkTest { } public void testEquals() { - final Collection data = Arrays.asList( new String[] { "a", "b", "c" }); + final Collection data = Arrays.asList("a", "b", "c"); final List a = new ArrayList( data ); final List b = new ArrayList( data ); @@ -194,7 +194,7 @@ public class ListUtilsTest extends BulkTest { } public void testHashCode() { - final Collection data = Arrays.asList( new String[] { "a", "b", "c" }); + final Collection data = Arrays.asList("a", "b", "c"); final List a = new ArrayList(data); final List b = new ArrayList(data); diff --git a/src/test/java/org/apache/commons/collections4/SetUtilsTest.java b/src/test/java/org/apache/commons/collections4/SetUtilsTest.java index 028c6aade..f39f9bba1 100644 --- a/src/test/java/org/apache/commons/collections4/SetUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/SetUtilsTest.java @@ -73,7 +73,7 @@ public class SetUtilsTest extends BulkTest { } public void testEquals() { - final Collection data = Arrays.asList( new String[] { "a", "b", "c" }); + final Collection data = Arrays.asList("a", "b", "c"); final Set a = new HashSet(data); final Set b = new HashSet(data); @@ -88,7 +88,7 @@ public class SetUtilsTest extends BulkTest { } public void testHashCode() { - final Collection data = Arrays.asList( new String[] { "a", "b", "c" }); + final Collection data = Arrays.asList("a", "b", "c"); final Set a = new HashSet(data); final Set b = new HashSet(data); diff --git a/src/test/java/org/apache/commons/collections4/bag/AbstractBagTest.java b/src/test/java/org/apache/commons/collections4/bag/AbstractBagTest.java index 6a7317bc6..ed5700ddc 100644 --- a/src/test/java/org/apache/commons/collections4/bag/AbstractBagTest.java +++ b/src/test/java/org/apache/commons/collections4/bag/AbstractBagTest.java @@ -357,7 +357,7 @@ public abstract class AbstractBagTest extends AbstractCollectionTest { final String element = (String) i.next(); // ignore the first A, remove the second via Iterator.remove() if (element.equals("A")) { - if (foundA == false) { + if (!foundA) { foundA = true; } else { i.remove(); diff --git a/src/test/java/org/apache/commons/collections4/bidimap/AbstractBidiMapTest.java b/src/test/java/org/apache/commons/collections4/bidimap/AbstractBidiMapTest.java index 6f02fad8d..c7065dfb3 100644 --- a/src/test/java/org/apache/commons/collections4/bidimap/AbstractBidiMapTest.java +++ b/src/test/java/org/apache/commons/collections4/bidimap/AbstractBidiMapTest.java @@ -80,7 +80,7 @@ public abstract class AbstractBidiMapTest extends AbstractIterableMapTest< //----------------------------------------------------------------------- @SuppressWarnings("unchecked") public void testBidiPut() { - if (isPutAddSupported() == false || isPutChangeSupported() == false) { + if (!isPutAddSupported() || !isPutChangeSupported()) { return; } @@ -152,7 +152,7 @@ public abstract class AbstractBidiMapTest extends AbstractIterableMapTest< getSampleKeys()[0]); } - private final void doTestGetKey(final BidiMap map, final Object key, final Object value) { + private void doTestGetKey(final BidiMap map, final Object key, final Object value) { assertEquals("Value not found for key.", value, map.get(key)); assertEquals("Key not found for value.", key, map.getKey(value)); } @@ -181,7 +181,7 @@ public abstract class AbstractBidiMapTest extends AbstractIterableMapTest< //----------------------------------------------------------------------- public void testBidiModifyEntrySet() { - if (isSetValueSupported() == false) { + if (!isSetValueSupported()) { return; } @@ -190,7 +190,7 @@ public abstract class AbstractBidiMapTest extends AbstractIterableMapTest< } @SuppressWarnings("unchecked") - private final void modifyEntrySet(final BidiMap map) { + private void modifyEntrySet(final BidiMap map) { // Gets first entry final Map.Entry entry = map.entrySet().iterator().next(); @@ -214,7 +214,7 @@ public abstract class AbstractBidiMapTest extends AbstractIterableMapTest< //----------------------------------------------------------------------- public void testBidiClear() { - if (isRemoveSupported() == false) { + if (!isRemoveSupported()) { try { makeFullMap().clear(); fail(); @@ -237,7 +237,7 @@ public abstract class AbstractBidiMapTest extends AbstractIterableMapTest< //----------------------------------------------------------------------- public void testBidiRemove() { - if (isRemoveSupported() == false) { + if (!isRemoveSupported()) { try { makeFullMap().remove(getSampleKeys()[0]); fail(); @@ -258,13 +258,13 @@ public abstract class AbstractBidiMapTest extends AbstractIterableMapTest< assertEquals(null, makeFullMap().removeValue("NotPresent")); } - private final void remove(final BidiMap map, final Object key) { + private void remove(final BidiMap map, final Object key) { final Object value = map.remove(key); assertTrue("Key was not removed.", !map.containsKey(key)); assertNull("Value was not removed.", map.getKey(value)); } - private final void removeValue(final BidiMap map, final Object value) { + private void removeValue(final BidiMap map, final Object value) { final Object key = map.removeValue(value); assertTrue("Key was not removed.", !map.containsKey(key)); assertNull("Value was not removed.", map.getKey(value)); @@ -286,7 +286,7 @@ public abstract class AbstractBidiMapTest extends AbstractIterableMapTest< //----------------------------------------------------------------------- public void testBidiRemoveByKeySet() { - if (isRemoveSupported() == false) { + if (!isRemoveSupported()) { return; } @@ -294,7 +294,7 @@ public abstract class AbstractBidiMapTest extends AbstractIterableMapTest< removeByKeySet(makeFullMap().inverseBidiMap(), getSampleValues()[0], getSampleKeys()[0]); } - private final void removeByKeySet(final BidiMap map, final Object key, final Object value) { + private void removeByKeySet(final BidiMap map, final Object key, final Object value) { map.keySet().remove(key); assertTrue("Key was not removed.", !map.containsKey(key)); @@ -310,7 +310,7 @@ public abstract class AbstractBidiMapTest extends AbstractIterableMapTest< //----------------------------------------------------------------------- public void testBidiRemoveByEntrySet() { - if (isRemoveSupported() == false) { + if (!isRemoveSupported()) { return; } @@ -318,7 +318,7 @@ public abstract class AbstractBidiMapTest extends AbstractIterableMapTest< removeByEntrySet(makeFullMap().inverseBidiMap(), getSampleValues()[0], getSampleKeys()[0]); } - private final void removeByEntrySet(final BidiMap map, final Object key, final Object value) { + private void removeByEntrySet(final BidiMap map, final Object key, final Object value) { final Map temp = new HashMap(); temp.put(key, value); map.entrySet().remove(temp.entrySet().iterator().next()); @@ -371,7 +371,7 @@ public abstract class AbstractBidiMapTest extends AbstractIterableMapTest< final Map.Entry entryConfirmed2 = getEntry(itConfirmed, key2); TestBidiMapEntrySet.this.verify(); - if (isSetValueSupported() == false) { + if (!isSetValueSupported()) { try { entry1.setValue(newValue1); } catch (final UnsupportedOperationException ex) { @@ -545,7 +545,7 @@ public abstract class AbstractBidiMapTest extends AbstractIterableMapTest< assertEquals(true, it.hasNext()); final K key1 = it.next(); - if (isSetValueSupported() == false) { + if (!isSetValueSupported()) { try { it.setValue(newValue1); fail(); diff --git a/src/test/java/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapTest.java b/src/test/java/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapTest.java index 20443cbea..6d0f2f6ee 100644 --- a/src/test/java/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapTest.java +++ b/src/test/java/org/apache/commons/collections4/bidimap/AbstractOrderedBidiMapTest.java @@ -80,7 +80,7 @@ public abstract class AbstractOrderedBidiMapTest extends AbstractBidiMapTe resetEmpty(); OrderedBidiMap bidi = (OrderedBidiMap) map; assertEquals(null, bidi.nextKey(getOtherKeys()[0])); - if (isAllowNullKey() == false) { + if (!isAllowNullKey()) { try { assertEquals(null, bidi.nextKey(null)); // this is allowed too } catch (final NullPointerException ex) {} @@ -99,7 +99,7 @@ public abstract class AbstractOrderedBidiMapTest extends AbstractBidiMapTe } assertEquals(null, bidi.nextKey(confirmedLast)); - if (isAllowNullKey() == false) { + if (!isAllowNullKey()) { try { bidi.nextKey(null); fail(); @@ -113,7 +113,7 @@ public abstract class AbstractOrderedBidiMapTest extends AbstractBidiMapTe resetEmpty(); OrderedBidiMap bidi = getMap(); assertEquals(null, bidi.previousKey(getOtherKeys()[0])); - if (isAllowNullKey() == false) { + if (!isAllowNullKey()) { try { assertEquals(null, bidi.previousKey(null)); // this is allowed too } catch (final NullPointerException ex) {} @@ -134,7 +134,7 @@ public abstract class AbstractOrderedBidiMapTest extends AbstractBidiMapTe } assertEquals(null, bidi.previousKey(confirmedLast)); - if (isAllowNullKey() == false) { + if (!isAllowNullKey()) { try { bidi.previousKey(null); fail(); diff --git a/src/test/java/org/apache/commons/collections4/bidimap/AbstractSortedBidiMapTest.java b/src/test/java/org/apache/commons/collections4/bidimap/AbstractSortedBidiMapTest.java index 953334a3b..385b8c1f9 100644 --- a/src/test/java/org/apache/commons/collections4/bidimap/AbstractSortedBidiMapTest.java +++ b/src/test/java/org/apache/commons/collections4/bidimap/AbstractSortedBidiMapTest.java @@ -129,7 +129,7 @@ public abstract class AbstractSortedBidiMapTest, V exten //----------------------------------------------------------------------- public void testBidiClearByHeadMap() { - if (isRemoveSupported() == false) { + if (!isRemoveSupported()) { return; } @@ -176,7 +176,7 @@ public abstract class AbstractSortedBidiMapTest, V exten //----------------------------------------------------------------------- public void testBidiRemoveByHeadMap() { - if (isRemoveSupported() == false) { + if (!isRemoveSupported()) { return; } @@ -220,7 +220,7 @@ public abstract class AbstractSortedBidiMapTest, V exten //----------------------------------------------------------------------- public void testBidiRemoveByHeadMapEntrySet() { - if (isRemoveSupported() == false) { + if (!isRemoveSupported()) { return; } @@ -303,7 +303,7 @@ public abstract class AbstractSortedBidiMapTest, V exten //----------------------------------------------------------------------- public void testBidiClearByTailMap() { - if (isRemoveSupported() == false) { + if (!isRemoveSupported()) { return; } @@ -352,7 +352,7 @@ public abstract class AbstractSortedBidiMapTest, V exten //----------------------------------------------------------------------- public void testBidiRemoveByTailMap() { - if (isRemoveSupported() == false) { + if (!isRemoveSupported()) { return; } @@ -397,7 +397,7 @@ public abstract class AbstractSortedBidiMapTest, V exten //----------------------------------------------------------------------- public void testBidiRemoveByTailMapEntrySet() { - if (isRemoveSupported() == false) { + if (!isRemoveSupported()) { return; } @@ -487,7 +487,7 @@ public abstract class AbstractSortedBidiMapTest, V exten //----------------------------------------------------------------------- public void testBidiClearBySubMap() { - if (isRemoveSupported() == false) { + if (!isRemoveSupported()) { return; } @@ -544,7 +544,7 @@ public abstract class AbstractSortedBidiMapTest, V exten //----------------------------------------------------------------------- public void testBidiRemoveBySubMap() { - if (isRemoveSupported() == false) { + if (!isRemoveSupported()) { return; } @@ -590,7 +590,7 @@ public abstract class AbstractSortedBidiMapTest, V exten //----------------------------------------------------------------------- public void testBidiRemoveBySubMapEntrySet() { - if (isRemoveSupported() == false) { + if (!isRemoveSupported()) { return; } diff --git a/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java b/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java index 9caa41cf3..443d2311a 100644 --- a/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java +++ b/src/test/java/org/apache/commons/collections4/collection/AbstractCollectionTest.java @@ -672,9 +672,9 @@ public abstract class AbstractCollectionTest extends AbstractObjectTest { resetFull(); elements = getOtherElements(); - for (int i = 0; i < elements.length; i++) { + for (Object element : elements) { assertTrue("Full collection shouldn't contain element", - !getCollection().contains(elements[i])); + !getCollection().contains(element)); } } @@ -862,16 +862,16 @@ public abstract class AbstractCollectionTest extends AbstractObjectTest { resetEmpty(); final E[] elements = getFullElements(); - for (int i = 0; i < elements.length; i++) { - assertTrue("Shouldn't remove nonexistent element", !getCollection().remove(elements[i])); + for (E element : elements) { + assertTrue("Shouldn't remove nonexistent element", !getCollection().remove(element)); verify(); } final E[] other = getOtherElements(); resetFull(); - for (int i = 0; i < other.length; i++) { - assertTrue("Shouldn't remove nonexistent other element", !getCollection().remove(other[i])); + for (E element : other) { + assertTrue("Shouldn't remove nonexistent other element", !getCollection().remove(element)); verify(); } @@ -940,10 +940,8 @@ public abstract class AbstractCollectionTest extends AbstractObjectTest { verify(); assertTrue("Collection should shrink after removeAll", getCollection().size() < size); - final Iterator iter = all.iterator(); - while (iter.hasNext()) { - assertTrue("Collection shouldn't contain removed element", - !getCollection().contains(iter.next())); + for (E element : all) { + assertTrue("Collection shouldn't contain removed element", !getCollection().contains(element)); } } @@ -994,10 +992,8 @@ public abstract class AbstractCollectionTest extends AbstractObjectTest { getConfirmed().retainAll(elements.subList(min, max)); verify(); - final Iterator iter = getCollection().iterator(); - while (iter.hasNext()) { - assertTrue("Collection only contains retained element", - elements.subList(min, max).contains(iter.next())); + for (E element : getCollection()) { + assertTrue("Collection only contains retained element", elements.subList(min, max).contains(element)); } } diff --git a/src/test/java/org/apache/commons/collections4/collection/TransformedCollectionTest.java b/src/test/java/org/apache/commons/collections4/collection/TransformedCollectionTest.java index 368c705b5..b59f1cc54 100644 --- a/src/test/java/org/apache/commons/collections4/collection/TransformedCollectionTest.java +++ b/src/test/java/org/apache/commons/collections4/collection/TransformedCollectionTest.java @@ -19,6 +19,7 @@ package org.apache.commons.collections4.collection; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.List; import org.apache.commons.collections4.Transformer; @@ -86,32 +87,30 @@ public class TransformedCollectionTest extends AbstractCollectionTest { public void testTransformedCollection() { final Collection coll = TransformedCollection.transformingCollection(new ArrayList(), STRING_TO_INTEGER_TRANSFORMER); assertEquals(0, coll.size()); - final Object[] els = getFullElements(); - for (int i = 0; i < els.length; i++) { - coll.add(els[i]); + final Object[] elements = getFullElements(); + for (int i = 0; i < elements.length; i++) { + coll.add(elements[i]); assertEquals(i + 1, coll.size()); - assertEquals(true, coll.contains(Integer.valueOf((String) els[i]))); - assertEquals(false, coll.contains(els[i])); + assertEquals(true, coll.contains(Integer.valueOf((String) elements[i]))); + assertEquals(false, coll.contains(elements[i])); } - assertEquals(true, coll.remove(Integer.valueOf((String) els[0]))); + assertEquals(true, coll.remove(Integer.valueOf((String) elements[0]))); } public void testTransformedCollection_decorateTransform() { final Collection originalCollection = new ArrayList(); - final Object[] els = getFullElements(); - for (final Object el : els) { - originalCollection.add(el); - } + final Object[] elements = getFullElements(); + Collections.addAll(originalCollection, elements); final Collection collection = TransformedCollection.transformedCollection(originalCollection, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); - assertEquals(els.length, collection.size()); - for (final Object el : els) { - assertEquals(true, collection.contains(Integer.valueOf((String) el))); - assertEquals(false, collection.contains(el)); + assertEquals(elements.length, collection.size()); + for (final Object element : elements) { + assertEquals(true, collection.contains(Integer.valueOf((String) element))); + assertEquals(false, collection.contains(element)); } - assertEquals(false, collection.remove(els[0])); - assertEquals(true, collection.remove(Integer.valueOf((String) els[0]))); + assertEquals(false, collection.remove(elements[0])); + assertEquals(true, collection.remove(Integer.valueOf((String) elements[0]))); } @Override diff --git a/src/test/java/org/apache/commons/collections4/comparators/FixedOrderComparatorTest.java b/src/test/java/org/apache/commons/collections4/comparators/FixedOrderComparatorTest.java index 12414d4f0..992e276ed 100644 --- a/src/test/java/org/apache/commons/collections4/comparators/FixedOrderComparatorTest.java +++ b/src/test/java/org/apache/commons/collections4/comparators/FixedOrderComparatorTest.java @@ -216,7 +216,7 @@ public class FixedOrderComparatorTest extends AbstractComparatorTest { boolean isInNewOrder = false; final Random rand = new Random(); - while (keys.length > 1 && isInNewOrder == false) { + while (keys.length > 1 && !isInNewOrder) { // shuffle: for (int i = keys.length-1; i > 0; i--) { final String swap = keys[i]; diff --git a/src/test/java/org/apache/commons/collections4/iterators/AbstractIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/AbstractIteratorTest.java index 34386433f..d46f99d1f 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/AbstractIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/AbstractIteratorTest.java @@ -101,7 +101,7 @@ public abstract class AbstractIteratorTest extends AbstractObjectTest { * Test the empty iterator. */ public void testEmptyIterator() { - if (supportsEmptyIterator() == false) { + if (!supportsEmptyIterator()) { return; } @@ -125,7 +125,7 @@ public abstract class AbstractIteratorTest extends AbstractObjectTest { * Test normal iteration behaviour. */ public void testFullIterator() { - if (supportsFullIterator() == false) { + if (!supportsFullIterator()) { return; } @@ -163,7 +163,7 @@ public abstract class AbstractIteratorTest extends AbstractObjectTest { public void testRemove() { final Iterator it = makeObject(); - if (supportsRemove() == false) { + if (!supportsRemove()) { // check for UnsupportedOperationException if not supported try { it.remove(); diff --git a/src/test/java/org/apache/commons/collections4/iterators/AbstractListIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/AbstractListIteratorTest.java index b7db7242b..2123d603d 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/AbstractListIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/AbstractListIteratorTest.java @@ -92,7 +92,7 @@ public abstract class AbstractListIteratorTest extends AbstractIteratorTest extends AbstractIteratorTest it = makeObject(); final E addValue = addSetValue(); - if (supportsAdd() == false) { + if (!supportsAdd()) { // check for UnsupportedOperationException if not supported try { it.add(addValue); @@ -198,7 +198,7 @@ public abstract class AbstractListIteratorTest extends AbstractIteratorTest it = makeObject(); - if (supportsSet() == false) { + if (!supportsSet()) { // check for UnsupportedOperationException if not supported try { it.set(addSetValue()); diff --git a/src/test/java/org/apache/commons/collections4/iterators/AbstractMapIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/AbstractMapIteratorTest.java index 1cdfde002..e938856dc 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/AbstractMapIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/AbstractMapIteratorTest.java @@ -112,7 +112,7 @@ public abstract class AbstractMapIteratorTest extends AbstractIteratorTest * Test that the empty list iterator contract is correct. */ public void testEmptyMapIterator() { - if (supportsEmptyIterator() == false) { + if (!supportsEmptyIterator()) { return; } @@ -137,7 +137,7 @@ public abstract class AbstractMapIteratorTest extends AbstractIteratorTest fail(); } catch (final IllegalStateException ex) {} - if (supportsSetValue() == false) { + if (!supportsSetValue()) { // setValue() should throw an UnsupportedOperationException/IllegalStateException try { it.setValue(addSetValues()[0]); @@ -158,7 +158,7 @@ public abstract class AbstractMapIteratorTest extends AbstractIteratorTest * Test that the full list iterator contract is correct. */ public void testFullMapIterator() { - if (supportsFullIterator() == false) { + if (!supportsFullIterator()) { return; } @@ -177,7 +177,7 @@ public abstract class AbstractMapIteratorTest extends AbstractIteratorTest // getValue final V value = it.getValue(); - if (isGetStructuralModify() == false) { + if (!isGetStructuralModify()) { assertSame("Value must be mapped to key", map.get(key), value); } assertTrue("Value must be in map", map.containsValue(value)); @@ -188,7 +188,7 @@ public abstract class AbstractMapIteratorTest extends AbstractIteratorTest //----------------------------------------------------------------------- public void testMapIteratorSet() { - if (supportsFullIterator() == false) { + if (!supportsFullIterator()) { return; } @@ -201,7 +201,7 @@ public abstract class AbstractMapIteratorTest extends AbstractIteratorTest final K key = it.next(); final V value = it.getValue(); - if (supportsSetValue() == false) { + if (!supportsSetValue()) { try { it.setValue(newValue); fail(); @@ -242,7 +242,7 @@ public abstract class AbstractMapIteratorTest extends AbstractIteratorTest assertEquals(true, it.hasNext()); final K key = it.next(); - if (supportsRemove() == false) { + if (!supportsRemove()) { try { it.remove(); fail(); @@ -265,7 +265,7 @@ public abstract class AbstractMapIteratorTest extends AbstractIteratorTest //----------------------------------------------------------------------- public void testMapIteratorSetRemoveSet() { - if (supportsSetValue() == false || supportsRemove() == false) { + if (!supportsSetValue() || !supportsRemove()) { return; } final V newValue = addSetValues()[0]; @@ -289,7 +289,7 @@ public abstract class AbstractMapIteratorTest extends AbstractIteratorTest //----------------------------------------------------------------------- public void testMapIteratorRemoveGetKey() { - if (supportsRemove() == false) { + if (!supportsRemove()) { return; } final MapIterator it = makeObject(); @@ -311,7 +311,7 @@ public abstract class AbstractMapIteratorTest extends AbstractIteratorTest //----------------------------------------------------------------------- public void testMapIteratorRemoveGetValue() { - if (supportsRemove() == false) { + if (!supportsRemove()) { return; } final MapIterator it = makeObject(); diff --git a/src/test/java/org/apache/commons/collections4/iterators/AbstractOrderedMapIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/AbstractOrderedMapIteratorTest.java index f33c364c3..e80e2e7ed 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/AbstractOrderedMapIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/AbstractOrderedMapIteratorTest.java @@ -61,7 +61,7 @@ public abstract class AbstractOrderedMapIteratorTest extends AbstractMapIt */ @Override public void testEmptyMapIterator() { - if (supportsEmptyIterator() == false) { + if (!supportsEmptyIterator()) { return; } @@ -81,7 +81,7 @@ public abstract class AbstractOrderedMapIteratorTest extends AbstractMapIt */ @Override public void testFullMapIterator() { - if (supportsFullIterator() == false) { + if (!supportsFullIterator()) { return; } @@ -102,7 +102,7 @@ public abstract class AbstractOrderedMapIteratorTest extends AbstractMapIt // getValue final V value = it.getValue(); - if (isGetStructuralModify() == false) { + if (!isGetStructuralModify()) { assertSame("Value must be mapped to key", map.get(key), value); } assertTrue("Value must be in map", map.containsValue(value)); @@ -120,7 +120,7 @@ public abstract class AbstractOrderedMapIteratorTest extends AbstractMapIt // getValue final Object value = it.getValue(); - if (isGetStructuralModify() == false) { + if (!isGetStructuralModify()) { assertSame("Value must be mapped to key", map.get(key), value); } assertTrue("Value must be in map", map.containsValue(value)); @@ -136,7 +136,7 @@ public abstract class AbstractOrderedMapIteratorTest extends AbstractMapIt * Test that the iterator order matches the keySet order. */ public void testMapIteratorOrder() { - if (supportsFullIterator() == false) { + if (!supportsFullIterator()) { return; } diff --git a/src/test/java/org/apache/commons/collections4/iterators/LoopingIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/LoopingIteratorTest.java index c0ef1199a..08fbae45d 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/LoopingIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/LoopingIteratorTest.java @@ -48,7 +48,7 @@ public class LoopingIteratorTest extends TestCase { public void testLooping0() throws Exception { final List list = new ArrayList(); final LoopingIterator loop = new LoopingIterator(list); - assertTrue("hasNext should return false", loop.hasNext() == false); + assertTrue("hasNext should return false", !loop.hasNext()); try { loop.next(); @@ -62,7 +62,7 @@ public class LoopingIteratorTest extends TestCase { * @throws Exception If something unexpected occurs. */ public void testLooping1() throws Exception { - final List list = Arrays.asList(new String[] { "a" }); + final List list = Arrays.asList("a"); final LoopingIterator loop = new LoopingIterator(list); assertTrue("1st hasNext should return true", loop.hasNext()); @@ -81,7 +81,7 @@ public class LoopingIteratorTest extends TestCase { * @throws Exception If something unexpected occurs. */ public void testLooping2() throws Exception { - final List list = Arrays.asList(new String[] { "a", "b" }); + final List list = Arrays.asList("a", "b"); final LoopingIterator loop = new LoopingIterator(list); assertTrue("1st hasNext should return true", loop.hasNext()); @@ -100,7 +100,7 @@ public class LoopingIteratorTest extends TestCase { * @throws Exception If something unexpected occurs. */ public void testLooping3() throws Exception { - final List list = Arrays.asList(new String[] { "a", "b", "c" }); + final List list = Arrays.asList("a", "b", "c"); final LoopingIterator loop = new LoopingIterator(list); assertTrue("1st hasNext should return true", loop.hasNext()); @@ -122,7 +122,7 @@ public class LoopingIteratorTest extends TestCase { * @throws Exception If something unexpected occurs. */ public void testRemoving1() throws Exception { - final List list = new ArrayList(Arrays.asList(new String[] { "a", "b", "c" })); + final List list = new ArrayList(Arrays.asList("a", "b", "c")); final LoopingIterator loop = new LoopingIterator(list); assertEquals("list should have 3 elements.", 3, list.size()); @@ -141,7 +141,7 @@ public class LoopingIteratorTest extends TestCase { loop.remove(); // removes c assertEquals("list should have 0 elements.", 0, list.size()); - assertTrue("4th hasNext should return false", loop.hasNext() == false); + assertFalse("4th hasNext should return false", loop.hasNext()); try { loop.next(); fail("Expected NoSuchElementException to be thrown."); @@ -154,7 +154,7 @@ public class LoopingIteratorTest extends TestCase { * @throws Exception If something unexpected occurs. */ public void testReset() throws Exception { - final List list = Arrays.asList(new String[] { "a", "b", "c" }); + final List list = Arrays.asList("a", "b", "c"); final LoopingIterator loop = new LoopingIterator(list); assertEquals("a", loop.next()); @@ -176,7 +176,7 @@ public class LoopingIteratorTest extends TestCase { * @throws Exception If something unexpected occurs. */ public void testSize() throws Exception { - final List list = new ArrayList(Arrays.asList(new String[] { "a", "b", "c" })); + final List list = new ArrayList(Arrays.asList("a", "b", "c")); final LoopingIterator loop = new LoopingIterator(list); assertEquals(3, loop.size()); diff --git a/src/test/java/org/apache/commons/collections4/iterators/LoopingListIteratorTest.java b/src/test/java/org/apache/commons/collections4/iterators/LoopingListIteratorTest.java index 2789e8452..95da95476 100644 --- a/src/test/java/org/apache/commons/collections4/iterators/LoopingListIteratorTest.java +++ b/src/test/java/org/apache/commons/collections4/iterators/LoopingListIteratorTest.java @@ -68,7 +68,7 @@ public class LoopingListIteratorTest extends TestCase { * one element. */ public void testLooping1() throws Exception { - final List list = Arrays.asList(new String[] { "a" }); + final List list = Arrays.asList("a"); final LoopingListIterator loop = new LoopingListIterator(list); // assertTrue(loop.hasNext()); @@ -95,7 +95,7 @@ public class LoopingListIteratorTest extends TestCase { * elements. */ public void testLooping2() throws Exception { - final List list = Arrays.asList(new String[] { "a", "b" }); + final List list = Arrays.asList("a", "b"); final LoopingListIterator loop = new LoopingListIterator(list); // b assertTrue(loop.hasNext()); @@ -125,7 +125,7 @@ public class LoopingListIteratorTest extends TestCase { * the begin/end boundary of the list. */ public void testJoggingNotOverBoundary() { - final List list = Arrays.asList(new String[] { "a", "b" }); + final List list = Arrays.asList("a", "b"); final LoopingListIterator loop = new LoopingListIterator(list); // b // Try jogging back and forth between the elements, but not @@ -145,7 +145,7 @@ public class LoopingListIteratorTest extends TestCase { * begin/end boundary of the list. */ public void testJoggingOverBoundary() { - final List list = Arrays.asList(new String[] { "a", "b" }); + final List list = Arrays.asList("a", "b"); final LoopingListIterator loop = new LoopingListIterator(list); // b // Try jogging back and forth between the elements, but not @@ -163,7 +163,7 @@ public class LoopingListIteratorTest extends TestCase { * Tests removing an element from a wrapped ArrayList. */ public void testRemovingElementsAndIteratingForward() { - final List list = new ArrayList(Arrays.asList(new String[] { "a", "b", "c" })); + final List list = new ArrayList(Arrays.asList("a", "b", "c")); final LoopingListIterator loop = new LoopingListIterator(list); // b c assertTrue(loop.hasNext()); @@ -193,7 +193,7 @@ public class LoopingListIteratorTest extends TestCase { * Tests removing an element from a wrapped ArrayList. */ public void testRemovingElementsAndIteratingBackwards() { - final List list = new ArrayList(Arrays.asList(new String[] { "a", "b", "c" })); + final List list = new ArrayList(Arrays.asList("a", "b", "c")); final LoopingListIterator loop = new LoopingListIterator(list); // b c assertTrue(loop.hasPrevious()); @@ -223,7 +223,7 @@ public class LoopingListIteratorTest extends TestCase { * Tests the reset method. */ public void testReset() { - final List list = Arrays.asList(new String[] { "a", "b", "c" }); + final List list = Arrays.asList("a", "b", "c"); final LoopingListIterator loop = new LoopingListIterator(list); // b c assertEquals("a", loop.next()); // a c @@ -250,7 +250,7 @@ public class LoopingListIteratorTest extends TestCase { * Tests the add method. */ public void testAdd() { - List list = new ArrayList(Arrays.asList(new String[] { "b", "e", "f" })); + List list = new ArrayList(Arrays.asList("b", "e", "f")); LoopingListIterator loop = new LoopingListIterator(list); // e f loop.add("a"); // b e f @@ -275,7 +275,7 @@ public class LoopingListIteratorTest extends TestCase { assertEquals("f", loop.next()); // b c d e f assertEquals("a", loop.next()); // a c d e f - list = new ArrayList(Arrays.asList(new String[] { "b", "e", "f" })); + list = new ArrayList(Arrays.asList("b", "e", "f")); loop = new LoopingListIterator(list); // e f loop.add("a"); // a e f @@ -304,7 +304,7 @@ public class LoopingListIteratorTest extends TestCase { * Tests nextIndex and previousIndex. */ public void testNextAndPreviousIndex() { - final List list = Arrays.asList(new String[] { "a", "b", "c" }); + final List list = Arrays.asList("a", "b", "c"); final LoopingListIterator loop = new LoopingListIterator(list); // b c assertEquals(0, loop.nextIndex()); @@ -335,7 +335,7 @@ public class LoopingListIteratorTest extends TestCase { * Tests using the set method to change elements. */ public void testSet() { - final List list = Arrays.asList(new String[] { "q", "r", "z" }); + final List list = Arrays.asList("q", "r", "z"); final LoopingListIterator loop = new LoopingListIterator(list); // r z assertEquals("z", loop.previous()); // q r diff --git a/src/test/java/org/apache/commons/collections4/keyvalue/MultiKeyTest.java b/src/test/java/org/apache/commons/collections4/keyvalue/MultiKeyTest.java index 2e1cc68e9..39f065939 100644 --- a/src/test/java/org/apache/commons/collections4/keyvalue/MultiKeyTest.java +++ b/src/test/java/org/apache/commons/collections4/keyvalue/MultiKeyTest.java @@ -53,7 +53,7 @@ public class MultiKeyTest extends TestCase { //----------------------------------------------------------------------- public void testConstructors() throws Exception { - MultiKey mk = null; + MultiKey mk; mk = new MultiKey(ONE, TWO); assertTrue(Arrays.equals(new Object[] { ONE, TWO }, mk.getKeys())); @@ -71,7 +71,7 @@ public class MultiKeyTest extends TestCase { } public void testConstructorsByArray() throws Exception { - MultiKey mk = null; + MultiKey mk; Integer[] keys = new Integer[] { THREE, FOUR, ONE, TWO }; mk = new MultiKey(keys); assertTrue(Arrays.equals(new Object[] { THREE, FOUR, ONE, TWO }, mk.getKeys())); @@ -193,9 +193,9 @@ public class MultiKeyTest extends TestCase { assertEquals(mk1, mk1); assertEquals(mk1, mk2); - assertTrue(mk1.equals(mk3) == false); - assertTrue(mk1.equals("") == false); - assertTrue(mk1.equals(null) == false); + assertFalse(mk1.equals(mk3)); + assertFalse(mk1.equals("")); + assertFalse(mk1.equals(null)); } static class SystemHashCodeSimulatingKey implements Serializable { diff --git a/src/test/java/org/apache/commons/collections4/list/AbstractLinkedListTest.java b/src/test/java/org/apache/commons/collections4/list/AbstractLinkedListTest.java index 5bed50bfb..dd421e43e 100644 --- a/src/test/java/org/apache/commons/collections4/list/AbstractLinkedListTest.java +++ b/src/test/java/org/apache/commons/collections4/list/AbstractLinkedListTest.java @@ -34,7 +34,7 @@ public abstract class AbstractLinkedListTest extends AbstractListTest { public void testRemoveFirst() { resetEmpty(); final AbstractLinkedList list = getCollection(); - if (isRemoveSupported() == false) { + if (!isRemoveSupported()) { try { list.removeFirst(); } catch (final UnsupportedOperationException ex) {} @@ -58,7 +58,7 @@ public abstract class AbstractLinkedListTest extends AbstractListTest { public void testRemoveLast() { resetEmpty(); final AbstractLinkedList list = getCollection(); - if (isRemoveSupported() == false) { + if (!isRemoveSupported()) { try { list.removeLast(); } catch (final UnsupportedOperationException ex) {} @@ -79,7 +79,7 @@ public abstract class AbstractLinkedListTest extends AbstractListTest { public void testAddNodeAfter() { resetEmpty(); final AbstractLinkedList list = getCollection(); - if (isAddSupported() == false) { + if (!isAddSupported()) { try { list.addFirst(null); } catch (final UnsupportedOperationException ex) {} @@ -111,7 +111,7 @@ public abstract class AbstractLinkedListTest extends AbstractListTest { @SuppressWarnings("unchecked") public void testRemoveNode() { resetEmpty(); - if (isAddSupported() == false || isRemoveSupported() == false) { + if (!isAddSupported() || !isRemoveSupported()) { return; } final AbstractLinkedList list = getCollection(); diff --git a/src/test/java/org/apache/commons/collections4/list/AbstractListTest.java b/src/test/java/org/apache/commons/collections4/list/AbstractListTest.java index 3926aa58c..452805cb8 100644 --- a/src/test/java/org/apache/commons/collections4/list/AbstractListTest.java +++ b/src/test/java/org/apache/commons/collections4/list/AbstractListTest.java @@ -473,11 +473,9 @@ public abstract class AbstractListTest extends AbstractCollectionTest { final List list1 = getCollection(); final List list2 = getConfirmed(); - final Iterator iterator = list2.iterator(); - while (iterator.hasNext()) { - final Object element = iterator.next(); + for (E element : list2) { assertEquals("indexOf should return correct result", - list1.indexOf(element), list2.indexOf(element)); + list1.indexOf(element), list2.indexOf(element)); verify(); } @@ -793,7 +791,7 @@ public abstract class AbstractListTest extends AbstractCollectionTest { * Tests remove on list iterator is correct. */ public void testListListIteratorPreviousRemoveNext() { - if (isRemoveSupported() == false) { + if (!isRemoveSupported()) { return; } resetFull(); @@ -825,7 +823,7 @@ public abstract class AbstractListTest extends AbstractCollectionTest { * Tests remove on list iterator is correct. */ public void testListListIteratorPreviousRemovePrevious() { - if (isRemoveSupported() == false) { + if (!isRemoveSupported()) { return; } resetFull(); @@ -857,7 +855,7 @@ public abstract class AbstractListTest extends AbstractCollectionTest { * Tests remove on list iterator is correct. */ public void testListListIteratorNextRemoveNext() { - if (isRemoveSupported() == false) { + if (!isRemoveSupported()) { return; } resetFull(); @@ -886,7 +884,7 @@ public abstract class AbstractListTest extends AbstractCollectionTest { * Tests remove on list iterator is correct. */ public void testListListIteratorNextRemovePrevious() { - if (isRemoveSupported() == false) { + if (!isRemoveSupported()) { return; } resetFull(); diff --git a/src/test/java/org/apache/commons/collections4/list/NodeCachingLinkedListTest.java b/src/test/java/org/apache/commons/collections4/list/NodeCachingLinkedListTest.java index 6ff895bc0..cb62502b9 100644 --- a/src/test/java/org/apache/commons/collections4/list/NodeCachingLinkedListTest.java +++ b/src/test/java/org/apache/commons/collections4/list/NodeCachingLinkedListTest.java @@ -52,7 +52,7 @@ public class NodeCachingLinkedListTest extends AbstractLinkedListTest { //----------------------------------------------------------------------- @SuppressWarnings("unchecked") public void testShrinkCache() { - if (isRemoveSupported() == false || isAddSupported() == false) { + if (!isRemoveSupported() || !isAddSupported()) { return; } resetEmpty(); diff --git a/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java b/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java index 932abf319..07b1a9e7c 100644 --- a/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java +++ b/src/test/java/org/apache/commons/collections4/list/SetUniqueListTest.java @@ -148,7 +148,7 @@ public class SetUniqueListTest extends AbstractListTest { // add two new unique elements at index 0 final Integer firstNewElement = Integer.valueOf(2); final Integer secondNewElement = Integer.valueOf(3); - Collection collection = Arrays.asList(new Integer[] {firstNewElement, secondNewElement}); + Collection collection = Arrays.asList(firstNewElement, secondNewElement); list.addAll(0, collection); assertEquals("Unique elements should be added.", 3, list.size()); assertEquals("First new element should be at index 0", firstNewElement, list.get(0)); @@ -157,7 +157,7 @@ public class SetUniqueListTest extends AbstractListTest { // add a duplicate element and a unique element at index 0 final Integer thirdNewElement = Integer.valueOf(4); - collection = Arrays.asList(new Integer[] {existingElement, thirdNewElement}); + collection = Arrays.asList(existingElement, thirdNewElement); list.addAll(0, collection); assertEquals("Duplicate element should not be added, unique element should be added.", 4, list.size()); diff --git a/src/test/java/org/apache/commons/collections4/map/AbstractIterableMapTest.java b/src/test/java/org/apache/commons/collections4/map/AbstractIterableMapTest.java index 99d7a268d..cfed604e2 100644 --- a/src/test/java/org/apache/commons/collections4/map/AbstractIterableMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/AbstractIterableMapTest.java @@ -57,10 +57,10 @@ public abstract class AbstractIterableMapTest extends AbstractMapTest extends AbstractMapTest extends AbstractMapTest extends AbstractObjectTest { final Object[] keys = getSampleKeys(); resetEmpty(); - for(int i = 0; i < keys.length; i++) { + for (Object key : keys) { assertTrue("Map must not contain key when map is empty", - !getMap().containsKey(keys[i])); + !getMap().containsKey(key)); } verify(); resetFull(); - for (final Object key : keys) { + for (Object key : keys) { assertTrue("Map must contain key for a mapping in the map. " + "Missing: " + key, getMap().containsKey(key)); } @@ -1614,7 +1614,7 @@ public abstract class AbstractMapTest extends AbstractObjectTest { final Map.Entry entry = it.next(); assertEquals(true, AbstractMapTest.this.getMap().containsKey(entry.getKey())); assertEquals(true, AbstractMapTest.this.getMap().containsValue(entry.getValue())); - if (isGetStructuralModify() == false) { + if (!isGetStructuralModify()) { assertEquals(AbstractMapTest.this.getMap().get(entry.getKey()), entry.getValue()); } count++; @@ -1641,7 +1641,7 @@ public abstract class AbstractMapTest extends AbstractObjectTest { final Map.Entry entryConfirmed2 = getEntry(itConfirmed, key2); verify(); - if (isSetValueSupported() == false) { + if (!isSetValueSupported()) { try { entry1.setValue(newValue1); } catch (final UnsupportedOperationException ex) { @@ -1693,7 +1693,7 @@ public abstract class AbstractMapTest extends AbstractObjectTest { } public void testMapEntrySetRemoveNonMapEntry() { - if (isRemoveSupported() == false) { + if (!isRemoveSupported()) { return; } resetFull(); diff --git a/src/test/java/org/apache/commons/collections4/map/AbstractOrderedMapTest.java b/src/test/java/org/apache/commons/collections4/map/AbstractOrderedMapTest.java index 39960ec7a..f6a6f6356 100644 --- a/src/test/java/org/apache/commons/collections4/map/AbstractOrderedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/AbstractOrderedMapTest.java @@ -140,7 +140,7 @@ public abstract class AbstractOrderedMapTest extends AbstractIterableMapTe } assertEquals(null, ordered.nextKey(confirmedLast)); - if (isAllowNullKey() == false) { + if (!isAllowNullKey()) { try { ordered.nextKey(null); fail(); @@ -154,7 +154,7 @@ public abstract class AbstractOrderedMapTest extends AbstractIterableMapTe resetEmpty(); OrderedMap ordered = getMap(); assertEquals(null, ordered.previousKey(getOtherKeys()[0])); - if (isAllowNullKey() == false) { + if (!isAllowNullKey()) { try { assertEquals(null, ordered.previousKey(null)); // this is allowed too } catch (final NullPointerException ex) {} @@ -175,13 +175,13 @@ public abstract class AbstractOrderedMapTest extends AbstractIterableMapTe } assertEquals(null, ordered.previousKey(confirmedLast)); - if (isAllowNullKey() == false) { + if (!isAllowNullKey()) { try { ordered.previousKey(null); fail(); } catch (final NullPointerException ex) {} } else { - if (isAllowNullKey() == false) { + if (!isAllowNullKey()) { assertEquals(null, ordered.previousKey(null)); } } diff --git a/src/test/java/org/apache/commons/collections4/map/AbstractSortedMapTest.java b/src/test/java/org/apache/commons/collections4/map/AbstractSortedMapTest.java index 649d3df83..9e603c3a0 100644 --- a/src/test/java/org/apache/commons/collections4/map/AbstractSortedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/AbstractSortedMapTest.java @@ -18,7 +18,6 @@ package org.apache.commons.collections4.map; import java.util.ArrayList; import java.util.Arrays; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -92,8 +91,8 @@ public abstract class AbstractSortedMapTest extends AbstractMapTest public void testLastKey() { final SortedMap sm = makeFullMap(); K obj = null; - for (final Iterator it = sm.keySet().iterator(); it.hasNext();) { - obj = it.next(); + for (K k : sm.keySet()) { + obj = k; } assertSame(obj, sm.lastKey()); } @@ -236,7 +235,7 @@ public abstract class AbstractSortedMapTest extends AbstractMapTest return ((SortedMap) main.makeFullMap()).headMap(toKey); } public void testHeadMapOutOfRange() { - if (isPutAddSupported() == false) { + if (!isPutAddSupported()) { return; } resetEmpty(); @@ -291,7 +290,7 @@ public abstract class AbstractSortedMapTest extends AbstractMapTest return ((SortedMap) main.makeFullMap()).tailMap(fromKey); } public void testTailMapOutOfRange() { - if (isPutAddSupported() == false) { + if (!isPutAddSupported()) { return; } resetEmpty(); @@ -353,7 +352,7 @@ public abstract class AbstractSortedMapTest extends AbstractMapTest return ((SortedMap) main.makeFullMap()).subMap(fromKey, toKey); } public void testSubMapOutOfRange() { - if (isPutAddSupported() == false) { + if (!isPutAddSupported()) { return; } resetEmpty(); diff --git a/src/test/java/org/apache/commons/collections4/map/IdentityMap.java b/src/test/java/org/apache/commons/collections4/map/IdentityMap.java index 7f9cdf2f7..a1a7a031c 100644 --- a/src/test/java/org/apache/commons/collections4/map/IdentityMap.java +++ b/src/test/java/org/apache/commons/collections4/map/IdentityMap.java @@ -159,7 +159,7 @@ public class IdentityMap if (obj == this) { return true; } - if (obj instanceof Map.Entry == false) { + if (!(obj instanceof Entry)) { return false; } final Map.Entry other = (Map.Entry) obj; diff --git a/src/test/java/org/apache/commons/collections4/map/LRUMapTest.java b/src/test/java/org/apache/commons/collections4/map/LRUMapTest.java index 06f6933c7..9c0d7d6c6 100644 --- a/src/test/java/org/apache/commons/collections4/map/LRUMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/LRUMapTest.java @@ -69,7 +69,7 @@ public class LRUMapTest extends AbstractOrderedMapTest { //----------------------------------------------------------------------- public void testLRU() { - if (isPutAddSupported() == false || isPutChangeSupported() == false) { + if (!isPutAddSupported() || !isPutChangeSupported()) { return; } final K[] keys = getSampleKeys(); @@ -151,7 +151,7 @@ public class LRUMapTest extends AbstractOrderedMapTest { //----------------------------------------------------------------------- public void testAccessOrder() { - if (isPutAddSupported() == false || isPutChangeSupported() == false) { + if (!isPutAddSupported() || !isPutChangeSupported()) { return; } final K[] keys = getSampleKeys(); @@ -378,7 +378,7 @@ public class LRUMapTest extends AbstractOrderedMapTest { @SuppressWarnings("unchecked") public void testInternalState_Buckets() { - if (isPutAddSupported() == false || isPutChangeSupported() == false) { + if (!isPutAddSupported() || !isPutChangeSupported()) { return; } final SingleHashCode one = new SingleHashCode("1"); @@ -468,7 +468,7 @@ public class LRUMapTest extends AbstractOrderedMapTest { @SuppressWarnings("unchecked") public void testInternalState_getEntry_int() { - if (isPutAddSupported() == false || isPutChangeSupported() == false) { + if (!isPutAddSupported() || !isPutChangeSupported()) { return; } final SingleHashCode one = new SingleHashCode("1"); diff --git a/src/test/java/org/apache/commons/collections4/map/LinkedMapTest.java b/src/test/java/org/apache/commons/collections4/map/LinkedMapTest.java index 481285f3e..ea04eefc5 100644 --- a/src/test/java/org/apache/commons/collections4/map/LinkedMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/LinkedMapTest.java @@ -81,7 +81,7 @@ public class LinkedMapTest extends AbstractOrderedMapTest { //----------------------------------------------------------------------- public void testInsertionOrder() { - if (isPutAddSupported() == false || isPutChangeSupported() == false) { + if (!isPutAddSupported() || !isPutChangeSupported()) { return; } final K[] keys = getSampleKeys(); diff --git a/src/test/java/org/apache/commons/collections4/map/MultiValueMapTest.java b/src/test/java/org/apache/commons/collections4/map/MultiValueMapTest.java index b27239766..02c5cc9bd 100644 --- a/src/test/java/org/apache/commons/collections4/map/MultiValueMapTest.java +++ b/src/test/java/org/apache/commons/collections4/map/MultiValueMapTest.java @@ -121,7 +121,7 @@ public class MultiValueMapTest extends AbstractObjectTest { public void testKeyedIterator() { final MultiValueMap map = createTestMap(); final ArrayList actual = new ArrayList(IteratorUtils.toList(map.iterator("one"))); - final ArrayList expected = new ArrayList(Arrays.asList(new String[]{ "uno", "un" })); + final ArrayList expected = new ArrayList(Arrays.asList("uno", "un")); assertEquals(expected, actual); } @@ -342,7 +342,7 @@ public class MultiValueMapTest extends AbstractObjectTest { @SuppressWarnings("unchecked") public void testPutAll_KeyCollection() { final MultiValueMap map = new MultiValueMap(); - Collection coll = (Collection) Arrays.asList(new Object[] { "X", "Y", "Z" }); + Collection coll = (Collection) Arrays.asList("X", "Y", "Z"); assertEquals(true, map.putAll((K) "A", coll)); assertEquals(3, map.size("A")); @@ -362,7 +362,7 @@ public class MultiValueMapTest extends AbstractObjectTest { assertEquals(true, map.containsValue("A", "Y")); assertEquals(true, map.containsValue("A", "Z")); - coll = (Collection) Arrays.asList(new Object[] { "M" }); + coll = (Collection) Arrays.asList("M"); assertEquals(true, map.putAll((K) "A", coll)); assertEquals(4, map.size("A")); assertEquals(true, map.containsValue("A", "X")); diff --git a/src/test/java/org/apache/commons/collections4/queue/AbstractQueueTest.java b/src/test/java/org/apache/commons/collections4/queue/AbstractQueueTest.java index 7a7c48ad8..e86ace2fd 100644 --- a/src/test/java/org/apache/commons/collections4/queue/AbstractQueueTest.java +++ b/src/test/java/org/apache/commons/collections4/queue/AbstractQueueTest.java @@ -73,11 +73,10 @@ public abstract class AbstractQueueTest extends AbstractCollectionTest { public void verify() { super.verify(); final Iterator iterator1 = getCollection().iterator(); - final Iterator iterator2 = getConfirmed().iterator(); - while (iterator2.hasNext()) { + for (E e : getConfirmed()) { assertTrue(iterator1.hasNext()); final Object o1 = iterator1.next(); - final Object o2 = iterator2.next(); + final Object o2 = e; assertEquals(o1, o2); } } diff --git a/src/test/java/org/apache/commons/collections4/queue/CircularFifoQueueTest.java b/src/test/java/org/apache/commons/collections4/queue/CircularFifoQueueTest.java index 0a89283a9..e3fe6549d 100644 --- a/src/test/java/org/apache/commons/collections4/queue/CircularFifoQueueTest.java +++ b/src/test/java/org/apache/commons/collections4/queue/CircularFifoQueueTest.java @@ -49,11 +49,10 @@ public class CircularFifoQueueTest extends AbstractQueueTest { public void verify() { super.verify(); final Iterator iterator1 = getCollection().iterator(); - final Iterator iterator2 = getConfirmed().iterator(); - while (iterator2.hasNext()) { + for (E e : getConfirmed()) { assertTrue(iterator1.hasNext()); final Object o1 = iterator1.next(); - final Object o2 = iterator2.next(); + final Object o2 = e; assertEquals(o1, o2); } } diff --git a/src/test/java/org/apache/commons/collections4/queue/TransformedQueueTest.java b/src/test/java/org/apache/commons/collections4/queue/TransformedQueueTest.java index ac2298002..a96958eae 100644 --- a/src/test/java/org/apache/commons/collections4/queue/TransformedQueueTest.java +++ b/src/test/java/org/apache/commons/collections4/queue/TransformedQueueTest.java @@ -17,6 +17,7 @@ package org.apache.commons.collections4.queue; import java.util.Arrays; +import java.util.Collections; import java.util.LinkedList; import java.util.Queue; @@ -70,36 +71,34 @@ public class TransformedQueueTest extends AbstractQueueTest { final Queue queue = TransformedQueue.transformingQueue(new LinkedList(), TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); assertEquals(0, queue.size()); - final Object[] els = new Object[] { "1", "3", "5", "7", "2", "4", "6" }; - for (int i = 0; i < els.length; i++) { - queue.add(els[i]); + final Object[] elements = new Object[] { "1", "3", "5", "7", "2", "4", "6" }; + for (int i = 0; i < elements.length; i++) { + queue.add(elements[i]); assertEquals(i + 1, queue.size()); - assertEquals(true, queue.contains(Integer.valueOf((String) els[i]))); - assertEquals(false, queue.contains(els[i])); + assertEquals(true, queue.contains(Integer.valueOf((String) elements[i]))); + assertEquals(false, queue.contains(elements[i])); } - assertEquals(false, queue.remove(els[0])); - assertEquals(true, queue.remove(Integer.valueOf((String) els[0]))); + assertEquals(false, queue.remove(elements[0])); + assertEquals(true, queue.remove(Integer.valueOf((String) elements[0]))); } @SuppressWarnings({ "rawtypes", "unchecked" }) public void testTransformedQueue_decorateTransform() { final Queue originalQueue = new LinkedList(); - final Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"}; - for (final Object el : els) { - originalQueue.add(el); - } + final Object[] elements = new Object[] {"1", "3", "5", "7", "2", "4", "6"}; + Collections.addAll(originalQueue, elements); final Queue queue = TransformedQueue.transformedQueue(originalQueue, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); - assertEquals(els.length, queue.size()); - for (final Object el : els) { + assertEquals(elements.length, queue.size()); + for (final Object el : elements) { assertEquals(true, queue.contains(Integer.valueOf((String) el))); assertEquals(false, queue.contains(el)); } - assertEquals(false, queue.remove(els[0])); - assertEquals(true, queue.remove(Integer.valueOf((String) els[0]))); + assertEquals(false, queue.remove(elements[0])); + assertEquals(true, queue.remove(Integer.valueOf((String) elements[0]))); } @Override diff --git a/src/test/java/org/apache/commons/collections4/sequence/SequencesComparatorTest.java b/src/test/java/org/apache/commons/collections4/sequence/SequencesComparatorTest.java index cb9471750..9e453ae1b 100644 --- a/src/test/java/org/apache/commons/collections4/sequence/SequencesComparatorTest.java +++ b/src/test/java/org/apache/commons/collections4/sequence/SequencesComparatorTest.java @@ -130,13 +130,13 @@ public class SequencesComparatorTest { final ExecutionVisitor ev = new ExecutionVisitor(); for (int i = 0; i < shadokSentences.size(); ++i) { - for (int j = 0; j < shadokSentences.size(); ++j) { + for (List shadokSentence : shadokSentences) { ev.setList(shadokSentences.get(i)); new SequencesComparator(shadokSentences.get(i), - shadokSentences.get(j)).getScript().visit(ev); + shadokSentence).getScript().visit(ev); final StringBuilder concat = new StringBuilder(); - for (final String s : shadokSentences.get(j)) { + for (final String s : shadokSentence) { concat.append(s); } Assert.assertEquals(concat.toString(), ev.getString()); @@ -175,7 +175,7 @@ public class SequencesComparatorTest { } public String getString() { - final StringBuffer buffer = new StringBuffer(); + final StringBuilder buffer = new StringBuilder(); for (final T c : v) { buffer.append(c); } @@ -187,7 +187,7 @@ public class SequencesComparatorTest { @Before public void setUp() { - before = Arrays.asList(new String[] { + before = Arrays.asList( "bottle", "nematode knowledge", "", @@ -196,10 +196,9 @@ public class SequencesComparatorTest { "ABCABBA", "glop glop", "coq", - "spider-man" - }); + "spider-man"); - after = Arrays.asList(new String[] { + after = Arrays.asList( "noodle", "empty bottle", "", @@ -208,8 +207,7 @@ public class SequencesComparatorTest { "CBABAC", "pas glop pas glop", "ane", - "klingon" - }); + "klingon"); length = new int[] { 6, diff --git a/src/test/java/org/apache/commons/collections4/set/AbstractSetTest.java b/src/test/java/org/apache/commons/collections4/set/AbstractSetTest.java index c906d7946..987db7a0f 100644 --- a/src/test/java/org/apache/commons/collections4/set/AbstractSetTest.java +++ b/src/test/java/org/apache/commons/collections4/set/AbstractSetTest.java @@ -64,9 +64,8 @@ public abstract class AbstractSetTest extends AbstractCollectionTest { assertEquals("Sets should have equal hashCodes", getConfirmed().hashCode(), getCollection().hashCode()); final Collection set = makeConfirmedCollection(); - final Iterator iterator = getCollection().iterator(); - while (iterator.hasNext()) { - assertTrue("Set.iterator should only return unique elements", set.add(iterator.next())); + for (E element : getCollection()) { + assertTrue("Set.iterator should only return unique elements", set.add(element)); } } diff --git a/src/test/java/org/apache/commons/collections4/set/TransformedSetTest.java b/src/test/java/org/apache/commons/collections4/set/TransformedSetTest.java index 80e2c8482..2c19b5ed1 100644 --- a/src/test/java/org/apache/commons/collections4/set/TransformedSetTest.java +++ b/src/test/java/org/apache/commons/collections4/set/TransformedSetTest.java @@ -17,6 +17,7 @@ package org.apache.commons.collections4.set; import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -85,9 +86,7 @@ public class TransformedSetTest extends AbstractSetTest { public void testTransformedSet_decorateTransform() { final Set originalSet = new HashSet(); final Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"}; - for (final Object el : els) { - originalSet.add(el); - } + Collections.addAll(originalSet, els); final Set set = TransformedSet.transformedSet(originalSet, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); assertEquals(els.length, set.size()); for (final Object el : els) { diff --git a/src/test/java/org/apache/commons/collections4/set/TransformedSortedSetTest.java b/src/test/java/org/apache/commons/collections4/set/TransformedSortedSetTest.java index 358dc548e..3e3fbe8cb 100644 --- a/src/test/java/org/apache/commons/collections4/set/TransformedSortedSetTest.java +++ b/src/test/java/org/apache/commons/collections4/set/TransformedSortedSetTest.java @@ -17,6 +17,7 @@ package org.apache.commons.collections4.set; import java.util.Arrays; +import java.util.Collections; import java.util.TreeSet; import java.util.Set; import java.util.SortedSet; @@ -78,9 +79,7 @@ public class TransformedSortedSetTest extends AbstractSortedSetTest { public void testTransformedSet_decorateTransform() { final Set originalSet = new TreeSet(); final Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"}; - for (final Object el : els) { - originalSet.add(el); - } + Collections.addAll(originalSet, els); final Set set = TransformedSortedSet.transformedSet(originalSet, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); assertEquals(els.length, set.size()); for (final Object el : els) {