|
||||||||||
| 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 | |
|---|---|
void |
add(long timeout,
K key,
V value)
Add a key-value pair with an associated timeout to the map. |
void |
addWithTimestamp(long timestamp,
K key,
V value)
Add a key-value pair with a specific timeout timestamp. |
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> |
pollTimeout()
finds the next entry which is timed out, based on the time of the invocation of this method. |
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 void add(long timeout,
K key,
V value)
TimeoutMap
add in interface TimeoutMap<K,V>key - -value - -
public void addWithTimestamp(long timestamp,
K key,
V value)
TimeoutMap
addWithTimestamp in interface TimeoutMap<K,V>timestamp - the timestamp when this key-value pair will expire (in milliseconds since the epoch).key - -value - -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> pollTimeout()
TimeoutMap
pollTimeout in interface TimeoutMap<K,V>null if there is no timed-out entry in this map. otherwise the oldest timed-out entry.public 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.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||