Top Description Fields Constructors Methods
org.codehaus.groovy.runtime.memoize

public final Class UnlimitedConcurrentCache<K, V>

extends Object
implements EvictableCache<K, V>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.codehaus.groovy.runtime.memoize.EvictableCache, java.util.Map, org.codehaus.groovy.runtime.memoize.MemoizeCache
Annotations
@ThreadSafe
Imports
javax.annotation.concurrent.ThreadSafe, java.io.Serializable, java.lang.ref.SoftReference, java.util.Collection, .LinkedHashMap, .Map, .Set, java.util.concurrent.ConcurrentHashMap

A cache backed by a ConcurrentHashMap

Field Summary

Modifier and TypeField and Description
private final ConcurrentHashMap<K, V>
private static final long

Constructor Summary

AccessConstructor and Description
public
UnlimitedConcurrentCache()

Constructs a cache with unlimited size

public
UnlimitedConcurrentCache(int
the initial capacity
initialCapacity
)

Constructs a cache with unlimited size and set its initial capacity

public
UnlimitedConcurrentCache(Map<? extends K, ? extends V>
the map to initialize the cache
m
)

Constructs a cache and initialize the cache with the specified map

Method Summary

Modifier and TypeMethod and Description
public void
cleanUpNullReferences()

Implements org.codehaus.groovy.runtime.memoize.MemoizeCache.cleanUpNullReferences.

Replying on the ConcurrentHashMap thread-safe iteration implementation the method will remove all entries holding SoftReferences to gc-evicted objects.
public Map<K, V>

Returns:

returns the content of the cleared map
clearAll
()

Implements org.codehaus.groovy.runtime.memoize.EvictableCache.clearAll.

Clear the cache
public boolean

Returns:

true if the cache contains a mapping for the specified key
containsKey
(Object
key whose presence in this cache is to be tested.
key
)

Implements org.codehaus.groovy.runtime.memoize.EvictableCache.containsKey.

Determines if the cache contains an entry for the specified key.
public boolean
containsValue(Object
value whose presence in this map is to be tested
value
)

Implements java.util.Map.containsValue.

Returns true if this map maps one or more keys to the specified value.
public Set<Map.Entry<K, V>>
entrySet()

Implements java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.
public V

Returns:

the value, or null, if it does not exist.
get
(Object
the key whose associated value is to be returned
key
)

Implements org.codehaus.groovy.runtime.memoize.MemoizeCache.get, java.util.Map.get.

Gets a value from the cache
public V

Returns:

the cached value
getAndPut
(K key, MemoizeCache.ValueProvider<? super K, ? extends V>
provide the value if the associated value not found
valueProvider
)

Overrides default org.codehaus.groovy.runtime.memoize.MemoizeCache.getAndPut.

Try to get the value from cache.
public boolean
isEmpty()

Implements java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.
public Set<K>

Returns:

all keys
keys
()

Implements org.codehaus.groovy.runtime.memoize.EvictableCache.keys.

Get all keys associated to cached values
public Set<K>
keySet()

Implements java.util.Map.keySet.

Returns a Set view of the keys contained in this map.
public V

Returns:

null, or the old value if the key associated with the specified key.
put
(K
key with which the specified value is to be associated
key
,
V
value to be associated with the specified key
value
)

Implements org.codehaus.groovy.runtime.memoize.MemoizeCache.put, java.util.Map.put.

Associates the specified value with the specified key in the cache.
public void
putAll(Map<? extends K, ? extends V>
mappings to be stored in this map
m
)

Implements java.util.Map.putAll.

Copies all of the mappings from the specified map to this map (optional operation).
public V

Returns:

returns the removed value
remove
(Object key)

Implements org.codehaus.groovy.runtime.memoize.EvictableCache.remove.

Remove the cached value by the key
public int

Returns:

the size of the cache
size
()

Implements org.codehaus.groovy.runtime.memoize.EvictableCache.size.

Get the size of the cache
public Collection<V>

Returns:

all cached values
values
()

Implements org.codehaus.groovy.runtime.memoize.EvictableCache.values.

Get all cached values
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

mapback to summary
private final ConcurrentHashMap<K, V> map
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

UnlimitedConcurrentCacheback to summary
public UnlimitedConcurrentCache()

Constructs a cache with unlimited size

UnlimitedConcurrentCacheback to summary
public UnlimitedConcurrentCache(int initialCapacity)

Constructs a cache with unlimited size and set its initial capacity

Parameters
initialCapacity:int

the initial capacity

UnlimitedConcurrentCacheback to summary
public UnlimitedConcurrentCache(Map<? extends K, ? extends V> m)

Constructs a cache and initialize the cache with the specified map

Parameters
m:Map<? extends K, ? extends V>

the map to initialize the cache

Method Detail

cleanUpNullReferencesback to summary
public void cleanUpNullReferences()

Implements org.codehaus.groovy.runtime.memoize.MemoizeCache.cleanUpNullReferences.

Replying on the ConcurrentHashMap thread-safe iteration implementation the method will remove all entries holding SoftReferences to gc-evicted objects.

Annotations
@Override
clearAllback to summary
public Map<K, V> clearAll()

Implements org.codehaus.groovy.runtime.memoize.EvictableCache.clearAll.

Clear the cache

Returns:Map<K, V>

returns the content of the cleared map

Annotations
@Override
containsKeyback to summary
public boolean containsKey(Object key)

Implements org.codehaus.groovy.runtime.memoize.EvictableCache.containsKey.

Determines if the cache contains an entry for the specified key.

Parameters
key:Object

key whose presence in this cache is to be tested.

Returns:boolean

true if the cache contains a mapping for the specified key

Annotations
@Override
containsValueback to summary
public boolean containsValue(Object value)

Implements java.util.Map.containsValue.

Doc from java.util.Map.containsValue.

Returns true if this map maps one or more keys to the specified value. More formally, returns true if and only if this map contains at least one mapping to a value v such that Objects.equals(value, v). This operation will probably require time linear in the map size for most implementations of the Map interface.

Parameters
value:Object

value whose presence in this map is to be tested

Returns:boolean

true if this map maps one or more keys to the specified value

Annotations
@Override
entrySetback to summary
public Set<Map.Entry<K, V>> entrySet()

Implements java.util.Map.entrySet.

Doc from java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Returns:Set<Map.Entry<K, V>>

a set view of the mappings contained in this map

Annotations
@Override
getback to summary
public V get(Object key)

Implements org.codehaus.groovy.runtime.memoize.MemoizeCache.get, java.util.Map.get.

Gets a value from the cache

Parameters
key:Object

the key whose associated value is to be returned

Returns:V

the value, or null, if it does not exist.

Annotations
@Override
getAndPutback to summary
public V getAndPut(K key, MemoizeCache.ValueProvider<? super K, ? extends V> valueProvider)

Overrides default org.codehaus.groovy.runtime.memoize.MemoizeCache.getAndPut.

Try to get the value from cache. If not found, create the value by MemoizeCache.ValueProvider and put it into the cache, at last return the value.

Parameters
valueProvider:MemoizeCache.ValueProvider<? super K, ? extends V>

provide the value if the associated value not found

Returns:V

the cached value

Annotations
@Override
isEmptyback to summary
public boolean isEmpty()

Implements java.util.Map.isEmpty.

Doc from java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.

Returns:boolean

true if this map contains no key-value mappings

Annotations
@Override
keysback to summary
public Set<K> keys()

Implements org.codehaus.groovy.runtime.memoize.EvictableCache.keys.

Get all keys associated to cached values

Returns:Set<K>

all keys

Annotations
@Override
keySetback to summary
public Set<K> keySet()

Implements java.util.Map.keySet.

Doc from java.util.Map.keySet.

Returns a Set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations.

Returns:Set<K>

a set view of the keys contained in this map

Annotations
@Override
putback to summary
public V put(K key, V value)

Implements org.codehaus.groovy.runtime.memoize.MemoizeCache.put, java.util.Map.put.

Associates the specified value with the specified key in the cache.

Parameters
key:K

key with which the specified value is to be associated

value:V

value to be associated with the specified key

Returns:V

null, or the old value if the key associated with the specified key.

Annotations
@Override
putAllback to summary
public void putAll(Map<? extends K, ? extends V> m)

Implements java.util.Map.putAll.

Doc from java.util.Map.putAll.

Copies all of the mappings from the specified map to this map (optional operation). The effect of this call is equivalent to that of calling put(k, v) on this map once for each mapping from key k to value v in the specified map. The behavior of this operation is undefined if the specified map is modified while the operation is in progress. If the specified map has a defined encounter order, processing of its mappings generally occurs in that order.

Parameters
m:Map<? extends K, ? extends V>

mappings to be stored in this map

Annotations
@Override
removeback to summary
public V remove(Object key)

Implements org.codehaus.groovy.runtime.memoize.EvictableCache.remove.

Remove the cached value by the key

Returns:V

returns the removed value

Annotations
@Override
sizeback to summary
public int size()

Implements org.codehaus.groovy.runtime.memoize.EvictableCache.size.

Get the size of the cache

Returns:int

the size of the cache

Annotations
@Override
valuesback to summary
public Collection<V> values()

Implements org.codehaus.groovy.runtime.memoize.EvictableCache.values.

Get all cached values

Returns:Collection<V>

all cached values

Annotations
@Override