src/share/classes/java/util/Map.java

Print this page
rev 3977 : 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.


 127     int size();
 128 
 129     /**
 130      * Returns <tt>true</tt> if this map contains no key-value mappings.
 131      *
 132      * @return <tt>true</tt> if this map contains no key-value mappings
 133      */
 134     boolean isEmpty();
 135 
 136     /**
 137      * Returns <tt>true</tt> if this map contains a mapping for the specified
 138      * key.  More formally, returns <tt>true</tt> if and only if
 139      * this map contains a mapping for a key <tt>k</tt> such that
 140      * <tt>(key==null ? k==null : key.equals(k))</tt>.  (There can be
 141      * at most one such mapping.)
 142      *
 143      * @param key key whose presence in this map is to be tested
 144      * @return <tt>true</tt> if this map contains a mapping for the specified
 145      *         key
 146      * @throws ClassCastException if the key is of an inappropriate type for
 147      *         this map (optional)

 148      * @throws NullPointerException if the specified key is null and this map
 149      *         does not permit null keys (optional)

 150      */
 151     boolean containsKey(Object key);
 152 
 153     /**
 154      * Returns <tt>true</tt> if this map maps one or more keys to the
 155      * specified value.  More formally, returns <tt>true</tt> if and only if
 156      * this map contains at least one mapping to a value <tt>v</tt> such that
 157      * <tt>(value==null ? v==null : value.equals(v))</tt>.  This operation
 158      * will probably require time linear in the map size for most
 159      * implementations of the <tt>Map</tt> interface.
 160      *
 161      * @param value value whose presence in this map is to be tested
 162      * @return <tt>true</tt> if this map maps one or more keys to the
 163      *         specified value
 164      * @throws ClassCastException if the value is of an inappropriate type for
 165      *         this map (optional)

 166      * @throws NullPointerException if the specified value is null and this
 167      *         map does not permit null values (optional)

 168      */
 169     boolean containsValue(Object value);
 170 
 171     /**
 172      * Returns the value to which the specified key is mapped,
 173      * or {@code null} if this map contains no mapping for the key.
 174      *
 175      * <p>More formally, if this map contains a mapping from a key
 176      * {@code k} to a value {@code v} such that {@code (key==null ? k==null :
 177      * key.equals(k))}, then this method returns {@code v}; otherwise
 178      * it returns {@code null}.  (There can be at most one such mapping.)
 179      *
 180      * <p>If this map permits null values, then a return value of
 181      * {@code null} does not <i>necessarily</i> indicate that the map
 182      * contains no mapping for the key; it's also possible that the map
 183      * explicitly maps the key to {@code null}.  The {@link #containsKey
 184      * containsKey} operation may be used to distinguish these two cases.
 185      *
 186      * @param key the key whose associated value is to be returned
 187      * @return the value to which the specified key is mapped, or
 188      *         {@code null} if this map contains no mapping for the key
 189      * @throws ClassCastException if the key is of an inappropriate type for
 190      *         this map (optional)

 191      * @throws NullPointerException if the specified key is null and this map
 192      *         does not permit null keys (optional)

 193      */
 194     V get(Object key);
 195 
 196     // Modification Operations
 197 
 198     /**
 199      * Associates the specified value with the specified key in this map
 200      * (optional operation).  If the map previously contained a mapping for
 201      * the key, the old value is replaced by the specified value.  (A map
 202      * <tt>m</tt> is said to contain a mapping for a key <tt>k</tt> if and only
 203      * if {@link #containsKey(Object) m.containsKey(k)} would return
 204      * <tt>true</tt>.)
 205      *
 206      * @param key key with which the specified value is to be associated
 207      * @param value value to be associated with the specified key
 208      * @return the previous value associated with <tt>key</tt>, or
 209      *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
 210      *         (A <tt>null</tt> return can also indicate that the map
 211      *         previously associated <tt>null</tt> with <tt>key</tt>,
 212      *         if the implementation supports <tt>null</tt> values.)


 228      * <code>(key==null ?  k==null : key.equals(k))</code>, that mapping
 229      * is removed.  (The map can contain at most one such mapping.)
 230      *
 231      * <p>Returns the value to which this map previously associated the key,
 232      * or <tt>null</tt> if the map contained no mapping for the key.
 233      *
 234      * <p>If this map permits null values, then a return value of
 235      * <tt>null</tt> does not <i>necessarily</i> indicate that the map
 236      * contained no mapping for the key; it's also possible that the map
 237      * explicitly mapped the key to <tt>null</tt>.
 238      *
 239      * <p>The map will not contain a mapping for the specified key once the
 240      * call returns.
 241      *
 242      * @param key key whose mapping is to be removed from the map
 243      * @return the previous value associated with <tt>key</tt>, or
 244      *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
 245      * @throws UnsupportedOperationException if the <tt>remove</tt> operation
 246      *         is not supported by this map
 247      * @throws ClassCastException if the key is of an inappropriate type for
 248      *         this map (optional)

 249      * @throws NullPointerException if the specified key is null and this
 250      *         map does not permit null keys (optional)

 251      */
 252     V remove(Object key);
 253 
 254 
 255     // Bulk Operations
 256 
 257     /**
 258      * Copies all of the mappings from the specified map to this map
 259      * (optional operation).  The effect of this call is equivalent to that
 260      * of calling {@link #put(Object,Object) put(k, v)} on this map once
 261      * for each mapping from key <tt>k</tt> to value <tt>v</tt> in the
 262      * specified map.  The behavior of this operation is undefined if the
 263      * specified map is modified while the operation is in progress.
 264      *
 265      * @param m mappings to be stored in this map
 266      * @throws UnsupportedOperationException if the <tt>putAll</tt> operation
 267      *         is not supported by this map
 268      * @throws ClassCastException if the class of a key or value in the
 269      *         specified map prevents it from being stored in this map
 270      * @throws NullPointerException if the specified map is null, or if




 127     int size();
 128 
 129     /**
 130      * Returns <tt>true</tt> if this map contains no key-value mappings.
 131      *
 132      * @return <tt>true</tt> if this map contains no key-value mappings
 133      */
 134     boolean isEmpty();
 135 
 136     /**
 137      * Returns <tt>true</tt> if this map contains a mapping for the specified
 138      * key.  More formally, returns <tt>true</tt> if and only if
 139      * this map contains a mapping for a key <tt>k</tt> such that
 140      * <tt>(key==null ? k==null : key.equals(k))</tt>.  (There can be
 141      * at most one such mapping.)
 142      *
 143      * @param key key whose presence in this map is to be tested
 144      * @return <tt>true</tt> if this map contains a mapping for the specified
 145      *         key
 146      * @throws ClassCastException if the key is of an inappropriate type for
 147      *         this map
 148      * (<a href="Collection.html#optional-restrictions">optional</a>)
 149      * @throws NullPointerException if the specified key is null and this map
 150      *         does not permit null keys
 151      * (<a href="Collection.html#optional-restrictions">optional</a>)
 152      */
 153     boolean containsKey(Object key);
 154 
 155     /**
 156      * Returns <tt>true</tt> if this map maps one or more keys to the
 157      * specified value.  More formally, returns <tt>true</tt> if and only if
 158      * this map contains at least one mapping to a value <tt>v</tt> such that
 159      * <tt>(value==null ? v==null : value.equals(v))</tt>.  This operation
 160      * will probably require time linear in the map size for most
 161      * implementations of the <tt>Map</tt> interface.
 162      *
 163      * @param value value whose presence in this map is to be tested
 164      * @return <tt>true</tt> if this map maps one or more keys to the
 165      *         specified value
 166      * @throws ClassCastException if the value is of an inappropriate type for
 167      *         this map
 168      * (<a href="Collection.html#optional-restrictions">optional</a>)
 169      * @throws NullPointerException if the specified value is null and this
 170      *         map does not permit null values
 171      * (<a href="Collection.html#optional-restrictions">optional</a>)
 172      */
 173     boolean containsValue(Object value);
 174 
 175     /**
 176      * Returns the value to which the specified key is mapped,
 177      * or {@code null} if this map contains no mapping for the key.
 178      *
 179      * <p>More formally, if this map contains a mapping from a key
 180      * {@code k} to a value {@code v} such that {@code (key==null ? k==null :
 181      * key.equals(k))}, then this method returns {@code v}; otherwise
 182      * it returns {@code null}.  (There can be at most one such mapping.)
 183      *
 184      * <p>If this map permits null values, then a return value of
 185      * {@code null} does not <i>necessarily</i> indicate that the map
 186      * contains no mapping for the key; it's also possible that the map
 187      * explicitly maps the key to {@code null}.  The {@link #containsKey
 188      * containsKey} operation may be used to distinguish these two cases.
 189      *
 190      * @param key the key whose associated value is to be returned
 191      * @return the value to which the specified key is mapped, or
 192      *         {@code null} if this map contains no mapping for the key
 193      * @throws ClassCastException if the key is of an inappropriate type for
 194      *         this map
 195      * (<a href="Collection.html#optional-restrictions">optional</a>)
 196      * @throws NullPointerException if the specified key is null and this map
 197      *         does not permit null keys
 198      * (<a href="Collection.html#optional-restrictions">optional</a>)
 199      */
 200     V get(Object key);
 201 
 202     // Modification Operations
 203 
 204     /**
 205      * Associates the specified value with the specified key in this map
 206      * (optional operation).  If the map previously contained a mapping for
 207      * the key, the old value is replaced by the specified value.  (A map
 208      * <tt>m</tt> is said to contain a mapping for a key <tt>k</tt> if and only
 209      * if {@link #containsKey(Object) m.containsKey(k)} would return
 210      * <tt>true</tt>.)
 211      *
 212      * @param key key with which the specified value is to be associated
 213      * @param value value to be associated with the specified key
 214      * @return the previous value associated with <tt>key</tt>, or
 215      *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
 216      *         (A <tt>null</tt> return can also indicate that the map
 217      *         previously associated <tt>null</tt> with <tt>key</tt>,
 218      *         if the implementation supports <tt>null</tt> values.)


 234      * <code>(key==null ?  k==null : key.equals(k))</code>, that mapping
 235      * is removed.  (The map can contain at most one such mapping.)
 236      *
 237      * <p>Returns the value to which this map previously associated the key,
 238      * or <tt>null</tt> if the map contained no mapping for the key.
 239      *
 240      * <p>If this map permits null values, then a return value of
 241      * <tt>null</tt> does not <i>necessarily</i> indicate that the map
 242      * contained no mapping for the key; it's also possible that the map
 243      * explicitly mapped the key to <tt>null</tt>.
 244      *
 245      * <p>The map will not contain a mapping for the specified key once the
 246      * call returns.
 247      *
 248      * @param key key whose mapping is to be removed from the map
 249      * @return the previous value associated with <tt>key</tt>, or
 250      *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
 251      * @throws UnsupportedOperationException if the <tt>remove</tt> operation
 252      *         is not supported by this map
 253      * @throws ClassCastException if the key is of an inappropriate type for
 254      *         this map
 255      * (<a href="Collection.html#optional-restrictions">optional</a>)
 256      * @throws NullPointerException if the specified key is null and this
 257      *         map does not permit null keys
 258      * (<a href="Collection.html#optional-restrictions">optional</a>)
 259      */
 260     V remove(Object key);
 261 
 262 
 263     // Bulk Operations
 264 
 265     /**
 266      * Copies all of the mappings from the specified map to this map
 267      * (optional operation).  The effect of this call is equivalent to that
 268      * of calling {@link #put(Object,Object) put(k, v)} on this map once
 269      * for each mapping from key <tt>k</tt> to value <tt>v</tt> in the
 270      * specified map.  The behavior of this operation is undefined if the
 271      * specified map is modified while the operation is in progress.
 272      *
 273      * @param m mappings to be stored in this map
 274      * @throws UnsupportedOperationException if the <tt>putAll</tt> operation
 275      *         is not supported by this map
 276      * @throws ClassCastException if the class of a key or value in the
 277      *         specified map prevents it from being stored in this map
 278      * @throws NullPointerException if the specified map is null, or if