Class ArrayWeakReferenceManager<T>

java.lang.Object
io.deephaven.util.datastructures.ArrayWeakReferenceManager<T>
All Implemented Interfaces:
WeakReferenceManager<T>

public class ArrayWeakReferenceManager<T> extends Object implements WeakReferenceManager<T>
Implementation of WeakReferenceManager backed by an ArrayList (when not concurrent) or a CopyOnWriteArrayList (when concurrent). Users should note the potential for poor performance when adding a large number of items to a concurrent ArrayWeakReferenceManager.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct a WeakReferenceManager as with new ArrayWeakReferenceManager(true).
    ArrayWeakReferenceManager(boolean concurrent)
    Construct a WeakReferenceManager.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(T item)
    Add item to this WeakReferenceManager.
    void
    Clear all items from this WeakReferenceManager.
    void
    forEachValidReference(@NotNull Consumer<T> consumer, boolean parallel)
    Invoke consumer.accept(item) for each item previously added to this WeakReferenceManager whose reference has not been cleared (i.e.
    getFirst(@NotNull Predicate<T> test)
    Retrieve the first valid item for which test.test(item) returns true.
    boolean
    Check whether this WeakReferenceManager is empty.
    void
    remove(T item)
    Remove item from this WeakReferenceManager, along with any cleared references.
    void
    removeAll(@NotNull Collection<T> items)
    Remove all items in items from this WeakReferenceManager, along with any cleared references.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.deephaven.util.datastructures.WeakReferenceManager

    forEachValidReference
  • Constructor Details

    • ArrayWeakReferenceManager

      public ArrayWeakReferenceManager()
      Construct a WeakReferenceManager as with new ArrayWeakReferenceManager(true).
    • ArrayWeakReferenceManager

      public ArrayWeakReferenceManager(boolean concurrent)
      Construct a WeakReferenceManager.
      Parameters:
      concurrent - Use CopyOnWriteArrayList if true, else ArrayList.
  • Method Details

    • add

      public void add(T item)
      Description copied from interface: WeakReferenceManager
      Add item to this WeakReferenceManager.
      Specified by:
      add in interface WeakReferenceManager<T>
      Parameters:
      item - The item to add
    • remove

      public void remove(T item)
      Description copied from interface: WeakReferenceManager
      Remove item from this WeakReferenceManager, along with any cleared references. Comparison is strictly by reference equality, so item must be the same object as one previously added.
      Specified by:
      remove in interface WeakReferenceManager<T>
      Parameters:
      item - The item to remove
    • removeAll

      public void removeAll(@NotNull @NotNull Collection<T> items)
      Description copied from interface: WeakReferenceManager
      Remove all items in items from this WeakReferenceManager, along with any cleared references. Comparison is strictly by reference equality.
      Specified by:
      removeAll in interface WeakReferenceManager<T>
      Parameters:
      items - The items to remove
    • forEachValidReference

      public void forEachValidReference(@NotNull @NotNull Consumer<T> consumer, boolean parallel)
      Description copied from interface: WeakReferenceManager
      Invoke consumer.accept(item) for each item previously added to this WeakReferenceManager whose reference has not been cleared (i.e. because it was garbage-collected). Removes cleared references as a side effect.
      Specified by:
      forEachValidReference in interface WeakReferenceManager<T>
      Parameters:
      consumer - The consumer to call for each valid item
      parallel - Whether to attempt to invoke consumer in parallel if the implementation supports this
    • getFirst

      public T getFirst(@NotNull @NotNull Predicate<T> test)
      Description copied from interface: WeakReferenceManager
      Retrieve the first valid item for which test.test(item) returns true. Any cleared references encountered are removed as a side effect.
      Specified by:
      getFirst in interface WeakReferenceManager<T>
      Parameters:
      test - The test to decide if a valid item should be returned
      Returns:
      The first valid item that passed test, or null if no such item existed
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: WeakReferenceManager
      Check whether this WeakReferenceManager is empty. Does not check for cleared references, and so a true return does not guarantee that items will be encountered by subsequent methods.
      Specified by:
      isEmpty in interface WeakReferenceManager<T>
      Returns:
      Whether this WeakReferenceManager is empty
    • clear

      public void clear()
      Description copied from interface: WeakReferenceManager
      Clear all items from this WeakReferenceManager.
      Specified by:
      clear in interface WeakReferenceManager<T>