Package org.drasyl.util
Class ExpiringSet<E>
java.lang.Object
org.drasyl.util.ExpiringSet<E>
- Type Parameters:
E
- the type of elements maintained by this set
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,Set<E>
A
Set
that expires elements based on oldest age (when maximum size has been exceeded) or
write
The expiration policy is only enforced on set access. There will be no automatic expiration
handling running in a background thread or similar. For performance reasons the policy is not
enforced on every single access, but only once every "expiration window" (Math
.max(expireAfterWrite, expireAfterAccess)). Therefore, it may happen that elements are kept
in the set up to the double expiration window length.
This data structure is not thread-safe!
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(Collection<? extends E> c) void
clear()
boolean
boolean
containsAll
(Collection<?> c) boolean
isEmpty()
iterator()
boolean
boolean
removeAll
(Collection<?> c) boolean
retainAll
(Collection<?> c) int
size()
Object[]
toArray()
<T> T[]
toArray
(T[] a) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.Set
equals, hashCode, spliterator
-
Constructor Details
-
ExpiringSet
public ExpiringSet(long maximumSize, long expireAfterWrite) - Parameters:
maximumSize
- maximum number of entries that the set should contain. On overflow, first elements based on expiration policy are removed.-1
deactivates a size limitation.expireAfterWrite
- time in milliseconds after which elements are automatically removed from the set after being added.- Throws:
IllegalArgumentException
- ifmaximumSize
is0
orexpireAfterWrite
is-1
.
-
-
Method Details
-
size
public int size() -
isEmpty
public boolean isEmpty() -
contains
-
iterator
-
toArray
-
toArray
public <T> T[] toArray(T[] a) -
add
-
remove
-
containsAll
- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceSet<E>
-
addAll
-
retainAll
-
removeAll
-
clear
public void clear()
-