Class 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
    • 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 cache
        max_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)
      • get

        public T get​(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()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.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