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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanaddAll(Collection<? extends E> c) voidclear()booleanbooleancontainsAll(Collection<?> c) booleanisEmpty()iterator()booleanbooleanremoveAll(Collection<?> c) booleanretainAll(Collection<?> c) intsize()Object[]toArray()<T> T[]toArray(T[] a) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods 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.-1deactivates a size limitation.expireAfterWrite- time in milliseconds after which elements are automatically removed from the set after being added.- Throws:
IllegalArgumentException- ifmaximumSizeis0orexpireAfterWriteis-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:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceSet<E>
-
addAll
-
retainAll
-
removeAll
-
clear
public void clear()
-