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