K - Type of the cache-keyV - Type of the cache-value@ThreadSafe public class ChangingValueCache<K,V> extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
ChangingValueCache.Builder<K,V>
Builder for building
ChangingValueCache instances |
| Modifier and Type | Field and Description |
|---|---|
protected ThreadLocal<V> |
alreadyWorkingOn |
protected com.google.common.cache.Cache<K,V> |
cache |
protected com.google.common.base.Function<V,V> |
defaultModifier |
protected com.google.common.base.Supplier<V> |
defaultNewCreator |
protected com.google.common.collect.Interner<Integer> |
newOrMovingCacheEntryInterner |
| Modifier | Constructor and Description |
|---|---|
protected |
ChangingValueCache() |
| Modifier and Type | Method and Description |
|---|---|
static <K,V> ChangingValueCache.Builder<K,V> |
builder()
Get a builder for building a
ChangingValueCache instance |
V |
getAddIfNotPresent(K key)
Calling
getAddIfNotPresent(Object, Supplier) (and returning value from) with
* key (K) Provided key
* newCreator (Supplier<V>) null |
V |
getAddIfNotPresent(K key,
com.google.common.base.Supplier<V> newCreator)
Get a cache-value of a cache-entry with a provided key, adding the cache-entry if not already present
|
protected Collection<com.google.common.cache.Cache<K,V>> |
getAllCaches() |
V |
getIfPresent(K key)
Get a cache-value of a cache-entry with a provided key
|
V |
modify(K key,
boolean createIfNotExists)
Calling
modify(Object, Supplier, Function, boolean) (and returning value from) with
* key (K) Provided key
* newCreator (Supplier<V>) null
* modifier (Function<V, V>) null
* createIfNotExists (boolean) Provided createIfNotExist |
V |
modify(K key,
com.google.common.base.Function<V,V> modifier,
boolean createIfNotExists)
Calling
modify(Object, Supplier, Function, boolean) (and returning value from) with
* key (K) Provided key
* newCreator (Supplier<V>) null
* modifier (Function<V, V>) Provided modifier
* createIfNotExists (boolean) Provided createIfNotExist |
V |
modify(K key,
com.google.common.base.Supplier<V> newCreator,
boolean createIfNotExists)
Calling
modify(Object, Supplier, Function, boolean) (and returning value from) with
* key (K) Provided key
* newCreator (Supplier<V>) Provided new-creator
* modifier (Function<V, V>) null
* createIfNotExists (boolean) Provided createIfNotExist |
V |
modify(K key,
com.google.common.base.Supplier<V> newCreator,
com.google.common.base.Function<V,V> modifier,
boolean createIfNotExists)
Calling
modify(Object, Supplier, Function, boolean, boolean) (and returning value from) with
* key (K) Provided key
* newCreator (Supplier<V>) Provided new-creator
* modifier (Function<V, V>) Provided modifier
* createIfNotExists (boolean) Provided createIfNotExist
* supportRecursiveCalls (boolean) false |
V |
modify(K key,
com.google.common.base.Supplier<V> newCreator,
com.google.common.base.Function<V,V> modifier,
boolean createIfNotExists,
boolean supportRecursiveCalls)
Modify cache-entry using provided new-creator and modifier
|
void |
modifyAll(com.google.common.base.Predicate<K> keyPredicate,
com.google.common.base.Predicate<V> valuePredicate)
Calling
modifyAll(Predicate, Predicate, Function) with
* keyPredicate (Predicate<K>) Provided keyPredicate
* valuePredicate (Predicate<V>) Provided valuePredicate
* modifier (Function<V, V>) null
* supportRecursiveCalls (boolean) false |
void |
modifyAll(com.google.common.base.Predicate<K> keyPredicate,
com.google.common.base.Predicate<V> valuePredicate,
com.google.common.base.Function<V,V> modifier)
Calling
modifyAll(Predicate, Predicate, Function, boolean) with
* keyPredicate (Predicate<K>) Provided keyPredicate
* valuePredicate (Predicate<V>) Provided valuePredicate
* modifier (Function<V, V>) Provided modifier
* supportRecursiveCalls (boolean) false |
void |
modifyAll(com.google.common.base.Predicate<K> keyPredicate,
com.google.common.base.Predicate<V> valuePredicate,
com.google.common.base.Function<V,V> modifier,
boolean supportRecursiveCalls)
Sequentially calling
modify(Object, Supplier, Function, boolean, boolean) for a selected set of existing cache-entries. |
protected V |
modifyImpl(K key,
com.google.common.base.Supplier<V> newCreator,
com.google.common.base.Function<V,V> modifier,
boolean createIfNotExists,
boolean supportRecursiveCalls) |
long |
size() |
protected com.google.common.base.Supplier<V> defaultNewCreator
protected final com.google.common.collect.Interner<Integer> newOrMovingCacheEntryInterner
protected ThreadLocal<V> alreadyWorkingOn
public static <K,V> ChangingValueCache.Builder<K,V> builder()
ChangingValueCache instanceK - Type of the cache-key of the built cacheV - Type of the cache-value of the built cachepublic final V modify(K key, boolean createIfNotExists)
modify(Object, Supplier, Function, boolean) (and returning value from) with
* key (K) Provided key
* newCreator (Supplier<V>) null
* modifier (Function<V, V>) null
* createIfNotExists (boolean) Provided createIfNotExistkey - To be forwarded to modify callcreateIfNotExists - To be forwarded to modify callpublic final V modify(K key, com.google.common.base.Function<V,V> modifier, boolean createIfNotExists)
modify(Object, Supplier, Function, boolean) (and returning value from) with
* key (K) Provided key
* newCreator (Supplier<V>) null
* modifier (Function<V, V>) Provided modifier
* createIfNotExists (boolean) Provided createIfNotExistkey - To be forwarded to modify callmodifier - To be forwarded to modify callcreateIfNotExists - To be forwarded to modify callpublic final V modify(K key, com.google.common.base.Supplier<V> newCreator, boolean createIfNotExists)
modify(Object, Supplier, Function, boolean) (and returning value from) with
* key (K) Provided key
* newCreator (Supplier<V>) Provided new-creator
* modifier (Function<V, V>) null
* createIfNotExists (boolean) Provided createIfNotExistkey - To be forwarded to modify callnewCreator - To be forwarded to modify callcreateIfNotExists - To be forwarded to modify callpublic final V modify(K key, com.google.common.base.Supplier<V> newCreator, com.google.common.base.Function<V,V> modifier, boolean createIfNotExists)
modify(Object, Supplier, Function, boolean, boolean) (and returning value from) with
* key (K) Provided key
* newCreator (Supplier<V>) Provided new-creator
* modifier (Function<V, V>) Provided modifier
* createIfNotExists (boolean) Provided createIfNotExist
* supportRecursiveCalls (boolean) falsekey - To be forwarded to modify callnewCreator - To be forwarded to modify callmodifier - To be forwarded to modify callcreateIfNotExists - To be forwarded to modify callpublic final V modify(K key, com.google.common.base.Supplier<V> newCreator, com.google.common.base.Function<V,V> modifier, boolean createIfNotExists, boolean supportRecursiveCalls)
key - Key for cache-entrynewCreator - Used to generate the new cache-value, if it does not already exist (if null default new-creator will be used)modifier - Used to modify the cache-value (if null default modifier will be used)createIfNotExists - Create the entry if it does not already existsupportRecursiveCalls - Support modifier that (directly or indirectly) calls modify on THE SAME cache-key (and the same thread).
Be careful setting this to true
* Modifier that calls modify on cache-key that is NOT the same will not work correctly - it will when set to false (default)
* Will add a small performance-hitpublic final void modifyAll(com.google.common.base.Predicate<K> keyPredicate, com.google.common.base.Predicate<V> valuePredicate)
modifyAll(Predicate, Predicate, Function) with
* keyPredicate (Predicate<K>) Provided keyPredicate
* valuePredicate (Predicate<V>) Provided valuePredicate
* modifier (Function<V, V>) null
* supportRecursiveCalls (boolean) falsekeyPredicate - To be forwarded to modifyAll callvaluePredicate - To be forwarded to modifyAll callpublic final void modifyAll(com.google.common.base.Predicate<K> keyPredicate, com.google.common.base.Predicate<V> valuePredicate, com.google.common.base.Function<V,V> modifier)
modifyAll(Predicate, Predicate, Function, boolean) with
* keyPredicate (Predicate<K>) Provided keyPredicate
* valuePredicate (Predicate<V>) Provided valuePredicate
* modifier (Function<V, V>) Provided modifier
* supportRecursiveCalls (boolean) falsekeyPredicate - To be forwarded to modifyAll callvaluePredicate - To be forwarded to modifyAll callmodifier - To be forwarded to modifyAll callpublic final void modifyAll(com.google.common.base.Predicate<K> keyPredicate, com.google.common.base.Predicate<V> valuePredicate, com.google.common.base.Function<V,V> modifier, boolean supportRecursiveCalls)
modify(Object, Supplier, Function, boolean, boolean) for a selected set of existing cache-entries. Called with
* key (K) The cache-key of the cache-entry in the selected set
* newCreator (Supplier<V>) null
* modifier (Function<V, V>) Provided modifier
* boolean createIfNotExists false
* boolean supportRecursiveCalls Provided supportRecursiveCallskeyPredicate - A cache-entry is (potentially - if valuePredicate also accepts) included in the selected set iff feeding keyPredicate with cache-key returns truevaluePredicate - A cache-entry is (potentially - if keyPredicate also accepts) included in the selected set iff feeding valuePredicate with cache-value returns truemodifier - Used for the modify callssupportRecursiveCalls - Used for the modify calls
The existing cache-entry has to match both criteria to be included in the setprotected V modifyImpl(K key, com.google.common.base.Supplier<V> newCreator, com.google.common.base.Function<V,V> modifier, boolean createIfNotExists, boolean supportRecursiveCalls)
protected Collection<com.google.common.cache.Cache<K,V>> getAllCaches()
public V getIfPresent(K key)
key - The key of the cache-entrypublic long size()
public V getAddIfNotPresent(K key)
getAddIfNotPresent(Object, Supplier) (and returning value from) with
* key (K) Provided key
* newCreator (Supplier<V>) nullkey - To be forwarded to getAddIfNotPresent callpublic V getAddIfNotPresent(K key, com.google.common.base.Supplier<V> newCreator)
key - The key of the cache entrynewCreator - Used to generate the new cache-value, if it does not already exist (if null default new-creator will be used)Copyright © 2015 teletronics.ae. All rights reserved.