Use Java 5 for each loop
This commit is contained in:
parent
0801d0d4ca
commit
8e4c50f928
|
@ -432,7 +432,6 @@ public class CollectionUtils {
|
|||
if (coll2.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
final Iterator<?> it = coll1.iterator();
|
||||
final Set<Object> elementsAlreadySeen = new HashSet<>();
|
||||
for (final Object nextElement : coll2) {
|
||||
if (elementsAlreadySeen.contains(nextElement)) {
|
||||
|
@ -440,8 +439,7 @@ public class CollectionUtils {
|
|||
}
|
||||
|
||||
boolean foundCurrentElement = false;
|
||||
while (it.hasNext()) {
|
||||
final Object p = it.next();
|
||||
for (final Object p : coll1) {
|
||||
elementsAlreadySeen.add(p);
|
||||
if (Objects.equals(nextElement, p)) {
|
||||
foundCurrentElement = true;
|
||||
|
|
|
@ -35,7 +35,6 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListResourceBundle;
|
||||
import java.util.Map;
|
||||
|
@ -274,10 +273,8 @@ public class MapUtilsTest {
|
|||
@Override
|
||||
public Object[][] getContents() {
|
||||
final Object[][] contents = new Object[in.size()][2];
|
||||
final Iterator<String> i = in.keySet().iterator();
|
||||
int n = 0;
|
||||
while (i.hasNext()) {
|
||||
final Object key = i.next();
|
||||
for (final Object key : in.keySet()) {
|
||||
final Object val = in.get(key);
|
||||
contents[n][0] = key;
|
||||
contents[n][1] = val;
|
||||
|
|
|
@ -137,9 +137,7 @@ public class DualTreeBidiMap2Test<K extends Comparable<K>, V extends Comparable<
|
|||
newSortedKeys = Collections.unmodifiableList(newSortedKeys);
|
||||
|
||||
final Iterator<K> mapIter = sm.keySet().iterator();
|
||||
final Iterator<K> expectedIter = newSortedKeys.iterator();
|
||||
while (expectedIter.hasNext()) {
|
||||
final K expectedKey = expectedIter.next();
|
||||
for (final K expectedKey : newSortedKeys) {
|
||||
final K mapKey = mapIter.next();
|
||||
assertNotNull("key in sorted list may not be null", expectedKey);
|
||||
assertNotNull("key in map may not be null", mapKey);
|
||||
|
|
|
@ -91,12 +91,10 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
|||
|
||||
int i = 0;
|
||||
final Iterator<E> iterator1 = list1.iterator();
|
||||
final Iterator<E> iterator2 = list2.iterator();
|
||||
final E[] array = (E[]) list1.toArray();
|
||||
while (iterator2.hasNext()) {
|
||||
for (Object o2 : list2) {
|
||||
assertTrue("List iterator should have next", iterator1.hasNext());
|
||||
final Object o1 = iterator1.next();
|
||||
Object o2 = iterator2.next();
|
||||
assertEquals("Iterator elements should be equal", o1, o2);
|
||||
o2 = list1.get(i);
|
||||
assertEquals("get should return correct element", o1, o2);
|
||||
|
@ -428,9 +426,7 @@ public abstract class AbstractListTest<E> extends AbstractCollectionTest<E> {
|
|||
final List<E> list1 = getCollection();
|
||||
final List<E> list2 = getConfirmed();
|
||||
|
||||
final Iterator<E> iterator = list2.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final E element = iterator.next();
|
||||
for (final E element : list2) {
|
||||
assertEquals("lastIndexOf should return correct result",
|
||||
list1.lastIndexOf(element), list2.lastIndexOf(element));
|
||||
verify();
|
||||
|
|
|
@ -1646,10 +1646,8 @@ public abstract class AbstractMapTest<K, V> extends AbstractObjectTest {
|
|||
@Test
|
||||
public void testMapEntrySetIteratorEntry() {
|
||||
resetFull();
|
||||
final Iterator<Map.Entry<K, V>> it = getCollection().iterator();
|
||||
int count = 0;
|
||||
while (it.hasNext()) {
|
||||
final Map.Entry<K, V> entry = it.next();
|
||||
for (final Entry<K, V> entry : getCollection()) {
|
||||
assertTrue(AbstractMapTest.this.getMap().containsKey(entry.getKey()));
|
||||
assertTrue(AbstractMapTest.this.getMap().containsValue(entry.getValue()));
|
||||
if (!isGetStructuralModify()) {
|
||||
|
|
|
@ -428,9 +428,7 @@ public abstract class AbstractMultiValuedMapTest<K, V> extends AbstractObjectTes
|
|||
public void testEntriesCollectionIterator() {
|
||||
final MultiValuedMap<K, V> map = makeFullMap();
|
||||
final Collection<V> values = new ArrayList<>(map.values());
|
||||
final Iterator<Map.Entry<K, V>> iterator = map.entries().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final Map.Entry<K, V> entry = iterator.next();
|
||||
for (final Entry<K, V> entry : map.entries()) {
|
||||
assertTrue(map.containsMapping(entry.getKey(), entry.getValue()));
|
||||
assertTrue(values.contains(entry.getValue()));
|
||||
if (isRemoveSupported()) {
|
||||
|
|
Loading…
Reference in New Issue