Package org.jgroups.util
Class LazyRemovalList<T>
- java.lang.Object
-
- org.jgroups.util.LazyRemovalList<T>
-
public class LazyRemovalList<T> extends java.lang.Object
List which doesn't remove elements on remove(), removeAll() or retainAll(), but only removes elements when a configurable size limit has been exceeded. In that case, all elements marked as removable and older than a configurable time are evicted. Elements are marked as removable by remove(), removeAll() and retainAll(). When an elements is marked as removable, but later reinserted, the mark is removed.
Note that methods get() and remove() iterate through the list (linear cost), so large lists will be slow.- Since:
- 5.4.4
- Author:
- Bela Ban
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LazyRemovalList.Entry<T>
static interface
LazyRemovalList.Printable<T>
-
Constructor Summary
Constructors Constructor Description LazyRemovalList()
LazyRemovalList(int max_elements, long max_age)
Creates a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(T val)
void
clear(boolean force)
void
forEach(java.util.function.Consumer<T> c)
T
get(T val)
java.util.List<T>
nonRemovedValues()
Adds all value which have not been marked as removable to the returned setjava.lang.String
printCache()
java.lang.String
printCache(LazyRemovalList.Printable<T> print_function)
void
remove(T val)
void
removeMarkedElements()
Removes elements marked as removablevoid
removeMarkedElements(boolean force)
Removes elements marked as removableint
size()
java.lang.String
toString()
-
-
-
Constructor Detail
-
LazyRemovalList
public LazyRemovalList()
-
LazyRemovalList
public LazyRemovalList(int max_elements, long max_age)
Creates a new instance- Parameters:
max_elements
- The max number of elements in the cachemax_age
- The max age (in ms) an entry can have before it is considered expired (and can be removed on the next sweep)
-
-
Method Detail
-
add
public boolean add(T val)
-
forEach
public void forEach(java.util.function.Consumer<T> c)
-
remove
public void remove(T val)
-
clear
public void clear(boolean force)
-
nonRemovedValues
public java.util.List<T> nonRemovedValues()
Adds all value which have not been marked as removable to the returned set- Returns:
-
size
public int size()
-
printCache
public java.lang.String printCache()
-
printCache
public java.lang.String printCache(LazyRemovalList.Printable<T> print_function)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
removeMarkedElements
public void removeMarkedElements(boolean force)
Removes elements marked as removable- Parameters:
force
- If set to true, all elements marked as 'removable' will get removed, regardless of expiration
-
removeMarkedElements
public void removeMarkedElements()
Removes elements marked as removable
-
-