src/share/classes/java/util/IdentityHashMap.java

Print this page
rev 7932 : 8021591: Additional explicit null checks
Reviewed-by: psandoz, martin, alanb


 980         public Iterator<K> iterator() {
 981             return new KeyIterator();
 982         }
 983         public int size() {
 984             return size;
 985         }
 986         public boolean contains(Object o) {
 987             return containsKey(o);
 988         }
 989         public boolean remove(Object o) {
 990             int oldSize = size;
 991             IdentityHashMap.this.remove(o);
 992             return size != oldSize;
 993         }
 994         /*
 995          * Must revert from AbstractSet's impl to AbstractCollection's, as
 996          * the former contains an optimization that results in incorrect
 997          * behavior when c is a smaller "normal" (non-identity-based) Set.
 998          */
 999         public boolean removeAll(Collection<?> c) {

1000             boolean modified = false;
1001             for (Iterator<K> i = iterator(); i.hasNext(); ) {
1002                 if (c.contains(i.next())) {
1003                     i.remove();
1004                     modified = true;
1005                 }
1006             }
1007             return modified;
1008         }
1009         public void clear() {
1010             IdentityHashMap.this.clear();
1011         }
1012         public int hashCode() {
1013             int result = 0;
1014             for (K key : this)
1015                 result += System.identityHashCode(key);
1016             return result;
1017         }
1018         public Object[] toArray() {
1019             return toArray(new Object[0]);


1195             return containsMapping(entry.getKey(), entry.getValue());
1196         }
1197         public boolean remove(Object o) {
1198             if (!(o instanceof Map.Entry))
1199                 return false;
1200             Map.Entry<?,?> entry = (Map.Entry<?,?>)o;
1201             return removeMapping(entry.getKey(), entry.getValue());
1202         }
1203         public int size() {
1204             return size;
1205         }
1206         public void clear() {
1207             IdentityHashMap.this.clear();
1208         }
1209         /*
1210          * Must revert from AbstractSet's impl to AbstractCollection's, as
1211          * the former contains an optimization that results in incorrect
1212          * behavior when c is a smaller "normal" (non-identity-based) Set.
1213          */
1214         public boolean removeAll(Collection<?> c) {

1215             boolean modified = false;
1216             for (Iterator<Map.Entry<K,V>> i = iterator(); i.hasNext(); ) {
1217                 if (c.contains(i.next())) {
1218                     i.remove();
1219                     modified = true;
1220                 }
1221             }
1222             return modified;
1223         }
1224 
1225         public Object[] toArray() {
1226             return toArray(new Object[0]);
1227         }
1228 
1229         @SuppressWarnings("unchecked")
1230         public <T> T[] toArray(T[] a) {
1231             int expectedModCount = modCount;
1232             int size = size();
1233             if (a.length < size)
1234                 a = (T[]) Array.newInstance(a.getClass().getComponentType(), size);




 980         public Iterator<K> iterator() {
 981             return new KeyIterator();
 982         }
 983         public int size() {
 984             return size;
 985         }
 986         public boolean contains(Object o) {
 987             return containsKey(o);
 988         }
 989         public boolean remove(Object o) {
 990             int oldSize = size;
 991             IdentityHashMap.this.remove(o);
 992             return size != oldSize;
 993         }
 994         /*
 995          * Must revert from AbstractSet's impl to AbstractCollection's, as
 996          * the former contains an optimization that results in incorrect
 997          * behavior when c is a smaller "normal" (non-identity-based) Set.
 998          */
 999         public boolean removeAll(Collection<?> c) {
1000             Objects.requireNonNull(c);
1001             boolean modified = false;
1002             for (Iterator<K> i = iterator(); i.hasNext(); ) {
1003                 if (c.contains(i.next())) {
1004                     i.remove();
1005                     modified = true;
1006                 }
1007             }
1008             return modified;
1009         }
1010         public void clear() {
1011             IdentityHashMap.this.clear();
1012         }
1013         public int hashCode() {
1014             int result = 0;
1015             for (K key : this)
1016                 result += System.identityHashCode(key);
1017             return result;
1018         }
1019         public Object[] toArray() {
1020             return toArray(new Object[0]);


1196             return containsMapping(entry.getKey(), entry.getValue());
1197         }
1198         public boolean remove(Object o) {
1199             if (!(o instanceof Map.Entry))
1200                 return false;
1201             Map.Entry<?,?> entry = (Map.Entry<?,?>)o;
1202             return removeMapping(entry.getKey(), entry.getValue());
1203         }
1204         public int size() {
1205             return size;
1206         }
1207         public void clear() {
1208             IdentityHashMap.this.clear();
1209         }
1210         /*
1211          * Must revert from AbstractSet's impl to AbstractCollection's, as
1212          * the former contains an optimization that results in incorrect
1213          * behavior when c is a smaller "normal" (non-identity-based) Set.
1214          */
1215         public boolean removeAll(Collection<?> c) {
1216             Objects.requireNonNull(c);
1217             boolean modified = false;
1218             for (Iterator<Map.Entry<K,V>> i = iterator(); i.hasNext(); ) {
1219                 if (c.contains(i.next())) {
1220                     i.remove();
1221                     modified = true;
1222                 }
1223             }
1224             return modified;
1225         }
1226 
1227         public Object[] toArray() {
1228             return toArray(new Object[0]);
1229         }
1230 
1231         @SuppressWarnings("unchecked")
1232         public <T> T[] toArray(T[] a) {
1233             int expectedModCount = modCount;
1234             int size = size();
1235             if (a.length < size)
1236                 a = (T[]) Array.newInstance(a.getClass().getComponentType(), size);