Object
TemporaryHashMap<K,V>
- All Implemented Interfaces:
Map<K,
V>
HashMap
which caches every pair for specified period of time and when it expires such
pair is removed.
The deletion of expired pairs is passive which means they may not be deleted immediately once
they are expired but only during next put(Object, Object)
or putAll(Map)
operations. To change it to active users can setup ScheduledExecutorService
to call cleanupExpired()
.
Keys are subject to expiration and not values associated with them. It means if user adds pair "key1": "val1", and later replace value to "key1": "val2" this will not affect this pair expiration time.
It is based on HashMap
so all HashMap
properties applies to TemporaryHashMap
.
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Removes expired pairsvoid
clear()
boolean
containsKey
(Object key) boolean
containsValue
(Object value) protected long
Visible for testingentrySet()
ReturnsCollections.unmodifiableSet(Set)
boolean
isEmpty()
keySet()
ReturnsCollections.unmodifiableSet(Set)
void
int
size()
toString()
values()
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
TemporaryHashMap
-
-
Method Details
-
size
public int size() -
isEmpty
public boolean isEmpty() -
clear
public void clear() -
toString
-
containsKey
- Specified by:
containsKey
in interfaceMap<K,
V>
-
containsValue
- Specified by:
containsValue
in interfaceMap<K,
V>
-
get
-
put
-
putAll
-
keySet
ReturnsCollections.unmodifiableSet(Set)
-
values
-
entrySet
ReturnsCollections.unmodifiableSet(Set)
-
remove
-
cleanupExpired
public void cleanupExpired()Removes expired pairs -
currentTimeMillis
protected long currentTimeMillis()Visible for testing
-