ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ConcurrentHashMap.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/ConcurrentHashMap.java (file contents):
Revision 1.81 by jsr166, Mon Aug 22 01:57:42 2005 UTC vs.
Revision 1.82 by jsr166, Mon Aug 22 03:05:49 2005 UTC

# Line 1050 | Line 1050 | public class ConcurrentHashMap<K, V> ext
1050  
1051      /* ---------------- Iterator Support -------------- */
1052  
1053 <    class HashIterator {
1053 >    abstract class HashIterator {
1054          int nextSegmentIndex;
1055          int nextTableIndex;
1056          HashEntry<K,V>[] currentTable;
# Line 1106 | Line 1106 | public class ConcurrentHashMap<K, V> ext
1106          }
1107      }
1108  
1109 <    final class KeyIterator extends HashIterator implements Iterator<K>, Enumeration<K> {
1110 <        public K next() { return super.nextEntry().key; }
1109 >    final class KeyIterator
1110 >        extends HashIterator
1111 >        implements Iterator<K>, Enumeration<K>
1112 >    {
1113 >        public K next()        { return super.nextEntry().key; }
1114          public K nextElement() { return super.nextEntry().key; }
1115      }
1116  
1117 <    final class ValueIterator extends HashIterator implements Iterator<V>, Enumeration<V> {
1118 <        public V next() { return super.nextEntry().value; }
1117 >    final class ValueIterator
1118 >        extends HashIterator
1119 >        implements Iterator<V>, Enumeration<V>
1120 >    {
1121 >        public V next()        { return super.nextEntry().value; }
1122          public V nextElement() { return super.nextEntry().value; }
1123      }
1124  
1119
1125      /**
1126       * Custom Entry class used by EntryIterator.next(), that relays
1127       * setValue changes to the underlying map.
# Line 1147 | Line 1152 | public class ConcurrentHashMap<K, V> ext
1152          }
1153      }
1154  
1155 <    final class EntryIterator extends HashIterator implements Iterator<Entry<K,V>> {
1155 >    final class EntryIterator
1156 >        extends HashIterator
1157 >        implements Iterator<Entry<K,V>>
1158 >    {
1159          public Map.Entry<K,V> next() {
1160              HashEntry<K,V> e = super.nextEntry();
1161              return new WriteThroughEntry<K,V>(ConcurrentHashMap.this,
# Line 1172 | Line 1180 | public class ConcurrentHashMap<K, V> ext
1180              ConcurrentHashMap.this.clear();
1181          }
1182          public Object[] toArray() {
1183 <            Collection<K> c = new ArrayList<K>();
1184 <            for (Iterator<K> i = iterator(); i.hasNext(); )
1185 <                c.add(i.next());
1183 >            Collection<K> c = new ArrayList<K>(size());
1184 >            for (K k : this)
1185 >                c.add(k);
1186              return c.toArray();
1187          }
1188          public <T> T[] toArray(T[] a) {
1189              Collection<K> c = new ArrayList<K>();
1190 <            for (Iterator<K> i = iterator(); i.hasNext(); )
1191 <                c.add(i.next());
1190 >            for (K k : this)
1191 >                c.add(k);
1192              return c.toArray(a);
1193          }
1194      }
# Line 1199 | Line 1207 | public class ConcurrentHashMap<K, V> ext
1207              ConcurrentHashMap.this.clear();
1208          }
1209          public Object[] toArray() {
1210 <            Collection<V> c = new ArrayList<V>();
1211 <            for (Iterator<V> i = iterator(); i.hasNext(); )
1212 <                c.add(i.next());
1210 >            Collection<V> c = new ArrayList<V>(size());
1211 >            for (V v : this)
1212 >                c.add(v);
1213              return c.toArray();
1214          }
1215          public <T> T[] toArray(T[] a) {
1216 <            Collection<V> c = new ArrayList<V>();
1217 <            for (Iterator<V> i = iterator(); i.hasNext(); )
1218 <                c.add(i.next());
1216 >            Collection<V> c = new ArrayList<V>(size());
1217 >            for (V v : this)
1218 >                c.add(v);
1219              return c.toArray(a);
1220          }
1221      }
# Line 1237 | Line 1245 | public class ConcurrentHashMap<K, V> ext
1245          }
1246          public Object[] toArray() {
1247              Collection<Map.Entry<K,V>> c = new ArrayList<Map.Entry<K,V>>(size());
1248 <            for (Iterator<Map.Entry<K,V>> i = iterator(); i.hasNext(); )
1249 <                c.add(i.next());
1248 >            for (Map.Entry<K,V> e : this)
1249 >                c.add(e);
1250              return c.toArray();
1251          }
1252          public <T> T[] toArray(T[] a) {
1253              Collection<Map.Entry<K,V>> c = new ArrayList<Map.Entry<K,V>>(size());
1254 <            for (Iterator<Map.Entry<K,V>> i = iterator(); i.hasNext(); )
1255 <                c.add(i.next());
1254 >            for (Map.Entry<K,V> e : this)
1255 >                c.add(e);
1256              return c.toArray(a);
1257          }
1258 +
1259      }
1260  
1261      /* ---------------- Serialization Support -------------- */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines