Use for-each loop
This commit is contained in:
parent
c811f541aa
commit
29d79003ea
|
@ -221,10 +221,8 @@ public class ListUtils {
|
|||
return 0;
|
||||
}
|
||||
int hashCode = 1;
|
||||
final Iterator<?> it = list.iterator();
|
||||
|
||||
while (it.hasNext()) {
|
||||
final Object obj = it.next();
|
||||
for (final Object obj : list) {
|
||||
hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode());
|
||||
}
|
||||
return hashCode;
|
||||
|
|
|
@ -25,10 +25,9 @@ import java.util.Collections;
|
|||
import java.util.Deque;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.SortedMap;
|
||||
|
@ -1497,9 +1496,7 @@ public class MapUtils {
|
|||
*/
|
||||
public static <K, V, E> void populateMap(final Map<K, V> map, final Iterable<? extends E> elements,
|
||||
final Transformer<E, K> keyTransformer, final Transformer<E, V> valueTransformer) {
|
||||
final Iterator<? extends E> iter = elements.iterator();
|
||||
while (iter.hasNext()) {
|
||||
final E temp = iter.next();
|
||||
for (final E temp : elements) {
|
||||
map.put(keyTransformer.transform(temp), valueTransformer.transform(temp));
|
||||
}
|
||||
}
|
||||
|
@ -1534,9 +1531,7 @@ public class MapUtils {
|
|||
*/
|
||||
public static <K, V, E> void populateMap(final MultiMap<K, V> map, final Iterable<? extends E> elements,
|
||||
final Transformer<E, K> keyTransformer, final Transformer<E, V> valueTransformer) {
|
||||
final Iterator<? extends E> iter = elements.iterator();
|
||||
while (iter.hasNext()) {
|
||||
final E temp = iter.next();
|
||||
for (final E temp : elements) {
|
||||
map.put(keyTransformer.transform(temp), valueTransformer.transform(temp));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -150,9 +150,7 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
|
|||
* @return {@code true} if the Bag contains all the collection
|
||||
*/
|
||||
boolean containsAll(final Bag<?> other) {
|
||||
final Iterator<?> it = other.uniqueSet().iterator();
|
||||
while (it.hasNext()) {
|
||||
final Object current = it.next();
|
||||
for (Object current : other.uniqueSet()) {
|
||||
if (getCount(current) < other.getCount(current)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -278,9 +276,8 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
|
|||
@Override
|
||||
public boolean addAll(final Collection<? extends E> coll) {
|
||||
boolean changed = false;
|
||||
final Iterator<? extends E> i = coll.iterator();
|
||||
while (i.hasNext()) {
|
||||
final boolean added = add(i.next());
|
||||
for (final E current : coll) {
|
||||
final boolean added = add(current);
|
||||
changed = changed || added;
|
||||
}
|
||||
return changed;
|
||||
|
@ -352,9 +349,8 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
|
|||
public boolean removeAll(final Collection<?> coll) {
|
||||
boolean result = false;
|
||||
if (coll != null) {
|
||||
final Iterator<?> i = coll.iterator();
|
||||
while (i.hasNext()) {
|
||||
final boolean changed = remove(i.next(), 1);
|
||||
for (final Object current : coll) {
|
||||
final boolean changed = remove(current, 1);
|
||||
result = result || changed;
|
||||
}
|
||||
}
|
||||
|
@ -387,9 +383,7 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
|
|||
boolean retainAll(final Bag<?> other) {
|
||||
boolean result = false;
|
||||
final Bag<E> excess = new HashBag<>();
|
||||
final Iterator<E> i = uniqueSet().iterator();
|
||||
while (i.hasNext()) {
|
||||
final E current = i.next();
|
||||
for (final E current : uniqueSet()) {
|
||||
final int myCount = getCount(current);
|
||||
final int otherCount = other.getCount(current);
|
||||
if (1 <= otherCount && otherCount <= myCount) {
|
||||
|
@ -442,9 +436,7 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
|
|||
public Object[] toArray() {
|
||||
final Object[] result = new Object[size()];
|
||||
int i = 0;
|
||||
final Iterator<E> it = map.keySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
final E current = it.next();
|
||||
for (final E current : map.keySet()) {
|
||||
for (int index = getCount(current); index > 0; index--) {
|
||||
result[i++] = current;
|
||||
}
|
||||
|
@ -474,9 +466,7 @@ public abstract class AbstractMapBag<E> implements Bag<E> {
|
|||
}
|
||||
|
||||
int i = 0;
|
||||
final Iterator<E> it = map.keySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
final E current = it.next();
|
||||
for (final E current : map.keySet()) {
|
||||
for (int index = getCount(current); index > 0; index--) {
|
||||
// unsafe, will throw ArrayStoreException if types are not compatible, see javadoc
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -105,13 +105,7 @@ public final class CollectionBag<E> extends AbstractBagDecorator<E> {
|
|||
*/
|
||||
@Override
|
||||
public boolean containsAll(final Collection<?> coll) {
|
||||
final Iterator<?> e = coll.iterator();
|
||||
while (e.hasNext()) {
|
||||
if (!contains(e.next())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return coll.stream().allMatch(this::contains);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -132,9 +126,8 @@ public final class CollectionBag<E> extends AbstractBagDecorator<E> {
|
|||
@Override
|
||||
public boolean addAll(final Collection<? extends E> coll) {
|
||||
boolean changed = false;
|
||||
final Iterator<? extends E> i = coll.iterator();
|
||||
while (i.hasNext()) {
|
||||
final boolean added = add(i.next(), 1);
|
||||
for (final E current : coll) {
|
||||
final boolean added = add(current, 1);
|
||||
changed = changed || added;
|
||||
}
|
||||
return changed;
|
||||
|
@ -168,9 +161,7 @@ public final class CollectionBag<E> extends AbstractBagDecorator<E> {
|
|||
public boolean removeAll(final Collection<?> coll) {
|
||||
if (coll != null) {
|
||||
boolean result = false;
|
||||
final Iterator<?> i = coll.iterator();
|
||||
while (i.hasNext()) {
|
||||
final Object obj = i.next();
|
||||
for (final Object obj : coll) {
|
||||
final boolean changed = remove(obj, getCount(obj));
|
||||
result = result || changed;
|
||||
}
|
||||
|
|
|
@ -86,13 +86,7 @@ public final class CollectionSortedBag<E> extends AbstractSortedBagDecorator<E>
|
|||
|
||||
@Override
|
||||
public boolean containsAll(final Collection<?> coll) {
|
||||
final Iterator<?> e = coll.iterator();
|
||||
while (e.hasNext()) {
|
||||
if (!contains(e.next())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return coll.stream().allMatch(this::contains);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -103,9 +97,8 @@ public final class CollectionSortedBag<E> extends AbstractSortedBagDecorator<E>
|
|||
@Override
|
||||
public boolean addAll(final Collection<? extends E> coll) {
|
||||
boolean changed = false;
|
||||
final Iterator<? extends E> i = coll.iterator();
|
||||
while (i.hasNext()) {
|
||||
final boolean added = add(i.next(), 1);
|
||||
for (final E current : coll) {
|
||||
final boolean added = add(current, 1);
|
||||
changed = changed || added;
|
||||
}
|
||||
return changed;
|
||||
|
@ -120,9 +113,7 @@ public final class CollectionSortedBag<E> extends AbstractSortedBagDecorator<E>
|
|||
public boolean removeAll(final Collection<?> coll) {
|
||||
if (coll != null) {
|
||||
boolean result = false;
|
||||
final Iterator<?> i = coll.iterator();
|
||||
while (i.hasNext()) {
|
||||
final Object obj = i.next();
|
||||
for (final Object obj : coll) {
|
||||
final boolean changed = remove(obj, getCount(obj));
|
||||
result = result || changed;
|
||||
}
|
||||
|
|
|
@ -389,9 +389,8 @@ public abstract class AbstractDualBidiMap<K, V> implements BidiMap<K, V> {
|
|||
return false;
|
||||
}
|
||||
boolean modified = false;
|
||||
final Iterator<?> it = coll.iterator();
|
||||
while (it.hasNext()) {
|
||||
modified |= remove(it.next());
|
||||
for (final Object current : coll) {
|
||||
modified |= remove(current);
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
|
|
@ -153,9 +153,7 @@ public class CompositeCollection<E> implements Collection<E>, Serializable {
|
|||
return EmptyIterator.<E>emptyIterator();
|
||||
}
|
||||
final IteratorChain<E> chain = new IteratorChain<>();
|
||||
for (final Collection<E> item : all) {
|
||||
chain.addIterator(item.iterator());
|
||||
}
|
||||
all.forEach(item -> chain.addIterator(item.iterator()));
|
||||
return chain;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@ import java.io.IOException;
|
|||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.collections4.Predicate;
|
||||
|
@ -99,12 +98,7 @@ public class PredicatedMap<K, V>
|
|||
super(map);
|
||||
this.keyPredicate = keyPredicate;
|
||||
this.valuePredicate = valuePredicate;
|
||||
|
||||
final Iterator<Map.Entry<K, V>> it = map.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
final Map.Entry<K, V> entry = it.next();
|
||||
validate(entry.getKey(), entry.getValue());
|
||||
}
|
||||
map.forEach(this::validate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -211,9 +211,7 @@ public abstract class AbstractMultiSet<E> extends AbstractCollection<E> implemen
|
|||
@Override
|
||||
public boolean removeAll(final Collection<?> coll) {
|
||||
boolean result = false;
|
||||
final Iterator<?> i = coll.iterator();
|
||||
while (i.hasNext()) {
|
||||
final Object obj = i.next();
|
||||
for (final Object obj : coll) {
|
||||
final boolean changed = remove(obj, getCount(obj)) != 0;
|
||||
result = result || changed;
|
||||
}
|
||||
|
|
|
@ -152,9 +152,7 @@ public class CompositeSet<E> implements Set<E>, Serializable {
|
|||
return EmptyIterator.<E>emptyIterator();
|
||||
}
|
||||
final IteratorChain<E> chain = new IteratorChain<>();
|
||||
for (final Set<E> item : all) {
|
||||
chain.addIterator(item.iterator());
|
||||
}
|
||||
all.forEach(item -> chain.addIterator(item.iterator()));
|
||||
return chain;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue