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:
parent
e79d3ffa4b
commit
745dd6673f
|
@ -896,8 +896,8 @@ public class CollectionUtils {
|
|||
*/
|
||||
public static <C> boolean addAll(Collection<C> 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;
|
||||
}
|
||||
|
|
|
@ -92,11 +92,11 @@ public class ComparatorUtils {
|
|||
*/
|
||||
public static <E extends Comparable<? super E>> Comparator<E> chainedComparator(Comparator<E>[] comparators) {
|
||||
ComparatorChain<E> chain = new ComparatorChain<E>();
|
||||
for (int i = 0; i < comparators.length; i++) {
|
||||
if (comparators[i] == null) {
|
||||
for (Comparator<E> comparator : comparators) {
|
||||
if (comparator == null) {
|
||||
throw new NullPointerException("Comparator cannot be null");
|
||||
}
|
||||
chain.addComparator(comparators[i]);
|
||||
chain.addComparator(comparator);
|
||||
}
|
||||
return chain;
|
||||
}
|
||||
|
|
|
@ -756,8 +756,7 @@ public class ExtendedProperties extends Hashtable<String, Object> {
|
|||
} else if (value instanceof List) {
|
||||
@SuppressWarnings("unchecked") // we only add Strings to the Lists
|
||||
List<String> values = (List<String>) value;
|
||||
for (Iterator<String> 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<String, Object> {
|
|||
|
||||
// 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<String, Object> {
|
|||
} else {
|
||||
@SuppressWarnings("unchecked") // OK to downcast here
|
||||
Map<String, Object> mapso = (Map<String,Object>) map;
|
||||
for (Iterator<Map.Entry<String, Object>> it = mapso.entrySet().iterator(); it.hasNext(); ) {
|
||||
Map.Entry<String,Object> entry = it.next();
|
||||
for (java.util.Map.Entry<String, Object> entry : mapso.entrySet()) {
|
||||
put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <K, V> Properties toProperties(final Map<K, V> map) {
|
||||
Properties answer = new Properties();
|
||||
if (map != null) {
|
||||
for (Iterator<Map.Entry<K, V>> iter = map.entrySet().iterator(); iter.hasNext();) {
|
||||
Map.Entry<?, ?> entry = iter.next();
|
||||
for (Entry<K, V> 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 <K, V> Map<V, K> invertMap(Map<K, V> map) {
|
||||
Map<V, K> out = new HashMap<V, K>(map.size());
|
||||
for (Iterator<Map.Entry<K, V>> it = map.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry<K, V> entry = it.next();
|
||||
for (Entry<K, V> 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<K, V> entry = (Map.Entry<K, V>) array[i];
|
||||
for (Object element : array) {
|
||||
Map.Entry<K, V> entry = (Map.Entry<K, V>) element;
|
||||
map.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
} else if (obj instanceof KeyValue) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
KeyValue<K, V> keyval = (KeyValue<K, V>) array[i];
|
||||
for (Object element : array) {
|
||||
KeyValue<K, V> keyval = (KeyValue<K, V>) element;
|
||||
map.put(keyval.getKey(), keyval.getValue());
|
||||
}
|
||||
} else if (obj instanceof Object[]) {
|
||||
|
|
|
@ -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<E> implements Bag<E> {
|
|||
*/
|
||||
protected void doWriteObject(ObjectOutputStream out) throws IOException {
|
||||
out.writeInt(map.size());
|
||||
for (Iterator<Map.Entry<E, MutableInteger>> it = map.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry<E, MutableInteger> entry = it.next();
|
||||
for (Entry<E, MutableInteger> entry : map.entrySet()) {
|
||||
out.writeObject(entry.getKey());
|
||||
out.writeInt(entry.getValue().value);
|
||||
}
|
||||
|
@ -540,8 +540,7 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
|
|||
if (other.size() != size()) {
|
||||
return false;
|
||||
}
|
||||
for (Iterator<E> 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<E> implements Bag<E> {
|
|||
@Override
|
||||
public int hashCode() {
|
||||
int total = 0;
|
||||
for (Iterator<Map.Entry<E, MutableInteger>> it = map.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry<E, MutableInteger> entry = it.next();
|
||||
for (Entry<E, MutableInteger> entry : map.entrySet()) {
|
||||
E element = entry.getKey();
|
||||
MutableInteger count = entry.getValue();
|
||||
total += (element == null ? 0 : element.hashCode()) ^ count.value;
|
||||
|
|
|
@ -78,8 +78,8 @@ public class TransformedBag<E> extends TransformedCollection<E> implements Bag<E
|
|||
@SuppressWarnings("unchecked") // Bag is of type E
|
||||
E[] values = (E[]) bag.toArray();
|
||||
bag.clear();
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
decorated.decorated().add(transformer.transform(values[i]));
|
||||
for (E value : values) {
|
||||
decorated.decorated().add(transformer.transform(value));
|
||||
}
|
||||
}
|
||||
return decorated;
|
||||
|
|
|
@ -78,8 +78,8 @@ public class TransformedSortedBag<E> extends TransformedBag<E> implements Sorted
|
|||
@SuppressWarnings("unchecked") // bag is type E
|
||||
E[] values = (E[]) bag.toArray();
|
||||
bag.clear();
|
||||
for(int i=0; i<values.length; i++) {
|
||||
decorated.decorated().add(transformer.transform(values[i]));
|
||||
for (E value : values) {
|
||||
decorated.decorated().add(transformer.transform(value));
|
||||
}
|
||||
}
|
||||
return decorated;
|
||||
|
|
|
@ -130,8 +130,8 @@ public class BoundedFifoBuffer<E> extends AbstractCollection<E>
|
|||
private void writeObject(ObjectOutputStream out) throws IOException {
|
||||
out.defaultWriteObject();
|
||||
out.writeInt(size());
|
||||
for (Iterator<E> it = iterator(); it.hasNext();) {
|
||||
out.writeObject(it.next());
|
||||
for (E e : this) {
|
||||
out.writeObject(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -79,8 +79,8 @@ public class TransformedBuffer<E> extends TransformedCollection<E> implements Bu
|
|||
@SuppressWarnings("unchecked") // buffer is type <E>
|
||||
E[] values = (E[]) buffer.toArray();
|
||||
buffer.clear();
|
||||
for(int i=0; i<values.length; i++) {
|
||||
decorated.decorated().add(transformer.transform(values[i]));
|
||||
for (E value : values) {
|
||||
decorated.decorated().add(transformer.transform(value));
|
||||
}
|
||||
}
|
||||
return decorated;
|
||||
|
|
|
@ -110,8 +110,8 @@ public class UnboundedFifoBuffer<E> extends AbstractCollection<E> implements Buf
|
|||
out.defaultWriteObject();
|
||||
out.writeInt(size());
|
||||
out.writeInt(buffer.length);
|
||||
for (Iterator<E> it = iterator(); it.hasNext();) {
|
||||
out.writeObject(it.next());
|
||||
for (E e : this) {
|
||||
out.writeObject(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -85,8 +85,8 @@ public class TransformedCollection<E> extends AbstractCollectionDecorator<E> {
|
|||
@SuppressWarnings("unchecked") // collection is of type E
|
||||
E[] values = (E[]) collection.toArray();
|
||||
collection.clear();
|
||||
for(int i=0; i<values.length; i++) {
|
||||
decorated.decorated().add(transformer.transform(values[i]));
|
||||
for (E value : values) {
|
||||
decorated.decorated().add(transformer.transform(value));
|
||||
}
|
||||
}
|
||||
return decorated;
|
||||
|
|
|
@ -94,8 +94,8 @@ public class FixedOrderComparator<T> implements Comparator<T>, 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -106,8 +106,8 @@ public final class AnyPredicate<T> implements Predicate<T>, PredicateDecorator<T
|
|||
* @return true if any decorated predicate return true
|
||||
*/
|
||||
public boolean evaluate(T object) {
|
||||
for (int i = 0; i < iPredicates.length; i++) {
|
||||
if (iPredicates[i].evaluate(object)) {
|
||||
for (Predicate<? super T> iPredicate : iPredicates) {
|
||||
if (iPredicate.evaluate(object)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,8 +98,8 @@ public class ChainedClosure<E> implements Closure<E>, 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<? super E> iClosure : iClosures) {
|
||||
iClosure.execute(input);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -96,8 +96,8 @@ public class ChainedTransformer<T> implements Transformer<T, T>, 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<? super T, ? extends T> iTransformer : iTransformers) {
|
||||
object = iTransformer.transform(object);
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
|
|
@ -96,8 +96,8 @@ public final class NonePredicate<T> implements Predicate<T>, 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<? super T> iPredicate : iPredicates) {
|
||||
if (iPredicate.evaluate(object)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,8 +98,8 @@ public final class OnePredicate<T> implements Predicate<T>, PredicateDecorator<T
|
|||
*/
|
||||
public boolean evaluate(T object) {
|
||||
boolean match = false;
|
||||
for (int i = 0; i < iPredicates.length; i++) {
|
||||
if (iPredicates[i].evaluate(object)) {
|
||||
for (Predicate<? super T> iPredicate : iPredicates) {
|
||||
if (iPredicate.evaluate(object)) {
|
||||
if (match) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -133,8 +133,8 @@ public class CollatingIterator<E> implements Iterator<E> {
|
|||
*/
|
||||
public CollatingIterator(final Comparator<? super E> comp, final Iterator<? extends E>[] iterators) {
|
||||
this(comp, iterators.length);
|
||||
for (int i = 0; i < iterators.length; i++) {
|
||||
addIterator(iterators[i]);
|
||||
for (Iterator<? extends E> iterator : iterators) {
|
||||
addIterator(iterator);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -125,8 +125,8 @@ public class IteratorChain<E> implements Iterator<E> {
|
|||
*/
|
||||
public IteratorChain(Iterator<? extends E>... iteratorChain) {
|
||||
super();
|
||||
for (int i = 0; i < iteratorChain.length; i++) {
|
||||
addIterator(iteratorChain[i]);
|
||||
for (Iterator<? extends E> element : iteratorChain) {
|
||||
addIterator(element);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -260,9 +260,9 @@ public class MultiKey<K> 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;
|
||||
|
|
|
@ -598,8 +598,8 @@ public abstract class AbstractLinkedList<E> implements List<E> {
|
|||
protected void doWriteObject(ObjectOutputStream outputStream) throws IOException {
|
||||
// Write the size so we know how many nodes to read back
|
||||
outputStream.writeInt(size());
|
||||
for (Iterator<E> itr = iterator(); itr.hasNext();) {
|
||||
outputStream.writeObject(itr.next());
|
||||
for (E e : this) {
|
||||
outputStream.writeObject(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -259,8 +259,8 @@ public class SetUniqueList<E> extends AbstractSerializableListDecorator<E> {
|
|||
@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<E> extends AbstractSerializableListDecorator<E> {
|
|||
@Override
|
||||
public boolean retainAll(Collection<?> coll) {
|
||||
Set<Object> setRetainAll = new HashSet<Object>();
|
||||
for (Iterator<?> it = coll.iterator(); it.hasNext();) {
|
||||
Object next = it.next();
|
||||
for (Object next : coll) {
|
||||
if (set.contains(next)) {
|
||||
setRetainAll.add(next);
|
||||
}
|
||||
|
|
|
@ -82,8 +82,8 @@ public class TransformedList<E> extends TransformedCollection<E> implements List
|
|||
@SuppressWarnings("unchecked") // list is of type E
|
||||
E[] values = (E[]) list.toArray();
|
||||
list.clear();
|
||||
for(int i=0; i<values.length; i++) {
|
||||
decorated.decorated().add(transformer.transform(values[i]));
|
||||
for (E value : values) {
|
||||
decorated.decorated().add(transformer.transform(value));
|
||||
}
|
||||
}
|
||||
return decorated;
|
||||
|
|
|
@ -239,8 +239,8 @@ public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements Iterab
|
|||
@Override
|
||||
public boolean containsValue(Object value) {
|
||||
if (value == null) {
|
||||
for (int i = 0, isize = data.length; i < isize; i++) {
|
||||
HashEntry<K, V> entry = data[i];
|
||||
for (HashEntry<K, V> element : data) {
|
||||
HashEntry<K, V> entry = element;
|
||||
while (entry != null) {
|
||||
if (entry.getValue() == null) {
|
||||
return true;
|
||||
|
@ -249,8 +249,8 @@ public class AbstractHashedMap<K, V> extends AbstractMap<K, V> implements Iterab
|
|||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0, isize = data.length; i < isize; i++) {
|
||||
HashEntry<K, V> entry = data[i];
|
||||
for (HashEntry<K, V> element : data) {
|
||||
HashEntry<K, V> entry = element;
|
||||
while (entry != null) {
|
||||
if (isEqualValue(value, entry.getValue())) {
|
||||
return true;
|
||||
|
|
|
@ -419,8 +419,8 @@ public class MultiValueMap<K, V> extends AbstractMapDecorator<K, Object> impleme
|
|||
@Override
|
||||
public Iterator<V> iterator() {
|
||||
final IteratorChain<V> chain = new IteratorChain<V>();
|
||||
for (Iterator<K> it = keySet().iterator(); it.hasNext();) {
|
||||
chain.addIterator(new ValuesIterator(it.next()));
|
||||
for (K k : keySet()) {
|
||||
chain.addIterator(new ValuesIterator(k));
|
||||
}
|
||||
return chain;
|
||||
}
|
||||
|
|
|
@ -218,8 +218,8 @@ public class ListOrderedSet<E>
|
|||
@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<E>
|
|||
@Override
|
||||
public boolean retainAll(Collection<?> coll) {
|
||||
Set<Object> collectionRetainAll = new HashSet<Object>();
|
||||
for (Iterator<?> it = coll.iterator(); it.hasNext();) {
|
||||
Object next = it.next();
|
||||
for (Object next : coll) {
|
||||
if (collection.contains(next)) {
|
||||
collectionRetainAll.add(next);
|
||||
}
|
||||
|
|
|
@ -77,8 +77,8 @@ public class TransformedSet<E> extends TransformedCollection<E> implements Set<E
|
|||
@SuppressWarnings("unchecked") // set is type E
|
||||
E[] values = (E[]) set.toArray();
|
||||
set.clear();
|
||||
for(int i=0; i<values.length; i++) {
|
||||
decorated.decorated().add(transformer.transform(values[i]));
|
||||
for (E value : values) {
|
||||
decorated.decorated().add(transformer.transform(value));
|
||||
}
|
||||
}
|
||||
return decorated;
|
||||
|
|
|
@ -79,8 +79,8 @@ public class TransformedSortedSet<E> extends TransformedSet<E> implements Sorted
|
|||
@SuppressWarnings("unchecked") // set is type E
|
||||
E[] values = (E[]) set.toArray();
|
||||
set.clear();
|
||||
for(int i=0; i<values.length; i++) {
|
||||
decorated.decorated().add(transformer.transform(values[i]));
|
||||
for (E value : values) {
|
||||
decorated.decorated().add(transformer.transform(value));
|
||||
}
|
||||
}
|
||||
return decorated;
|
||||
|
|
|
@ -323,9 +323,9 @@ class BulkTestSuiteMaker {
|
|||
void make(BulkTest bulk) {
|
||||
Class<? extends BulkTest> 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 <T extends BulkTest> BulkTest makeFirstTestCase(Class<T> 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.");
|
||||
|
|
|
@ -353,10 +353,10 @@ public abstract class AbstractBagTest<T> 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<T> 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);
|
||||
|
|
|
@ -62,15 +62,15 @@ public class TransformedBagTest<T> extends AbstractBagTest<T> {
|
|||
public void testTransformedBag_decorateTransform() {
|
||||
Bag<T> originalBag = new HashBag<T>();
|
||||
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<T> bag = TransformedBag.transformedBag(originalBag,
|
||||
(Transformer<T, T>) 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]));
|
||||
|
|
|
@ -58,13 +58,13 @@ public class TransformedSortedBagTest<T> extends AbstractSortedBagTest<T> {
|
|||
public void testTransformedBag_decorateTransform() {
|
||||
Bag<Object> originalBag = new TreeBag<Object>();
|
||||
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])));
|
||||
|
|
|
@ -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]));
|
||||
|
|
|
@ -500,10 +500,10 @@ public abstract class AbstractCollectionTest<E> 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<E> 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<E> 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<E> 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<E> 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<E> extends AbstractObjectTest {
|
|||
//
|
||||
// see areEqualElementsDistinguishable()
|
||||
if (!areEqualElementsDistinguishable()) {
|
||||
getConfirmed().remove(elements[i]);
|
||||
getConfirmed().remove(element);
|
||||
verify();
|
||||
}
|
||||
|
||||
|
@ -1043,9 +1043,9 @@ public abstract class AbstractCollectionTest<E> 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<E> extends AbstractObjectTest {
|
|||
// Figure out if they're all the same class
|
||||
// TODO: It'd be nicer to detect a common superclass
|
||||
HashSet<Class<?>> classes = new HashSet<Class<?>>();
|
||||
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;
|
||||
|
||||
|
|
|
@ -76,9 +76,9 @@ public class CompositeCollectionTest<E> extends AbstractCollectionTest<E> {
|
|||
public Collection<E> makeFullCollection() {
|
||||
CompositeCollection<E> compositeCollection = new CompositeCollection<E>();
|
||||
E[] elements = getFullElements();
|
||||
for (int i = 0; i < elements.length; i++) {
|
||||
for (E element : elements) {
|
||||
Collection<E> summand = new HashSet<E>();
|
||||
summand.add(elements[i]);
|
||||
summand.add(element);
|
||||
compositeCollection.addComposited(summand);
|
||||
}
|
||||
return compositeCollection;
|
||||
|
|
|
@ -100,14 +100,14 @@ public class TransformedCollectionTest extends AbstractCollectionTest<Object> {
|
|||
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<Object> 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]));
|
||||
|
|
|
@ -85,8 +85,8 @@ public class FixedOrderComparatorTest extends AbstractComparatorTest<String> {
|
|||
@Test
|
||||
public void testConstructorPlusAdd() {
|
||||
FixedOrderComparator<String> comparator = new FixedOrderComparator<String>();
|
||||
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);
|
||||
|
|
|
@ -117,10 +117,10 @@ public class SequencesComparatorTest {
|
|||
for (int lg=0; lg<lgMax; ++lg) {
|
||||
List<List<String>> newTab = new ArrayList<List<String>>();
|
||||
newTab.add(new ArrayList<String>());
|
||||
for (int k = 0; k < shadokAlph.length; k++) {
|
||||
for (String element : shadokAlph) {
|
||||
for (List<String> sentence : shadokSentences) {
|
||||
List<String> newSentence = new ArrayList<String>(sentence);
|
||||
newSentence.add(shadokAlph[k]);
|
||||
newSentence.add(element);
|
||||
newTab.add(newSentence);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,8 +61,8 @@ public class ArrayIterator2Test<E> extends AbstractIteratorTest<E> {
|
|||
|
||||
public void testIterator() {
|
||||
Iterator<E> 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);
|
||||
|
|
|
@ -51,8 +51,7 @@ public class ArrayIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||
|
||||
public void testIterator() {
|
||||
Iterator<E> 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);
|
||||
|
|
|
@ -92,7 +92,7 @@ public class FilterIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||
}
|
||||
|
||||
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<E> extends AbstractIteratorTest<E> {
|
|||
private void verifyElementsInPredicate(final String[] elements) {
|
||||
Predicate<E> pred = new Predicate<E>() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,8 +74,7 @@ public class IteratorChainTest extends AbstractIteratorTest<String> {
|
|||
|
||||
public void testIterator() {
|
||||
Iterator<String> 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<String> {
|
|||
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -65,8 +65,7 @@ public class ListIteratorWrapper2Test<E> extends AbstractIteratorTest<E> {
|
|||
|
||||
public void testIterator() {
|
||||
ListIterator<E> 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<E> extends AbstractIteratorTest<E> {
|
|||
}
|
||||
|
||||
// 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);
|
||||
|
|
|
@ -66,8 +66,7 @@ public class ListIteratorWrapperTest<E> extends AbstractIteratorTest<E> {
|
|||
|
||||
public void testIterator() {
|
||||
ListIterator<E> 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<E> extends AbstractIteratorTest<E> {
|
|||
}
|
||||
|
||||
// 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);
|
||||
|
|
|
@ -67,8 +67,7 @@ public class ObjectArrayIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||
|
||||
public void testIterator() {
|
||||
Iterator<E> 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);
|
||||
|
|
|
@ -68,8 +68,7 @@ public class UniqueFilterIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||
|
||||
public void testIterator() {
|
||||
Iterator<E> 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 );
|
||||
|
|
|
@ -487,9 +487,9 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
|||
}
|
||||
|
||||
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<E> extends AbstractCollectionTest<E> {
|
|||
}
|
||||
|
||||
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<E> extends AbstractCollectionTest<E> {
|
|||
ListIterator<E> iter1 = list1.listIterator();
|
||||
ListIterator<E> 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<E> extends AbstractCollectionTest<E> {
|
|||
resetFull();
|
||||
ListIterator<E> iter1 = getCollection().listIterator();
|
||||
ListIterator<E> 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<E> extends AbstractCollectionTest<E> {
|
|||
*/
|
||||
protected void failFastAll(List<E> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1516,9 +1516,9 @@ public class CursorableLinkedListTest<E> extends AbstractLinkedListTest<E> {
|
|||
".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]);
|
||||
}
|
||||
|
|
|
@ -94,20 +94,20 @@ public class SetUniqueListTest<E> extends AbstractListTest<E> {
|
|||
ListIterator<E> iter1 = list1.listIterator();
|
||||
ListIterator<E> 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<E> extends AbstractListTest<E> {
|
|||
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();
|
||||
|
|
|
@ -116,14 +116,14 @@ public class TransformedListTest<E> extends AbstractListTest<E> {
|
|||
public void testTransformedList_decorateTransform() {
|
||||
List<Object> originalList = new ArrayList<Object>();
|
||||
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]));
|
||||
|
|
|
@ -632,9 +632,9 @@ public abstract class AbstractMapTest<K, V> 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<K, V> 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<K, V> 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<K, V> 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<K, V> 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<K, V> extends AbstractObjectTest {
|
|||
"\nTest: " + test + "\nReal: " + known,
|
||||
known.containsAll(test));
|
||||
// originally coded to use a HashBag, but now separate jar so...
|
||||
for (Iterator<V> 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());
|
||||
|
|
|
@ -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<K, V> extends AbstractMapTest<K, V>
|
|||
public TestHeadMap(AbstractMapTest<K, V> main) {
|
||||
super("SortedMap.HeadMap", main);
|
||||
Map<K, V> sm = main.makeFullMap();
|
||||
for (Iterator<Map.Entry<K, V>> it = sm.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry<K, V> entry = it.next();
|
||||
for (Entry<K, V> entry : sm.entrySet()) {
|
||||
this.subSortedKeys.add(entry.getKey());
|
||||
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) {
|
||||
super("SortedMap.TailMap", main);
|
||||
Map<K, V> sm = main.makeFullMap();
|
||||
for (Iterator<Map.Entry<K, V>> it = sm.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry<K, V> entry = it.next();
|
||||
for (Entry<K, V> entry : sm.entrySet()) {
|
||||
this.subSortedKeys.add(entry.getKey());
|
||||
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) {
|
||||
super("SortedMap.SubMap", main);
|
||||
Map<K, V> sm = main.makeFullMap();
|
||||
for (Iterator<Map.Entry<K, V>> it = sm.entrySet().iterator(); it.hasNext();) {
|
||||
Map.Entry<K, V> entry = it.next();
|
||||
for (Entry<K, V> entry : sm.entrySet()) {
|
||||
this.subSortedKeys.add(entry.getKey());
|
||||
this.subSortedValues.add(entry.getValue());
|
||||
}
|
||||
|
|
|
@ -132,8 +132,8 @@ public class CaseInsensitiveMapTest<K, V> extends AbstractIterableMapTest<K, V>
|
|||
};
|
||||
|
||||
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<String, String> map = new CaseInsensitiveMap<String, String>();
|
||||
|
|
|
@ -529,27 +529,27 @@ public class LRUMapTest<K, V> extends AbstractOrderedMapTest<K, V> {
|
|||
};
|
||||
}
|
||||
|
||||
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<K, V> extends AbstractOrderedMapTest<K, V> {
|
|||
};
|
||||
}
|
||||
|
||||
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<K, V> extends AbstractOrderedMapTest<K, V> {
|
|||
};
|
||||
}
|
||||
|
||||
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<K, V> extends AbstractOrderedMapTest<K, V> {
|
|||
};
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -196,9 +196,7 @@ public class MultiKeyMapTest<K, V> extends AbstractIterableMapTest<MultiKey<? ex
|
|||
MultiKeyMap<K, V> multimap = getMap();
|
||||
MultiKey<K>[] keys = getMultiKeyKeys();
|
||||
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
MultiKey<K> key = keys[i];
|
||||
|
||||
for (MultiKey<K> key : keys) {
|
||||
switch (key.size()) {
|
||||
case 2:
|
||||
assertEquals(true, multimap.containsKey(key.getKey(0), key.getKey(1)));
|
||||
|
|
|
@ -407,8 +407,7 @@ public class MultiValueMapTest<K, V> 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);
|
||||
}
|
||||
|
|
|
@ -85,14 +85,14 @@ public class TransformedSetTest<E> extends AbstractSetTest<E> {
|
|||
public void testTransformedSet_decorateTransform() {
|
||||
Set<Object> originalSet = new HashSet<Object>();
|
||||
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]));
|
||||
|
|
|
@ -78,13 +78,13 @@ public class TransformedSortedSetTest<E> extends AbstractSortedSetTest<E> {
|
|||
public void testTransformedSet_decorateTransform() {
|
||||
Set<Object> originalSet = new TreeSet<Object>();
|
||||
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])));
|
||||
|
|
Loading…
Reference in New Issue