Package org.jgroups.util
Class LazyRemovalList<T>
- java.lang.Object
-
- org.jgroups.util.LazyRemovalList<T>
-
public class LazyRemovalList<T> extends java.lang.ObjectList 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 classLazyRemovalList.Entry<T>static interfaceLazyRemovalList.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 booleanadd(T val)voidclear(boolean force)voidforEach(java.util.function.Consumer<T> c)Tget(T val)java.util.List<T>nonRemovedValues()Adds all value which have not been marked as removable to the returned setjava.lang.StringprintCache()java.lang.StringprintCache(LazyRemovalList.Printable<T> print_function)voidremove(T val)voidremoveMarkedElements()Removes elements marked as removablevoidremoveMarkedElements(boolean force)Removes elements marked as removableintsize()java.lang.StringtoString()
-
-
-
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:
toStringin 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
-
-