Class WeakReferenceManager<T>

java.lang.Object
io.deephaven.base.WeakReferenceManager<T>

public class WeakReferenceManager<T> extends Object
A helper for manging a list of WeakReferences. It hides the internal management of expired references and provides for iteration over the valid ones
  • Constructor Details

    • WeakReferenceManager

      public WeakReferenceManager()
      Create a WeakReferenceManager, with CopyOnWriteArrayList as backing structure.
    • WeakReferenceManager

      public WeakReferenceManager(boolean useCowList)
      Create a WeakReferenceManager, with either ArrayList or CopyOnWriteArrayList as backing structure.
      Parameters:
      useCowList - Use CopyOnWriteArrayList if true, else ArrayList.
  • Method Details

    • add

      public void add(T item)
      Add the specified item to the list.
      Parameters:
      item - the item to add.
    • remove

      public void remove(T item)
      Remove item from the list if present, and also any expired references.
      Parameters:
      item - the item to remove.
    • removeAll

      public void removeAll(Collection<T> items)
      Remove items in the collection from the list, and also any expired references.
      Parameters:
      items - the items to remove.
    • forEachValidReference

      public void forEachValidReference(Consumer<T> proc)
      Execute the provided procedure on each listener that has not been GC'd. If a listener was GC'd the reference will be removed from the internal list of refs.
      Parameters:
      proc - The procedure to call with each valid listener
    • getFirst

      public T getFirst(Predicate<T> test)
      Retrieve the first valid ref that satisfies the test
      Parameters:
      test - The test to decide if a valid ref should be returned
      Returns:
      The first valid ref that passed test
    • isEmpty

      public boolean isEmpty()
      Return true if the list is empty. Does not check for expired references.
      Returns:
      true if the list is empty.
    • clear

      public void clear()
      Clear the list of references.