src/share/classes/java/util/Hashtable.java

Print this page
rev 5958 : 8000955: Hashtable.Entry.hashCode() does not conform to Map.Entry.hashCode() defined behaviour
Reviewed-by: mduigou


1042 
1043         public V setValue(V value) {
1044             if (value == null)
1045                 throw new NullPointerException();
1046 
1047             V oldValue = this.value;
1048             this.value = value;
1049             return oldValue;
1050         }
1051 
1052         public boolean equals(Object o) {
1053             if (!(o instanceof Map.Entry))
1054                 return false;
1055             Map.Entry<?,?> e = (Map.Entry<?,?>)o;
1056 
1057             return (key==null ? e.getKey()==null : key.equals(e.getKey())) &&
1058                (value==null ? e.getValue()==null : value.equals(e.getValue()));
1059         }
1060 
1061         public int hashCode() {
1062             return hash ^ (value==null ? 0 : value.hashCode());

1063         }
1064 
1065         public String toString() {
1066             return key.toString()+"="+value.toString();
1067         }
1068     }
1069 
1070     // Types of Enumerations/Iterations
1071     private static final int KEYS = 0;
1072     private static final int VALUES = 1;
1073     private static final int ENTRIES = 2;
1074 
1075     /**
1076      * A hashtable enumerator class.  This class implements both the
1077      * Enumeration and Iterator interfaces, but individual instances
1078      * can be created with the Iterator methods disabled.  This is necessary
1079      * to avoid unintentionally increasing the capabilities granted a user
1080      * by passing an Enumeration.
1081      */
1082     private class Enumerator<T> implements Enumeration<T>, Iterator<T> {




1042 
1043         public V setValue(V value) {
1044             if (value == null)
1045                 throw new NullPointerException();
1046 
1047             V oldValue = this.value;
1048             this.value = value;
1049             return oldValue;
1050         }
1051 
1052         public boolean equals(Object o) {
1053             if (!(o instanceof Map.Entry))
1054                 return false;
1055             Map.Entry<?,?> e = (Map.Entry<?,?>)o;
1056 
1057             return (key==null ? e.getKey()==null : key.equals(e.getKey())) &&
1058                (value==null ? e.getValue()==null : value.equals(e.getValue()));
1059         }
1060 
1061         public int hashCode() {
1062             return ((key == null ? 0 : key.hashCode()) ^
1063                     (value==null ? 0 : value.hashCode()));
1064         }
1065 
1066         public String toString() {
1067             return key.toString()+"="+value.toString();
1068         }
1069     }
1070 
1071     // Types of Enumerations/Iterations
1072     private static final int KEYS = 0;
1073     private static final int VALUES = 1;
1074     private static final int ENTRIES = 2;
1075 
1076     /**
1077      * A hashtable enumerator class.  This class implements both the
1078      * Enumeration and Iterator interfaces, but individual instances
1079      * can be created with the Iterator methods disabled.  This is necessary
1080      * to avoid unintentionally increasing the capabilities granted a user
1081      * by passing an Enumeration.
1082      */
1083     private class Enumerator<T> implements Enumeration<T>, Iterator<T> {