@ Nullable public CloseableReference < V > reuse ( K key ) { Preconditions . checkNotNull ( key ) ; CloseableReference < V > clientRef = null ; boolean removed = false ; Entry < K , V > oldExclusive = null ; synchronized ( this ) { oldExclusive = mExclusiveEntries . remove ( key ) ; if ( oldExclusive != null ) { Entry < K , V > entry = mCachedEntries . remove ( key ) ; Preconditions . checkNotNull ( entry ) ; Preconditions . checkState ( entry . clientCount == 0 ) ; // optimization: instead of cloning and then closing the original reference, // we just do a move clientRef = entry . valueRef ; removed = true ; } } if ( removed ) { maybeNotifyExclusiveEntryRemoval ( oldExclusive ) ; } return clientRef ; }
Gets the value with the given key to be reused or null if there is no such value .