Convert to Java 5 enhanced loops.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1429890 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2013-01-07 16:48:10 +00:00
parent e79d3ffa4b
commit 745dd6673f
58 changed files with 250 additions and 271 deletions

View File

@ -896,8 +896,8 @@ public class CollectionUtils {
*/ */
public static <C> boolean addAll(Collection<C> collection, C[] elements) { public static <C> boolean addAll(Collection<C> collection, C[] elements) {
boolean changed = false; boolean changed = false;
for (int i = 0, size = elements.length; i < size; i++) { for (C element : elements) {
changed |= collection.add(elements[i]); changed |= collection.add(element);
} }
return changed; return changed;
} }

View File

@ -92,11 +92,11 @@ public class ComparatorUtils {
*/ */
public static <E extends Comparable<? super E>> Comparator<E> chainedComparator(Comparator<E>[] comparators) { public static <E extends Comparable<? super E>> Comparator<E> chainedComparator(Comparator<E>[] comparators) {
ComparatorChain<E> chain = new ComparatorChain<E>(); ComparatorChain<E> chain = new ComparatorChain<E>();
for (int i = 0; i < comparators.length; i++) { for (Comparator<E> comparator : comparators) {
if (comparators[i] == null) { if (comparator == null) {
throw new NullPointerException("Comparator cannot be null"); throw new NullPointerException("Comparator cannot be null");
} }
chain.addComparator(comparators[i]); chain.addComparator(comparator);
} }
return chain; return chain;
} }

View File

@ -756,8 +756,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
} else if (value instanceof List) { } else if (value instanceof List) {
@SuppressWarnings("unchecked") // we only add Strings to the Lists @SuppressWarnings("unchecked") // we only add Strings to the Lists
List<String> values = (List<String>) value; List<String> values = (List<String>) value;
for (Iterator<String> it = values.iterator(); it.hasNext(); ) { for (String currentElement : values) {
String currentElement = it.next();
StringBuilder currentOutput = new StringBuilder(); StringBuilder currentOutput = new StringBuilder();
currentOutput.append(key); currentOutput.append(key);
currentOutput.append("="); currentOutput.append("=");
@ -976,8 +975,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
// Each token is of the form 'key=value'. // Each token is of the form 'key=value'.
Properties props = new Properties(defaults); Properties props = new Properties(defaults);
for (int i = 0; i < tokens.length; i++) { for (String token : tokens) {
String token = tokens[i];
int equalSign = token.indexOf('='); int equalSign = token.indexOf('=');
if (equalSign > 0) { if (equalSign > 0) {
String pkey = token.substring(0, equalSign).trim(); String pkey = token.substring(0, equalSign).trim();
@ -1738,8 +1736,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
} else { } else {
@SuppressWarnings("unchecked") // OK to downcast here @SuppressWarnings("unchecked") // OK to downcast here
Map<String, Object> mapso = (Map<String,Object>) map; Map<String, Object> mapso = (Map<String,Object>) map;
for (Iterator<Map.Entry<String, Object>> it = mapso.entrySet().iterator(); it.hasNext(); ) { for (java.util.Map.Entry<String, Object> entry : mapso.entrySet()) {
Map.Entry<String,Object> entry = it.next();
put(entry.getKey(), entry.getValue()); put(entry.getKey(), entry.getValue());
} }
} }

View File

@ -25,6 +25,7 @@ import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties; import java.util.Properties;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.SortedMap; import java.util.SortedMap;
@ -843,8 +844,8 @@ public class MapUtils {
public static <K, V> Properties toProperties(final Map<K, V> map) { public static <K, V> Properties toProperties(final Map<K, V> map) {
Properties answer = new Properties(); Properties answer = new Properties();
if (map != null) { if (map != null) {
for (Iterator<Map.Entry<K, V>> iter = map.entrySet().iterator(); iter.hasNext();) { for (Entry<K, V> entry2 : map.entrySet()) {
Map.Entry<?, ?> entry = iter.next(); Map.Entry<?, ?> entry = entry2;
Object key = entry.getKey(); Object key = entry.getKey();
Object value = entry.getValue(); Object value = entry.getValue();
answer.put(key, value); answer.put(key, value);
@ -1049,8 +1050,7 @@ public class MapUtils {
*/ */
public static <K, V> Map<V, K> invertMap(Map<K, V> map) { public static <K, V> Map<V, K> invertMap(Map<K, V> map) {
Map<V, K> out = new HashMap<V, K>(map.size()); Map<V, K> out = new HashMap<V, K>(map.size());
for (Iterator<Map.Entry<K, V>> it = map.entrySet().iterator(); it.hasNext();) { for (Entry<K, V> entry : map.entrySet()) {
Map.Entry<K, V> entry = it.next();
out.put(entry.getValue(), entry.getKey()); out.put(entry.getValue(), entry.getKey());
} }
return out; return out;
@ -1136,13 +1136,13 @@ public class MapUtils {
} }
Object obj = array[0]; Object obj = array[0];
if (obj instanceof Map.Entry) { if (obj instanceof Map.Entry) {
for (int i = 0; i < array.length; i++) { for (Object element : array) {
Map.Entry<K, V> entry = (Map.Entry<K, V>) array[i]; Map.Entry<K, V> entry = (Map.Entry<K, V>) element;
map.put(entry.getKey(), entry.getValue()); map.put(entry.getKey(), entry.getValue());
} }
} else if (obj instanceof KeyValue) { } else if (obj instanceof KeyValue) {
for (int i = 0; i < array.length; i++) { for (Object element : array) {
KeyValue<K, V> keyval = (KeyValue<K, V>) array[i]; KeyValue<K, V> keyval = (KeyValue<K, V>) element;
map.put(keyval.getKey(), keyval.getValue()); map.put(keyval.getKey(), keyval.getValue());
} }
} else if (obj instanceof Object[]) { } else if (obj instanceof Object[]) {

View File

@ -24,6 +24,7 @@ import java.util.Collection;
import java.util.ConcurrentModificationException; import java.util.ConcurrentModificationException;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import org.apache.commons.collections.Bag; import org.apache.commons.collections.Bag;
@ -492,8 +493,7 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
*/ */
protected void doWriteObject(ObjectOutputStream out) throws IOException { protected void doWriteObject(ObjectOutputStream out) throws IOException {
out.writeInt(map.size()); out.writeInt(map.size());
for (Iterator<Map.Entry<E, MutableInteger>> it = map.entrySet().iterator(); it.hasNext();) { for (Entry<E, MutableInteger> entry : map.entrySet()) {
Map.Entry<E, MutableInteger> entry = it.next();
out.writeObject(entry.getKey()); out.writeObject(entry.getKey());
out.writeInt(entry.getValue().value); out.writeInt(entry.getValue().value);
} }
@ -540,8 +540,7 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
if (other.size() != size()) { if (other.size() != size()) {
return false; return false;
} }
for (Iterator<E> it = map.keySet().iterator(); it.hasNext();) { for (E element : map.keySet()) {
E element = it.next();
if (other.getCount(element) != getCount(element)) { if (other.getCount(element) != getCount(element)) {
return false; return false;
} }
@ -561,8 +560,7 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
@Override @Override
public int hashCode() { public int hashCode() {
int total = 0; int total = 0;
for (Iterator<Map.Entry<E, MutableInteger>> it = map.entrySet().iterator(); it.hasNext();) { for (Entry<E, MutableInteger> entry : map.entrySet()) {
Map.Entry<E, MutableInteger> entry = it.next();
E element = entry.getKey(); E element = entry.getKey();
MutableInteger count = entry.getValue(); MutableInteger count = entry.getValue();
total += (element == null ? 0 : element.hashCode()) ^ count.value; total += (element == null ? 0 : element.hashCode()) ^ count.value;

View File

@ -78,8 +78,8 @@ public class TransformedBag<E> extends TransformedCollection<E> implements Bag<E
@SuppressWarnings("unchecked") // Bag is of type E @SuppressWarnings("unchecked") // Bag is of type E
E[] values = (E[]) bag.toArray(); E[] values = (E[]) bag.toArray();
bag.clear(); bag.clear();
for (int i = 0; i < values.length; i++) { for (E value : values) {
decorated.decorated().add(transformer.transform(values[i])); decorated.decorated().add(transformer.transform(value));
} }
} }
return decorated; return decorated;

View File

@ -78,8 +78,8 @@ public class TransformedSortedBag<E> extends TransformedBag<E> implements Sorted
@SuppressWarnings("unchecked") // bag is type E @SuppressWarnings("unchecked") // bag is type E
E[] values = (E[]) bag.toArray(); E[] values = (E[]) bag.toArray();
bag.clear(); bag.clear();
for(int i=0; i<values.length; i++) { for (E value : values) {
decorated.decorated().add(transformer.transform(values[i])); decorated.decorated().add(transformer.transform(value));
} }
} }
return decorated; return decorated;

View File

@ -130,8 +130,8 @@ public class BoundedFifoBuffer<E> extends AbstractCollection<E>
private void writeObject(ObjectOutputStream out) throws IOException { private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject(); out.defaultWriteObject();
out.writeInt(size()); out.writeInt(size());
for (Iterator<E> it = iterator(); it.hasNext();) { for (E e : this) {
out.writeObject(it.next()); out.writeObject(e);
} }
} }

View File

@ -79,8 +79,8 @@ public class TransformedBuffer<E> extends TransformedCollection<E> implements Bu
@SuppressWarnings("unchecked") // buffer is type <E> @SuppressWarnings("unchecked") // buffer is type <E>
E[] values = (E[]) buffer.toArray(); E[] values = (E[]) buffer.toArray();
buffer.clear(); buffer.clear();
for(int i=0; i<values.length; i++) { for (E value : values) {
decorated.decorated().add(transformer.transform(values[i])); decorated.decorated().add(transformer.transform(value));
} }
} }
return decorated; return decorated;

View File

@ -110,8 +110,8 @@ public class UnboundedFifoBuffer<E> extends AbstractCollection<E> implements Buf
out.defaultWriteObject(); out.defaultWriteObject();
out.writeInt(size()); out.writeInt(size());
out.writeInt(buffer.length); out.writeInt(buffer.length);
for (Iterator<E> it = iterator(); it.hasNext();) { for (E e : this) {
out.writeObject(it.next()); out.writeObject(e);
} }
} }

View File

@ -85,8 +85,8 @@ public class TransformedCollection<E> extends AbstractCollectionDecorator<E> {
@SuppressWarnings("unchecked") // collection is of type E @SuppressWarnings("unchecked") // collection is of type E
E[] values = (E[]) collection.toArray(); E[] values = (E[]) collection.toArray();
collection.clear(); collection.clear();
for(int i=0; i<values.length; i++) { for (E value : values) {
decorated.decorated().add(transformer.transform(values[i])); decorated.decorated().add(transformer.transform(value));
} }
} }
return decorated; return decorated;

View File

@ -94,8 +94,8 @@ public class FixedOrderComparator<T> implements Comparator<T>, Serializable {
if (items == null) { if (items == null) {
throw new IllegalArgumentException("The list of items must not be null"); throw new IllegalArgumentException("The list of items must not be null");
} }
for (int i = 0; i < items.length; i++) { for (T item : items) {
add(items[i]); add(item);
} }
} }

View File

@ -106,8 +106,8 @@ public final class AnyPredicate<T> implements Predicate<T>, PredicateDecorator<T
* @return true if any decorated predicate return true * @return true if any decorated predicate return true
*/ */
public boolean evaluate(T object) { public boolean evaluate(T object) {
for (int i = 0; i < iPredicates.length; i++) { for (Predicate<? super T> iPredicate : iPredicates) {
if (iPredicates[i].evaluate(object)) { if (iPredicate.evaluate(object)) {
return true; return true;
} }
} }

View File

@ -98,8 +98,8 @@ public class ChainedClosure<E> implements Closure<E>, Serializable {
* @param input the input object passed to each closure * @param input the input object passed to each closure
*/ */
public void execute(E input) { public void execute(E input) {
for (int i = 0; i < iClosures.length; i++) { for (Closure<? super E> iClosure : iClosures) {
iClosures[i].execute(input); iClosure.execute(input);
} }
} }

View File

@ -96,8 +96,8 @@ public class ChainedTransformer<T> implements Transformer<T, T>, Serializable {
* @return the transformed result * @return the transformed result
*/ */
public T transform(T object) { public T transform(T object) {
for (int i = 0; i < iTransformers.length; i++) { for (Transformer<? super T, ? extends T> iTransformer : iTransformers) {
object = iTransformers[i].transform(object); object = iTransformer.transform(object);
} }
return object; return object;
} }

View File

@ -96,8 +96,8 @@ public final class NonePredicate<T> implements Predicate<T>, PredicateDecorator<
* @return true if none of decorated predicates return true * @return true if none of decorated predicates return true
*/ */
public boolean evaluate(T object) { public boolean evaluate(T object) {
for (int i = 0; i < iPredicates.length; i++) { for (Predicate<? super T> iPredicate : iPredicates) {
if (iPredicates[i].evaluate(object)) { if (iPredicate.evaluate(object)) {
return false; return false;
} }
} }

View File

@ -98,8 +98,8 @@ public final class OnePredicate<T> implements Predicate<T>, PredicateDecorator<T
*/ */
public boolean evaluate(T object) { public boolean evaluate(T object) {
boolean match = false; boolean match = false;
for (int i = 0; i < iPredicates.length; i++) { for (Predicate<? super T> iPredicate : iPredicates) {
if (iPredicates[i].evaluate(object)) { if (iPredicate.evaluate(object)) {
if (match) { if (match) {
return false; return false;
} }

View File

@ -133,8 +133,8 @@ public class CollatingIterator<E> implements Iterator<E> {
*/ */
public CollatingIterator(final Comparator<? super E> comp, final Iterator<? extends E>[] iterators) { public CollatingIterator(final Comparator<? super E> comp, final Iterator<? extends E>[] iterators) {
this(comp, iterators.length); this(comp, iterators.length);
for (int i = 0; i < iterators.length; i++) { for (Iterator<? extends E> iterator : iterators) {
addIterator(iterators[i]); addIterator(iterator);
} }
} }

View File

@ -125,8 +125,8 @@ public class IteratorChain<E> implements Iterator<E> {
*/ */
public IteratorChain(Iterator<? extends E>... iteratorChain) { public IteratorChain(Iterator<? extends E>... iteratorChain) {
super(); super();
for (int i = 0; i < iteratorChain.length; i++) { for (Iterator<? extends E> element : iteratorChain) {
addIterator(iteratorChain[i]); addIterator(element);
} }
} }

View File

@ -260,9 +260,9 @@ public class MultiKey<K> implements Serializable {
private void calculateHashCode(Object[] keys) private void calculateHashCode(Object[] keys)
{ {
int total = 0; int total = 0;
for (int i = 0; i < keys.length; i++) { for (Object key : keys) {
if (keys[i] != null) { if (key != null) {
total ^= keys[i].hashCode(); total ^= key.hashCode();
} }
} }
hashCode = total; hashCode = total;

View File

@ -598,8 +598,8 @@ public abstract class AbstractLinkedList<E> implements List<E> {
protected void doWriteObject(ObjectOutputStream outputStream) throws IOException { protected void doWriteObject(ObjectOutputStream outputStream) throws IOException {
// Write the size so we know how many nodes to read back // Write the size so we know how many nodes to read back
outputStream.writeInt(size()); outputStream.writeInt(size());
for (Iterator<E> itr = iterator(); itr.hasNext();) { for (E e : this) {
outputStream.writeObject(itr.next()); outputStream.writeObject(e);
} }
} }

View File

@ -259,8 +259,8 @@ public class SetUniqueList<E> extends AbstractSerializableListDecorator<E> {
@Override @Override
public boolean removeAll(Collection<?> coll) { public boolean removeAll(Collection<?> coll) {
boolean result = false; boolean result = false;
for (Iterator<?> it = coll.iterator(); it.hasNext();) { for (Object name : coll) {
result |= remove(it.next()); result |= remove(name);
} }
return result; return result;
} }
@ -268,8 +268,7 @@ public class SetUniqueList<E> extends AbstractSerializableListDecorator<E> {
@Override @Override
public boolean retainAll(Collection<?> coll) { public boolean retainAll(Collection<?> coll) {
Set<Object> setRetainAll = new HashSet<Object>(); Set<Object> setRetainAll = new HashSet<Object>();
for (Iterator<?> it = coll.iterator(); it.hasNext();) { for (Object next : coll) {
Object next = it.next();
if (set.contains(next)) { if (set.contains(next)) {
setRetainAll.add(next); setRetainAll.add(next);
} }

View File

@ -82,8 +82,8 @@ public class TransformedList<E> extends TransformedCollection<E> implements List
@SuppressWarnings("unchecked") // list is of type E @SuppressWarnings("unchecked") // list is of type E
E[] values = (E[]) list.toArray(); E[] values = (E[]) list.toArray();
list.clear(); list.clear();
for(int i=0; i<values.length; i++) { for (E value : values) {
decorated.decorated().add(transformer.transform(values[i])); decorated.decorated().add(transformer.transform(value));
} }
} }
return decorated; return decorated;

View File

@ -239,8 +239,8 @@ public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements Iterab
@Override @Override
public boolean containsValue(Object value) { public boolean containsValue(Object value) {
if (value == null) { if (value == null) {
for (int i = 0, isize = data.length; i < isize; i++) { for (HashEntry<K, V> element : data) {
HashEntry<K, V> entry = data[i]; HashEntry<K, V> entry = element;
while (entry != null) { while (entry != null) {
if (entry.getValue() == null) { if (entry.getValue() == null) {
return true; return true;
@ -249,8 +249,8 @@ public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements Iterab
} }
} }
} else { } else {
for (int i = 0, isize = data.length; i < isize; i++) { for (HashEntry<K, V> element : data) {
HashEntry<K, V> entry = data[i]; HashEntry<K, V> entry = element;
while (entry != null) { while (entry != null) {
if (isEqualValue(value, entry.getValue())) { if (isEqualValue(value, entry.getValue())) {
return true; return true;

View File

@ -419,8 +419,8 @@ public class MultiValueMap<K, V> extends AbstractMapDecorator<K, Object> impleme
@Override @Override
public Iterator<V> iterator() { public Iterator<V> iterator() {
final IteratorChain<V> chain = new IteratorChain<V>(); final IteratorChain<V> chain = new IteratorChain<V>();
for (Iterator<K> it = keySet().iterator(); it.hasNext();) { for (K k : keySet()) {
chain.addIterator(new ValuesIterator(it.next())); chain.addIterator(new ValuesIterator(k));
} }
return chain; return chain;
} }

View File

@ -218,8 +218,8 @@ public class ListOrderedSet<E>
@Override @Override
public boolean removeAll(Collection<?> coll) { public boolean removeAll(Collection<?> coll) {
boolean result = false; boolean result = false;
for (Iterator<?> it = coll.iterator(); it.hasNext();) { for (Object name : coll) {
result |= remove(it.next()); result |= remove(name);
} }
return result; return result;
} }
@ -227,8 +227,7 @@ public class ListOrderedSet<E>
@Override @Override
public boolean retainAll(Collection<?> coll) { public boolean retainAll(Collection<?> coll) {
Set<Object> collectionRetainAll = new HashSet<Object>(); Set<Object> collectionRetainAll = new HashSet<Object>();
for (Iterator<?> it = coll.iterator(); it.hasNext();) { for (Object next : coll) {
Object next = it.next();
if (collection.contains(next)) { if (collection.contains(next)) {
collectionRetainAll.add(next); collectionRetainAll.add(next);
} }

View File

@ -77,8 +77,8 @@ public class TransformedSet<E> extends TransformedCollection<E> implements Set<E
@SuppressWarnings("unchecked") // set is type E @SuppressWarnings("unchecked") // set is type E
E[] values = (E[]) set.toArray(); E[] values = (E[]) set.toArray();
set.clear(); set.clear();
for(int i=0; i<values.length; i++) { for (E value : values) {
decorated.decorated().add(transformer.transform(values[i])); decorated.decorated().add(transformer.transform(value));
} }
} }
return decorated; return decorated;

View File

@ -79,8 +79,8 @@ public class TransformedSortedSet<E> extends TransformedSet<E> implements Sorted
@SuppressWarnings("unchecked") // set is type E @SuppressWarnings("unchecked") // set is type E
E[] values = (E[]) set.toArray(); E[] values = (E[]) set.toArray();
set.clear(); set.clear();
for(int i=0; i<values.length; i++) { for (E value : values) {
decorated.decorated().add(transformer.transform(values[i])); decorated.decorated().add(transformer.transform(value));
} }
} }
return decorated; return decorated;

View File

@ -323,9 +323,9 @@ class BulkTestSuiteMaker {
void make(BulkTest bulk) { void make(BulkTest bulk) {
Class<? extends BulkTest> c = bulk.getClass(); Class<? extends BulkTest> c = bulk.getClass();
Method[] all = c.getMethods(); Method[] all = c.getMethods();
for (int i = 0; i < all.length; i++) { for (Method element : all) {
if (isTest(all[i])) addTest(bulk, all[i]); if (isTest(element)) addTest(bulk, element);
if (isBulk(all[i])) addBulk(bulk, all[i]); if (isBulk(element)) addBulk(bulk, element);
} }
} }
@ -431,8 +431,8 @@ class BulkTestSuiteMaker {
private static <T extends BulkTest> BulkTest makeFirstTestCase(Class<T> c) { private static <T extends BulkTest> BulkTest makeFirstTestCase(Class<T> c) {
Method[] all = c.getMethods(); Method[] all = c.getMethods();
for (int i = 0; i < all.length; i++) { for (Method element : all) {
if (isTest(all[i])) return makeTestCase(c, all[i]); if (isTest(element)) return makeTestCase(c, element);
} }
throw new IllegalArgumentException(c.getName() + " must provide " throw new IllegalArgumentException(c.getName() + " must provide "
+ " at least one test method."); + " at least one test method.");

View File

@ -353,10 +353,10 @@ public abstract class AbstractBagTest<T> extends AbstractObjectTest {
bag.add((T) "C"); bag.add((T) "C");
Object[] array = bag.toArray(); Object[] array = bag.toArray();
int a = 0, b = 0, c = 0; int a = 0, b = 0, c = 0;
for (int i = 0; i < array.length; i++) { for (Object element : array) {
a += (array[i].equals("A") ? 1 : 0); a += (element.equals("A") ? 1 : 0);
b += (array[i].equals("B") ? 1 : 0); b += (element.equals("B") ? 1 : 0);
c += (array[i].equals("C") ? 1 : 0); c += (element.equals("C") ? 1 : 0);
} }
assertEquals(2, a); assertEquals(2, a);
assertEquals(2, b); assertEquals(2, b);
@ -373,10 +373,10 @@ public abstract class AbstractBagTest<T> extends AbstractObjectTest {
bag.add((T) "C"); bag.add((T) "C");
String[] array = bag.toArray(new String[0]); String[] array = bag.toArray(new String[0]);
int a = 0, b = 0, c = 0; int a = 0, b = 0, c = 0;
for (int i = 0; i < array.length; i++) { for (String element : array) {
a += (array[i].equals("A") ? 1 : 0); a += (element.equals("A") ? 1 : 0);
b += (array[i].equals("B") ? 1 : 0); b += (element.equals("B") ? 1 : 0);
c += (array[i].equals("C") ? 1 : 0); c += (element.equals("C") ? 1 : 0);
} }
assertEquals(2, a); assertEquals(2, a);
assertEquals(2, b); assertEquals(2, b);

View File

@ -62,15 +62,15 @@ public class TransformedBagTest<T> extends AbstractBagTest<T> {
public void testTransformedBag_decorateTransform() { public void testTransformedBag_decorateTransform() {
Bag<T> originalBag = new HashBag<T>(); Bag<T> originalBag = new HashBag<T>();
Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"}; Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
for (int i = 0; i < els.length; i++) { for (Object el : els) {
originalBag.add((T) els[i]); originalBag.add((T) el);
} }
Bag<T> bag = TransformedBag.transformedBag(originalBag, Bag<T> bag = TransformedBag.transformedBag(originalBag,
(Transformer<T, T>) TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); (Transformer<T, T>) TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(els.length, bag.size()); assertEquals(els.length, bag.size());
for (int i = 0; i < els.length; i++) { for (Object el : els) {
assertEquals(true, bag.contains(new Integer((String) els[i]))); assertEquals(true, bag.contains(new Integer((String) el)));
assertEquals(false, bag.contains(els[i])); assertEquals(false, bag.contains(el));
} }
assertEquals(false, bag.remove(els[0])); assertEquals(false, bag.remove(els[0]));

View File

@ -58,13 +58,13 @@ public class TransformedSortedBagTest<T> extends AbstractSortedBagTest<T> {
public void testTransformedBag_decorateTransform() { public void testTransformedBag_decorateTransform() {
Bag<Object> originalBag = new TreeBag<Object>(); Bag<Object> originalBag = new TreeBag<Object>();
Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"}; Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
for (int i = 0; i < els.length; i++) { for (Object el : els) {
originalBag.add(els[i]); originalBag.add(el);
} }
Bag<?> bag = TransformedBag.transformedBag(originalBag, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); Bag<?> bag = TransformedBag.transformedBag(originalBag, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(els.length, bag.size()); assertEquals(els.length, bag.size());
for (int i = 0; i < els.length; i++) { for (Object el : els) {
assertEquals(true, bag.contains(new Integer((String) els[i]))); assertEquals(true, bag.contains(new Integer((String) el)));
} }
assertEquals(true, bag.remove(new Integer((String) els[0]))); assertEquals(true, bag.remove(new Integer((String) els[0])));

View File

@ -53,14 +53,14 @@ public class TransformedBufferTest extends TestCase {
public void testTransformedBuffer_decorateTransform() { public void testTransformedBuffer_decorateTransform() {
Buffer originalBuffer = new ArrayStack(); Buffer originalBuffer = new ArrayStack();
Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"}; Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
for (int i = 0; i < els.length; i++) { for (Object el : els) {
originalBuffer.add(els[i]); originalBuffer.add(el);
} }
Buffer buffer = TransformedBuffer.transformedBuffer(originalBuffer, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); Buffer buffer = TransformedBuffer.transformedBuffer(originalBuffer, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(els.length, buffer.size()); assertEquals(els.length, buffer.size());
for (int i = 0; i < els.length; i++) { for (Object el : els) {
assertEquals(true, buffer.contains(new Integer((String) els[i]))); assertEquals(true, buffer.contains(new Integer((String) el)));
assertEquals(false, buffer.contains(els[i])); assertEquals(false, buffer.contains(el));
} }
assertEquals(false, buffer.remove(els[0])); assertEquals(false, buffer.remove(els[0]));

View File

@ -500,10 +500,10 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
if (!isAddSupported()) return; if (!isAddSupported()) return;
E[] elements = getFullElements(); E[] elements = getFullElements();
for (int i = 0; i < elements.length; i++) { for (E element : elements) {
resetEmpty(); resetEmpty();
boolean r = getCollection().add(elements[i]); boolean r = getCollection().add(element);
getConfirmed().add(elements[i]); getConfirmed().add(element);
verify(); verify();
assertTrue("Empty collection changed after add", r); assertTrue("Empty collection changed after add", r);
assertEquals("Collection size is 1 after first add", 1, getCollection().size()); assertEquals("Collection size is 1 after first add", 1, getCollection().size());
@ -511,13 +511,13 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
resetEmpty(); resetEmpty();
int size = 0; int size = 0;
for (int i = 0; i < elements.length; i++) { for (E element : elements) {
boolean r = getCollection().add(elements[i]); boolean r = getCollection().add(element);
getConfirmed().add(elements[i]); getConfirmed().add(element);
verify(); verify();
if (r) size++; if (r) size++;
assertEquals("Collection size should grow after add", size, getCollection().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<E> extends AbstractObjectTest {
getConfirmed().addAll(Arrays.asList(elements)); getConfirmed().addAll(Arrays.asList(elements));
verify(); verify();
assertTrue("Empty collection should change after addAll", r); 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])); assertTrue("Collection should contain added element", getCollection().contains(element));
} }
resetFull(); resetFull();
@ -544,9 +544,9 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
getConfirmed().addAll(Arrays.asList(elements)); getConfirmed().addAll(Arrays.asList(elements));
verify(); verify();
assertTrue("Full collection should change after addAll", r); 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", 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()); assertEquals("Size should increase after addAll", size + elements.length, getCollection().size());
@ -862,10 +862,10 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
} }
int size = getCollection().size(); int size = getCollection().size();
for (int i = 0; i < elements.length; i++) { for (E element : elements) {
resetFull(); resetFull();
assertTrue("Collection should remove extant element: " + elements[i], assertTrue("Collection should remove extant element: " + element,
getCollection().remove(elements[i])); getCollection().remove(element));
// if the elements aren't distinguishable, we can just remove a // if the elements aren't distinguishable, we can just remove a
// matching element from the confirmed collection and verify // matching element from the confirmed collection and verify
@ -876,7 +876,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
// //
// see areEqualElementsDistinguishable() // see areEqualElementsDistinguishable()
if (!areEqualElementsDistinguishable()) { if (!areEqualElementsDistinguishable()) {
getConfirmed().remove(elements[i]); getConfirmed().remove(element);
verify(); verify();
} }
@ -1043,9 +1043,9 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
+ "in the confirmed collection's array"); + "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, assertEquals("Collection should return all its elements in " + "toArray", true,
matched[i]); element);
} }
} }
@ -1085,8 +1085,8 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
// Figure out if they're all the same class // Figure out if they're all the same class
// TODO: It'd be nicer to detect a common superclass // TODO: It'd be nicer to detect a common superclass
HashSet<Class<?>> classes = new HashSet<Class<?>>(); HashSet<Class<?>> classes = new HashSet<Class<?>>();
for (int i = 0; i < array.length; i++) { for (Object element : array) {
classes.add((array[i] == null) ? null : array[i].getClass()); classes.add((element == null) ? null : element.getClass());
} }
if (classes.size() > 1) return; if (classes.size() > 1) return;

View File

@ -76,9 +76,9 @@ public class CompositeCollectionTest<E> extends AbstractCollectionTest<E> {
public Collection<E> makeFullCollection() { public Collection<E> makeFullCollection() {
CompositeCollection<E> compositeCollection = new CompositeCollection<E>(); CompositeCollection<E> compositeCollection = new CompositeCollection<E>();
E[] elements = getFullElements(); E[] elements = getFullElements();
for (int i = 0; i < elements.length; i++) { for (E element : elements) {
Collection<E> summand = new HashSet<E>(); Collection<E> summand = new HashSet<E>();
summand.add(elements[i]); summand.add(element);
compositeCollection.addComposited(summand); compositeCollection.addComposited(summand);
} }
return compositeCollection; return compositeCollection;

View File

@ -100,14 +100,14 @@ public class TransformedCollectionTest extends AbstractCollectionTest<Object> {
public void testTransformedCollection_decorateTransform() { public void testTransformedCollection_decorateTransform() {
Collection originalCollection = new ArrayList(); Collection originalCollection = new ArrayList();
Object[] els = getFullElements(); Object[] els = getFullElements();
for (int i = 0; i < els.length; i++) { for (Object el : els) {
originalCollection.add(els[i]); originalCollection.add(el);
} }
Collection<Object> collection = TransformedCollection.transformedCollection(originalCollection, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); Collection<Object> collection = TransformedCollection.transformedCollection(originalCollection, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(els.length, collection.size()); assertEquals(els.length, collection.size());
for (int i = 0; i < els.length; i++) { for (Object el : els) {
assertEquals(true, collection.contains(new Integer((String) els[i]))); assertEquals(true, collection.contains(new Integer((String) el)));
assertEquals(false, collection.contains(els[i])); assertEquals(false, collection.contains(el));
} }
assertEquals(false, collection.remove(els[0])); assertEquals(false, collection.remove(els[0]));

View File

@ -85,8 +85,8 @@ public class FixedOrderComparatorTest extends AbstractComparatorTest<String> {
@Test @Test
public void testConstructorPlusAdd() { public void testConstructorPlusAdd() {
FixedOrderComparator<String> comparator = new FixedOrderComparator<String>(); FixedOrderComparator<String> comparator = new FixedOrderComparator<String>();
for (int i = 0; i < topCities.length; i++) { for (String topCitie : topCities) {
comparator.add(topCities[i]); comparator.add(topCitie);
} }
String[] keys = topCities.clone(); String[] keys = topCities.clone();
assertComparatorYieldsOrder(keys, comparator); assertComparatorYieldsOrder(keys, comparator);

View File

@ -117,10 +117,10 @@ public class SequencesComparatorTest {
for (int lg=0; lg<lgMax; ++lg) { for (int lg=0; lg<lgMax; ++lg) {
List<List<String>> newTab = new ArrayList<List<String>>(); List<List<String>> newTab = new ArrayList<List<String>>();
newTab.add(new ArrayList<String>()); newTab.add(new ArrayList<String>());
for (int k = 0; k < shadokAlph.length; k++) { for (String element : shadokAlph) {
for (List<String> sentence : shadokSentences) { for (List<String> sentence : shadokSentences) {
List<String> newSentence = new ArrayList<String>(sentence); List<String> newSentence = new ArrayList<String>(sentence);
newSentence.add(shadokAlph[k]); newSentence.add(element);
newTab.add(newSentence); newTab.add(newSentence);
} }
} }

View File

@ -61,8 +61,8 @@ public class ArrayIterator2Test<E> extends AbstractIteratorTest<E> {
public void testIterator() { public void testIterator() {
Iterator<E> iter = makeObject(); Iterator<E> iter = makeObject();
for (int i = 0; i < testArray.length; i++) { for (int element : testArray) {
Integer testValue = new Integer(testArray[i]); Integer testValue = new Integer(element);
Number iterValue = (Number) iter.next(); Number iterValue = (Number) iter.next();
assertEquals("Iteration value is correct", testValue, iterValue); assertEquals("Iteration value is correct", testValue, iterValue);

View File

@ -51,8 +51,7 @@ public class ArrayIteratorTest<E> extends AbstractIteratorTest<E> {
public void testIterator() { public void testIterator() {
Iterator<E> iter = makeObject(); Iterator<E> iter = makeObject();
for (int i = 0; i < testArray.length; i++) { for (String testValue : testArray) {
Object testValue = testArray[i];
E iterValue = iter.next(); E iterValue = iter.next();
assertEquals("Iteration value is correct", testValue, iterValue); assertEquals("Iteration value is correct", testValue, iterValue);

View File

@ -92,7 +92,7 @@ public class FilterIteratorTest<E> extends AbstractIteratorTest<E> {
} }
public void testRepeatedNext() { public void testRepeatedNext() {
for (int i = 0; i < array.length; i++) { for (String element : array) {
iterator.next(); iterator.next();
} }
verifyNoMoreElements(); verifyNoMoreElements();
@ -159,8 +159,8 @@ public class FilterIteratorTest<E> extends AbstractIteratorTest<E> {
private void verifyElementsInPredicate(final String[] elements) { private void verifyElementsInPredicate(final String[] elements) {
Predicate<E> pred = new Predicate<E>() { Predicate<E> pred = new Predicate<E>() {
public boolean evaluate(E x) { public boolean evaluate(E x) {
for (int i = 0; i < elements.length; i++) { for (String element : elements) {
if (elements[i].equals(x)) { if (element.equals(x)) {
return true; return true;
} }
} }

View File

@ -74,8 +74,7 @@ public class IteratorChainTest extends AbstractIteratorTest<String> {
public void testIterator() { public void testIterator() {
Iterator<String> iter = makeObject(); Iterator<String> iter = makeObject();
for (int i = 0; i < testArray.length; i++) { for (String testValue : testArray) {
Object testValue = testArray[i];
Object iterValue = iter.next(); Object iterValue = iter.next();
assertEquals( "Iteration value is correct", testValue, iterValue ); assertEquals( "Iteration value is correct", testValue, iterValue );
@ -130,8 +129,7 @@ public class IteratorChainTest extends AbstractIteratorTest<String> {
} }
for (int i = 0; i < testArray.length; i++) { for (String testValue : testArray) {
String testValue = testArray[i];
String iterValue = iter.next(); String iterValue = iter.next();
assertEquals("Iteration value is correct", testValue, iterValue); assertEquals("Iteration value is correct", testValue, iterValue);

View File

@ -65,8 +65,7 @@ public class ListIteratorWrapper2Test<E> extends AbstractIteratorTest<E> {
public void testIterator() { public void testIterator() {
ListIterator<E> iter = makeObject(); ListIterator<E> iter = makeObject();
for (int i = 0; i < testArray.length; i++) { for (String testValue : testArray) {
Object testValue = testArray[i];
Object iterValue = iter.next(); Object iterValue = iter.next();
assertEquals("Iteration value is correct", testValue, iterValue); assertEquals("Iteration value is correct", testValue, iterValue);
@ -97,8 +96,7 @@ public class ListIteratorWrapper2Test<E> extends AbstractIteratorTest<E> {
} }
// now, read it forwards again // now, read it forwards again
for (int i = 0; i < testArray.length; i++) { for (String testValue : testArray) {
Object testValue = testArray[i];
Object iterValue = iter.next(); Object iterValue = iter.next();
assertEquals("Iteration value is correct", testValue, iterValue); assertEquals("Iteration value is correct", testValue, iterValue);

View File

@ -66,8 +66,7 @@ public class ListIteratorWrapperTest<E> extends AbstractIteratorTest<E> {
public void testIterator() { public void testIterator() {
ListIterator<E> iter = makeObject(); ListIterator<E> iter = makeObject();
for (int i = 0; i < testArray.length; i++) { for (String testValue : testArray) {
Object testValue = testArray[i];
Object iterValue = iter.next(); Object iterValue = iter.next();
assertEquals("Iteration value is correct", testValue, iterValue); assertEquals("Iteration value is correct", testValue, iterValue);
@ -98,8 +97,7 @@ public class ListIteratorWrapperTest<E> extends AbstractIteratorTest<E> {
} }
// now, read it forwards again // now, read it forwards again
for (int i = 0; i < testArray.length; i++) { for (String testValue : testArray) {
Object testValue = testArray[i];
Object iterValue = iter.next(); Object iterValue = iter.next();
assertEquals("Iteration value is correct", testValue, iterValue); assertEquals("Iteration value is correct", testValue, iterValue);

View File

@ -67,8 +67,7 @@ public class ObjectArrayIteratorTest<E> extends AbstractIteratorTest<E> {
public void testIterator() { public void testIterator() {
Iterator<E> iter = makeObject(); Iterator<E> iter = makeObject();
for (int i = 0; i < testArray.length; i++) { for (String testValue : testArray) {
Object testValue = testArray[i];
E iterValue = iter.next(); E iterValue = iter.next();
assertEquals("Iteration value is correct", testValue, iterValue); assertEquals("Iteration value is correct", testValue, iterValue);

View File

@ -68,8 +68,7 @@ public class UniqueFilterIteratorTest<E> extends AbstractIteratorTest<E> {
public void testIterator() { public void testIterator() {
Iterator<E> iter = makeObject(); Iterator<E> iter = makeObject();
for (int i = 0; i < testArray.length; i++) { for (String testValue : testArray) {
Object testValue = testArray[i];
E iterValue = iter.next(); E iterValue = iter.next();
assertEquals( "Iteration value is correct", testValue, iterValue ); assertEquals( "Iteration value is correct", testValue, iterValue );

View File

@ -487,9 +487,9 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
} }
E[] other = getOtherElements(); E[] other = getOtherElements();
for (int i = 0; i < other.length; i++) { for (E element : other) {
assertEquals("indexOf should return -1 for nonexistent element", assertEquals("indexOf should return -1 for nonexistent element",
-1, list1.indexOf(other[i])); -1, list1.indexOf(element));
verify(); verify();
} }
} }
@ -511,9 +511,9 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
} }
E[] other = getOtherElements(); E[] other = getOtherElements();
for (int i = 0; i < other.length; i++) { for (E element : other) {
assertEquals("lastIndexOf should return -1 for nonexistent " + assertEquals("lastIndexOf should return -1 for nonexistent " +
"element", -1, list1.lastIndexOf(other[i])); "element", -1, list1.lastIndexOf(element));
verify(); verify();
} }
} }
@ -974,20 +974,20 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
ListIterator<E> iter1 = list1.listIterator(); ListIterator<E> iter1 = list1.listIterator();
ListIterator<E> iter2 = list2.listIterator(); ListIterator<E> iter2 = list2.listIterator();
for (int i = 0; i < elements.length; i++) { for (E element : elements) {
iter1.add(elements[i]); iter1.add(element);
iter2.add(elements[i]); iter2.add(element);
verify(); verify();
} }
resetFull(); resetFull();
iter1 = getCollection().listIterator(); iter1 = getCollection().listIterator();
iter2 = getConfirmed().listIterator(); iter2 = getConfirmed().listIterator();
for (int i = 0; i < elements.length; i++) { for (E element : elements) {
iter1.next(); iter1.next();
iter2.next(); iter2.next();
iter1.add(elements[i]); iter1.add(element);
iter2.add(elements[i]); iter2.add(element);
verify(); verify();
} }
} }
@ -1004,11 +1004,11 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
resetFull(); resetFull();
ListIterator<E> iter1 = getCollection().listIterator(); ListIterator<E> iter1 = getCollection().listIterator();
ListIterator<E> iter2 = getConfirmed().listIterator(); ListIterator<E> iter2 = getConfirmed().listIterator();
for (int i = 0; i < elements.length; i++) { for (E element : elements) {
iter1.next(); iter1.next();
iter2.next(); iter2.next();
iter1.set(elements[i]); iter1.set(element);
iter2.set(elements[i]); iter2.set(element);
verify(); verify();
} }
} }
@ -1262,8 +1262,8 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
*/ */
protected void failFastAll(List<E> list) { protected void failFastAll(List<E> list) {
Method[] methods = List.class.getMethods(); Method[] methods = List.class.getMethods();
for (int i = 0; i < methods.length; i++) { for (Method method : methods) {
failFastMethod(list, methods[i]); failFastMethod(list, method);
} }
} }

View File

@ -1516,9 +1516,9 @@ public class CursorableLinkedListTest<E> extends AbstractLinkedListTest<E> {
".testCanonicalFullCollectionExists", ".testCanonicalFullCollectionExists",
".testSerializeDeserializeThenCompare" ".testSerializeDeserializeThenCompare"
}; };
for (int i = 0; i < ignored.length; i++) { for (String element : ignored) {
list.add(prefix + bulk + ignored[i]); list.add(prefix + bulk + element);
list.add(prefix + bulk + bulk + ignored[i]); list.add(prefix + bulk + bulk + element);
} }
return list.toArray(new String[0]); return list.toArray(new String[0]);
} }

View File

@ -94,20 +94,20 @@ public class SetUniqueListTest<E> extends AbstractListTest<E> {
ListIterator<E> iter1 = list1.listIterator(); ListIterator<E> iter1 = list1.listIterator();
ListIterator<E> iter2 = list2.listIterator(); ListIterator<E> iter2 = list2.listIterator();
for (int i = 0; i < elements.length; i++) { for (E element : elements) {
iter1.add(elements[i]); iter1.add(element);
iter2.add(elements[i]); iter2.add(element);
super.verify(); // changed here super.verify(); // changed here
} }
resetFull(); resetFull();
iter1 = getCollection().listIterator(); iter1 = getCollection().listIterator();
iter2 = getConfirmed().listIterator(); iter2 = getConfirmed().listIterator();
for (int i = 0; i < elements.length; i++) { for (E element : elements) {
iter1.next(); iter1.next();
iter2.next(); iter2.next();
iter1.add(elements[i]); iter1.add(element);
iter2.add(elements[i]); iter2.add(element);
super.verify(); // changed here super.verify(); // changed here
} }
} }
@ -121,9 +121,9 @@ public class SetUniqueListTest<E> extends AbstractListTest<E> {
getConfirmed().addAll(Arrays.asList(elements)); getConfirmed().addAll(Arrays.asList(elements));
verify(); verify();
assertTrue("Empty collection should change after addAll", r); 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", assertTrue("Collection should contain added element",
getCollection().contains(elements[i])); getCollection().contains(element));
} }
resetFull(); resetFull();

View File

@ -116,14 +116,14 @@ public class TransformedListTest<E> extends AbstractListTest<E> {
public void testTransformedList_decorateTransform() { public void testTransformedList_decorateTransform() {
List<Object> originalList = new ArrayList<Object>(); List<Object> originalList = new ArrayList<Object>();
Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"}; Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
for (int i = 0; i < els.length; i++) { for (Object el : els) {
originalList.add(els[i]); originalList.add(el);
} }
List<?> list = TransformedList.transformedList(originalList, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); List<?> list = TransformedList.transformedList(originalList, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(els.length, list.size()); assertEquals(els.length, list.size());
for (int i = 0; i < els.length; i++) { for (Object el : els) {
assertEquals(true, list.contains(new Integer((String) els[i]))); assertEquals(true, list.contains(new Integer((String) el)));
assertEquals(false, list.contains(els[i])); assertEquals(false, list.contains(el));
} }
assertEquals(false, list.remove(els[0])); assertEquals(false, list.remove(els[0]));

View File

@ -632,9 +632,9 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
verify(); verify();
resetFull(); resetFull();
for(int i = 0; i < keys.length; i++) { for (Object key : keys) {
assertTrue("Map must contain key for a mapping in the map. " + assertTrue("Map must contain key for a mapping in the map. " +
"Missing: " + keys[i], getMap().containsKey(keys[i])); "Missing: " + key, getMap().containsKey(key));
} }
verify(); verify();
} }
@ -655,9 +655,9 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
verify(); verify();
resetFull(); resetFull();
for(int i = 0; i < values.length; i++) { for (Object value : values) {
assertTrue("Map must contain value for a mapping in the map.", assertTrue("Map must contain value for a mapping in the map.",
getMap().containsValue(values[i])); getMap().containsValue(value));
} }
verify(); verify();
} }
@ -699,9 +699,9 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
Object[] keys = getSampleKeys(); Object[] keys = getSampleKeys();
Object[] values = getSampleValues(); Object[] values = getSampleValues();
for (int i = 0; i < keys.length; i++) { for (Object key : keys) {
assertTrue("Empty map.get() should return null.", assertTrue("Empty map.get() should return null.",
getMap().get(keys[i]) == null); getMap().get(key) == null);
} }
verify(); verify();
@ -992,8 +992,8 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
Object[] keys = getSampleKeys(); Object[] keys = getSampleKeys();
Object[] values = getSampleValues(); Object[] values = getSampleValues();
for (int i = 0; i < keys.length; i++) { for (Object key : keys) {
Object o = getMap().remove(keys[i]); Object o = getMap().remove(key);
assertTrue("First map.remove should return null", o == null); assertTrue("First map.remove should return null", o == null);
} }
verify(); verify();
@ -1013,8 +1013,8 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
resetFull(); resetFull();
int size = getMap().size(); int size = getMap().size();
for (int i = 0; i < other.length; i++) { for (Object element : other) {
Object o = getMap().remove(other[i]); Object o = getMap().remove(element);
assertNull("map.remove for nonexistent key should return null", o); assertNull("map.remove for nonexistent key should return null", o);
assertEquals("map.remove for nonexistent key should not " + assertEquals("map.remove for nonexistent key should not " +
"shrink map", size, getMap().size()); "shrink map", size, getMap().size());
@ -2004,8 +2004,8 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
"\nTest: " + test + "\nReal: " + known, "\nTest: " + test + "\nReal: " + known,
known.containsAll(test)); known.containsAll(test));
// originally coded to use a HashBag, but now separate jar so... // originally coded to use a HashBag, but now separate jar so...
for (Iterator<V> it = known.iterator(); it.hasNext();) { for (V v : known) {
boolean removed = test.remove(it.next()); boolean removed = test.remove(v);
assertTrue("Map's values should still equal HashMap's", removed); assertTrue("Map's values should still equal HashMap's", removed);
} }
assertTrue("Map's values should still equal HashMap's", test.isEmpty()); assertTrue("Map's values should still equal HashMap's", test.isEmpty());

View File

@ -21,6 +21,7 @@ import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.SortedMap; import java.util.SortedMap;
import java.util.TreeMap; import java.util.TreeMap;
@ -218,8 +219,7 @@ public abstract class AbstractSortedMapTest<K, V> extends AbstractMapTest<K, V>
public TestHeadMap(AbstractMapTest<K, V> main) { public TestHeadMap(AbstractMapTest<K, V> main) {
super("SortedMap.HeadMap", main); super("SortedMap.HeadMap", main);
Map<K, V> sm = main.makeFullMap(); Map<K, V> sm = main.makeFullMap();
for (Iterator<Map.Entry<K, V>> it = sm.entrySet().iterator(); it.hasNext();) { for (Entry<K, V> entry : sm.entrySet()) {
Map.Entry<K, V> entry = it.next();
this.subSortedKeys.add(entry.getKey()); this.subSortedKeys.add(entry.getKey());
this.subSortedValues.add(entry.getValue()); this.subSortedValues.add(entry.getValue());
} }
@ -271,8 +271,7 @@ public abstract class AbstractSortedMapTest<K, V> extends AbstractMapTest<K, V>
public TestTailMap(AbstractMapTest<K, V> main) { public TestTailMap(AbstractMapTest<K, V> main) {
super("SortedMap.TailMap", main); super("SortedMap.TailMap", main);
Map<K, V> sm = main.makeFullMap(); Map<K, V> sm = main.makeFullMap();
for (Iterator<Map.Entry<K, V>> it = sm.entrySet().iterator(); it.hasNext();) { for (Entry<K, V> entry : sm.entrySet()) {
Map.Entry<K, V> entry = it.next();
this.subSortedKeys.add(entry.getKey()); this.subSortedKeys.add(entry.getKey());
this.subSortedValues.add(entry.getValue()); this.subSortedValues.add(entry.getValue());
} }
@ -325,8 +324,7 @@ public abstract class AbstractSortedMapTest<K, V> extends AbstractMapTest<K, V>
public TestSubMap(AbstractMapTest<K, V> main) { public TestSubMap(AbstractMapTest<K, V> main) {
super("SortedMap.SubMap", main); super("SortedMap.SubMap", main);
Map<K, V> sm = main.makeFullMap(); Map<K, V> sm = main.makeFullMap();
for (Iterator<Map.Entry<K, V>> it = sm.entrySet().iterator(); it.hasNext();) { for (Entry<K, V> entry : sm.entrySet()) {
Map.Entry<K, V> entry = it.next();
this.subSortedKeys.add(entry.getKey()); this.subSortedKeys.add(entry.getKey());
this.subSortedValues.add(entry.getValue()); this.subSortedValues.add(entry.getValue());
} }

View File

@ -132,8 +132,8 @@ public class CaseInsensitiveMapTest<K, V> extends AbstractIterableMapTest<K, V>
}; };
try { try {
for (int i = 0; i < locales.length; i++) { for (Locale locale : locales) {
Locale.setDefault(locales[i]); Locale.setDefault(locale);
for (int j = 0; j < data.length; j++) { for (int j = 0; j < data.length; j++) {
assertTrue("Test data corrupt: " + j, data[j][0].equalsIgnoreCase(data[j][1])); assertTrue("Test data corrupt: " + j, data[j][0].equalsIgnoreCase(data[j][1]));
CaseInsensitiveMap<String, String> map = new CaseInsensitiveMap<String, String>(); CaseInsensitiveMap<String, String> map = new CaseInsensitiveMap<String, String>();

View File

@ -529,27 +529,27 @@ public class LRUMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
}; };
} }
for (int i = 0; i < threads.length; ++i) { for (Thread thread : threads) {
synchronized (threads[i]) { synchronized (thread) {
threads[i].start(); thread.start();
threads[i].wait(); thread.wait();
} }
} }
for (int i = 0; i < threads.length; ++i) { for (Thread thread : threads) {
synchronized (threads[i]) { synchronized (thread) {
threads[i].notifyAll(); thread.notifyAll();
} }
} }
Thread.sleep(1000); Thread.sleep(1000);
for (int i = 0; i < threads.length; ++i) { for (Thread thread : threads) {
threads[i].interrupt(); thread.interrupt();
} }
for (int i = 0; i < threads.length; ++i) { for (Thread thread : threads) {
synchronized (threads[i]) { synchronized (thread) {
threads[i].join(); thread.join();
} }
} }
@ -612,27 +612,27 @@ public class LRUMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
}; };
} }
for (int i = 0; i < threads.length; ++i) { for (Thread thread : threads) {
synchronized (threads[i]) { synchronized (thread) {
threads[i].start(); thread.start();
threads[i].wait(); thread.wait();
} }
} }
for (int i = 0; i < threads.length; ++i) { for (Thread thread : threads) {
synchronized (threads[i]) { synchronized (thread) {
threads[i].notifyAll(); thread.notifyAll();
} }
} }
Thread.sleep(1000); Thread.sleep(1000);
for (int i = 0; i < threads.length; ++i) { for (Thread thread : threads) {
threads[i].interrupt(); thread.interrupt();
} }
for (int i = 0; i < threads.length; ++i) { for (Thread thread : threads) {
synchronized (threads[i]) { synchronized (thread) {
threads[i].join(); thread.join();
} }
} }
@ -695,27 +695,27 @@ public class LRUMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
}; };
} }
for (int i = 0; i < threads.length; ++i) { for (Thread thread : threads) {
synchronized (threads[i]) { synchronized (thread) {
threads[i].start(); thread.start();
threads[i].wait(); thread.wait();
} }
} }
for (int i = 0; i < threads.length; ++i) { for (Thread thread : threads) {
synchronized (threads[i]) { synchronized (thread) {
threads[i].notifyAll(); thread.notifyAll();
} }
} }
Thread.sleep(1000); Thread.sleep(1000);
for (int i = 0; i < threads.length; ++i) { for (Thread thread : threads) {
threads[i].interrupt(); thread.interrupt();
} }
for (int i = 0; i < threads.length; ++i) { for (Thread thread : threads) {
synchronized (threads[i]) { synchronized (thread) {
threads[i].join(); thread.join();
} }
} }
@ -777,27 +777,27 @@ public class LRUMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
}; };
} }
for (int i = 0; i < threads.length; ++i) { for (Thread thread : threads) {
synchronized (threads[i]) { synchronized (thread) {
threads[i].start(); thread.start();
threads[i].wait(); thread.wait();
} }
} }
for (int i = 0; i < threads.length; ++i) { for (Thread thread : threads) {
synchronized (threads[i]) { synchronized (thread) {
threads[i].notifyAll(); thread.notifyAll();
} }
} }
Thread.sleep(1000); Thread.sleep(1000);
for (int i = 0; i < threads.length; ++i) { for (Thread thread : threads) {
threads[i].interrupt(); thread.interrupt();
} }
for (int i = 0; i < threads.length; ++i) { for (Thread thread : threads) {
synchronized (threads[i]) { synchronized (thread) {
threads[i].join(); thread.join();
} }
} }

View File

@ -196,9 +196,7 @@ public class MultiKeyMapTest<K, V> extends AbstractIterableMapTest<MultiKey<? ex
MultiKeyMap<K, V> multimap = getMap(); MultiKeyMap<K, V> multimap = getMap();
MultiKey<K>[] keys = getMultiKeyKeys(); MultiKey<K>[] keys = getMultiKeyKeys();
for (int i = 0; i < keys.length; i++) { for (MultiKey<K> key : keys) {
MultiKey<K> key = keys[i];
switch (key.size()) { switch (key.size()) {
case 2: case 2:
assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1))); assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1)));

View File

@ -407,8 +407,7 @@ public class MultiValueMapTest<K, V> extends AbstractObjectTest {
Map<?,?> map = (Map<?,?>) makeObject(); Map<?,?> map = (Map<?,?>) makeObject();
Map<?,?> map2 = (Map<?,?>) readExternalFormFromDisk(getCanonicalFullCollectionName(map)); Map<?,?> map2 = (Map<?,?>) readExternalFormFromDisk(getCanonicalFullCollectionName(map));
assertEquals("Map is the right size", map.size(), map2.size()); assertEquals("Map is the right size", map.size(), map2.size());
for (Iterator<?> it = map.keySet().iterator(); it.hasNext();) { for (Object key : map.keySet()) {
Object key = it.next();
assertEquals( "Map had inequal elements", map.get(key), map2.get(key) ); assertEquals( "Map had inequal elements", map.get(key), map2.get(key) );
map2.remove(key); map2.remove(key);
} }

View File

@ -85,14 +85,14 @@ public class TransformedSetTest<E> extends AbstractSetTest<E> {
public void testTransformedSet_decorateTransform() { public void testTransformedSet_decorateTransform() {
Set<Object> originalSet = new HashSet<Object>(); Set<Object> originalSet = new HashSet<Object>();
Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"}; Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
for (int i = 0; i < els.length; i++) { for (Object el : els) {
originalSet.add(els[i]); originalSet.add(el);
} }
Set<?> set = TransformedSet.transformedSet(originalSet, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); Set<?> set = TransformedSet.transformedSet(originalSet, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(els.length, set.size()); assertEquals(els.length, set.size());
for (int i = 0; i < els.length; i++) { for (Object el : els) {
assertEquals(true, set.contains(new Integer((String) els[i]))); assertEquals(true, set.contains(new Integer((String) el)));
assertEquals(false, set.contains(els[i])); assertEquals(false, set.contains(el));
} }
assertEquals(false, set.remove(els[0])); assertEquals(false, set.remove(els[0]));

View File

@ -78,13 +78,13 @@ public class TransformedSortedSetTest<E> extends AbstractSortedSetTest<E> {
public void testTransformedSet_decorateTransform() { public void testTransformedSet_decorateTransform() {
Set<Object> originalSet = new TreeSet<Object>(); Set<Object> originalSet = new TreeSet<Object>();
Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"}; Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
for (int i = 0; i < els.length; i++) { for (Object el : els) {
originalSet.add(els[i]); originalSet.add(el);
} }
Set<?> set = TransformedSortedSet.transformedSet(originalSet, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER); Set<?> set = TransformedSortedSet.transformedSet(originalSet, TransformedCollectionTest.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(els.length, set.size()); assertEquals(els.length, set.size());
for (int i = 0; i < els.length; i++) { for (Object el : els) {
assertEquals(true, set.contains(new Integer((String) els[i]))); assertEquals(true, set.contains(new Integer((String) el)));
} }
assertEquals(true, set.remove(new Integer((String) els[0]))); assertEquals(true, set.remove(new Integer((String) els[0])));