Package io.deephaven.util.datastructures
Class ArrayWeakReferenceManager<T>
java.lang.Object
io.deephaven.util.datastructures.ArrayWeakReferenceManager<T>
- All Implemented Interfaces:
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
ConstructorsConstructorDescriptionConstruct a WeakReferenceManager as withnew ArrayWeakReferenceManager(true).ArrayWeakReferenceManager(boolean concurrent) Construct a WeakReferenceManager. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdditemto this WeakReferenceManager.voidclear()Clear all items from this WeakReferenceManager.voidforEachValidReference(@NotNull Consumer<T> consumer, boolean parallel) Invokeconsumer.accept(item)for each item previously added to this WeakReferenceManager whose reference has not been cleared (i.e.Retrieve the first valid item for whichtest.test(item)returnstrue.booleanisEmpty()Check whether this WeakReferenceManager is empty.voidRemoveitemfrom this WeakReferenceManager, along with any cleared references.voidremoveAll(@NotNull Collection<T> items) Remove all items initemsfrom this WeakReferenceManager, along with any cleared references.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.deephaven.util.datastructures.WeakReferenceManager
forEachValidReference
-
Constructor Details
-
ArrayWeakReferenceManager
public ArrayWeakReferenceManager()Construct a WeakReferenceManager as withnew ArrayWeakReferenceManager(true). -
ArrayWeakReferenceManager
public ArrayWeakReferenceManager(boolean concurrent) Construct a WeakReferenceManager.- Parameters:
concurrent- UseCopyOnWriteArrayListiftrue, elseArrayList.
-
-
Method Details
-
add
Description copied from interface:WeakReferenceManagerAdditemto this WeakReferenceManager.- Specified by:
addin interfaceWeakReferenceManager<T>- Parameters:
item- The item to add
-
remove
Description copied from interface:WeakReferenceManagerRemoveitemfrom this WeakReferenceManager, along with any cleared references. Comparison is strictly by reference equality, soitemmust be the same object as one previouslyadded.- Specified by:
removein interfaceWeakReferenceManager<T>- Parameters:
item- The item to remove
-
removeAll
Description copied from interface:WeakReferenceManagerRemove all items initemsfrom this WeakReferenceManager, along with any cleared references. Comparison is strictly by reference equality.- Specified by:
removeAllin interfaceWeakReferenceManager<T>- Parameters:
items- The items to remove
-
forEachValidReference
Description copied from interface:WeakReferenceManagerInvokeconsumer.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:
forEachValidReferencein interfaceWeakReferenceManager<T>- Parameters:
consumer- The consumer to call for each valid itemparallel- Whether to attempt to invokeconsumerin parallel if the implementation supports this
-
getFirst
Description copied from interface:WeakReferenceManagerRetrieve the first valid item for whichtest.test(item)returnstrue. Any cleared references encountered are removed as a side effect.- Specified by:
getFirstin interfaceWeakReferenceManager<T>- Parameters:
test- The test to decide if a valid item should be returned- Returns:
- The first valid item that passed
test, ornullif no such item existed
-
isEmpty
public boolean isEmpty()Description copied from interface:WeakReferenceManagerCheck whether this WeakReferenceManager is empty. Does not check for cleared references, and so atruereturn does not guarantee that items will be encountered by subsequent methods.- Specified by:
isEmptyin interfaceWeakReferenceManager<T>- Returns:
- Whether this WeakReferenceManager is empty
-
clear
public void clear()Description copied from interface:WeakReferenceManagerClear all items from this WeakReferenceManager.- Specified by:
clearin interfaceWeakReferenceManager<T>
-