Package org.jxmpp.util.cache
Class LruCache<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
java.util.LinkedHashMap<K,V>
org.jxmpp.util.cache.LruCache<K,V>
- Type Parameters:
K
- the type of the keys of this cache.V
- the type of the values this cache caches.
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<K,
,V> Cache<K,
V>
A specialized Map that is size-limited (using an LRU algorithm). The Map is
thread-safe.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,
V>, AbstractMap.SimpleImmutableEntry<K, V> -
Constructor Summary
ConstructorDescriptionLruCache
(int maxSize) Create a new cache and specify the maximum size of for the cache in bytes, and the maximum lifetime of objects. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
clear()
final boolean
containsKey
(Object key) final boolean
containsValue
(Object value) entrySet()
final V
final long
Get the number of cache hits.final long
Get the number of cache misses.final int
Return the maximum cache Size.final boolean
isEmpty()
keySet()
final V
Returns the value of the specified key, ornull
.final V
Put a value in the cache.final void
final V
protected final boolean
removeEldestEntry
(Map.Entry<K, V> eldest) final void
setMaxCacheSize
(int maxCacheSize) Set the maximum cache size.final int
size()
final Collection
<V> values()
Methods inherited from class java.util.LinkedHashMap
forEach, getOrDefault, replaceAll
Methods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, merge, putIfAbsent, remove, replace, replace
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, hashCode, merge, putIfAbsent, remove, replace, replace
-
Constructor Details
-
LruCache
Create a new cache and specify the maximum size of for the cache in bytes, and the maximum lifetime of objects.- Parameters:
maxSize
- the maximum number of objects the cache will hold. -1 means the cache has no max size.
-
-
Method Details
-
removeEldestEntry
- Overrides:
removeEldestEntry
in classLinkedHashMap<K,
V>
-
put
Description copied from interface:Cache
Put a value in the cache. -
lookup
Description copied from interface:Cache
Returns the value of the specified key, ornull
. -
get
-
remove
-
clear
-
size
-
isEmpty
-
values
-
containsKey
- Specified by:
containsKey
in interfaceMap<K,
V> - Overrides:
containsKey
in classHashMap<K,
V>
-
putAll
-
containsValue
- Specified by:
containsValue
in interfaceMap<K,
V> - Overrides:
containsValue
in classLinkedHashMap<K,
V>
-
entrySet
-
keySet
-
getCacheHits
Get the number of cache hits.- Returns:
- the number of cache hits.
-
getCacheMisses
Get the number of cache misses.- Returns:
- the number of cache misses.
-
getMaxCacheSize
Description copied from interface:Cache
Return the maximum cache Size.- Specified by:
getMaxCacheSize
in interfaceCache<K,
V> - Returns:
- the maximum cache size.
-
setMaxCacheSize
Description copied from interface:Cache
Set the maximum cache size.- Specified by:
setMaxCacheSize
in interfaceCache<K,
V> - Parameters:
maxCacheSize
- the new maximum cache size.
-