jdk/src/share/classes/java/util/Map.java
author alanb
Fri, 02 Nov 2012 15:50:11 +0000
changeset 14342 8435a30053c1
parent 9503 588cf31d584a
child 16867 76499721c6c1
permissions -rw-r--r--
7197491: update copyright year to match last edit in jdk8 jdk repository Reviewed-by: chegar, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 9503
diff changeset
     2
 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * An object that maps keys to values.  A map cannot contain duplicate keys;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * each key can map to at most one value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * <p>This interface takes the place of the <tt>Dictionary</tt> class, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * was a totally abstract class rather than an interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <p>The <tt>Map</tt> interface provides three <i>collection views</i>, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * allow a map's contents to be viewed as a set of keys, collection of values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * or set of key-value mappings.  The <i>order</i> of a map is defined as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * the order in which the iterators on the map's collection views return their
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * elements.  Some map implementations, like the <tt>TreeMap</tt> class, make
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * specific guarantees as to their order; others, like the <tt>HashMap</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * class, do not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>Note: great care must be exercised if mutable objects are used as map
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * keys.  The behavior of a map is not specified if the value of an object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * changed in a manner that affects <tt>equals</tt> comparisons while the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * object is a key in the map.  A special case of this prohibition is that it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * is not permissible for a map to contain itself as a key.  While it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * permissible for a map to contain itself as a value, extreme caution is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * advised: the <tt>equals</tt> and <tt>hashCode</tt> methods are no longer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * well defined on such a map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <p>All general-purpose map implementation classes should provide two
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * "standard" constructors: a void (no arguments) constructor which creates an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * empty map, and a constructor with a single argument of type <tt>Map</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * which creates a new map with the same key-value mappings as its argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * In effect, the latter constructor allows the user to copy any map,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * producing an equivalent map of the desired class.  There is no way to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * enforce this recommendation (as interfaces cannot contain constructors) but
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * all of the general-purpose map implementations in the JDK comply.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <p>The "destructive" methods contained in this interface, that is, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * methods that modify the map on which they operate, are specified to throw
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <tt>UnsupportedOperationException</tt> if this map does not support the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * operation.  If this is the case, these methods may, but are not required
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * to, throw an <tt>UnsupportedOperationException</tt> if the invocation would
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * have no effect on the map.  For example, invoking the {@link #putAll(Map)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * method on an unmodifiable map may, but is not required to, throw the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * exception if the map whose mappings are to be "superimposed" is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <p>Some map implementations have restrictions on the keys and values they
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * may contain.  For example, some implementations prohibit null keys and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * values, and some have restrictions on the types of their keys.  Attempting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * to insert an ineligible key or value throws an unchecked exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * typically <tt>NullPointerException</tt> or <tt>ClassCastException</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * Attempting to query the presence of an ineligible key or value may throw an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * exception, or it may simply return false; some implementations will exhibit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * the former behavior and some will exhibit the latter.  More generally,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * attempting an operation on an ineligible key or value whose completion
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * would not result in the insertion of an ineligible element into the map may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * throw an exception or it may succeed, at the option of the implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * Such exceptions are marked as "optional" in the specification for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * <p>This interface is a member of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <a href="{@docRoot}/../technotes/guides/collections/index.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * Java Collections Framework</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * <p>Many methods in Collections Framework interfaces are defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * in terms of the {@link Object#equals(Object) equals} method.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * example, the specification for the {@link #containsKey(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * containsKey(Object key)} method says: "returns <tt>true</tt> if and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * only if this map contains a mapping for a key <tt>k</tt> such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * <tt>(key==null ? k==null : key.equals(k))</tt>." This specification should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * <i>not</i> be construed to imply that invoking <tt>Map.containsKey</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * with a non-null argument <tt>key</tt> will cause <tt>key.equals(k)</tt> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * be invoked for any key <tt>k</tt>.  Implementations are free to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * implement optimizations whereby the <tt>equals</tt> invocation is avoided,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * for example, by first comparing the hash codes of the two keys.  (The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * {@link Object#hashCode()} specification guarantees that two objects with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * unequal hash codes cannot be equal.)  More generally, implementations of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * the various Collections Framework interfaces are free to take advantage of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * the specified behavior of underlying {@link Object} methods wherever the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * implementor deems it appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * @param <K> the type of keys maintained by this map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * @param <V> the type of mapped values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * @author  Josh Bloch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * @see HashMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * @see TreeMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * @see Hashtable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * @see SortedMap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * @see Collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * @see Set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
public interface Map<K,V> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    // Query Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Returns the number of key-value mappings in this map.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * map contains more than <tt>Integer.MAX_VALUE</tt> elements, returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * <tt>Integer.MAX_VALUE</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @return the number of key-value mappings in this map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    int size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Returns <tt>true</tt> if this map contains no key-value mappings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @return <tt>true</tt> if this map contains no key-value mappings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    boolean isEmpty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Returns <tt>true</tt> if this map contains a mapping for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * key.  More formally, returns <tt>true</tt> if and only if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * this map contains a mapping for a key <tt>k</tt> such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * <tt>(key==null ? k==null : key.equals(k))</tt>.  (There can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * at most one such mapping.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @param key key whose presence in this map is to be tested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @return <tt>true</tt> if this map contains a mapping for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *         key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @throws ClassCastException if the key is of an inappropriate type for
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   147
     *         this map
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   148
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @throws NullPointerException if the specified key is null and this map
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   150
     *         does not permit null keys
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   151
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    boolean containsKey(Object key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * Returns <tt>true</tt> if this map maps one or more keys to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * specified value.  More formally, returns <tt>true</tt> if and only if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * this map contains at least one mapping to a value <tt>v</tt> such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * <tt>(value==null ? v==null : value.equals(v))</tt>.  This operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * will probably require time linear in the map size for most
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * implementations of the <tt>Map</tt> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @param value value whose presence in this map is to be tested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @return <tt>true</tt> if this map maps one or more keys to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *         specified value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @throws ClassCastException if the value is of an inappropriate type for
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   167
     *         this map
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   168
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @throws NullPointerException if the specified value is null and this
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   170
     *         map does not permit null values
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   171
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    boolean containsValue(Object value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Returns the value to which the specified key is mapped,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * or {@code null} if this map contains no mapping for the key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * <p>More formally, if this map contains a mapping from a key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * {@code k} to a value {@code v} such that {@code (key==null ? k==null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * key.equals(k))}, then this method returns {@code v}; otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * it returns {@code null}.  (There can be at most one such mapping.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * <p>If this map permits null values, then a return value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * {@code null} does not <i>necessarily</i> indicate that the map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * contains no mapping for the key; it's also possible that the map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * explicitly maps the key to {@code null}.  The {@link #containsKey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * containsKey} operation may be used to distinguish these two cases.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @param key the key whose associated value is to be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @return the value to which the specified key is mapped, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *         {@code null} if this map contains no mapping for the key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @throws ClassCastException if the key is of an inappropriate type for
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   194
     *         this map
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   195
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @throws NullPointerException if the specified key is null and this map
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   197
     *         does not permit null keys
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   198
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    V get(Object key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    // Modification Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * Associates the specified value with the specified key in this map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * (optional operation).  If the map previously contained a mapping for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * the key, the old value is replaced by the specified value.  (A map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * <tt>m</tt> is said to contain a mapping for a key <tt>k</tt> if and only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * if {@link #containsKey(Object) m.containsKey(k)} would return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * <tt>true</tt>.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @param key key with which the specified value is to be associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @param value value to be associated with the specified key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @return the previous value associated with <tt>key</tt>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *         (A <tt>null</tt> return can also indicate that the map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *         previously associated <tt>null</tt> with <tt>key</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *         if the implementation supports <tt>null</tt> values.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @throws UnsupportedOperationException if the <tt>put</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *         is not supported by this map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @throws ClassCastException if the class of the specified key or value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *         prevents it from being stored in this map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @throws NullPointerException if the specified key or value is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *         and this map does not permit null keys or values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @throws IllegalArgumentException if some property of the specified key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *         or value prevents it from being stored in this map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    V put(K key, V value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Removes the mapping for a key from this map if it is present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * (optional operation).   More formally, if this map contains a mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * from key <tt>k</tt> to value <tt>v</tt> such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * <code>(key==null ?  k==null : key.equals(k))</code>, that mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * is removed.  (The map can contain at most one such mapping.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * <p>Returns the value to which this map previously associated the key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * or <tt>null</tt> if the map contained no mapping for the key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * <p>If this map permits null values, then a return value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * <tt>null</tt> does not <i>necessarily</i> indicate that the map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * contained no mapping for the key; it's also possible that the map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * explicitly mapped the key to <tt>null</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * <p>The map will not contain a mapping for the specified key once the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * call returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @param key key whose mapping is to be removed from the map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @return the previous value associated with <tt>key</tt>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @throws UnsupportedOperationException if the <tt>remove</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *         is not supported by this map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @throws ClassCastException if the key is of an inappropriate type for
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   254
     *         this map
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   255
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @throws NullPointerException if the specified key is null and this
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   257
     *         map does not permit null keys
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   258
     * (<a href="Collection.html#optional-restrictions">optional</a>)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    V remove(Object key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    // Bulk Operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Copies all of the mappings from the specified map to this map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * (optional operation).  The effect of this call is equivalent to that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * of calling {@link #put(Object,Object) put(k, v)} on this map once
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * for each mapping from key <tt>k</tt> to value <tt>v</tt> in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * specified map.  The behavior of this operation is undefined if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * specified map is modified while the operation is in progress.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @param m mappings to be stored in this map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @throws UnsupportedOperationException if the <tt>putAll</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *         is not supported by this map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @throws ClassCastException if the class of a key or value in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *         specified map prevents it from being stored in this map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @throws NullPointerException if the specified map is null, or if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *         this map does not permit null keys or values, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *         specified map contains null keys or values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @throws IllegalArgumentException if some property of a key or value in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *         the specified map prevents it from being stored in this map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    void putAll(Map<? extends K, ? extends V> m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Removes all of the mappings from this map (optional operation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * The map will be empty after this call returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @throws UnsupportedOperationException if the <tt>clear</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *         is not supported by this map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    void clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    // Views
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * Returns a {@link Set} view of the keys contained in this map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * The set is backed by the map, so changes to the map are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * reflected in the set, and vice-versa.  If the map is modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * while an iteration over the set is in progress (except through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * the iterator's own <tt>remove</tt> operation), the results of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * the iteration are undefined.  The set supports element removal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * which removes the corresponding mapping from the map, via the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * <tt>Iterator.remove</tt>, <tt>Set.remove</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * <tt>removeAll</tt>, <tt>retainAll</tt>, and <tt>clear</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * operations.  It does not support the <tt>add</tt> or <tt>addAll</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @return a set view of the keys contained in this map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    Set<K> keySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * Returns a {@link Collection} view of the values contained in this map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * The collection is backed by the map, so changes to the map are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * reflected in the collection, and vice-versa.  If the map is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * modified while an iteration over the collection is in progress
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * (except through the iterator's own <tt>remove</tt> operation),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * the results of the iteration are undefined.  The collection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * supports element removal, which removes the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * mapping from the map, via the <tt>Iterator.remove</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * <tt>Collection.remove</tt>, <tt>removeAll</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * <tt>retainAll</tt> and <tt>clear</tt> operations.  It does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * support the <tt>add</tt> or <tt>addAll</tt> operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @return a collection view of the values contained in this map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    Collection<V> values();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * Returns a {@link Set} view of the mappings contained in this map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * The set is backed by the map, so changes to the map are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * reflected in the set, and vice-versa.  If the map is modified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * while an iteration over the set is in progress (except through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * the iterator's own <tt>remove</tt> operation, or through the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * <tt>setValue</tt> operation on a map entry returned by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * iterator) the results of the iteration are undefined.  The set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * supports element removal, which removes the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * mapping from the map, via the <tt>Iterator.remove</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * <tt>Set.remove</tt>, <tt>removeAll</tt>, <tt>retainAll</tt> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * <tt>clear</tt> operations.  It does not support the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * <tt>add</tt> or <tt>addAll</tt> operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @return a set view of the mappings contained in this map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    Set<Map.Entry<K, V>> entrySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * A map entry (key-value pair).  The <tt>Map.entrySet</tt> method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * a collection-view of the map, whose elements are of this class.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * <i>only</i> way to obtain a reference to a map entry is from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * iterator of this collection-view.  These <tt>Map.Entry</tt> objects are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * valid <i>only</i> for the duration of the iteration; more formally,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * the behavior of a map entry is undefined if the backing map has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * modified after the entry was returned by the iterator, except through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * the <tt>setValue</tt> operation on the map entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @see Map#entrySet()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    interface Entry<K,V> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
         * Returns the key corresponding to this entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
         * @return the key corresponding to this entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
         * @throws IllegalStateException implementations may, but are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
         *         required to, throw this exception if the entry has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
         *         removed from the backing map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        K getKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
         * Returns the value corresponding to this entry.  If the mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
         * has been removed from the backing map (by the iterator's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
         * <tt>remove</tt> operation), the results of this call are undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
         * @return the value corresponding to this entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
         * @throws IllegalStateException implementations may, but are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
         *         required to, throw this exception if the entry has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
         *         removed from the backing map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        V getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
         * Replaces the value corresponding to this entry with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
         * value (optional operation).  (Writes through to the map.)  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
         * behavior of this call is undefined if the mapping has already been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
         * removed from the map (by the iterator's <tt>remove</tt> operation).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
         * @param value new value to be stored in this entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
         * @return old value corresponding to the entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
         * @throws UnsupportedOperationException if the <tt>put</tt> operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
         *         is not supported by the backing map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
         * @throws ClassCastException if the class of the specified value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
         *         prevents it from being stored in the backing map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
         * @throws NullPointerException if the backing map does not permit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
         *         null values, and the specified value is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
         * @throws IllegalArgumentException if some property of this value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
         *         prevents it from being stored in the backing map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
         * @throws IllegalStateException implementations may, but are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
         *         required to, throw this exception if the entry has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
         *         removed from the backing map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        V setValue(V value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
         * Compares the specified object with this entry for equality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
         * Returns <tt>true</tt> if the given object is also a map entry and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
         * the two entries represent the same mapping.  More formally, two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
         * entries <tt>e1</tt> and <tt>e2</tt> represent the same mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
         * if<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
         *     (e1.getKey()==null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
         *      e2.getKey()==null : e1.getKey().equals(e2.getKey()))  &amp;&amp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
         *     (e1.getValue()==null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
         *      e2.getValue()==null : e1.getValue().equals(e2.getValue()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
         * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
         * This ensures that the <tt>equals</tt> method works properly across
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
         * different implementations of the <tt>Map.Entry</tt> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
         * @param o object to be compared for equality with this map entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
         * @return <tt>true</tt> if the specified object is equal to this map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
         *         entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        boolean equals(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
         * Returns the hash code value for this map entry.  The hash code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
         * of a map entry <tt>e</tt> is defined to be: <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
         *     (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
         *     (e.getValue()==null ? 0 : e.getValue().hashCode())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
         * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
         * This ensures that <tt>e1.equals(e2)</tt> implies that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
         * <tt>e1.hashCode()==e2.hashCode()</tt> for any two Entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
         * <tt>e1</tt> and <tt>e2</tt>, as required by the general
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
         * contract of <tt>Object.hashCode</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
         * @return the hash code value for this map entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
         * @see Object#hashCode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
         * @see Object#equals(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
         * @see #equals(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        int hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    // Comparison and hashing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * Compares the specified object with this map for equality.  Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * <tt>true</tt> if the given object is also a map and the two maps
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * represent the same mappings.  More formally, two maps <tt>m1</tt> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * <tt>m2</tt> represent the same mappings if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * <tt>m1.entrySet().equals(m2.entrySet())</tt>.  This ensures that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * <tt>equals</tt> method works properly across different implementations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * of the <tt>Map</tt> interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @param o object to be compared for equality with this map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @return <tt>true</tt> if the specified object is equal to this map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    boolean equals(Object o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * Returns the hash code value for this map.  The hash code of a map is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * defined to be the sum of the hash codes of each entry in the map's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * <tt>entrySet()</tt> view.  This ensures that <tt>m1.equals(m2)</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * implies that <tt>m1.hashCode()==m2.hashCode()</tt> for any two maps
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * <tt>m1</tt> and <tt>m2</tt>, as required by the general contract of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * {@link Object#hashCode}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @return the hash code value for this map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * @see Map.Entry#hashCode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * @see Object#equals(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * @see #equals(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    int hashCode();
9503
588cf31d584a 6546713: link the word (optional) in exception specifications to the text which provides explanation and context.
mduigou
parents: 5506
diff changeset
   477
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
}