Package io.atlasmap.expression.internal
Class LRUCache<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<K,V>
-
- java.util.LinkedHashMap<K,V>
-
- io.atlasmap.expression.internal.LRUCache<K,V>
-
- Type Parameters:
K- keyV- value
- All Implemented Interfaces:
Serializable,Cloneable,Map<K,V>
public class LRUCache<K,V> extends LinkedHashMap<K,V>
A Simple LRU Cache.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Field Summary
Fields Modifier and Type Field Description protected intmaxCacheSizemax cache size
-
Constructor Summary
Constructors Constructor Description LRUCache()Default constructor for an LRU Cache The default capacity is 10000.LRUCache(int maximumCacheSize)Constructs a LRUCache with a maximum capacity.LRUCache(int initialCapacity, int maximumCacheSize, float loadFactor, boolean accessOrder)Constructs an emptyLRUCacheinstance with the specified initial capacity, maximumCacheSize,load factor and ordering mode.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetMaxCacheSize()Gets max cache size.protected voidonCacheEviction(Map.Entry<K,V> eldest)Do nothing for now.protected booleanremoveEldestEntry(Map.Entry<K,V> eldest)Removes eldest entry.voidsetMaxCacheSize(int maxCacheSize)Sets max cache size.-
Methods inherited from class java.util.LinkedHashMap
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, replaceAll, values
-
Methods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
-
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, containsKey, equals, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
-
-
-
-
Constructor Detail
-
LRUCache
public LRUCache()
Default constructor for an LRU Cache The default capacity is 10000.
-
LRUCache
public LRUCache(int maximumCacheSize)
Constructs a LRUCache with a maximum capacity.- Parameters:
maximumCacheSize- maximum cache size
-
LRUCache
public LRUCache(int initialCapacity, int maximumCacheSize, float loadFactor, boolean accessOrder)Constructs an emptyLRUCacheinstance with the specified initial capacity, maximumCacheSize,load factor and ordering mode.- Parameters:
initialCapacity- the initial capacity.maximumCacheSize- maximum cache sizeloadFactor- the load factor.accessOrder- the ordering mode -truefor access-order,falsefor insertion-order.- Throws:
IllegalArgumentException- if the initial capacity is negative or the load factor is non-positive.
-
-
Method Detail
-
getMaxCacheSize
public int getMaxCacheSize()
Gets max cache size.- Returns:
- Returns the maxCacheSize.
-
setMaxCacheSize
public void setMaxCacheSize(int maxCacheSize)
Sets max cache size.- Parameters:
maxCacheSize- The maxCacheSize to set.
-
removeEldestEntry
protected boolean removeEldestEntry(Map.Entry<K,V> eldest)
Removes eldest entry.- Overrides:
removeEldestEntryin classLinkedHashMap<K,V>- Parameters:
eldest- eldest entry- Returns:
- true if removed, or false
-
-