diff --git a/src/main/java/org/apache/commons/collections/CollectionUtils.java b/src/main/java/org/apache/commons/collections/CollectionUtils.java index ec1ea58c4..2ae6e8e43 100644 --- a/src/main/java/org/apache/commons/collections/CollectionUtils.java +++ b/src/main/java/org/apache/commons/collections/CollectionUtils.java @@ -896,8 +896,8 @@ public class CollectionUtils { */ public static boolean addAll(Collection collection, C[] elements) { boolean changed = false; - for (int i = 0, size = elements.length; i < size; i++) { - changed |= collection.add(elements[i]); + for (C element : elements) { + changed |= collection.add(element); } return changed; } diff --git a/src/main/java/org/apache/commons/collections/ComparatorUtils.java b/src/main/java/org/apache/commons/collections/ComparatorUtils.java index e0ddf206a..ee81d0bdb 100644 --- a/src/main/java/org/apache/commons/collections/ComparatorUtils.java +++ b/src/main/java/org/apache/commons/collections/ComparatorUtils.java @@ -92,11 +92,11 @@ public class ComparatorUtils { */ public static > Comparator chainedComparator(Comparator[] comparators) { ComparatorChain chain = new ComparatorChain(); - for (int i = 0; i < comparators.length; i++) { - if (comparators[i] == null) { + for (Comparator comparator : comparators) { + if (comparator == null) { throw new NullPointerException("Comparator cannot be null"); } - chain.addComparator(comparators[i]); + chain.addComparator(comparator); } return chain; } diff --git a/src/main/java/org/apache/commons/collections/ExtendedProperties.java b/src/main/java/org/apache/commons/collections/ExtendedProperties.java index 5b80385ad..e5e1dcc8d 100644 --- a/src/main/java/org/apache/commons/collections/ExtendedProperties.java +++ b/src/main/java/org/apache/commons/collections/ExtendedProperties.java @@ -756,8 +756,7 @@ public class ExtendedProperties extends Hashtable { } else if (value instanceof List) { @SuppressWarnings("unchecked") // we only add Strings to the Lists List values = (List) value; - for (Iterator it = values.iterator(); it.hasNext(); ) { - String currentElement = it.next(); + for (String currentElement : values) { StringBuilder currentOutput = new StringBuilder(); currentOutput.append(key); currentOutput.append("="); @@ -976,8 +975,7 @@ public class ExtendedProperties extends Hashtable { // Each token is of the form 'key=value'. Properties props = new Properties(defaults); - for (int i = 0; i < tokens.length; i++) { - String token = tokens[i]; + for (String token : tokens) { int equalSign = token.indexOf('='); if (equalSign > 0) { String pkey = token.substring(0, equalSign).trim(); @@ -1738,8 +1736,7 @@ public class ExtendedProperties extends Hashtable { } else { @SuppressWarnings("unchecked") // OK to downcast here Map mapso = (Map) map; - for (Iterator> it = mapso.entrySet().iterator(); it.hasNext(); ) { - Map.Entry entry = it.next(); + for (java.util.Map.Entry entry : mapso.entrySet()) { put(entry.getKey(), entry.getValue()); } } diff --git a/src/main/java/org/apache/commons/collections/MapUtils.java b/src/main/java/org/apache/commons/collections/MapUtils.java index 0edcd5935..e7597c7b7 100644 --- a/src/main/java/org/apache/commons/collections/MapUtils.java +++ b/src/main/java/org/apache/commons/collections/MapUtils.java @@ -25,6 +25,7 @@ import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import java.util.Map.Entry; import java.util.Properties; import java.util.ResourceBundle; import java.util.SortedMap; @@ -843,8 +844,8 @@ public class MapUtils { public static Properties toProperties(final Map map) { Properties answer = new Properties(); if (map != null) { - for (Iterator> iter = map.entrySet().iterator(); iter.hasNext();) { - Map.Entry entry = iter.next(); + for (Entry entry2 : map.entrySet()) { + Map.Entry entry = entry2; Object key = entry.getKey(); Object value = entry.getValue(); answer.put(key, value); @@ -1049,8 +1050,7 @@ public class MapUtils { */ public static Map invertMap(Map map) { Map out = new HashMap(map.size()); - for (Iterator> it = map.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = it.next(); + for (Entry entry : map.entrySet()) { out.put(entry.getValue(), entry.getKey()); } return out; @@ -1136,13 +1136,13 @@ public class MapUtils { } Object obj = array[0]; if (obj instanceof Map.Entry) { - for (int i = 0; i < array.length; i++) { - Map.Entry entry = (Map.Entry) array[i]; + for (Object element : array) { + Map.Entry entry = (Map.Entry) element; map.put(entry.getKey(), entry.getValue()); } } else if (obj instanceof KeyValue) { - for (int i = 0; i < array.length; i++) { - KeyValue keyval = (KeyValue) array[i]; + for (Object element : array) { + KeyValue keyval = (KeyValue) element; map.put(keyval.getKey(), keyval.getValue()); } } else if (obj instanceof Object[]) { diff --git a/src/main/java/org/apache/commons/collections/bag/AbstractMapBag.java b/src/main/java/org/apache/commons/collections/bag/AbstractMapBag.java index 05e5c7500..2b2ab2108 100644 --- a/src/main/java/org/apache/commons/collections/bag/AbstractMapBag.java +++ b/src/main/java/org/apache/commons/collections/bag/AbstractMapBag.java @@ -24,6 +24,7 @@ import java.util.Collection; import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import org.apache.commons.collections.Bag; @@ -492,8 +493,7 @@ public abstract class AbstractMapBag implements Bag { */ protected void doWriteObject(ObjectOutputStream out) throws IOException { out.writeInt(map.size()); - for (Iterator> it = map.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = it.next(); + for (Entry entry : map.entrySet()) { out.writeObject(entry.getKey()); out.writeInt(entry.getValue().value); } @@ -540,8 +540,7 @@ public abstract class AbstractMapBag implements Bag { if (other.size() != size()) { return false; } - for (Iterator it = map.keySet().iterator(); it.hasNext();) { - E element = it.next(); + for (E element : map.keySet()) { if (other.getCount(element) != getCount(element)) { return false; } @@ -561,8 +560,7 @@ public abstract class AbstractMapBag implements Bag { @Override public int hashCode() { int total = 0; - for (Iterator> it = map.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = it.next(); + for (Entry entry : map.entrySet()) { E element = entry.getKey(); MutableInteger count = entry.getValue(); total += (element == null ? 0 : element.hashCode()) ^ count.value; diff --git a/src/main/java/org/apache/commons/collections/bag/TransformedBag.java b/src/main/java/org/apache/commons/collections/bag/TransformedBag.java index e5416f767..f48d84934 100644 --- a/src/main/java/org/apache/commons/collections/bag/TransformedBag.java +++ b/src/main/java/org/apache/commons/collections/bag/TransformedBag.java @@ -78,8 +78,8 @@ public class TransformedBag extends TransformedCollection implements Bag extends TransformedBag implements Sorted @SuppressWarnings("unchecked") // bag is type E E[] values = (E[]) bag.toArray(); bag.clear(); - for(int i=0; i extends AbstractCollection private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); out.writeInt(size()); - for (Iterator it = iterator(); it.hasNext();) { - out.writeObject(it.next()); + for (E e : this) { + out.writeObject(e); } } diff --git a/src/main/java/org/apache/commons/collections/buffer/TransformedBuffer.java b/src/main/java/org/apache/commons/collections/buffer/TransformedBuffer.java index b8feeeb5f..04c25a0a1 100644 --- a/src/main/java/org/apache/commons/collections/buffer/TransformedBuffer.java +++ b/src/main/java/org/apache/commons/collections/buffer/TransformedBuffer.java @@ -79,8 +79,8 @@ public class TransformedBuffer extends TransformedCollection implements Bu @SuppressWarnings("unchecked") // buffer is type E[] values = (E[]) buffer.toArray(); buffer.clear(); - for(int i=0; i extends AbstractCollection implements Buf out.defaultWriteObject(); out.writeInt(size()); out.writeInt(buffer.length); - for (Iterator it = iterator(); it.hasNext();) { - out.writeObject(it.next()); + for (E e : this) { + out.writeObject(e); } } diff --git a/src/main/java/org/apache/commons/collections/collection/TransformedCollection.java b/src/main/java/org/apache/commons/collections/collection/TransformedCollection.java index 7b371ba4c..31b9907f7 100644 --- a/src/main/java/org/apache/commons/collections/collection/TransformedCollection.java +++ b/src/main/java/org/apache/commons/collections/collection/TransformedCollection.java @@ -85,8 +85,8 @@ public class TransformedCollection extends AbstractCollectionDecorator { @SuppressWarnings("unchecked") // collection is of type E E[] values = (E[]) collection.toArray(); collection.clear(); - for(int i=0; i implements Comparator, Serializable { if (items == null) { throw new IllegalArgumentException("The list of items must not be null"); } - for (int i = 0; i < items.length; i++) { - add(items[i]); + for (T item : items) { + add(item); } } diff --git a/src/main/java/org/apache/commons/collections/functors/AnyPredicate.java b/src/main/java/org/apache/commons/collections/functors/AnyPredicate.java index c0ce7477c..80c94ce6d 100644 --- a/src/main/java/org/apache/commons/collections/functors/AnyPredicate.java +++ b/src/main/java/org/apache/commons/collections/functors/AnyPredicate.java @@ -106,8 +106,8 @@ public final class AnyPredicate implements Predicate, PredicateDecorator iPredicate : iPredicates) { + if (iPredicate.evaluate(object)) { return true; } } diff --git a/src/main/java/org/apache/commons/collections/functors/ChainedClosure.java b/src/main/java/org/apache/commons/collections/functors/ChainedClosure.java index 4f68fdac7..810b55d79 100644 --- a/src/main/java/org/apache/commons/collections/functors/ChainedClosure.java +++ b/src/main/java/org/apache/commons/collections/functors/ChainedClosure.java @@ -98,8 +98,8 @@ public class ChainedClosure implements Closure, Serializable { * @param input the input object passed to each closure */ public void execute(E input) { - for (int i = 0; i < iClosures.length; i++) { - iClosures[i].execute(input); + for (Closure iClosure : iClosures) { + iClosure.execute(input); } } diff --git a/src/main/java/org/apache/commons/collections/functors/ChainedTransformer.java b/src/main/java/org/apache/commons/collections/functors/ChainedTransformer.java index a885e467f..420eb12f6 100644 --- a/src/main/java/org/apache/commons/collections/functors/ChainedTransformer.java +++ b/src/main/java/org/apache/commons/collections/functors/ChainedTransformer.java @@ -96,8 +96,8 @@ public class ChainedTransformer implements Transformer, Serializable { * @return the transformed result */ public T transform(T object) { - for (int i = 0; i < iTransformers.length; i++) { - object = iTransformers[i].transform(object); + for (Transformer iTransformer : iTransformers) { + object = iTransformer.transform(object); } return object; } diff --git a/src/main/java/org/apache/commons/collections/functors/NonePredicate.java b/src/main/java/org/apache/commons/collections/functors/NonePredicate.java index 1f42a5056..46659c669 100644 --- a/src/main/java/org/apache/commons/collections/functors/NonePredicate.java +++ b/src/main/java/org/apache/commons/collections/functors/NonePredicate.java @@ -96,8 +96,8 @@ public final class NonePredicate implements Predicate, PredicateDecorator< * @return true if none of decorated predicates return true */ public boolean evaluate(T object) { - for (int i = 0; i < iPredicates.length; i++) { - if (iPredicates[i].evaluate(object)) { + for (Predicate iPredicate : iPredicates) { + if (iPredicate.evaluate(object)) { return false; } } diff --git a/src/main/java/org/apache/commons/collections/functors/OnePredicate.java b/src/main/java/org/apache/commons/collections/functors/OnePredicate.java index 0b0adc5dd..6690e16da 100644 --- a/src/main/java/org/apache/commons/collections/functors/OnePredicate.java +++ b/src/main/java/org/apache/commons/collections/functors/OnePredicate.java @@ -98,8 +98,8 @@ public final class OnePredicate implements Predicate, PredicateDecorator iPredicate : iPredicates) { + if (iPredicate.evaluate(object)) { if (match) { return false; } diff --git a/src/main/java/org/apache/commons/collections/iterators/CollatingIterator.java b/src/main/java/org/apache/commons/collections/iterators/CollatingIterator.java index 7cc6c569c..91e0f6982 100644 --- a/src/main/java/org/apache/commons/collections/iterators/CollatingIterator.java +++ b/src/main/java/org/apache/commons/collections/iterators/CollatingIterator.java @@ -133,8 +133,8 @@ public class CollatingIterator implements Iterator { */ public CollatingIterator(final Comparator comp, final Iterator[] iterators) { this(comp, iterators.length); - for (int i = 0; i < iterators.length; i++) { - addIterator(iterators[i]); + for (Iterator iterator : iterators) { + addIterator(iterator); } } diff --git a/src/main/java/org/apache/commons/collections/iterators/IteratorChain.java b/src/main/java/org/apache/commons/collections/iterators/IteratorChain.java index c22b9a6a7..3169c476e 100644 --- a/src/main/java/org/apache/commons/collections/iterators/IteratorChain.java +++ b/src/main/java/org/apache/commons/collections/iterators/IteratorChain.java @@ -125,8 +125,8 @@ public class IteratorChain implements Iterator { */ public IteratorChain(Iterator... iteratorChain) { super(); - for (int i = 0; i < iteratorChain.length; i++) { - addIterator(iteratorChain[i]); + for (Iterator element : iteratorChain) { + addIterator(element); } } diff --git a/src/main/java/org/apache/commons/collections/keyvalue/MultiKey.java b/src/main/java/org/apache/commons/collections/keyvalue/MultiKey.java index b80a78aca..724405351 100644 --- a/src/main/java/org/apache/commons/collections/keyvalue/MultiKey.java +++ b/src/main/java/org/apache/commons/collections/keyvalue/MultiKey.java @@ -260,9 +260,9 @@ public class MultiKey implements Serializable { private void calculateHashCode(Object[] keys) { int total = 0; - for (int i = 0; i < keys.length; i++) { - if (keys[i] != null) { - total ^= keys[i].hashCode(); + for (Object key : keys) { + if (key != null) { + total ^= key.hashCode(); } } hashCode = total; diff --git a/src/main/java/org/apache/commons/collections/list/AbstractLinkedList.java b/src/main/java/org/apache/commons/collections/list/AbstractLinkedList.java index 9c3f1c084..4dec69186 100644 --- a/src/main/java/org/apache/commons/collections/list/AbstractLinkedList.java +++ b/src/main/java/org/apache/commons/collections/list/AbstractLinkedList.java @@ -598,8 +598,8 @@ public abstract class AbstractLinkedList implements List { protected void doWriteObject(ObjectOutputStream outputStream) throws IOException { // Write the size so we know how many nodes to read back outputStream.writeInt(size()); - for (Iterator itr = iterator(); itr.hasNext();) { - outputStream.writeObject(itr.next()); + for (E e : this) { + outputStream.writeObject(e); } } diff --git a/src/main/java/org/apache/commons/collections/list/SetUniqueList.java b/src/main/java/org/apache/commons/collections/list/SetUniqueList.java index db4319f0e..9cb924d7d 100644 --- a/src/main/java/org/apache/commons/collections/list/SetUniqueList.java +++ b/src/main/java/org/apache/commons/collections/list/SetUniqueList.java @@ -259,8 +259,8 @@ public class SetUniqueList extends AbstractSerializableListDecorator { @Override public boolean removeAll(Collection coll) { boolean result = false; - for (Iterator it = coll.iterator(); it.hasNext();) { - result |= remove(it.next()); + for (Object name : coll) { + result |= remove(name); } return result; } @@ -268,8 +268,7 @@ public class SetUniqueList extends AbstractSerializableListDecorator { @Override public boolean retainAll(Collection coll) { Set setRetainAll = new HashSet(); - for (Iterator it = coll.iterator(); it.hasNext();) { - Object next = it.next(); + for (Object next : coll) { if (set.contains(next)) { setRetainAll.add(next); } diff --git a/src/main/java/org/apache/commons/collections/list/TransformedList.java b/src/main/java/org/apache/commons/collections/list/TransformedList.java index fdbefd9bb..1f195d4b0 100644 --- a/src/main/java/org/apache/commons/collections/list/TransformedList.java +++ b/src/main/java/org/apache/commons/collections/list/TransformedList.java @@ -82,8 +82,8 @@ public class TransformedList extends TransformedCollection implements List @SuppressWarnings("unchecked") // list is of type E E[] values = (E[]) list.toArray(); list.clear(); - for(int i=0; i extends AbstractMap implements Iterab @Override public boolean containsValue(Object value) { if (value == null) { - for (int i = 0, isize = data.length; i < isize; i++) { - HashEntry entry = data[i]; + for (HashEntry element : data) { + HashEntry entry = element; while (entry != null) { if (entry.getValue() == null) { return true; @@ -249,8 +249,8 @@ public class AbstractHashedMap extends AbstractMap implements Iterab } } } else { - for (int i = 0, isize = data.length; i < isize; i++) { - HashEntry entry = data[i]; + for (HashEntry element : data) { + HashEntry entry = element; while (entry != null) { if (isEqualValue(value, entry.getValue())) { return true; diff --git a/src/main/java/org/apache/commons/collections/map/MultiValueMap.java b/src/main/java/org/apache/commons/collections/map/MultiValueMap.java index ffb7166ae..e707c89e7 100644 --- a/src/main/java/org/apache/commons/collections/map/MultiValueMap.java +++ b/src/main/java/org/apache/commons/collections/map/MultiValueMap.java @@ -419,8 +419,8 @@ public class MultiValueMap extends AbstractMapDecorator impleme @Override public Iterator iterator() { final IteratorChain chain = new IteratorChain(); - for (Iterator it = keySet().iterator(); it.hasNext();) { - chain.addIterator(new ValuesIterator(it.next())); + for (K k : keySet()) { + chain.addIterator(new ValuesIterator(k)); } return chain; } diff --git a/src/main/java/org/apache/commons/collections/set/ListOrderedSet.java b/src/main/java/org/apache/commons/collections/set/ListOrderedSet.java index 48cab8efa..998f6c1b0 100644 --- a/src/main/java/org/apache/commons/collections/set/ListOrderedSet.java +++ b/src/main/java/org/apache/commons/collections/set/ListOrderedSet.java @@ -218,8 +218,8 @@ public class ListOrderedSet @Override public boolean removeAll(Collection coll) { boolean result = false; - for (Iterator it = coll.iterator(); it.hasNext();) { - result |= remove(it.next()); + for (Object name : coll) { + result |= remove(name); } return result; } @@ -227,8 +227,7 @@ public class ListOrderedSet @Override public boolean retainAll(Collection coll) { Set collectionRetainAll = new HashSet(); - for (Iterator it = coll.iterator(); it.hasNext();) { - Object next = it.next(); + for (Object next : coll) { if (collection.contains(next)) { collectionRetainAll.add(next); } diff --git a/src/main/java/org/apache/commons/collections/set/TransformedSet.java b/src/main/java/org/apache/commons/collections/set/TransformedSet.java index 0dcf3a469..c1550d819 100644 --- a/src/main/java/org/apache/commons/collections/set/TransformedSet.java +++ b/src/main/java/org/apache/commons/collections/set/TransformedSet.java @@ -77,8 +77,8 @@ public class TransformedSet extends TransformedCollection implements Set extends TransformedSet implements Sorted @SuppressWarnings("unchecked") // set is type E E[] values = (E[]) set.toArray(); set.clear(); - for(int i=0; i c = bulk.getClass(); Method[] all = c.getMethods(); - for (int i = 0; i < all.length; i++) { - if (isTest(all[i])) addTest(bulk, all[i]); - if (isBulk(all[i])) addBulk(bulk, all[i]); + for (Method element : all) { + if (isTest(element)) addTest(bulk, element); + if (isBulk(element)) addBulk(bulk, element); } } @@ -431,8 +431,8 @@ class BulkTestSuiteMaker { private static BulkTest makeFirstTestCase(Class c) { Method[] all = c.getMethods(); - for (int i = 0; i < all.length; i++) { - if (isTest(all[i])) return makeTestCase(c, all[i]); + for (Method element : all) { + if (isTest(element)) return makeTestCase(c, element); } throw new IllegalArgumentException(c.getName() + " must provide " + " at least one test method."); diff --git a/src/test/java/org/apache/commons/collections/bag/AbstractBagTest.java b/src/test/java/org/apache/commons/collections/bag/AbstractBagTest.java index d52d127ca..fe9c38590 100644 --- a/src/test/java/org/apache/commons/collections/bag/AbstractBagTest.java +++ b/src/test/java/org/apache/commons/collections/bag/AbstractBagTest.java @@ -353,10 +353,10 @@ public abstract class AbstractBagTest extends AbstractObjectTest { bag.add((T) "C"); Object[] array = bag.toArray(); int a = 0, b = 0, c = 0; - for (int i = 0; i < array.length; i++) { - a += (array[i].equals("A") ? 1 : 0); - b += (array[i].equals("B") ? 1 : 0); - c += (array[i].equals("C") ? 1 : 0); + for (Object element : array) { + a += (element.equals("A") ? 1 : 0); + b += (element.equals("B") ? 1 : 0); + c += (element.equals("C") ? 1 : 0); } assertEquals(2, a); assertEquals(2, b); @@ -373,10 +373,10 @@ public abstract class AbstractBagTest extends AbstractObjectTest { bag.add((T) "C"); String[] array = bag.toArray(new String[0]); int a = 0, b = 0, c = 0; - for (int i = 0; i < array.length; i++) { - a += (array[i].equals("A") ? 1 : 0); - b += (array[i].equals("B") ? 1 : 0); - c += (array[i].equals("C") ? 1 : 0); + for (String element : array) { + a += (element.equals("A") ? 1 : 0); + b += (element.equals("B") ? 1 : 0); + c += (element.equals("C") ? 1 : 0); } assertEquals(2, a); assertEquals(2, b); diff --git a/src/test/java/org/apache/commons/collections/bag/TransformedBagTest.java b/src/test/java/org/apache/commons/collections/bag/TransformedBagTest.java index 6be82a8f3..caabbf39f 100644 --- a/src/test/java/org/apache/commons/collections/bag/TransformedBagTest.java +++ b/src/test/java/org/apache/commons/collections/bag/TransformedBagTest.java @@ -62,15 +62,15 @@ public class TransformedBagTest extends AbstractBagTest { public void testTransformedBag_decorateTransform() { Bag originalBag = new HashBag(); Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"}; - for (int i = 0; i < els.length; i++) { - originalBag.add((T) els[i]); + for (Object el : els) { + originalBag.add((T) el); } Bag bag = TransformedBag.transformedBag(originalBag, (Transformer) TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); assertEquals(els.length, bag.size()); - for (int i = 0; i < els.length; i++) { - assertEquals(true, bag.contains(new Integer((String) els[i]))); - assertEquals(false, bag.contains(els[i])); + for (Object el : els) { + assertEquals(true, bag.contains(new Integer((String) el))); + assertEquals(false, bag.contains(el)); } assertEquals(false, bag.remove(els[0])); diff --git a/src/test/java/org/apache/commons/collections/bag/TransformedSortedBagTest.java b/src/test/java/org/apache/commons/collections/bag/TransformedSortedBagTest.java index 8be29e702..e51ee29df 100644 --- a/src/test/java/org/apache/commons/collections/bag/TransformedSortedBagTest.java +++ b/src/test/java/org/apache/commons/collections/bag/TransformedSortedBagTest.java @@ -58,13 +58,13 @@ public class TransformedSortedBagTest extends AbstractSortedBagTest { public void testTransformedBag_decorateTransform() { Bag originalBag = new TreeBag(); Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"}; - for (int i = 0; i < els.length; i++) { - originalBag.add(els[i]); + for (Object el : els) { + originalBag.add(el); } Bag bag = TransformedBag.transformedBag(originalBag, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); assertEquals(els.length, bag.size()); - for (int i = 0; i < els.length; i++) { - assertEquals(true, bag.contains(new Integer((String) els[i]))); + for (Object el : els) { + assertEquals(true, bag.contains(new Integer((String) el))); } assertEquals(true, bag.remove(new Integer((String) els[0]))); diff --git a/src/test/java/org/apache/commons/collections/buffer/TransformedBufferTest.java b/src/test/java/org/apache/commons/collections/buffer/TransformedBufferTest.java index a4f8e8896..35616fa03 100644 --- a/src/test/java/org/apache/commons/collections/buffer/TransformedBufferTest.java +++ b/src/test/java/org/apache/commons/collections/buffer/TransformedBufferTest.java @@ -53,14 +53,14 @@ public class TransformedBufferTest extends TestCase { public void testTransformedBuffer_decorateTransform() { Buffer originalBuffer = new ArrayStack(); Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"}; - for (int i = 0; i < els.length; i++) { - originalBuffer.add(els[i]); + for (Object el : els) { + originalBuffer.add(el); } Buffer buffer = TransformedBuffer.transformedBuffer(originalBuffer, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); assertEquals(els.length, buffer.size()); - for (int i = 0; i < els.length; i++) { - assertEquals(true, buffer.contains(new Integer((String) els[i]))); - assertEquals(false, buffer.contains(els[i])); + for (Object el : els) { + assertEquals(true, buffer.contains(new Integer((String) el))); + assertEquals(false, buffer.contains(el)); } assertEquals(false, buffer.remove(els[0])); diff --git a/src/test/java/org/apache/commons/collections/collection/AbstractCollectionTest.java b/src/test/java/org/apache/commons/collections/collection/AbstractCollectionTest.java index a670cb740..77d797313 100644 --- a/src/test/java/org/apache/commons/collections/collection/AbstractCollectionTest.java +++ b/src/test/java/org/apache/commons/collections/collection/AbstractCollectionTest.java @@ -500,10 +500,10 @@ public abstract class AbstractCollectionTest extends AbstractObjectTest { if (!isAddSupported()) return; E[] elements = getFullElements(); - for (int i = 0; i < elements.length; i++) { + for (E element : elements) { resetEmpty(); - boolean r = getCollection().add(elements[i]); - getConfirmed().add(elements[i]); + boolean r = getCollection().add(element); + getConfirmed().add(element); verify(); assertTrue("Empty collection changed after add", r); assertEquals("Collection size is 1 after first add", 1, getCollection().size()); @@ -511,13 +511,13 @@ public abstract class AbstractCollectionTest extends AbstractObjectTest { resetEmpty(); int size = 0; - for (int i = 0; i < elements.length; i++) { - boolean r = getCollection().add(elements[i]); - getConfirmed().add(elements[i]); + for (E element : elements) { + boolean r = getCollection().add(element); + getConfirmed().add(element); verify(); if (r) size++; assertEquals("Collection size should grow after add", size, getCollection().size()); - assertTrue("Collection should contain added element", getCollection().contains(elements[i])); + assertTrue("Collection should contain added element", getCollection().contains(element)); } } @@ -533,8 +533,8 @@ public abstract class AbstractCollectionTest extends AbstractObjectTest { getConfirmed().addAll(Arrays.asList(elements)); verify(); assertTrue("Empty collection should change after addAll", r); - for (int i = 0; i < elements.length; i++) { - assertTrue("Collection should contain added element", getCollection().contains(elements[i])); + for (E element : elements) { + assertTrue("Collection should contain added element", getCollection().contains(element)); } resetFull(); @@ -544,9 +544,9 @@ public abstract class AbstractCollectionTest extends AbstractObjectTest { getConfirmed().addAll(Arrays.asList(elements)); verify(); assertTrue("Full collection should change after addAll", r); - for (int i = 0; i < elements.length; i++) { + for (E element : elements) { assertTrue("Full collection should contain added element", - getCollection().contains(elements[i])); + getCollection().contains(element)); } assertEquals("Size should increase after addAll", size + elements.length, getCollection().size()); @@ -862,10 +862,10 @@ public abstract class AbstractCollectionTest extends AbstractObjectTest { } int size = getCollection().size(); - for (int i = 0; i < elements.length; i++) { + for (E element : elements) { resetFull(); - assertTrue("Collection should remove extant element: " + elements[i], - getCollection().remove(elements[i])); + assertTrue("Collection should remove extant element: " + element, + getCollection().remove(element)); // if the elements aren't distinguishable, we can just remove a // matching element from the confirmed collection and verify @@ -876,7 +876,7 @@ public abstract class AbstractCollectionTest extends AbstractObjectTest { // // see areEqualElementsDistinguishable() if (!areEqualElementsDistinguishable()) { - getConfirmed().remove(elements[i]); + getConfirmed().remove(element); verify(); } @@ -1043,9 +1043,9 @@ public abstract class AbstractCollectionTest extends AbstractObjectTest { + "in the confirmed collection's array"); } } - for (int i = 0; i < matched.length; i++) { + for (boolean element : matched) { assertEquals("Collection should return all its elements in " + "toArray", true, - matched[i]); + element); } } @@ -1085,8 +1085,8 @@ public abstract class AbstractCollectionTest extends AbstractObjectTest { // Figure out if they're all the same class // TODO: It'd be nicer to detect a common superclass HashSet> classes = new HashSet>(); - for (int i = 0; i < array.length; i++) { - classes.add((array[i] == null) ? null : array[i].getClass()); + for (Object element : array) { + classes.add((element == null) ? null : element.getClass()); } if (classes.size() > 1) return; diff --git a/src/test/java/org/apache/commons/collections/collection/CompositeCollectionTest.java b/src/test/java/org/apache/commons/collections/collection/CompositeCollectionTest.java index bc08f0a92..eb6a92a3f 100644 --- a/src/test/java/org/apache/commons/collections/collection/CompositeCollectionTest.java +++ b/src/test/java/org/apache/commons/collections/collection/CompositeCollectionTest.java @@ -76,9 +76,9 @@ public class CompositeCollectionTest extends AbstractCollectionTest { public Collection makeFullCollection() { CompositeCollection compositeCollection = new CompositeCollection(); E[] elements = getFullElements(); - for (int i = 0; i < elements.length; i++) { + for (E element : elements) { Collection summand = new HashSet(); - summand.add(elements[i]); + summand.add(element); compositeCollection.addComposited(summand); } return compositeCollection; diff --git a/src/test/java/org/apache/commons/collections/collection/TransformedCollectionTest.java b/src/test/java/org/apache/commons/collections/collection/TransformedCollectionTest.java index a1b0d5591..9d34f5156 100644 --- a/src/test/java/org/apache/commons/collections/collection/TransformedCollectionTest.java +++ b/src/test/java/org/apache/commons/collections/collection/TransformedCollectionTest.java @@ -100,14 +100,14 @@ public class TransformedCollectionTest extends AbstractCollectionTest { public void testTransformedCollection_decorateTransform() { Collection originalCollection = new ArrayList(); Object[] els = getFullElements(); - for (int i = 0; i < els.length; i++) { - originalCollection.add(els[i]); + for (Object el : els) { + originalCollection.add(el); } Collection collection = TransformedCollection.transformedCollection(originalCollection, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); assertEquals(els.length, collection.size()); - for (int i = 0; i < els.length; i++) { - assertEquals(true, collection.contains(new Integer((String) els[i]))); - assertEquals(false, collection.contains(els[i])); + for (Object el : els) { + assertEquals(true, collection.contains(new Integer((String) el))); + assertEquals(false, collection.contains(el)); } assertEquals(false, collection.remove(els[0])); diff --git a/src/test/java/org/apache/commons/collections/comparators/FixedOrderComparatorTest.java b/src/test/java/org/apache/commons/collections/comparators/FixedOrderComparatorTest.java index 30f587dac..12b26b3ff 100644 --- a/src/test/java/org/apache/commons/collections/comparators/FixedOrderComparatorTest.java +++ b/src/test/java/org/apache/commons/collections/comparators/FixedOrderComparatorTest.java @@ -85,8 +85,8 @@ public class FixedOrderComparatorTest extends AbstractComparatorTest { @Test public void testConstructorPlusAdd() { FixedOrderComparator comparator = new FixedOrderComparator(); - for (int i = 0; i < topCities.length; i++) { - comparator.add(topCities[i]); + for (String topCitie : topCities) { + comparator.add(topCitie); } String[] keys = topCities.clone(); assertComparatorYieldsOrder(keys, comparator); diff --git a/src/test/java/org/apache/commons/collections/comparators/sequence/SequencesComparatorTest.java b/src/test/java/org/apache/commons/collections/comparators/sequence/SequencesComparatorTest.java index 972b8a131..9e8422f4f 100644 --- a/src/test/java/org/apache/commons/collections/comparators/sequence/SequencesComparatorTest.java +++ b/src/test/java/org/apache/commons/collections/comparators/sequence/SequencesComparatorTest.java @@ -117,10 +117,10 @@ public class SequencesComparatorTest { for (int lg=0; lg> newTab = new ArrayList>(); newTab.add(new ArrayList()); - for (int k = 0; k < shadokAlph.length; k++) { + for (String element : shadokAlph) { for (List sentence : shadokSentences) { List newSentence = new ArrayList(sentence); - newSentence.add(shadokAlph[k]); + newSentence.add(element); newTab.add(newSentence); } } diff --git a/src/test/java/org/apache/commons/collections/iterators/ArrayIterator2Test.java b/src/test/java/org/apache/commons/collections/iterators/ArrayIterator2Test.java index 1c7744100..e6bc29623 100644 --- a/src/test/java/org/apache/commons/collections/iterators/ArrayIterator2Test.java +++ b/src/test/java/org/apache/commons/collections/iterators/ArrayIterator2Test.java @@ -61,8 +61,8 @@ public class ArrayIterator2Test extends AbstractIteratorTest { public void testIterator() { Iterator iter = makeObject(); - for (int i = 0; i < testArray.length; i++) { - Integer testValue = new Integer(testArray[i]); + for (int element : testArray) { + Integer testValue = new Integer(element); Number iterValue = (Number) iter.next(); assertEquals("Iteration value is correct", testValue, iterValue); diff --git a/src/test/java/org/apache/commons/collections/iterators/ArrayIteratorTest.java b/src/test/java/org/apache/commons/collections/iterators/ArrayIteratorTest.java index 01f84efdb..e05acb1c3 100644 --- a/src/test/java/org/apache/commons/collections/iterators/ArrayIteratorTest.java +++ b/src/test/java/org/apache/commons/collections/iterators/ArrayIteratorTest.java @@ -51,8 +51,7 @@ public class ArrayIteratorTest extends AbstractIteratorTest { public void testIterator() { Iterator iter = makeObject(); - for (int i = 0; i < testArray.length; i++) { - Object testValue = testArray[i]; + for (String testValue : testArray) { E iterValue = iter.next(); assertEquals("Iteration value is correct", testValue, iterValue); diff --git a/src/test/java/org/apache/commons/collections/iterators/FilterIteratorTest.java b/src/test/java/org/apache/commons/collections/iterators/FilterIteratorTest.java index 09dd44dbb..2f5c66c1b 100644 --- a/src/test/java/org/apache/commons/collections/iterators/FilterIteratorTest.java +++ b/src/test/java/org/apache/commons/collections/iterators/FilterIteratorTest.java @@ -92,7 +92,7 @@ public class FilterIteratorTest extends AbstractIteratorTest { } public void testRepeatedNext() { - for (int i = 0; i < array.length; i++) { + for (String element : array) { iterator.next(); } verifyNoMoreElements(); @@ -159,8 +159,8 @@ public class FilterIteratorTest extends AbstractIteratorTest { private void verifyElementsInPredicate(final String[] elements) { Predicate pred = new Predicate() { public boolean evaluate(E x) { - for (int i = 0; i < elements.length; i++) { - if (elements[i].equals(x)) { + for (String element : elements) { + if (element.equals(x)) { return true; } } diff --git a/src/test/java/org/apache/commons/collections/iterators/IteratorChainTest.java b/src/test/java/org/apache/commons/collections/iterators/IteratorChainTest.java index 1790fc9b3..7e2eef3ef 100644 --- a/src/test/java/org/apache/commons/collections/iterators/IteratorChainTest.java +++ b/src/test/java/org/apache/commons/collections/iterators/IteratorChainTest.java @@ -74,8 +74,7 @@ public class IteratorChainTest extends AbstractIteratorTest { public void testIterator() { Iterator iter = makeObject(); - for (int i = 0; i < testArray.length; i++) { - Object testValue = testArray[i]; + for (String testValue : testArray) { Object iterValue = iter.next(); assertEquals( "Iteration value is correct", testValue, iterValue ); @@ -130,8 +129,7 @@ public class IteratorChainTest extends AbstractIteratorTest { } - for (int i = 0; i < testArray.length; i++) { - String testValue = testArray[i]; + for (String testValue : testArray) { String iterValue = iter.next(); assertEquals("Iteration value is correct", testValue, iterValue); diff --git a/src/test/java/org/apache/commons/collections/iterators/ListIteratorWrapper2Test.java b/src/test/java/org/apache/commons/collections/iterators/ListIteratorWrapper2Test.java index 2d8a4fa33..fcc391458 100644 --- a/src/test/java/org/apache/commons/collections/iterators/ListIteratorWrapper2Test.java +++ b/src/test/java/org/apache/commons/collections/iterators/ListIteratorWrapper2Test.java @@ -65,8 +65,7 @@ public class ListIteratorWrapper2Test extends AbstractIteratorTest { public void testIterator() { ListIterator iter = makeObject(); - for (int i = 0; i < testArray.length; i++) { - Object testValue = testArray[i]; + for (String testValue : testArray) { Object iterValue = iter.next(); assertEquals("Iteration value is correct", testValue, iterValue); @@ -97,8 +96,7 @@ public class ListIteratorWrapper2Test extends AbstractIteratorTest { } // now, read it forwards again - for (int i = 0; i < testArray.length; i++) { - Object testValue = testArray[i]; + for (String testValue : testArray) { Object iterValue = iter.next(); assertEquals("Iteration value is correct", testValue, iterValue); diff --git a/src/test/java/org/apache/commons/collections/iterators/ListIteratorWrapperTest.java b/src/test/java/org/apache/commons/collections/iterators/ListIteratorWrapperTest.java index d0713cbdc..75ce5296f 100644 --- a/src/test/java/org/apache/commons/collections/iterators/ListIteratorWrapperTest.java +++ b/src/test/java/org/apache/commons/collections/iterators/ListIteratorWrapperTest.java @@ -66,8 +66,7 @@ public class ListIteratorWrapperTest extends AbstractIteratorTest { public void testIterator() { ListIterator iter = makeObject(); - for (int i = 0; i < testArray.length; i++) { - Object testValue = testArray[i]; + for (String testValue : testArray) { Object iterValue = iter.next(); assertEquals("Iteration value is correct", testValue, iterValue); @@ -98,8 +97,7 @@ public class ListIteratorWrapperTest extends AbstractIteratorTest { } // now, read it forwards again - for (int i = 0; i < testArray.length; i++) { - Object testValue = testArray[i]; + for (String testValue : testArray) { Object iterValue = iter.next(); assertEquals("Iteration value is correct", testValue, iterValue); diff --git a/src/test/java/org/apache/commons/collections/iterators/ObjectArrayIteratorTest.java b/src/test/java/org/apache/commons/collections/iterators/ObjectArrayIteratorTest.java index fd733be1c..caf7e806c 100644 --- a/src/test/java/org/apache/commons/collections/iterators/ObjectArrayIteratorTest.java +++ b/src/test/java/org/apache/commons/collections/iterators/ObjectArrayIteratorTest.java @@ -67,8 +67,7 @@ public class ObjectArrayIteratorTest extends AbstractIteratorTest { public void testIterator() { Iterator iter = makeObject(); - for (int i = 0; i < testArray.length; i++) { - Object testValue = testArray[i]; + for (String testValue : testArray) { E iterValue = iter.next(); assertEquals("Iteration value is correct", testValue, iterValue); diff --git a/src/test/java/org/apache/commons/collections/iterators/UniqueFilterIteratorTest.java b/src/test/java/org/apache/commons/collections/iterators/UniqueFilterIteratorTest.java index 0eb7a4298..fccbb6f7f 100644 --- a/src/test/java/org/apache/commons/collections/iterators/UniqueFilterIteratorTest.java +++ b/src/test/java/org/apache/commons/collections/iterators/UniqueFilterIteratorTest.java @@ -68,8 +68,7 @@ public class UniqueFilterIteratorTest extends AbstractIteratorTest { public void testIterator() { Iterator iter = makeObject(); - for (int i = 0; i < testArray.length; i++) { - Object testValue = testArray[i]; + for (String testValue : testArray) { E iterValue = iter.next(); assertEquals( "Iteration value is correct", testValue, iterValue ); diff --git a/src/test/java/org/apache/commons/collections/list/AbstractListTest.java b/src/test/java/org/apache/commons/collections/list/AbstractListTest.java index bc96f473e..6fe213ce6 100644 --- a/src/test/java/org/apache/commons/collections/list/AbstractListTest.java +++ b/src/test/java/org/apache/commons/collections/list/AbstractListTest.java @@ -487,9 +487,9 @@ public abstract class AbstractListTest extends AbstractCollectionTest { } E[] other = getOtherElements(); - for (int i = 0; i < other.length; i++) { + for (E element : other) { assertEquals("indexOf should return -1 for nonexistent element", - -1, list1.indexOf(other[i])); + -1, list1.indexOf(element)); verify(); } } @@ -511,9 +511,9 @@ public abstract class AbstractListTest extends AbstractCollectionTest { } E[] other = getOtherElements(); - for (int i = 0; i < other.length; i++) { + for (E element : other) { assertEquals("lastIndexOf should return -1 for nonexistent " + - "element", -1, list1.lastIndexOf(other[i])); + "element", -1, list1.lastIndexOf(element)); verify(); } } @@ -974,20 +974,20 @@ public abstract class AbstractListTest extends AbstractCollectionTest { ListIterator iter1 = list1.listIterator(); ListIterator iter2 = list2.listIterator(); - for (int i = 0; i < elements.length; i++) { - iter1.add(elements[i]); - iter2.add(elements[i]); + for (E element : elements) { + iter1.add(element); + iter2.add(element); verify(); } resetFull(); iter1 = getCollection().listIterator(); iter2 = getConfirmed().listIterator(); - for (int i = 0; i < elements.length; i++) { + for (E element : elements) { iter1.next(); iter2.next(); - iter1.add(elements[i]); - iter2.add(elements[i]); + iter1.add(element); + iter2.add(element); verify(); } } @@ -1004,11 +1004,11 @@ public abstract class AbstractListTest extends AbstractCollectionTest { resetFull(); ListIterator iter1 = getCollection().listIterator(); ListIterator iter2 = getConfirmed().listIterator(); - for (int i = 0; i < elements.length; i++) { + for (E element : elements) { iter1.next(); iter2.next(); - iter1.set(elements[i]); - iter2.set(elements[i]); + iter1.set(element); + iter2.set(element); verify(); } } @@ -1262,8 +1262,8 @@ public abstract class AbstractListTest extends AbstractCollectionTest { */ protected void failFastAll(List list) { Method[] methods = List.class.getMethods(); - for (int i = 0; i < methods.length; i++) { - failFastMethod(list, methods[i]); + for (Method method : methods) { + failFastMethod(list, method); } } diff --git a/src/test/java/org/apache/commons/collections/list/CursorableLinkedListTest.java b/src/test/java/org/apache/commons/collections/list/CursorableLinkedListTest.java index d6b72414c..56d9cf5cf 100644 --- a/src/test/java/org/apache/commons/collections/list/CursorableLinkedListTest.java +++ b/src/test/java/org/apache/commons/collections/list/CursorableLinkedListTest.java @@ -1516,9 +1516,9 @@ public class CursorableLinkedListTest extends AbstractLinkedListTest { ".testCanonicalFullCollectionExists", ".testSerializeDeserializeThenCompare" }; - for (int i = 0; i < ignored.length; i++) { - list.add(prefix + bulk + ignored[i]); - list.add(prefix + bulk + bulk + ignored[i]); + for (String element : ignored) { + list.add(prefix + bulk + element); + list.add(prefix + bulk + bulk + element); } return list.toArray(new String[0]); } diff --git a/src/test/java/org/apache/commons/collections/list/SetUniqueListTest.java b/src/test/java/org/apache/commons/collections/list/SetUniqueListTest.java index f0a51fa78..4591ecc77 100644 --- a/src/test/java/org/apache/commons/collections/list/SetUniqueListTest.java +++ b/src/test/java/org/apache/commons/collections/list/SetUniqueListTest.java @@ -94,20 +94,20 @@ public class SetUniqueListTest extends AbstractListTest { ListIterator iter1 = list1.listIterator(); ListIterator iter2 = list2.listIterator(); - for (int i = 0; i < elements.length; i++) { - iter1.add(elements[i]); - iter2.add(elements[i]); + for (E element : elements) { + iter1.add(element); + iter2.add(element); super.verify(); // changed here } resetFull(); iter1 = getCollection().listIterator(); iter2 = getConfirmed().listIterator(); - for (int i = 0; i < elements.length; i++) { + for (E element : elements) { iter1.next(); iter2.next(); - iter1.add(elements[i]); - iter2.add(elements[i]); + iter1.add(element); + iter2.add(element); super.verify(); // changed here } } @@ -121,9 +121,9 @@ public class SetUniqueListTest extends AbstractListTest { getConfirmed().addAll(Arrays.asList(elements)); verify(); assertTrue("Empty collection should change after addAll", r); - for (int i = 0; i < elements.length; i++) { + for (E element : elements) { assertTrue("Collection should contain added element", - getCollection().contains(elements[i])); + getCollection().contains(element)); } resetFull(); diff --git a/src/test/java/org/apache/commons/collections/list/TransformedListTest.java b/src/test/java/org/apache/commons/collections/list/TransformedListTest.java index 5cfb81060..f5316fc0a 100644 --- a/src/test/java/org/apache/commons/collections/list/TransformedListTest.java +++ b/src/test/java/org/apache/commons/collections/list/TransformedListTest.java @@ -116,14 +116,14 @@ public class TransformedListTest extends AbstractListTest { public void testTransformedList_decorateTransform() { List originalList = new ArrayList(); Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"}; - for (int i = 0; i < els.length; i++) { - originalList.add(els[i]); + for (Object el : els) { + originalList.add(el); } List list = TransformedList.transformedList(originalList, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); assertEquals(els.length, list.size()); - for (int i = 0; i < els.length; i++) { - assertEquals(true, list.contains(new Integer((String) els[i]))); - assertEquals(false, list.contains(els[i])); + for (Object el : els) { + assertEquals(true, list.contains(new Integer((String) el))); + assertEquals(false, list.contains(el)); } assertEquals(false, list.remove(els[0])); diff --git a/src/test/java/org/apache/commons/collections/map/AbstractMapTest.java b/src/test/java/org/apache/commons/collections/map/AbstractMapTest.java index f9eac5f61..85730fbd4 100644 --- a/src/test/java/org/apache/commons/collections/map/AbstractMapTest.java +++ b/src/test/java/org/apache/commons/collections/map/AbstractMapTest.java @@ -632,9 +632,9 @@ public abstract class AbstractMapTest extends AbstractObjectTest { verify(); resetFull(); - for(int i = 0; i < keys.length; i++) { + for (Object key : keys) { assertTrue("Map must contain key for a mapping in the map. " + - "Missing: " + keys[i], getMap().containsKey(keys[i])); + "Missing: " + key, getMap().containsKey(key)); } verify(); } @@ -655,9 +655,9 @@ public abstract class AbstractMapTest extends AbstractObjectTest { verify(); resetFull(); - for(int i = 0; i < values.length; i++) { + for (Object value : values) { assertTrue("Map must contain value for a mapping in the map.", - getMap().containsValue(values[i])); + getMap().containsValue(value)); } verify(); } @@ -699,9 +699,9 @@ public abstract class AbstractMapTest extends AbstractObjectTest { Object[] keys = getSampleKeys(); Object[] values = getSampleValues(); - for (int i = 0; i < keys.length; i++) { + for (Object key : keys) { assertTrue("Empty map.get() should return null.", - getMap().get(keys[i]) == null); + getMap().get(key) == null); } verify(); @@ -992,8 +992,8 @@ public abstract class AbstractMapTest extends AbstractObjectTest { Object[] keys = getSampleKeys(); Object[] values = getSampleValues(); - for (int i = 0; i < keys.length; i++) { - Object o = getMap().remove(keys[i]); + for (Object key : keys) { + Object o = getMap().remove(key); assertTrue("First map.remove should return null", o == null); } verify(); @@ -1013,8 +1013,8 @@ public abstract class AbstractMapTest extends AbstractObjectTest { resetFull(); int size = getMap().size(); - for (int i = 0; i < other.length; i++) { - Object o = getMap().remove(other[i]); + for (Object element : other) { + Object o = getMap().remove(element); assertNull("map.remove for nonexistent key should return null", o); assertEquals("map.remove for nonexistent key should not " + "shrink map", size, getMap().size()); @@ -2004,8 +2004,8 @@ public abstract class AbstractMapTest extends AbstractObjectTest { "\nTest: " + test + "\nReal: " + known, known.containsAll(test)); // originally coded to use a HashBag, but now separate jar so... - for (Iterator it = known.iterator(); it.hasNext();) { - boolean removed = test.remove(it.next()); + for (V v : known) { + boolean removed = test.remove(v); assertTrue("Map's values should still equal HashMap's", removed); } assertTrue("Map's values should still equal HashMap's", test.isEmpty()); diff --git a/src/test/java/org/apache/commons/collections/map/AbstractSortedMapTest.java b/src/test/java/org/apache/commons/collections/map/AbstractSortedMapTest.java index 34ab09a3b..8546ee246 100644 --- a/src/test/java/org/apache/commons/collections/map/AbstractSortedMapTest.java +++ b/src/test/java/org/apache/commons/collections/map/AbstractSortedMapTest.java @@ -21,6 +21,7 @@ import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.SortedMap; import java.util.TreeMap; @@ -218,8 +219,7 @@ public abstract class AbstractSortedMapTest extends AbstractMapTest public TestHeadMap(AbstractMapTest main) { super("SortedMap.HeadMap", main); Map sm = main.makeFullMap(); - for (Iterator> it = sm.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = it.next(); + for (Entry entry : sm.entrySet()) { this.subSortedKeys.add(entry.getKey()); this.subSortedValues.add(entry.getValue()); } @@ -271,8 +271,7 @@ public abstract class AbstractSortedMapTest extends AbstractMapTest public TestTailMap(AbstractMapTest main) { super("SortedMap.TailMap", main); Map sm = main.makeFullMap(); - for (Iterator> it = sm.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = it.next(); + for (Entry entry : sm.entrySet()) { this.subSortedKeys.add(entry.getKey()); this.subSortedValues.add(entry.getValue()); } @@ -325,8 +324,7 @@ public abstract class AbstractSortedMapTest extends AbstractMapTest public TestSubMap(AbstractMapTest main) { super("SortedMap.SubMap", main); Map sm = main.makeFullMap(); - for (Iterator> it = sm.entrySet().iterator(); it.hasNext();) { - Map.Entry entry = it.next(); + for (Entry entry : sm.entrySet()) { this.subSortedKeys.add(entry.getKey()); this.subSortedValues.add(entry.getValue()); } diff --git a/src/test/java/org/apache/commons/collections/map/CaseInsensitiveMapTest.java b/src/test/java/org/apache/commons/collections/map/CaseInsensitiveMapTest.java index df17e5fcc..22fd4d625 100644 --- a/src/test/java/org/apache/commons/collections/map/CaseInsensitiveMapTest.java +++ b/src/test/java/org/apache/commons/collections/map/CaseInsensitiveMapTest.java @@ -132,8 +132,8 @@ public class CaseInsensitiveMapTest extends AbstractIterableMapTest }; try { - for (int i = 0; i < locales.length; i++) { - Locale.setDefault(locales[i]); + for (Locale locale : locales) { + Locale.setDefault(locale); for (int j = 0; j < data.length; j++) { assertTrue("Test data corrupt: " + j, data[j][0].equalsIgnoreCase(data[j][1])); CaseInsensitiveMap map = new CaseInsensitiveMap(); diff --git a/src/test/java/org/apache/commons/collections/map/LRUMapTest.java b/src/test/java/org/apache/commons/collections/map/LRUMapTest.java index 6bdf94e7e..cda018eb5 100644 --- a/src/test/java/org/apache/commons/collections/map/LRUMapTest.java +++ b/src/test/java/org/apache/commons/collections/map/LRUMapTest.java @@ -529,27 +529,27 @@ public class LRUMapTest extends AbstractOrderedMapTest { }; } - for (int i = 0; i < threads.length; ++i) { - synchronized (threads[i]) { - threads[i].start(); - threads[i].wait(); + for (Thread thread : threads) { + synchronized (thread) { + thread.start(); + thread.wait(); } } - for (int i = 0; i < threads.length; ++i) { - synchronized (threads[i]) { - threads[i].notifyAll(); + for (Thread thread : threads) { + synchronized (thread) { + thread.notifyAll(); } } Thread.sleep(1000); - for (int i = 0; i < threads.length; ++i) { - threads[i].interrupt(); + for (Thread thread : threads) { + thread.interrupt(); } - for (int i = 0; i < threads.length; ++i) { - synchronized (threads[i]) { - threads[i].join(); + for (Thread thread : threads) { + synchronized (thread) { + thread.join(); } } @@ -612,27 +612,27 @@ public class LRUMapTest extends AbstractOrderedMapTest { }; } - for (int i = 0; i < threads.length; ++i) { - synchronized (threads[i]) { - threads[i].start(); - threads[i].wait(); + for (Thread thread : threads) { + synchronized (thread) { + thread.start(); + thread.wait(); } } - for (int i = 0; i < threads.length; ++i) { - synchronized (threads[i]) { - threads[i].notifyAll(); + for (Thread thread : threads) { + synchronized (thread) { + thread.notifyAll(); } } Thread.sleep(1000); - for (int i = 0; i < threads.length; ++i) { - threads[i].interrupt(); + for (Thread thread : threads) { + thread.interrupt(); } - for (int i = 0; i < threads.length; ++i) { - synchronized (threads[i]) { - threads[i].join(); + for (Thread thread : threads) { + synchronized (thread) { + thread.join(); } } @@ -695,27 +695,27 @@ public class LRUMapTest extends AbstractOrderedMapTest { }; } - for (int i = 0; i < threads.length; ++i) { - synchronized (threads[i]) { - threads[i].start(); - threads[i].wait(); + for (Thread thread : threads) { + synchronized (thread) { + thread.start(); + thread.wait(); } } - for (int i = 0; i < threads.length; ++i) { - synchronized (threads[i]) { - threads[i].notifyAll(); + for (Thread thread : threads) { + synchronized (thread) { + thread.notifyAll(); } } Thread.sleep(1000); - for (int i = 0; i < threads.length; ++i) { - threads[i].interrupt(); + for (Thread thread : threads) { + thread.interrupt(); } - for (int i = 0; i < threads.length; ++i) { - synchronized (threads[i]) { - threads[i].join(); + for (Thread thread : threads) { + synchronized (thread) { + thread.join(); } } @@ -777,27 +777,27 @@ public class LRUMapTest extends AbstractOrderedMapTest { }; } - for (int i = 0; i < threads.length; ++i) { - synchronized (threads[i]) { - threads[i].start(); - threads[i].wait(); + for (Thread thread : threads) { + synchronized (thread) { + thread.start(); + thread.wait(); } } - for (int i = 0; i < threads.length; ++i) { - synchronized (threads[i]) { - threads[i].notifyAll(); + for (Thread thread : threads) { + synchronized (thread) { + thread.notifyAll(); } } Thread.sleep(1000); - for (int i = 0; i < threads.length; ++i) { - threads[i].interrupt(); + for (Thread thread : threads) { + thread.interrupt(); } - for (int i = 0; i < threads.length; ++i) { - synchronized (threads[i]) { - threads[i].join(); + for (Thread thread : threads) { + synchronized (thread) { + thread.join(); } } diff --git a/src/test/java/org/apache/commons/collections/map/MultiKeyMapTest.java b/src/test/java/org/apache/commons/collections/map/MultiKeyMapTest.java index 1bbe8a16b..d55704b6c 100644 --- a/src/test/java/org/apache/commons/collections/map/MultiKeyMapTest.java +++ b/src/test/java/org/apache/commons/collections/map/MultiKeyMapTest.java @@ -196,9 +196,7 @@ public class MultiKeyMapTest extends AbstractIterableMapTest multimap = getMap(); MultiKey[] keys = getMultiKeyKeys(); - for (int i = 0; i < keys.length; i++) { - MultiKey key = keys[i]; - + for (MultiKey key : keys) { switch (key.size()) { case 2: assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1))); diff --git a/src/test/java/org/apache/commons/collections/map/MultiValueMapTest.java b/src/test/java/org/apache/commons/collections/map/MultiValueMapTest.java index cda83c6a5..ad6400027 100644 --- a/src/test/java/org/apache/commons/collections/map/MultiValueMapTest.java +++ b/src/test/java/org/apache/commons/collections/map/MultiValueMapTest.java @@ -407,8 +407,7 @@ public class MultiValueMapTest extends AbstractObjectTest { Map map = (Map) makeObject(); Map map2 = (Map) readExternalFormFromDisk(getCanonicalFullCollectionName(map)); assertEquals("Map is the right size", map.size(), map2.size()); - for (Iterator it = map.keySet().iterator(); it.hasNext();) { - Object key = it.next(); + for (Object key : map.keySet()) { assertEquals( "Map had inequal elements", map.get(key), map2.get(key) ); map2.remove(key); } diff --git a/src/test/java/org/apache/commons/collections/set/TransformedSetTest.java b/src/test/java/org/apache/commons/collections/set/TransformedSetTest.java index 957a65338..89ab99f44 100644 --- a/src/test/java/org/apache/commons/collections/set/TransformedSetTest.java +++ b/src/test/java/org/apache/commons/collections/set/TransformedSetTest.java @@ -85,14 +85,14 @@ public class TransformedSetTest extends AbstractSetTest { public void testTransformedSet_decorateTransform() { Set originalSet = new HashSet(); Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"}; - for (int i = 0; i < els.length; i++) { - originalSet.add(els[i]); + for (Object el : els) { + originalSet.add(el); } Set set = TransformedSet.transformedSet(originalSet, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); assertEquals(els.length, set.size()); - for (int i = 0; i < els.length; i++) { - assertEquals(true, set.contains(new Integer((String) els[i]))); - assertEquals(false, set.contains(els[i])); + for (Object el : els) { + assertEquals(true, set.contains(new Integer((String) el))); + assertEquals(false, set.contains(el)); } assertEquals(false, set.remove(els[0])); diff --git a/src/test/java/org/apache/commons/collections/set/TransformedSortedSetTest.java b/src/test/java/org/apache/commons/collections/set/TransformedSortedSetTest.java index 731f3273f..71903d0ff 100644 --- a/src/test/java/org/apache/commons/collections/set/TransformedSortedSetTest.java +++ b/src/test/java/org/apache/commons/collections/set/TransformedSortedSetTest.java @@ -78,13 +78,13 @@ public class TransformedSortedSetTest extends AbstractSortedSetTest { public void testTransformedSet_decorateTransform() { Set originalSet = new TreeSet(); Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"}; - for (int i = 0; i < els.length; i++) { - originalSet.add(els[i]); + for (Object el : els) { + originalSet.add(el); } Set set = TransformedSortedSet.transformedSet(originalSet, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); assertEquals(els.length, set.size()); - for (int i = 0; i < els.length; i++) { - assertEquals(true, set.contains(new Integer((String) els[i]))); + for (Object el : els) { + assertEquals(true, set.contains(new Integer((String) el))); } assertEquals(true, set.remove(new Integer((String) els[0])));