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.13 by jsr166, Mon Jun 20 18:02:22 2005 UTC vs.
Revision 1.16 by jsr166, Wed Aug 24 04:47:24 2005 UTC

# Line 388 | Line 388 | public abstract class AbstractMap<K,V> i
388      // Comparison and hashing
389  
390      /**
391 <     * {@inheritDoc}
391 >     * Compares the specified object with this map for equality.  Returns
392 >     * <tt>true</tt> if the given object is also a map and the two maps
393 >     * represent the same mappings.  More formally, two maps <tt>m1</tt> and
394 >     * <tt>m2</tt> represent the same mappings if
395 >     * <tt>m1.entrySet().equals(m2.entrySet())</tt>.  This ensures that the
396 >     * <tt>equals</tt> method works properly across different implementations
397 >     * of the <tt>Map</tt> interface.
398       *
399       * <p>This implementation first checks if the specified object is this map;
400       * if so it returns <tt>true</tt>.  Then, it checks if the specified
# Line 398 | Line 404 | public abstract class AbstractMap<K,V> i
404       * contains each mapping that this map contains.  If the specified map
405       * fails to contain such a mapping, <tt>false</tt> is returned.  If the
406       * iteration completes, <tt>true</tt> is returned.
407 +     *
408 +     * @param o object to be compared for equality with this map
409 +     * @return <tt>true</tt> if the specified object is equal to this map
410       */
411      public boolean equals(Object o) {
412          if (o == this)
# Line 433 | Line 442 | public abstract class AbstractMap<K,V> i
442      }
443  
444      /**
445 <     * {@inheritDoc}
445 >     * Returns the hash code value for this map.  The hash code of a map is
446 >     * defined to be the sum of the hash codes of each entry in the map's
447 >     * <tt>entrySet()</tt> view.  This ensures that <tt>m1.equals(m2)</tt>
448 >     * implies that <tt>m1.hashCode()==m2.hashCode()</tt> for any two maps
449 >     * <tt>m1</tt> and <tt>m2</tt>, as required by the general contract of
450 >     * {@link Object#hashCode}.
451       *
452       * <p>This implementation iterates over <tt>entrySet()</tt>, calling
453 <     * <tt>hashCode()</tt> on each element (entry) in the set, and
454 <     * adding up the results.
453 >     * {@link Map.Entry#hashCode hashCode()} on each element (entry) in the
454 >     * set, and adding up the results.
455       *
456 +     * @return the hash code value for this map
457       * @see Map.Entry#hashCode()
443     * @see Object#hashCode()
458       * @see Object#equals(Object)
459       * @see Set#equals(Object)
460       */
# Line 517 | Line 531 | public abstract class AbstractMap<K,V> i
531       * Test for equality, checking for nulls.
532       */
533      private static boolean eq(Object o1, Object o2) {
534 <        return (o1 == null ? o2 == null : o1.equals(o2));
534 >        return o1 == null ? o2 == null : o1.equals(o2);
535      }
536  
537      // Implementation Note: SimpleEntry and SimpleImmutableEntry
# Line 534 | Line 548 | public abstract class AbstractMap<K,V> i
548       * facilitates the process of building custom map
549       * implementations. For example, it may be convenient to return
550       * arrays of <tt>SimpleEntry</tt> instances in method
551 <     * <tt>Map.entrySet().toArray</tt>
551 >     * <tt>Map.entrySet().toArray</tt>.
552 >     *
553 >     * @since 1.6
554       */
555 <    public static class SimpleEntry<K,V> implements Entry<K,V> {
555 >    public static class SimpleEntry<K,V>
556 >        implements Entry<K,V>, java.io.Serializable
557 >    {
558 >        private static final long serialVersionUID = -8499721149061103585L;
559 >
560          private final K key;
561          private V value;
562  
# Line 602 | Line 622 | public abstract class AbstractMap<K,V> i
622          }
623  
624          public int hashCode() {
625 <            return ((key   == null)   ? 0 :   key.hashCode()) ^
626 <                   ((value == null)   ? 0 : value.hashCode());
625 >            return (key   == null ? 0 :   key.hashCode()) ^
626 >                   (value == null ? 0 : value.hashCode());
627          }
628  
629          /**
# Line 621 | Line 641 | public abstract class AbstractMap<K,V> i
641      }
642  
643      /**
644 <     * An Entry maintaining an immutable key and value, This class
644 >     * An Entry maintaining an immutable key and value.  This class
645       * does not support method <tt>setValue</tt>.  This class may be
646       * convenient in methods that return thread-safe snapshots of
647       * key-value mappings.
648 +     *
649 +     * @since 1.6
650       */
651 <    public static class SimpleImmutableEntry<K,V> implements Entry<K,V> {
651 >    public static class SimpleImmutableEntry<K,V>
652 >        implements Entry<K,V>, java.io.Serializable
653 >    {
654 >        private static final long serialVersionUID = 7138329143949025153L;
655 >
656          private final K key;
657          private final V value;
658  
# Line 693 | Line 719 | public abstract class AbstractMap<K,V> i
719          }
720  
721          public int hashCode() {
722 <            return ((key   == null)   ? 0 :   key.hashCode()) ^
723 <                   ((value == null)   ? 0 : value.hashCode());
722 >            return (key   == null ? 0 :   key.hashCode()) ^
723 >                   (value == null ? 0 : value.hashCode());
724          }
725  
726          /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines