Class ExpireHashMap<K,V>
java.lang.Object
com.comphenix.protocol.collections.ExpireHashMap<K,V>
- Type Parameters:
K- - type of the keys.V- - type of the values.
Represents a hash map where each association may expire after a given time has elapsed.
Note that replaced key-value associations are only collected once the original expiration time has elapsed.
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new hash map where each entry may expire at a given time.ExpireHashMap(com.google.common.base.Ticker ticker) Construct a new hash map where each entry may expire at a given time. -
Method Summary
Modifier and TypeMethodDescriptionasMap()Retrieve a view of this expire map as an ordinary map that does not support insertion.voidclear()Clear all the entries in the current map.voidcollect()Clear all references to key-value pairs that have been removed or replaced before they were naturally evicted.booleancontainsKey(K key) Determine if the given key is referring to an unexpired association in the map.booleancontainsValue(V value) Determine if the given value is referring to an unexpired association in the map.entrySet()Retrieve a view of all the entries in the set.protected voidEvict any expired entries in the map.Retrieve the value associated with the given key, if it has not expired.keySet()Retrieve a view of the keys in the current map.Associate the given key with the given value, until the expire delay have elapsed.Remove a key and its associated value from the map.intsize()Retrieve the number of entries in the map.toString()values()Retrieve a view of all the values in the current map.
-
Constructor Details
-
ExpireHashMap
public ExpireHashMap()Construct a new hash map where each entry may expire at a given time. -
ExpireHashMap
public ExpireHashMap(com.google.common.base.Ticker ticker) Construct a new hash map where each entry may expire at a given time.- Parameters:
ticker- - supplier of the current time.
-
-
Method Details
-
get
Retrieve the value associated with the given key, if it has not expired.- Parameters:
key- - the key.- Returns:
- The value, or NULL if not found or it has expired.
-
put
Associate the given key with the given value, until the expire delay have elapsed.- Parameters:
key- - the key.value- - the value.expireDelay- - the amount of time until this association expires. Must be greater than zero.expireUnit- - the unit of the expiration.- Returns:
- Any previously unexpired association with this key, or NULL.
-
containsKey
Determine if the given key is referring to an unexpired association in the map.- Parameters:
key- - the key.- Returns:
- TRUE if it is, FALSE otherwise.
-
containsValue
Determine if the given value is referring to an unexpired association in the map.- Parameters:
value- - the value.- Returns:
- TRUE if it is, FALSE otherwise.
-
removeKey
Remove a key and its associated value from the map.- Parameters:
key- - the key to remove.- Returns:
- Value of the removed association, NULL otherwise.
-
size
public int size()Retrieve the number of entries in the map.- Returns:
- The number of entries.
-
keySet
Retrieve a view of the keys in the current map.- Returns:
- View of the keys.
-
values
Retrieve a view of all the values in the current map.- Returns:
- All the values.
-
entrySet
Retrieve a view of all the entries in the set.- Returns:
- All the entries.
-
asMap
Retrieve a view of this expire map as an ordinary map that does not support insertion.- Returns:
- The map.
-
collect
public void collect()Clear all references to key-value pairs that have been removed or replaced before they were naturally evicted.This operation requires a linear scan of the current entries in the map.
-
clear
public void clear()Clear all the entries in the current map. -
evictExpired
protected void evictExpired()Evict any expired entries in the map.This is called automatically by any of the read or write operations.
-
toString
-