1 |
|
/* |
2 |
|
* %W% %E% |
3 |
|
* |
4 |
< |
* Copyright 2005 Sun Microsystems, Inc. All rights reserved. |
4 |
> |
* Copyright 2006 Sun Microsystems, Inc. All rights reserved. |
5 |
|
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. |
6 |
|
*/ |
7 |
|
|
8 |
|
package java.util; |
9 |
– |
import java.util.*; // for javadoc (till 6280605 is fixed) |
9 |
|
import java.util.Map.Entry; |
10 |
|
|
11 |
|
/** |
29 |
|
* constructor, as per the recommendation in the <tt>Map</tt> interface |
30 |
|
* specification. |
31 |
|
* |
32 |
< |
* <p>The documentation for each non-abstract methods in this class describes its |
32 |
> |
* <p>The documentation for each non-abstract method in this class describes its |
33 |
|
* implementation in detail. Each of these methods may be overridden if the |
34 |
|
* map being implemented admits a more efficient implementation. |
35 |
|
* |
36 |
|
* <p>This class is a member of the |
37 |
< |
* <a href="{@docRoot}/../guide/collections/index.html"> |
37 |
> |
* <a href="{@docRoot}/../technotes/guides/collections/index.html"> |
38 |
|
* Java Collections Framework</a>. |
39 |
|
* |
40 |
|
* @param <K> the type of keys maintained by this map |
595 |
|
return oldValue; |
596 |
|
} |
597 |
|
|
598 |
+ |
/** |
599 |
+ |
* Compares the specified object with this entry for equality. |
600 |
+ |
* Returns {@code true} if the given object is also a map entry and |
601 |
+ |
* the two entries represent the same mapping. More formally, two |
602 |
+ |
* entries {@code e1} and {@code e2} represent the same mapping |
603 |
+ |
* if<pre> |
604 |
+ |
* (e1.getKey()==null ? |
605 |
+ |
* e2.getKey()==null : |
606 |
+ |
* e1.getKey().equals(e2.getKey())) |
607 |
+ |
* && |
608 |
+ |
* (e1.getValue()==null ? |
609 |
+ |
* e2.getValue()==null : |
610 |
+ |
* e1.getValue().equals(e2.getValue()))</pre> |
611 |
+ |
* This ensures that the {@code equals} method works properly across |
612 |
+ |
* different implementations of the {@code Map.Entry} interface. |
613 |
+ |
* |
614 |
+ |
* @param o object to be compared for equality with this map entry |
615 |
+ |
* @return {@code true} if the specified object is equal to this map |
616 |
+ |
* entry |
617 |
+ |
* @see #hashCode |
618 |
+ |
*/ |
619 |
|
public boolean equals(Object o) { |
620 |
|
if (!(o instanceof Map.Entry)) |
621 |
|
return false; |
623 |
|
return eq(key, e.getKey()) && eq(value, e.getValue()); |
624 |
|
} |
625 |
|
|
626 |
+ |
/** |
627 |
+ |
* Returns the hash code value for this map entry. The hash code |
628 |
+ |
* of a map entry {@code e} is defined to be: <pre> |
629 |
+ |
* (e.getKey()==null ? 0 : e.getKey().hashCode()) ^ |
630 |
+ |
* (e.getValue()==null ? 0 : e.getValue().hashCode())</pre> |
631 |
+ |
* This ensures that {@code e1.equals(e2)} implies that |
632 |
+ |
* {@code e1.hashCode()==e2.hashCode()} for any two Entries |
633 |
+ |
* {@code e1} and {@code e2}, as required by the general |
634 |
+ |
* contract of {@link Object#hashCode}. |
635 |
+ |
* |
636 |
+ |
* @return the hash code value for this map entry |
637 |
+ |
* @see #equals |
638 |
+ |
*/ |
639 |
|
public int hashCode() { |
640 |
|
return (key == null ? 0 : key.hashCode()) ^ |
641 |
|
(value == null ? 0 : value.hashCode()); |
726 |
|
throw new UnsupportedOperationException(); |
727 |
|
} |
728 |
|
|
729 |
+ |
/** |
730 |
+ |
* Compares the specified object with this entry for equality. |
731 |
+ |
* Returns {@code true} if the given object is also a map entry and |
732 |
+ |
* the two entries represent the same mapping. More formally, two |
733 |
+ |
* entries {@code e1} and {@code e2} represent the same mapping |
734 |
+ |
* if<pre> |
735 |
+ |
* (e1.getKey()==null ? |
736 |
+ |
* e2.getKey()==null : |
737 |
+ |
* e1.getKey().equals(e2.getKey())) |
738 |
+ |
* && |
739 |
+ |
* (e1.getValue()==null ? |
740 |
+ |
* e2.getValue()==null : |
741 |
+ |
* e1.getValue().equals(e2.getValue()))</pre> |
742 |
+ |
* This ensures that the {@code equals} method works properly across |
743 |
+ |
* different implementations of the {@code Map.Entry} interface. |
744 |
+ |
* |
745 |
+ |
* @param o object to be compared for equality with this map entry |
746 |
+ |
* @return {@code true} if the specified object is equal to this map |
747 |
+ |
* entry |
748 |
+ |
* @see #hashCode |
749 |
+ |
*/ |
750 |
|
public boolean equals(Object o) { |
751 |
|
if (!(o instanceof Map.Entry)) |
752 |
|
return false; |
754 |
|
return eq(key, e.getKey()) && eq(value, e.getValue()); |
755 |
|
} |
756 |
|
|
757 |
+ |
/** |
758 |
+ |
* Returns the hash code value for this map entry. The hash code |
759 |
+ |
* of a map entry {@code e} is defined to be: <pre> |
760 |
+ |
* (e.getKey()==null ? 0 : e.getKey().hashCode()) ^ |
761 |
+ |
* (e.getValue()==null ? 0 : e.getValue().hashCode())</pre> |
762 |
+ |
* This ensures that {@code e1.equals(e2)} implies that |
763 |
+ |
* {@code e1.hashCode()==e2.hashCode()} for any two Entries |
764 |
+ |
* {@code e1} and {@code e2}, as required by the general |
765 |
+ |
* contract of {@link Object#hashCode}. |
766 |
+ |
* |
767 |
+ |
* @return the hash code value for this map entry |
768 |
+ |
* @see #equals |
769 |
+ |
*/ |
770 |
|
public int hashCode() { |
771 |
|
return (key == null ? 0 : key.hashCode()) ^ |
772 |
|
(value == null ? 0 : value.hashCode()); |