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.83 by jsr166, Mon Aug 22 03:42:10 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.
1128       */
1129 <    static final class WriteThroughEntry<K,V>
1129 >    final class WriteThroughEntry
1130          extends AbstractMap.SimpleEntry<K,V>
1131      {
1132 <        private final ConcurrentHashMap<K,V> map;
1128 <        WriteThroughEntry(ConcurrentHashMap map, K k, V v) {
1132 >        WriteThroughEntry(K k, V v) {
1133              super(k,v);
1130            this.map = map;
1134          }
1135  
1136          /**
# Line 1142 | Line 1145 | public class ConcurrentHashMap<K, V> ext
1145          public V setValue(V value) {
1146              if (value == null) throw new NullPointerException();
1147              V v = super.setValue(value);
1148 <            map.put(getKey(), value);
1148 >            ConcurrentHashMap.this.put(getKey(), value);
1149              return v;
1150          }
1151      }
1152  
1153 <    final class EntryIterator extends HashIterator implements Iterator<Entry<K,V>> {
1153 >    final class EntryIterator
1154 >        extends HashIterator
1155 >        implements Iterator<Entry<K,V>>
1156 >    {
1157          public Map.Entry<K,V> next() {
1158              HashEntry<K,V> e = super.nextEntry();
1159 <            return new WriteThroughEntry<K,V>(ConcurrentHashMap.this,
1154 <                                              e.key, e.value);
1159 >            return new WriteThroughEntry(e.key, e.value);
1160          }
1161      }
1162  
# Line 1172 | Line 1177 | public class ConcurrentHashMap<K, V> ext
1177              ConcurrentHashMap.this.clear();
1178          }
1179          public Object[] toArray() {
1180 <            Collection<K> c = new ArrayList<K>();
1181 <            for (Iterator<K> i = iterator(); i.hasNext(); )
1182 <                c.add(i.next());
1180 >            Collection<K> c = new ArrayList<K>(size());
1181 >            for (K k : this)
1182 >                c.add(k);
1183              return c.toArray();
1184          }
1185          public <T> T[] toArray(T[] a) {
1186              Collection<K> c = new ArrayList<K>();
1187 <            for (Iterator<K> i = iterator(); i.hasNext(); )
1188 <                c.add(i.next());
1187 >            for (K k : this)
1188 >                c.add(k);
1189              return c.toArray(a);
1190          }
1191      }
# Line 1199 | Line 1204 | public class ConcurrentHashMap<K, V> ext
1204              ConcurrentHashMap.this.clear();
1205          }
1206          public Object[] toArray() {
1207 <            Collection<V> c = new ArrayList<V>();
1208 <            for (Iterator<V> i = iterator(); i.hasNext(); )
1209 <                c.add(i.next());
1207 >            Collection<V> c = new ArrayList<V>(size());
1208 >            for (V v : this)
1209 >                c.add(v);
1210              return c.toArray();
1211          }
1212          public <T> T[] toArray(T[] a) {
1213 <            Collection<V> c = new ArrayList<V>();
1214 <            for (Iterator<V> i = iterator(); i.hasNext(); )
1215 <                c.add(i.next());
1213 >            Collection<V> c = new ArrayList<V>(size());
1214 >            for (V v : this)
1215 >                c.add(v);
1216              return c.toArray(a);
1217          }
1218      }
# Line 1237 | Line 1242 | public class ConcurrentHashMap<K, V> ext
1242          }
1243          public Object[] toArray() {
1244              Collection<Map.Entry<K,V>> c = new ArrayList<Map.Entry<K,V>>(size());
1245 <            for (Iterator<Map.Entry<K,V>> i = iterator(); i.hasNext(); )
1246 <                c.add(i.next());
1245 >            for (Map.Entry<K,V> e : this)
1246 >                c.add(e);
1247              return c.toArray();
1248          }
1249          public <T> T[] toArray(T[] a) {
1250              Collection<Map.Entry<K,V>> c = new ArrayList<Map.Entry<K,V>>(size());
1251 <            for (Iterator<Map.Entry<K,V>> i = iterator(); i.hasNext(); )
1252 <                c.add(i.next());
1251 >            for (Map.Entry<K,V> e : this)
1252 >                c.add(e);
1253              return c.toArray(a);
1254          }
1255 +
1256      }
1257  
1258      /* ---------------- Serialization Support -------------- */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines