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

Comparing jsr166/src/main/java/util/AbstractMap.java (file contents):
Revision 1.6 by jsr166, Mon Apr 18 05:18:29 2005 UTC vs.
Revision 1.7 by jsr166, Wed Apr 27 01:39:03 2005 UTC

# Line 33 | Line 33 | import java.util.Map.Entry;
33   * implementation in detail.  Each of these methods may be overridden if the
34   * map being implemented admits a more efficient implementation.<p>
35   *
36 < * This class is a member of the
36 > * This class is a member of the
37   * <a href="{@docRoot}/../guide/collections/index.html">
38   * Java Collections Framework</a>.
39   *
40 + * @param <K> the type of keys maintained by this map
41 + * @param <V> the type of mapped values
42 + *
43   * @author  Josh Bloch
44   * @author  Neal Gafter
45   * @version %I%, %G%
# Line 84 | Line 87 | public abstract class AbstractMap<K,V> i
87       * More formally, returns <tt>true</tt> if and only if this map contains
88       * at least one mapping to a value <tt>v</tt> such that <tt>(value==null ?
89       * v==null : value.equals(v))</tt>.  This operation will probably require
90 <     * time linear in the map size for most implementations of map.<p>
90 >     * time linear in the map size for most implementations of <tt>Map</tt>.<p>
91       *
92 <     * This implementation iterates over entrySet() searching for an entry
92 >     * This implementation iterates over <tt>entrySet()</tt> searching for an entry
93       * with the specified value.  If such an entry is found, <tt>true</tt> is
94       * returned.  If the iteration terminates without finding such an entry,
95       * <tt>false</tt> is returned.  Note that this implementation requires
96       * linear time in the size of the map.
97       *
98       * @param value value whose presence in this map is to be tested.
99 <     *
99 >     *
100       * @return <tt>true</tt> if this map maps one or more keys to this value.
101       */
102      public boolean containsValue(Object value) {
# Line 127 | Line 130 | public abstract class AbstractMap<K,V> i
130       *
131       * @param key key whose presence in this map is to be tested.
132       * @return <tt>true</tt> if this map contains a mapping for the specified
133 <     *            key.
134 <     *
135 <     * @throws NullPointerException if the key is <tt>null</tt> and this map
133 <     *            does not permit <tt>null</tt> keys.
133 >     *         key.
134 >     * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>
135 >     *         and this map does not permit <tt>null</tt> keys.
136       */
137      public boolean containsKey(Object key) {
138          Iterator<Map.Entry<K,V>> i = entrySet().iterator();
# Line 167 | Line 169 | public abstract class AbstractMap<K,V> i
169       *
170       * @param key key whose associated value is to be returned.
171       * @return the value to which this map maps the specified key.
172 <     *
173 <     * @throws NullPointerException if the key is <tt>null</tt> and this map
174 <     *            does not permit <tt>null</tt> keys.
175 <     *
172 >     *
173 >     * @throws NullPointerException if <tt>key</tt> is <tt>null</tt>
174 >     *         and this map does not permit <tt>null</tt> keys.
175 >     *
176       * @see #containsKey(Object)
177       */
178      public V get(Object key) {
# Line 204 | Line 206 | public abstract class AbstractMap<K,V> i
206       *
207       * @param key key with which the specified value is to be associated.
208       * @param value value to be associated with the specified key.
209 <     *
209 >     *
210       * @return the previous value associated with specified key, or <tt>null</tt>
211       *         if there was no mapping for key.  (A <tt>null</tt> return can
212       *         also indicate that the map previously associated <tt>null</tt>
213       *         with the specified key, if the implementation supports
214       *         <tt>null</tt> values.)
215 <     *
216 <     * @throws UnsupportedOperationException if the <tt>put</tt> operation is
217 <     *            not supported by this map.
216 <     *
215 >     *
216 >     * @throws UnsupportedOperationException if the <tt>put</tt> operation
217 >     *         is not supported by this map.
218       * @throws ClassCastException if the class of the specified key or value
219 <     *            prevents it from being stored in this map.
220 <     *
221 <     * @throws IllegalArgumentException if some aspect of this key or value *
221 <     *            prevents it from being stored in this map.
222 <     *
219 >     *         prevents it from being stored in this map.
220 >     * @throws IllegalArgumentException if some aspect of this key or value
221 >     *         prevents it from being stored in this map.
222       * @throws NullPointerException if this map does not permit <tt>null</tt>
223 <     *            keys or values, and the specified key or value is
225 <     *            <tt>null</tt>.
223 >     *         keys or values, and the specified key or value is <tt>null</tt>.
224       */
225      public V put(K key, V value) {
226          throw new UnsupportedOperationException();
# Line 235 | Line 233 | public abstract class AbstractMap<K,V> i
233       * This implementation iterates over <tt>entrySet()</tt> searching for an
234       * entry with the specified key.  If such an entry is found, its value is
235       * obtained with its <tt>getValue</tt> operation, the entry is removed
236 <     * from the Collection (and the backing map) with the iterator's
236 >     * from the collection (and the backing map) with the iterator's
237       * <tt>remove</tt> operation, and the saved value is returned.  If the
238       * iteration terminates without finding such an entry, <tt>null</tt> is
239       * returned.  Note that this implementation requires linear time in the
# Line 253 | Line 251 | public abstract class AbstractMap<K,V> i
251       *         with the specified key, if the implementation supports
252       *         <tt>null</tt> values.)
253       * @throws UnsupportedOperationException if the <tt>remove</tt> operation
254 <     *            is not supported by this map.
254 >     *         is not supported by this map.
255       */
256      public V remove(Object key) {
257          Iterator<Entry<K,V>> i = entrySet().iterator();
# Line 297 | Line 295 | public abstract class AbstractMap<K,V> i
295       * the <tt>put</tt> operation and the specified map is nonempty.
296       *
297       * @param t mappings to be stored in this map.
298 <     *
298 >     *
299       * @throws UnsupportedOperationException if the <tt>putAll</tt> operation
300 <     *            is not supported by this map.
303 <     *
300 >     *         is not supported by this map.
301       * @throws ClassCastException if the class of a key or value in the
302 <     *            specified map prevents it from being stored in this map.
306 <     *
302 >     *         specified map prevents it from being stored in this map.
303       * @throws IllegalArgumentException if some aspect of a key or value in
304 <     *            the specified map prevents it from being stored in this map.
304 >     *         the specified map prevents it from being stored in this map.
305       * @throws NullPointerException if the specified map is <tt>null</tt>, or if
306       *         this map does not permit <tt>null</tt> keys or values, and the
307       *         specified map contains <tt>null</tt> keys or values.
# Line 327 | Line 323 | public abstract class AbstractMap<K,V> i
323       * <tt>UnsupportedOperationException</tt> if the <tt>entrySet</tt>
324       * does not support the <tt>clear</tt> operation.
325       *
326 <     * @throws    UnsupportedOperationException clear is not supported
327 <     *            by this map.
326 >     * @throws UnsupportedOperationException if the <tt>clear</tt> operation
327 >     *         is not supported by this map.
328       */
329      public void clear() {
330          entrySet().clear();
# Line 346 | Line 342 | public abstract class AbstractMap<K,V> i
342      transient volatile Collection<V> values = null;
343  
344      /**
345 <     * Returns a Set view of the keys contained in this map.  The Set is
346 <     * backed by the map, so changes to the map are reflected in the Set,
347 <     * and vice-versa.  (If the map is modified while an iteration over
348 <     * the Set is in progress, the results of the iteration are undefined.)
349 <     * The Set supports element removal, which removes the corresponding entry
350 <     * from the map, via the Iterator.remove, Set.remove,  removeAll
351 <     * retainAll, and clear operations.  It does not support the add or
352 <     * addAll operations.<p>
353 <     *
354 <     * This implementation returns a Set that subclasses
355 <     * AbstractSet.  The subclass's iterator method returns a "wrapper
356 <     * object" over this map's entrySet() iterator.  The size method delegates
357 <     * to this map's size method and the contains method delegates to this
358 <     * map's containsKey method.<p>
345 >     * Returns a {@link Set} view of the keys contained in this map.
346 >     * The set is backed by the map, so changes to the map are
347 >     * reflected in the set, and vice-versa.  If the map is modified
348 >     * while an iteration over the set is in progress (except through
349 >     * the iterator's own <tt>remove</tt> operation), the results of
350 >     * the iteration are undefined.  The set supports element removal,
351 >     * which removes the corresponding mapping from the map, via the
352 >     * <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
353 >     * <tt>removeAll</tt> <tt>retainAll</tt>, and <tt>clear</tt>
354 >     * operations.  It does not support the add or <tt>addAll</tt>
355 >     * operations.
356 >     *
357 >     * <p>This implementation returns a set that subclasses {@link AbstractSet}.
358 >     * The subclass's iterator method returns a "wrapper object" over this
359 >     * map's <tt>entrySet()</tt> iterator.  The <tt>size</tt> method
360 >     * delegates to this map's <tt>size</tt> method and the
361 >     * <tt>contains</tt> method delegates to this map's
362 >     * <tt>containsKey</tt> method.
363       *
364 <     * The Set is created the first time this method is called,
364 >     * <p>The set is created the first time this method is called,
365       * and returned in response to all subsequent calls.  No synchronization
366       * is performed, so there is a slight chance that multiple calls to this
367 <     * method will not all return the same Set.
368 <     *
369 <     * @return a Set view of the keys contained in this map.
367 >     * method will not all return the same set.
368       */
369      public Set<K> keySet() {
370          if (keySet == null) {
# Line 402 | Line 400 | public abstract class AbstractMap<K,V> i
400      }
401  
402      /**
403 <     * Returns a collection view of the values contained in this map.  The
404 <     * collection is backed by the map, so changes to the map are reflected in
405 <     * the collection, and vice-versa.  (If the map is modified while an
406 <     * iteration over the collection is in progress, the results of the
407 <     * iteration are undefined.)  The collection supports element removal,
408 <     * which removes the corresponding entry from the map, via the
409 <     * <tt>Iterator.remove</tt>, <tt>Collection.remove</tt>,
410 <     * <tt>removeAll</tt>, <tt>retainAll</tt> and <tt>clear</tt> operations.
411 <     * It does not support the <tt>add</tt> or <tt>addAll</tt> operations.<p>
412 <     *
413 <     * This implementation returns a collection that subclasses abstract
414 <     * collection.  The subclass's iterator method returns a "wrapper object"
415 <     * over this map's <tt>entrySet()</tt> iterator.  The size method
416 <     * delegates to this map's size method and the contains method delegates
417 <     * to this map's containsValue method.<p>
403 >     * Returns a {@link Collection} view of the values contained in this map.
404 >     * The collection is backed by the map, so changes to the map are
405 >     * reflected in the collection, and vice-versa.  If the map is
406 >     * modified while an iteration over the collection is in progress
407 >     * (except through the iterator's own <tt>remove</tt> operation),
408 >     * the results of the iteration are undefined.  The collection
409 >     * supports element removal, which removes the corresponding
410 >     * mapping from the map, via the <tt>Iterator.remove</tt>,
411 >     * <tt>Collection.remove</tt>, <tt>removeAll</tt>,
412 >     * <tt>retainAll</tt> and <tt>clear</tt> operations.  It does not
413 >     * support the add or <tt>addAll</tt> operations.
414 >     *
415 >     * <p>This implementation returns a collection that subclasses {@link
416 >     * AbstractCollection}.  The subclass's iterator method returns a
417 >     * "wrapper object" over this map's <tt>entrySet()</tt> iterator.
418 >     * The <tt>size</tt> method delegates to this map's <tt>size</tt>
419 >     * method and the <tt>contains</tt> method delegates to this map's
420 >     * <tt>containsValue</tt> method.
421       *
422 <     * The collection is created the first time this method is called, and
422 >     * <p>The collection is created the first time this method is called, and
423       * returned in response to all subsequent calls.  No synchronization is
424       * performed, so there is a slight chance that multiple calls to this
425 <     * method will not all return the same Collection.
425 >     * method will not all return the same collection.
426       *
427       * @return a collection view of the values contained in this map.
428       */
# Line 458 | Line 459 | public abstract class AbstractMap<K,V> i
459          return values;
460      }
461  
461    /**
462     * Returns a set view of the mappings contained in this map.  Each element
463     * in this set is a Map.Entry.  The set is backed by the map, so changes
464     * to the map are reflected in the set, and vice-versa.  (If the map is
465     * modified while an iteration over the set is in progress, the results of
466     * the iteration are undefined.)  The set supports element removal, which
467     * removes the corresponding entry from the map, via the
468     * <tt>Iterator.remove</tt>, <tt>Set.remove</tt>, <tt>removeAll</tt>,
469     * <tt>retainAll</tt> and <tt>clear</tt> operations.  It does not support
470     * the <tt>add</tt> or <tt>addAll</tt> operations.
471     *
472     * @return a set view of the mappings contained in this map.
473     */
462      public abstract Set<Entry<K,V>> entrySet();
463  
464  
# Line 523 | Line 511 | public abstract class AbstractMap<K,V> i
511                          return false;
512                  }
513              }
514 <        } catch(ClassCastException unused) {
514 >        } catch (ClassCastException unused) {
515              return false;
516 <        } catch(NullPointerException unused) {
516 >        } catch (NullPointerException unused) {
517              return false;
518          }
519  
# Line 604 | Line 592 | public abstract class AbstractMap<K,V> i
592          buf.append("}");
593          return buf.toString();
594      }
595 <    
595 >
596      /**
597       * Returns a shallow copy of this <tt>AbstractMap</tt> instance: the keys
598       * and values themselves are not cloned.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines