public class Memoizer<K,V> extends Object implements IComputable<K,V>
IComputable.
It is extended by the soft reference mechanism so references could be garbage collected in case
of memory needs.| Constructor and Description |
|---|
Memoizer(IComputable<K,V> computable)
The constructor to create a memoizer with default values for the internal
ConcurrentHashMap |
Memoizer(IComputable<K,V> computable,
int initSize,
float loadFactor,
int concurrencyLevel)
This constructor needs next to the
IComputable also the initial size, the load factor
and the concurrency level. |
| Modifier and Type | Method and Description |
|---|---|
V |
compute(K key)
Compute an object of type V identified by the key of type K
|
Class<? super V> |
getValueClass()
Getting the
Class of the value this computable produces. |
static RuntimeException |
launderThrowable(Throwable t)
Coerce an unchecked Throwable to a RuntimeException
|
public Memoizer(IComputable<K,V> computable)
ConcurrentHashMapcomputable - the IComputable to load new itemspublic Memoizer(IComputable<K,V> computable, int initSize, float loadFactor, int concurrencyLevel)
IComputable also the initial size, the load factor
and the concurrency level. These parameters are only for tuning purpose and are directly
forwarded to the internal ConcurrentHashMap.computable - The IComputable to load new itemsinitSize - the initial size @see ConcurrentHashMaploadFactor - the load factor @see ConcurrentHashMapconcurrencyLevel - the concurrency level @see ConcurrentHashMappublic V compute(K key) throws InterruptedException
IComputablecompute in interface IComputable<K,V>key - the key to identify the objectInterruptedException - When computation was interruptedpublic static RuntimeException launderThrowable(Throwable t)
If the Throwable is an Error, throw it; if it is a RuntimeException return it, otherwise throw IllegalStateException
public Class<? super V> getValueClass()
IComputableClass of the value this computable produces.getValueClass in interface IComputable<K,V>Copyright © 2017. All rights reserved.