jdk/src/share/classes/java/util/AbstractMap.java
changeset 22096 ca113030b2b3
parent 18818 a9ceff754226
child 22097 49bc688ee68b
equal deleted inserted replaced
22010:a1ee9743f4ee 22096:ca113030b2b3
    76     // Query Operations
    76     // Query Operations
    77 
    77 
    78     /**
    78     /**
    79      * {@inheritDoc}
    79      * {@inheritDoc}
    80      *
    80      *
    81      * <p>This implementation returns <tt>entrySet().size()</tt>.
    81      * @implSpec
       
    82      * This implementation returns <tt>entrySet().size()</tt>.
    82      */
    83      */
    83     public int size() {
    84     public int size() {
    84         return entrySet().size();
    85         return entrySet().size();
    85     }
    86     }
    86 
    87 
    87     /**
    88     /**
    88      * {@inheritDoc}
    89      * {@inheritDoc}
    89      *
    90      *
    90      * <p>This implementation returns <tt>size() == 0</tt>.
    91      * @implSpec
       
    92      * This implementation returns <tt>size() == 0</tt>.
    91      */
    93      */
    92     public boolean isEmpty() {
    94     public boolean isEmpty() {
    93         return size() == 0;
    95         return size() == 0;
    94     }
    96     }
    95 
    97 
    96     /**
    98     /**
    97      * {@inheritDoc}
    99      * {@inheritDoc}
    98      *
   100      *
    99      * <p>This implementation iterates over <tt>entrySet()</tt> searching
   101      * @implSpec
       
   102      * This implementation iterates over <tt>entrySet()</tt> searching
   100      * for an entry with the specified value.  If such an entry is found,
   103      * for an entry with the specified value.  If such an entry is found,
   101      * <tt>true</tt> is returned.  If the iteration terminates without
   104      * <tt>true</tt> is returned.  If the iteration terminates without
   102      * finding such an entry, <tt>false</tt> is returned.  Note that this
   105      * finding such an entry, <tt>false</tt> is returned.  Note that this
   103      * implementation requires linear time in the size of the map.
   106      * implementation requires linear time in the size of the map.
   104      *
   107      *
   124     }
   127     }
   125 
   128 
   126     /**
   129     /**
   127      * {@inheritDoc}
   130      * {@inheritDoc}
   128      *
   131      *
   129      * <p>This implementation iterates over <tt>entrySet()</tt> searching
   132      * @implSpec
       
   133      * This implementation iterates over <tt>entrySet()</tt> searching
   130      * for an entry with the specified key.  If such an entry is found,
   134      * for an entry with the specified key.  If such an entry is found,
   131      * <tt>true</tt> is returned.  If the iteration terminates without
   135      * <tt>true</tt> is returned.  If the iteration terminates without
   132      * finding such an entry, <tt>false</tt> is returned.  Note that this
   136      * finding such an entry, <tt>false</tt> is returned.  Note that this
   133      * implementation requires linear time in the size of the map; many
   137      * implementation requires linear time in the size of the map; many
   134      * implementations will override this method.
   138      * implementations will override this method.
   155     }
   159     }
   156 
   160 
   157     /**
   161     /**
   158      * {@inheritDoc}
   162      * {@inheritDoc}
   159      *
   163      *
   160      * <p>This implementation iterates over <tt>entrySet()</tt> searching
   164      * @implSpec
       
   165      * This implementation iterates over <tt>entrySet()</tt> searching
   161      * for an entry with the specified key.  If such an entry is found,
   166      * for an entry with the specified key.  If such an entry is found,
   162      * the entry's value is returned.  If the iteration terminates without
   167      * the entry's value is returned.  If the iteration terminates without
   163      * finding such an entry, <tt>null</tt> is returned.  Note that this
   168      * finding such an entry, <tt>null</tt> is returned.  Note that this
   164      * implementation requires linear time in the size of the map; many
   169      * implementation requires linear time in the size of the map; many
   165      * implementations will override this method.
   170      * implementations will override this method.
   189     // Modification Operations
   194     // Modification Operations
   190 
   195 
   191     /**
   196     /**
   192      * {@inheritDoc}
   197      * {@inheritDoc}
   193      *
   198      *
   194      * <p>This implementation always throws an
   199      * @implSpec
       
   200      * This implementation always throws an
   195      * <tt>UnsupportedOperationException</tt>.
   201      * <tt>UnsupportedOperationException</tt>.
   196      *
   202      *
   197      * @throws UnsupportedOperationException {@inheritDoc}
   203      * @throws UnsupportedOperationException {@inheritDoc}
   198      * @throws ClassCastException            {@inheritDoc}
   204      * @throws ClassCastException            {@inheritDoc}
   199      * @throws NullPointerException          {@inheritDoc}
   205      * @throws NullPointerException          {@inheritDoc}
   204     }
   210     }
   205 
   211 
   206     /**
   212     /**
   207      * {@inheritDoc}
   213      * {@inheritDoc}
   208      *
   214      *
   209      * <p>This implementation iterates over <tt>entrySet()</tt> searching for an
   215      * @implSpec
       
   216      * This implementation iterates over <tt>entrySet()</tt> searching for an
   210      * entry with the specified key.  If such an entry is found, its value is
   217      * entry with the specified key.  If such an entry is found, its value is
   211      * obtained with its <tt>getValue</tt> operation, the entry is removed
   218      * obtained with its <tt>getValue</tt> operation, the entry is removed
   212      * from the collection (and the backing map) with the iterator's
   219      * from the collection (and the backing map) with the iterator's
   213      * <tt>remove</tt> operation, and the saved value is returned.  If the
   220      * <tt>remove</tt> operation, and the saved value is returned.  If the
   214      * iteration terminates without finding such an entry, <tt>null</tt> is
   221      * iteration terminates without finding such an entry, <tt>null</tt> is
   253     // Bulk Operations
   260     // Bulk Operations
   254 
   261 
   255     /**
   262     /**
   256      * {@inheritDoc}
   263      * {@inheritDoc}
   257      *
   264      *
   258      * <p>This implementation iterates over the specified map's
   265      * @implSpec
       
   266      * This implementation iterates over the specified map's
   259      * <tt>entrySet()</tt> collection, and calls this map's <tt>put</tt>
   267      * <tt>entrySet()</tt> collection, and calls this map's <tt>put</tt>
   260      * operation once for each entry returned by the iteration.
   268      * operation once for each entry returned by the iteration.
   261      *
   269      *
   262      * <p>Note that this implementation throws an
   270      * <p>Note that this implementation throws an
   263      * <tt>UnsupportedOperationException</tt> if this map does not support
   271      * <tt>UnsupportedOperationException</tt> if this map does not support
   274     }
   282     }
   275 
   283 
   276     /**
   284     /**
   277      * {@inheritDoc}
   285      * {@inheritDoc}
   278      *
   286      *
   279      * <p>This implementation calls <tt>entrySet().clear()</tt>.
   287      * @implSpec
       
   288      * This implementation calls <tt>entrySet().clear()</tt>.
   280      *
   289      *
   281      * <p>Note that this implementation throws an
   290      * <p>Note that this implementation throws an
   282      * <tt>UnsupportedOperationException</tt> if the <tt>entrySet</tt>
   291      * <tt>UnsupportedOperationException</tt> if the <tt>entrySet</tt>
   283      * does not support the <tt>clear</tt> operation.
   292      * does not support the <tt>clear</tt> operation.
   284      *
   293      *
   300     transient volatile Collection<V> values = null;
   309     transient volatile Collection<V> values = null;
   301 
   310 
   302     /**
   311     /**
   303      * {@inheritDoc}
   312      * {@inheritDoc}
   304      *
   313      *
   305      * <p>This implementation returns a set that subclasses {@link AbstractSet}.
   314      * @implSpec
       
   315      * This implementation returns a set that subclasses {@link AbstractSet}.
   306      * The subclass's iterator method returns a "wrapper object" over this
   316      * The subclass's iterator method returns a "wrapper object" over this
   307      * map's <tt>entrySet()</tt> iterator.  The <tt>size</tt> method
   317      * map's <tt>entrySet()</tt> iterator.  The <tt>size</tt> method
   308      * delegates to this map's <tt>size</tt> method and the
   318      * delegates to this map's <tt>size</tt> method and the
   309      * <tt>contains</tt> method delegates to this map's
   319      * <tt>contains</tt> method delegates to this map's
   310      * <tt>containsKey</tt> method.
   320      * <tt>containsKey</tt> method.
   356     }
   366     }
   357 
   367 
   358     /**
   368     /**
   359      * {@inheritDoc}
   369      * {@inheritDoc}
   360      *
   370      *
   361      * <p>This implementation returns a collection that subclasses {@link
   371      * @implSpec
       
   372      * This implementation returns a collection that subclasses {@link
   362      * AbstractCollection}.  The subclass's iterator method returns a
   373      * AbstractCollection}.  The subclass's iterator method returns a
   363      * "wrapper object" over this map's <tt>entrySet()</tt> iterator.
   374      * "wrapper object" over this map's <tt>entrySet()</tt> iterator.
   364      * The <tt>size</tt> method delegates to this map's <tt>size</tt>
   375      * The <tt>size</tt> method delegates to this map's <tt>size</tt>
   365      * method and the <tt>contains</tt> method delegates to this map's
   376      * method and the <tt>contains</tt> method delegates to this map's
   366      * <tt>containsValue</tt> method.
   377      * <tt>containsValue</tt> method.
   423      * <tt>m2</tt> represent the same mappings if
   434      * <tt>m2</tt> represent the same mappings if
   424      * <tt>m1.entrySet().equals(m2.entrySet())</tt>.  This ensures that the
   435      * <tt>m1.entrySet().equals(m2.entrySet())</tt>.  This ensures that the
   425      * <tt>equals</tt> method works properly across different implementations
   436      * <tt>equals</tt> method works properly across different implementations
   426      * of the <tt>Map</tt> interface.
   437      * of the <tt>Map</tt> interface.
   427      *
   438      *
   428      * <p>This implementation first checks if the specified object is this map;
   439      * @implSpec
       
   440      * This implementation first checks if the specified object is this map;
   429      * if so it returns <tt>true</tt>.  Then, it checks if the specified
   441      * if so it returns <tt>true</tt>.  Then, it checks if the specified
   430      * object is a map whose size is identical to the size of this map; if
   442      * object is a map whose size is identical to the size of this map; if
   431      * not, it returns <tt>false</tt>.  If so, it iterates over this map's
   443      * not, it returns <tt>false</tt>.  If so, it iterates over this map's
   432      * <tt>entrySet</tt> collection, and checks that the specified map
   444      * <tt>entrySet</tt> collection, and checks that the specified map
   433      * contains each mapping that this map contains.  If the specified map
   445      * contains each mapping that this map contains.  If the specified map
   476      * <tt>entrySet()</tt> view.  This ensures that <tt>m1.equals(m2)</tt>
   488      * <tt>entrySet()</tt> view.  This ensures that <tt>m1.equals(m2)</tt>
   477      * implies that <tt>m1.hashCode()==m2.hashCode()</tt> for any two maps
   489      * implies that <tt>m1.hashCode()==m2.hashCode()</tt> for any two maps
   478      * <tt>m1</tt> and <tt>m2</tt>, as required by the general contract of
   490      * <tt>m1</tt> and <tt>m2</tt>, as required by the general contract of
   479      * {@link Object#hashCode}.
   491      * {@link Object#hashCode}.
   480      *
   492      *
   481      * <p>This implementation iterates over <tt>entrySet()</tt>, calling
   493      * @implSpec
       
   494      * This implementation iterates over <tt>entrySet()</tt>, calling
   482      * {@link Map.Entry#hashCode hashCode()} on each element (entry) in the
   495      * {@link Map.Entry#hashCode hashCode()} on each element (entry) in the
   483      * set, and adding up the results.
   496      * set, and adding up the results.
   484      *
   497      *
   485      * @return the hash code value for this map
   498      * @return the hash code value for this map
   486      * @see Map.Entry#hashCode()
   499      * @see Map.Entry#hashCode()