Class LFUMap
java.lang.Object
org.pentaho.reporting.libraries.base.util.LFUMap
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
public class LFUMap
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable
A Least-Frequently-Used Map.
This is not a real map in the sense of the Java-Collections-API. This is a slimmed down version of a
Least-Frequently-Used map with no unnecessary extra stuff like iterators or other costly but rarely used
java.util.Collections features. The cache does not accept null-keys, and any attempt to store null-values
will yield an error.
To remove a couple of ugly checks and thus improving performance, this map enforces a minimum size of 3 items.
- Author:
- Thomas Morgner
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionLFUMap
(int cacheSize) Creates a new LFU-Map with a maximum size ofcacheSize
entries. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
java.lang.Object
clone()
java.lang.Object
get
(java.lang.Object key) Return the entry for the given key.int
Returns the defined maximum size.boolean
isEmpty()
Checks whether this map is empty.void
put
(java.lang.Object key, java.lang.Object value) Puts the given value into the map using the specified non-null key.void
remove
(java.lang.Object key) Removes the entry for the given key.int
size()
Returns the number of items in this map.void
validate()
Validates the map's internal datastructures.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
LFUMap
public LFUMap(int cacheSize) Creates a new LFU-Map with a maximum size ofcacheSize
entries.- Parameters:
cacheSize
- the maximum number of elements this map will be able to store.
-
-
Method Details
-
clear
public void clear() -
get
public java.lang.Object get(java.lang.Object key) Return the entry for the given key. Any successful lookup moves the entry to the top of the list.- Parameters:
key
- the lookup key.- Returns:
- the value stored for the key or null.
-
put
public void put(java.lang.Object key, java.lang.Object value) Puts the given value into the map using the specified non-null key. The new entry is added as first entry in the list of recently used values.- Parameters:
key
- the key.value
- the value.
-
remove
public void remove(java.lang.Object key) Removes the entry for the given key.- Parameters:
key
- the key for which an entry should be removed.
-
size
public int size()Returns the number of items in this map.- Returns:
- the number of items in the map.
-
isEmpty
public boolean isEmpty()Checks whether this map is empty.- Returns:
- true, if the map is empty, false otherwise.
-
getMaximumSize
public int getMaximumSize()Returns the defined maximum size.- Returns:
- the defines maximum size.
-
validate
public void validate()Validates the map's internal datastructures. There should be no need to call this method manually. -
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException- Throws:
java.lang.CloneNotSupportedException
-