summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/util/Collections.java32
-rw-r--r--java/util/HashMap.java16
-rw-r--r--java/util/Hashtable.java18
-rw-r--r--java/util/TreeMap.java8
4 files changed, 43 insertions, 31 deletions
diff --git a/java/util/Collections.java b/java/util/Collections.java
index 1c3735eab..fd802fe9d 100644
--- a/java/util/Collections.java
+++ b/java/util/Collections.java
@@ -1462,8 +1462,10 @@ public class Collections
public static int frequency (Collection<?> c, Object o)
{
int result = 0;
- for (Object v : c)
+ final Iterator<?> it = c.iterator();
+ while (it.hasNext())
{
+ Object v = it.next();
if (AbstractCollection.equals(o, v))
++result;
}
@@ -1524,8 +1526,9 @@ public class Collections
public static boolean disjoint(Collection<?> c1, Collection<?> c2)
{
Collection<Object> oc1 = (Collection<Object>) c1;
- for (Object o : oc1)
- if (c2.contains(o))
+ final Iterator<Object> it = oc1.iterator();
+ while (it.hasNext())
+ if (c2.contains(it.next()))
return false;
return true;
}
@@ -5827,8 +5830,10 @@ public class Collections
public boolean addAll(Collection<? extends E> coll)
{
Collection<E> typedColl = (Collection<E>) c;
- for (E element : typedColl)
+ final Iterator<E> it = typedColl.iterator();
+ while (it.hasNext())
{
+ final E element = it.next();
if (!type.isInstance(element))
throw new ClassCastException("A member of the collection is not of the correct type.");
}
@@ -6169,9 +6174,10 @@ public class Collections
public boolean addAll(int index, Collection<? extends E> coll)
{
Collection<E> typedColl = (Collection<E>) coll;
- for (E element : typedColl)
+ final Iterator<E> it = typedColl.iterator();
+ while (it.hasNext())
{
- if (!type.isInstance(element))
+ if (!type.isInstance(it.next()))
throw new ClassCastException("A member of the collection is not of the correct type.");
}
return list.addAll(index, coll);
@@ -6872,8 +6878,10 @@ public class Collections
public void putAll(Map<? extends K, ? extends V> map)
{
Map<K,V> typedMap = (Map<K,V>) map;
- for (Map.Entry<K,V> entry : typedMap.entrySet())
+ final Iterator<Map.Entry<K,V>> it = typedMap.entrySet().iterator();
+ while (it.hasNext())
{
+ final Map.Entry<K,V> entry = it.next();
if (!keyType.isInstance(entry.getKey()))
throw new ClassCastException("A key is of the wrong type.");
if (!valueType.isInstance(entry.getValue()))
@@ -7494,8 +7502,9 @@ public class Collections
public boolean addAll(Collection<? extends T> c)
{
boolean result = false;
- for (T e : c)
- result |= deque.offerFirst(e);
+ final Iterator<? extends T> it = c.iterator();
+ while (it.hasNext())
+ result |= deque.offerFirst(it.next());
return result;
}
@@ -7572,8 +7581,9 @@ public class Collections
public boolean addAll(Collection<? extends E> c)
{
boolean result = false;
- for (E e : c)
- result |= (map.put(e, true) == null);
+ final Iterator<? extends E> it = c.iterator();
+ while (it.hasNext())
+ result |= (map.put(it.next(), true) == null);
return result;
}
diff --git a/java/util/HashMap.java b/java/util/HashMap.java
index 92022a7d5..eca3ad6aa 100644
--- a/java/util/HashMap.java
+++ b/java/util/HashMap.java
@@ -380,11 +380,11 @@ public class HashMap<K, V> extends AbstractMap<K, V>
*/
public void putAll(Map<? extends K, ? extends V> m)
{
- Map<K,V> addMap;
-
- addMap = (Map<K,V>) m;
- for (Map.Entry<K,V> e : addMap.entrySet())
+ final Map<K,V> addMap = (Map<K,V>) m;
+ final Iterator<Map.Entry<K,V>> it = addMap.entrySet().iterator();
+ while (it.hasNext())
{
+ final Map.Entry<K,V> e = it.next();
// Optimize in case the Entry is one of our own.
if (e instanceof AbstractMap.SimpleEntry)
{
@@ -710,12 +710,12 @@ public class HashMap<K, V> extends AbstractMap<K, V>
*/
void putAllInternal(Map<? extends K, ? extends V> m)
{
- Map<K,V> addMap;
-
- addMap = (Map<K,V>) m;
+ final Map<K,V> addMap = (Map<K,V>) m;
+ final Iterator<Map.Entry<K,V>> it = addMap.entrySet().iterator();
size = 0;
- for (Map.Entry<K,V> e : addMap.entrySet())
+ while (it.hasNext())
{
+ final Map.Entry<K,V> e = it.next();
size++;
K key = e.getKey();
int idx = hash(key);
diff --git a/java/util/Hashtable.java b/java/util/Hashtable.java
index 2e265a473..20fb002b9 100644
--- a/java/util/Hashtable.java
+++ b/java/util/Hashtable.java
@@ -505,12 +505,11 @@ public class Hashtable<K, V> extends Dictionary<K, V>
*/
public synchronized void putAll(Map<? extends K, ? extends V> m)
{
- Map<K,V> addMap;
-
- addMap = (Map<K,V>) m;
-
- for (Map.Entry<K,V> e : addMap.entrySet())
+ final Map<K,V> addMap = (Map<K,V>) m;
+ final Iterator<Map.Entry<K,V>> it = addMap.entrySet().iterator();
+ while (it.hasNext())
{
+ final Map.Entry<K,V> e = it.next();
// Optimize in case the Entry is one of our own.
if (e instanceof AbstractMap.SimpleEntry)
{
@@ -857,13 +856,12 @@ public class Hashtable<K, V> extends Dictionary<K, V>
*/
void putAllInternal(Map<? extends K, ? extends V> m)
{
- Map<K,V> addMap;
-
- addMap = (Map<K,V>) m;
+ final Map<K,V> addMap = (Map<K,V>) m;
+ final Iterator<Map.Entry<K,V>> it = addMap.entrySet().iterator();
size = 0;
-
- for (Map.Entry<K,V> e : addMap.entrySet())
+ while (it.hasNext());
{
+ final Map.Entry<K,V> e = it.next();
size++;
K key = e.getKey();
int idx = hash(key);
diff --git a/java/util/TreeMap.java b/java/util/TreeMap.java
index 71047cfc9..f54cbc336 100644
--- a/java/util/TreeMap.java
+++ b/java/util/TreeMap.java
@@ -2721,8 +2721,10 @@ public class TreeMap<K, V> extends AbstractMap<K, V>
public String toString()
{
StringBuilder r = new StringBuilder("{");
- for (Entry<DK,DV> e : entrySet())
+ final Iterator<Entry<DK,DV>> it = entrySet().iterator();
+ while (it.hasNext())
{
+ final Entry<DK,DV> e = it.next();
r.append(e.getKey());
r.append('=');
r.append(e.getValue());
@@ -3157,8 +3159,10 @@ public class TreeMap<K, V> extends AbstractMap<K, V>
public String toString()
{
StringBuilder r = new StringBuilder("[");
- for (D o : this)
+ final Iterator<D> it = iterator();
+ while (it.hasNext())
{
+ final D o = it.next();
if (o == this)
r.append("<this>");
else