public V computeIfPresent(K key,BiFunction<? super K,? super V,? extends V> remappingFunction){
  if (key == null || remappingFunction == null)   throw new NullPointerException();
  int h=spread(key.hashCode());
  V val=null;
  int delta=0;
  int binCount=0;
  for (Node<K,V>[] tab=table; ; ) {
    Node<K,V> f;
    int n, i, fh;
    if (tab == null || (n=tab.length) == 0)     tab=initTable();
 else     if ((f=tabAt(tab,i=(n - 1) & h)) == null)     break;
 else     if ((fh=f.hash) == MOVED)     tab=helpTransfer(tab,f);
 else {
synchronized (f) {
        if (tabAt(tab,i) == f) {
          if (fh >= 0) {
            binCount=1;
            for (Node<K,V> e=f, pred=null; ; ++binCount) {
              K ek;
              if (e.hash == h && ((ek=e.key) == key || (ek != null && key.equals(ek)))) {
                val=remappingFunction.apply(key,e.val);
                if (val != null)                 e.val=val;
 else {
                  delta=-1;
                  Node<K,V> en=e.next;
                  if (pred != null)                   pred.next=en;
 else                   setTabAt(tab,i,en);
                }
                break;
              }
              pred=e;
              if ((e=e.next) == null)               break;
            }
          }
 else           if (f instanceof TreeBin) {
            binCount=2;
            TreeBin<K,V> t=(TreeBin<K,V>)f;
            TreeNode<K,V> r, p;
            if ((r=t.root) != null && (p=r.findTreeNode(h,key,null)) != null) {
              val=remappingFunction.apply(key,p.val);
              if (val != null)               p.val=val;
 else {
                delta=-1;
                if (t.removeTreeNode(p))                 setTabAt(tab,i,untreeify(t.first));
              }
            }
          }
        }
      }
      if (binCount != 0)       break;
    }
  }
  if (delta != 0)   addCount((long)delta,binCount);
  return val;
}

public V computeIfPresent ( K key , BiFunction < ? super K , ? super V , ? extends V > remappingFunction ) { if ( key == null || remappingFunction == null ) throw new NullPointerException ( ) ; int h = spread ( key . hashCode ( ) ) ; V val = null ; int delta = 0 ; int binCount = 0 ; for ( Node < K , V > [ ] tab = table ; ; ) { Node < K , V > f ; int n , i , fh ; if ( tab == null || ( n = tab . length ) == 0 ) tab = initTable ( ) ; else if ( ( f = tabAt ( tab , i = ( n - 1 ) & h ) ) == null ) break ; else if ( ( fh = f . hash ) == MOVED ) tab = helpTransfer ( tab , f ) ; else { synchronized ( f ) { if ( tabAt ( tab , i ) == f ) { if ( fh >= 0 ) { binCount = 1 ; for ( Node < K , V > e = f , pred = null ; ; ++ binCount ) { K ek ; if ( e . hash == h && ( ( ek = e . key ) == key || ( ek != null && key . equals ( ek ) ) ) ) { val = remappingFunction . apply ( key , e . val ) ; if ( val != null ) e . val = val ; else { delta = - 1 ; Node < K , V > en = e . next ; if ( pred != null ) pred . next = en ; else setTabAt ( tab , i , en ) ; } break ; } pred = e ; if ( ( e = e . next ) == null ) break ; } } else if ( f instanceof TreeBin ) { binCount = 2 ; TreeBin < K , V > t = ( TreeBin < K , V > ) f ; TreeNode < K , V > r , p ; if ( ( r = t . root ) != null && ( p = r . findTreeNode ( h , key , null ) ) != null ) { val = remappingFunction . apply ( key , p . val ) ; if ( val != null ) p . val = val ; else { delta = - 1 ; if ( t . removeTreeNode ( p ) ) setTabAt ( tab , i , untreeify ( t . first ) ) ; } } } } } if ( binCount != 0 ) break ; } } if ( delta != 0 ) addCount ( ( long ) delta , binCount ) ; return val ; }
if the value for the specified key is present , attempts to compute a new mapping given the key and its current mapped value . the entire method invocation is performed atomically . some attempted update operations on this map by other threads may be blocked while computation is in progress , so the computation should be short and simple , and must not attempt to update any other mappings of this map .
