src/share/classes/java/util/HashMap.java

Print this page




1195                 removeNode(hash, key, null, false, true);
1196         }
1197         else if (v != null) {
1198             if (t != null)
1199                 t.putTreeVal(this, tab, hash, key, v);
1200             else {
1201                 tab[i] = newNode(hash, key, v, first);
1202                 if (binCount >= TREEIFY_THRESHOLD - 1)
1203                     treeifyBin(tab, hash);
1204             }
1205             ++modCount;
1206             ++size;
1207             afterNodeInsertion(true);
1208         }
1209         return v;
1210     }
1211 
1212     @Override
1213     public V merge(K key, V value,
1214                    BiFunction<? super V, ? super V, ? extends V> remappingFunction) {


1215         if (remappingFunction == null)
1216             throw new NullPointerException();
1217         int hash = hash(key);
1218         Node<K,V>[] tab; Node<K,V> first; int n, i;
1219         int binCount = 0;
1220         TreeNode<K,V> t = null;
1221         Node<K,V> old = null;
1222         if (size > threshold || (tab = table) == null ||
1223             (n = tab.length) == 0)
1224             n = (tab = resize()).length;
1225         if ((first = tab[i = (n - 1) & hash]) != null) {
1226             if (first instanceof TreeNode)
1227                 old = (t = (TreeNode<K,V>)first).getTreeNode(hash, key);
1228             else {
1229                 Node<K,V> e = first; K k;
1230                 do {
1231                     if (e.hash == hash &&
1232                         ((k = e.key) == key || (key != null && key.equals(k)))) {
1233                         old = e;
1234                         break;




1195                 removeNode(hash, key, null, false, true);
1196         }
1197         else if (v != null) {
1198             if (t != null)
1199                 t.putTreeVal(this, tab, hash, key, v);
1200             else {
1201                 tab[i] = newNode(hash, key, v, first);
1202                 if (binCount >= TREEIFY_THRESHOLD - 1)
1203                     treeifyBin(tab, hash);
1204             }
1205             ++modCount;
1206             ++size;
1207             afterNodeInsertion(true);
1208         }
1209         return v;
1210     }
1211 
1212     @Override
1213     public V merge(K key, V value,
1214                    BiFunction<? super V, ? super V, ? extends V> remappingFunction) {
1215         if (value == null)
1216             throw new NullPointerException();
1217         if (remappingFunction == null)
1218             throw new NullPointerException();
1219         int hash = hash(key);
1220         Node<K,V>[] tab; Node<K,V> first; int n, i;
1221         int binCount = 0;
1222         TreeNode<K,V> t = null;
1223         Node<K,V> old = null;
1224         if (size > threshold || (tab = table) == null ||
1225             (n = tab.length) == 0)
1226             n = (tab = resize()).length;
1227         if ((first = tab[i = (n - 1) & hash]) != null) {
1228             if (first instanceof TreeNode)
1229                 old = (t = (TreeNode<K,V>)first).getTreeNode(hash, key);
1230             else {
1231                 Node<K,V> e = first; K k;
1232                 do {
1233                     if (e.hash == hash &&
1234                         ((k = e.key) == key || (key != null && key.equals(k)))) {
1235                         old = e;
1236                         break;