@Override public V putIfAbsent(final K k,final V v){
  try {
    final WeakReference<V> ref=newWeakRef(k,v,referenceQueue);
    final WeakReference<V> oldRef=map.putIfAbsent(k,ref);
    final V oldVal=oldRef == null ? null : oldRef.get();
    if (oldRef != null && oldVal == null) {
      if (map.replace(k,oldRef,ref)) {
        if (queue != null) {
synchronized (queue) {
            if (queue.add(v) && DEBUG) {
              log.debug("put: key=" + k + ", val="+ v);
            }
          }
        }
        didUpdate(k,ref,oldRef);
        return null;
      }
 else {
        return putIfAbsent(k,v);
      }
    }
    if (oldVal == null) {
      if (queue != null) {
synchronized (queue) {
          if (queue.add(v) && DEBUG) {
            log.debug("put: key=" + k + ", val="+ v);
          }
        }
      }
      didUpdate(k,ref,null);
      return null;
    }
    return oldVal;
  }
  finally {
    removeClearedEntries();
  }
}

@ Override public V putIfAbsent ( final K k , final V v ) { try { final WeakReference < V > ref = newWeakRef ( k , v , referenceQueue ) ; final WeakReference < V > oldRef = map . putIfAbsent ( k , ref ) ; final V oldVal = oldRef == null ? null : oldRef . get ( ) ; if ( oldRef != null && oldVal == null ) { if ( map . replace ( k , oldRef , ref ) ) { if ( queue != null ) { synchronized ( queue ) { if ( queue . add ( v ) && DEBUG ) { log . debug ( "put: key=" + k + ", val=" + v ) ; } } } didUpdate ( k , ref , oldRef ) ; return null ; } else { return putIfAbsent ( k , v ) ; } } if ( oldVal == null ) { if ( queue != null ) { synchronized ( queue ) { if ( queue . add ( v ) && DEBUG ) { log . debug ( "put: key=" + k + ", val=" + v ) ; } } } didUpdate ( k , ref , null ) ; return null ; } return oldVal ; } finally { removeClearedEntries ( ) ; } }
adds the key - value mapping to the cache iff there is no entry for that key . note that a cleared reference under a key is treated in exactly the same manner as if there were no entry under the key ( the entry under the key is replaced atomically ) .
