Module org.omnifaces
Package org.omnifaces.util.cache
Class LruCache<K extends Serializable,V extends Serializable>
- java.lang.Object
-
- org.omnifaces.util.cache.LruCache<K,V>
-
- Type Parameters:
K- The generic map key type.V- The generic map value type.
- All Implemented Interfaces:
Serializable,ConcurrentMap<K,V>,Map<K,V>
public class LruCache<K extends Serializable,V extends Serializable> extends Object implements ConcurrentMap<K,V>, Serializable
Minimal implementation of thread safe LRU cache with support for eviction listener. Inspired by ConcurrentLinkedHashMap.- Since:
- 4.4
- Author:
- Bauke Scholtz
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description LruCache(int maximumCapacity)Construct LRU cache with given maximum capacity.LruCache(int maximumCapacity, FunctionalInterfaces.SerializableBiConsumer<K,V> evictionListener)Construct LRU cache with given maximum capacity and eviction listener.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()booleancontainsKey(Object key)booleancontainsValue(Object value)Set<Map.Entry<K,V>>entrySet()Vget(Object key)booleanisEmpty()Set<K>keySet()Vput(K key, V value)voidputAll(Map<? extends K,? extends V> map)VputIfAbsent(K key, V value)Vremove(Object key)booleanremove(Object key, Object value)Vreplace(K key, V value)booleanreplace(K key, V oldValue, V newValue)intsize()Collection<V>values()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.concurrent.ConcurrentMap
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, replaceAll
-
-
-
-
Constructor Detail
-
LruCache
public LruCache(int maximumCapacity)
Construct LRU cache with given maximum capacity.- Parameters:
maximumCapacity- The maximum capacity.- Throws:
IllegalArgumentException- when maximum capacity is less than 2.
-
LruCache
public LruCache(int maximumCapacity, FunctionalInterfaces.SerializableBiConsumer<K,V> evictionListener)Construct LRU cache with given maximum capacity and eviction listener.- Parameters:
maximumCapacity- The maximum capacity.evictionListener- The eviction listener.- Throws:
IllegalArgumentException- when maximum capacity is less than 2.
-
-
Method Detail
-
get
public V get(Object key)
- Specified by:
getin interfaceMap<K extends Serializable,V extends Serializable>
-
put
public V put(K key, V value)
- Specified by:
putin interfaceMap<K extends Serializable,V extends Serializable>
-
putIfAbsent
public V putIfAbsent(K key, V value)
- Specified by:
putIfAbsentin interfaceConcurrentMap<K extends Serializable,V extends Serializable>- Specified by:
putIfAbsentin interfaceMap<K extends Serializable,V extends Serializable>
-
putAll
public void putAll(Map<? extends K,? extends V> map)
- Specified by:
putAllin interfaceMap<K extends Serializable,V extends Serializable>
-
remove
public V remove(Object key)
- Specified by:
removein interfaceMap<K extends Serializable,V extends Serializable>
-
remove
public boolean remove(Object key, Object value)
- Specified by:
removein interfaceConcurrentMap<K extends Serializable,V extends Serializable>- Specified by:
removein interfaceMap<K extends Serializable,V extends Serializable>
-
replace
public V replace(K key, V value)
- Specified by:
replacein interfaceConcurrentMap<K extends Serializable,V extends Serializable>- Specified by:
replacein interfaceMap<K extends Serializable,V extends Serializable>
-
replace
public boolean replace(K key, V oldValue, V newValue)
- Specified by:
replacein interfaceConcurrentMap<K extends Serializable,V extends Serializable>- Specified by:
replacein interfaceMap<K extends Serializable,V extends Serializable>
-
clear
public void clear()
- Specified by:
clearin interfaceMap<K extends Serializable,V extends Serializable>
-
size
public int size()
- Specified by:
sizein interfaceMap<K extends Serializable,V extends Serializable>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceMap<K extends Serializable,V extends Serializable>
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKeyin interfaceMap<K extends Serializable,V extends Serializable>
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValuein interfaceMap<K extends Serializable,V extends Serializable>
-
keySet
public Set<K> keySet()
- Specified by:
keySetin interfaceMap<K extends Serializable,V extends Serializable>
-
values
public Collection<V> values()
- Specified by:
valuesin interfaceMap<K extends Serializable,V extends Serializable>
-
entrySet
public Set<Map.Entry<K,V>> entrySet()
- Specified by:
entrySetin interfaceMap<K extends Serializable,V extends Serializable>
-
-