596 |
|
return oldValue; |
597 |
|
} |
598 |
|
|
599 |
+ |
/** |
600 |
+ |
* Compares the specified object with this entry for equality. |
601 |
+ |
* Returns {@code true} if the given object is also a map entry and |
602 |
+ |
* the two entries represent the same mapping. More formally, two |
603 |
+ |
* entries {@code e1} and {@code e2} represent the same mapping |
604 |
+ |
* if<pre> |
605 |
+ |
* (e1.getKey()==null ? |
606 |
+ |
* e2.getKey()==null : |
607 |
+ |
* e1.getKey().equals(e2.getKey())) |
608 |
+ |
* && |
609 |
+ |
* (e1.getValue()==null ? |
610 |
+ |
* e2.getValue()==null : |
611 |
+ |
* e1.getValue().equals(e2.getValue()))</pre> |
612 |
+ |
* This ensures that the {@code equals} method works properly across |
613 |
+ |
* different implementations of the {@code Map.Entry} interface. |
614 |
+ |
* |
615 |
+ |
* @param o object to be compared for equality with this map entry |
616 |
+ |
* @return {@code true} if the specified object is equal to this map |
617 |
+ |
* entry |
618 |
+ |
* @see #hashCode |
619 |
+ |
*/ |
620 |
|
public boolean equals(Object o) { |
621 |
|
if (!(o instanceof Map.Entry)) |
622 |
|
return false; |
624 |
|
return eq(key, e.getKey()) && eq(value, e.getValue()); |
625 |
|
} |
626 |
|
|
627 |
+ |
/** |
628 |
+ |
* Returns the hash code value for this map entry. The hash code |
629 |
+ |
* of a map entry {@code e} is defined to be: <pre> |
630 |
+ |
* (e.getKey()==null ? 0 : e.getKey().hashCode()) ^ |
631 |
+ |
* (e.getValue()==null ? 0 : e.getValue().hashCode())</pre> |
632 |
+ |
* This ensures that {@code e1.equals(e2)} implies that |
633 |
+ |
* {@code e1.hashCode()==e2.hashCode()} for any two Entries |
634 |
+ |
* {@code e1} and {@code e2}, as required by the general |
635 |
+ |
* contract of {@link Object#hashCode}. |
636 |
+ |
* |
637 |
+ |
* @return the hash code value for this map entry |
638 |
+ |
* @see #equals |
639 |
+ |
*/ |
640 |
|
public int hashCode() { |
641 |
|
return (key == null ? 0 : key.hashCode()) ^ |
642 |
|
(value == null ? 0 : value.hashCode()); |
727 |
|
throw new UnsupportedOperationException(); |
728 |
|
} |
729 |
|
|
730 |
+ |
/** |
731 |
+ |
* Compares the specified object with this entry for equality. |
732 |
+ |
* Returns {@code true} if the given object is also a map entry and |
733 |
+ |
* the two entries represent the same mapping. More formally, two |
734 |
+ |
* entries {@code e1} and {@code e2} represent the same mapping |
735 |
+ |
* if<pre> |
736 |
+ |
* (e1.getKey()==null ? |
737 |
+ |
* e2.getKey()==null : |
738 |
+ |
* e1.getKey().equals(e2.getKey())) |
739 |
+ |
* && |
740 |
+ |
* (e1.getValue()==null ? |
741 |
+ |
* e2.getValue()==null : |
742 |
+ |
* e1.getValue().equals(e2.getValue()))</pre> |
743 |
+ |
* This ensures that the {@code equals} method works properly across |
744 |
+ |
* different implementations of the {@code Map.Entry} interface. |
745 |
+ |
* |
746 |
+ |
* @param o object to be compared for equality with this map entry |
747 |
+ |
* @return {@code true} if the specified object is equal to this map |
748 |
+ |
* entry |
749 |
+ |
* @see #hashCode |
750 |
+ |
*/ |
751 |
|
public boolean equals(Object o) { |
752 |
|
if (!(o instanceof Map.Entry)) |
753 |
|
return false; |
755 |
|
return eq(key, e.getKey()) && eq(value, e.getValue()); |
756 |
|
} |
757 |
|
|
758 |
+ |
/** |
759 |
+ |
* Returns the hash code value for this map entry. The hash code |
760 |
+ |
* of a map entry {@code e} is defined to be: <pre> |
761 |
+ |
* (e.getKey()==null ? 0 : e.getKey().hashCode()) ^ |
762 |
+ |
* (e.getValue()==null ? 0 : e.getValue().hashCode())</pre> |
763 |
+ |
* This ensures that {@code e1.equals(e2)} implies that |
764 |
+ |
* {@code e1.hashCode()==e2.hashCode()} for any two Entries |
765 |
+ |
* {@code e1} and {@code e2}, as required by the general |
766 |
+ |
* contract of {@link Object#hashCode}. |
767 |
+ |
* |
768 |
+ |
* @return the hash code value for this map entry |
769 |
+ |
* @see #equals |
770 |
+ |
*/ |
771 |
|
public int hashCode() { |
772 |
|
return (key == null ? 0 : key.hashCode()) ^ |
773 |
|
(value == null ? 0 : value.hashCode()); |