|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectch.bind.philib.util.SimpleTimeoutMap<K,V>
K - type parameter for the map's keys.V - type parameter for the map's values.public final class SimpleTimeoutMap<K,V>
An implementation of TimeoutMap which uses the TreeMap and HashMap from java.util for
internal data management. This implementation is threadsafe.
TimeoutMap| Constructor Summary | |
|---|---|
SimpleTimeoutMap()
|
|
| Method Summary | |
|---|---|
long |
_getTimeToNextTimeoutNs(long nowNs)
|
void |
clear()
removes all key-value pairs from this map. |
boolean |
containsKey(K key)
Check for the existence of a key. |
V |
get(K key)
Searches a value by its key |
long |
getTimeToNextTimeout()
|
boolean |
isEmpty()
|
Map.Entry<K,V> |
pollTimeoutBlocking()
Blocking poll for the next entry which is timed out. |
Map.Entry<K,V> |
pollTimeoutBlocking(long duration,
TimeUnit timeUnit)
Blocking poll for the next entry which is timed out. |
Map.Entry<K,V> |
pollTimeoutNow()
Nonblocking poll for the next entry which is timed out, based on the time of the invocation of this method. |
V |
put(long timeout,
K key,
V value)
Add a key-value pair with an associated timeout to the map. |
V |
remove(K key)
removes an entry by it's key |
int |
size()
query the number of entries in this map. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public SimpleTimeoutMap()
| Method Detail |
|---|
public V put(long timeout,
K key,
V value)
TimeoutMap
put in interface TimeoutMap<K,V>timeout - the timeout for this key-value pair (in milliseconds)key - -value - -
null if none.public V get(K key)
TimeoutMap
get in interface TimeoutMap<K,V>null if the key does not exist.public V remove(K key)
TimeoutMap
remove in interface TimeoutMap<K,V>key - the key for which an entry must be removed.
null if there was no entry for this key in that map, otherwise the value of the removed entry.public Map.Entry<K,V> pollTimeoutNow()
TimeoutMap
pollTimeoutNow in interface TimeoutMap<K,V>null if there is no timed-out entry in this map. otherwise the oldest timed-out entry.
public Map.Entry<K,V> pollTimeoutBlocking()
throws InterruptedException
TimeoutMap
pollTimeoutBlocking in interface TimeoutMap<K,V>null if there is no timed-out entry in this map within the given duration. otherwise the oldest
timed-out entry.
InterruptedException
public Map.Entry<K,V> pollTimeoutBlocking(long duration,
TimeUnit timeUnit)
throws InterruptedException
TimeoutMap
pollTimeoutBlocking in interface TimeoutMap<K,V>null if there is no timed-out entry in this map within the given duration. otherwise the oldest
timed-out entry.
InterruptedExceptionpublic void clear()
TimeoutMap
clear in interface TimeoutMap<K,V>public int size()
TimeoutMap
size in interface TimeoutMap<K,V>public boolean isEmpty()
isEmpty in interface TimeoutMap<K,V>true if this map is empty, false otherwise.public boolean containsKey(K key)
TimeoutMap
containsKey in interface TimeoutMap<K,V>key - -
true if there is an entry identified by that key in this map, false otherwise.public long getTimeToNextTimeout()
getTimeToNextTimeout in interface TimeoutMap<K,V>Long.MAX_VALUE if the TimeoutMap is empty. Otherwise the time until the next entry times out (in
milliseconds since the epoch). A return value of zero indicates that there is at least one entry which
has already timed out.public long _getTimeToNextTimeoutNs(long nowNs)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||