Package net.sourceforge.jnlp.util
Class TimedHashMap<K,V>
java.lang.Object
net.sourceforge.jnlp.util.TimedHashMap<K,V>
- Record Components:
K
- The key typeV
- The Object type
- All Implemented Interfaces:
Map<K,
V>
Simple utility class that extends HashMap by adding an expiry to the entries.
This map stores entries, and returns them only if the entries were last accessed within a specified timeout period.
Otherwise, null is returned.
This map does not allow null keys but does allow null values.
-
Nested Class Summary
-
Constructor Summary
ConstructorsConstructorDescriptionTimedHashMap
(long timeout, TimeUnit unit) Create a new map with a non-default entry timeout period -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
boolean
containsKey
(Object key) boolean
containsValue
(Object value) entrySet()
Return cached item if it has not already expired.boolean
isEmpty()
keySet()
Store the item in the map and associate a timestamp with it.void
void
setTimeout
(long timeout, TimeUnit unit) Specify how long (in nanoseconds) entries are valid forint
size()
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.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
TimedHashMap
public TimedHashMap() -
TimedHashMap
Create a new map with a non-default entry timeout period- Parameters:
timeout
- the length of the timeoutunit
- the units of the timeout
-
-
Method Details
-
setTimeout
Specify how long (in nanoseconds) entries are valid for- Parameters:
timeout
- the length of the timeoutunit
- the units of the timeout
-
put
Store the item in the map and associate a timestamp with it. null is not accepted as a key. -
get
Return cached item if it has not already expired. Before returning, this method also resets the "last accessed" time for this entry, so it is good for another 10 seconds -
containsKey
- Specified by:
containsKey
in interfaceMap<K,
V>
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsValue
- Specified by:
containsValue
in interfaceMap<K,
V>
-
remove
-
putAll
-
clear
public void clear() -
keySet
-
values
-
entrySet
-