ELEMENT
- Element typepublic class Cache<ELEMENT>
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.util.HashMap<java.lang.String,CacheElement<ELEMENT>> |
cache
The cache itself
|
Constructor and Description |
---|
Cache()
Constructs Cache
|
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.String key,
CacheElement<ELEMENT> element)
Add element inside the cache
|
void |
clear()
Clear the cache
|
void |
destroy()
Destroy the cache (Never use it after that)
|
ELEMENT |
get(java.lang.String key)
Obtain an element
|
ELEMENT |
get(java.lang.String key,
CacheElement<ELEMENT> cacheElement)
Obtain an element and give a default value if key is not already present
|
void |
remove(java.lang.String key)
Remove an element from cache
|
private java.util.HashMap<java.lang.String,CacheElement<ELEMENT>> cache
public void add(java.lang.String key, CacheElement<ELEMENT> element)
key
- Key associateelement
- Describe how create elementpublic void clear()
public void destroy()
public ELEMENT get(java.lang.String key)
key
- Element keypublic ELEMENT get(java.lang.String key, CacheElement<ELEMENT> cacheElement)
key
- Key to getcacheElement
- Cache element to store and use if the key is not already definedpublic void remove(java.lang.String key)
key
- Element key