Package xyz.gmitch215.socketmc.util
Class LifecycleMap<T>
java.lang.Object
xyz.gmitch215.socketmc.util.LifecycleMap<T>
- Type Parameters:
T
- The type of object to store
- All Implemented Interfaces:
Iterable<T>
A map that contains objects for a certain amount of time.
-
Constructor Summary
ConstructorDescriptionConstructs a new, empty LifecycleMap.LifecycleMap
(@Nullable LifecycleMap<T> map) Constructs a new LifecycleMap with the same mappings as the specified map. -
Method Summary
Modifier and TypeMethodDescriptionboolean
containsKey
(T key) Returns true if this map contains a mapping for the specified key.long
getDuration
(T key) Returns the duration of the specified key.long
getRemainingTime
(T key) Returns the remaining time of the specified key.long
Returns the start time of the specified key.iterator()
void
Associates the specified value with the specified key in this map.void
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.void
run()
Runs the map, removing any expired values.int
size()
Gets the size of the map.void
Stores the specified key in this map for the specified duration.void
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.void
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
LifecycleMap
public LifecycleMap()Constructs a new, empty LifecycleMap. -
LifecycleMap
Constructs a new LifecycleMap with the same mappings as the specified map.- Parameters:
map
- The map whose mappings are to be placed in this map
-
-
Method Details
-
run
public void run()Runs the map, removing any expired values. -
put
Associates the specified value with the specified key in this map.- Parameters:
key
- The key with which the specified value is to be associatedstartMillis
- The start time of the value, in millisecondsdurationMillis
- The duration of the value, in milliseconds
-
store
Stores the specified key in this map for the specified duration.- Parameters:
key
- The key to storemillis
- The duration to store the key for, in milliseconds
-
store
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.- Parameters:
key
- The key whose associated value is to be returnedtime
- The current time, in millisecondsunit
- The time unit of the duration
-
store
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.- Parameters:
key
- The key whose associated value is to be returnedduration
- The duration to store the key for
-
remove
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.- Parameters:
key
- The key whose associated value is to be returned
-
getStart
Returns the start time of the specified key.- Parameters:
key
- The key whose start time is to be returned- Returns:
- The start time of the key, in milliseconds
-
getDuration
Returns the duration of the specified key.- Parameters:
key
- The key whose duration is to be returned- Returns:
- The duration of the key, in milliseconds
-
getRemainingTime
Returns the remaining time of the specified key.- Parameters:
key
- The key whose remaining time is to be returned- Returns:
- The remaining time of the key, in milliseconds, or -1 if the key is not present
-
size
public int size()Gets the size of the map.- Returns:
- The size of the map
-
containsKey
Returns true if this map contains a mapping for the specified key.- Parameters:
key
- The key whose presence in this map is to be tested- Returns:
- True if this map contains a mapping for the specified key
-
iterator
-