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 TypeMethodDescriptionvoid
Additem
to this WeakReferenceManager.void
clear()
Clear all items from this WeakReferenceManager.void
forEachValidReference
(@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
.boolean
isEmpty()
Check whether this WeakReferenceManager is empty.void
Removeitem
from this WeakReferenceManager, along with any cleared references.void
removeAll
(@NotNull Collection<T> items) Remove all items initems
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 withnew ArrayWeakReferenceManager(true)
. -
ArrayWeakReferenceManager
public ArrayWeakReferenceManager(boolean concurrent) Construct a WeakReferenceManager.- Parameters:
concurrent
- UseCopyOnWriteArrayList
iftrue
, elseArrayList
.
-
-
Method Details
-
add
Description copied from interface:WeakReferenceManager
Additem
to this WeakReferenceManager.- Specified by:
add
in interfaceWeakReferenceManager<T>
- Parameters:
item
- The item to add
-
remove
Description copied from interface:WeakReferenceManager
Removeitem
from this WeakReferenceManager, along with any cleared references. Comparison is strictly by reference equality, soitem
must be the same object as one previouslyadded
.- Specified by:
remove
in interfaceWeakReferenceManager<T>
- Parameters:
item
- The item to remove
-
removeAll
Description copied from interface:WeakReferenceManager
Remove all items initems
from this WeakReferenceManager, along with any cleared references. Comparison is strictly by reference equality.- Specified by:
removeAll
in interfaceWeakReferenceManager<T>
- Parameters:
items
- The items to remove
-
forEachValidReference
Description copied from interface:WeakReferenceManager
Invokeconsumer.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 interfaceWeakReferenceManager<T>
- Parameters:
consumer
- The consumer to call for each valid itemparallel
- Whether to attempt to invokeconsumer
in parallel if the implementation supports this
-
getFirst
Description copied from interface:WeakReferenceManager
Retrieve the first valid item for whichtest.test(item)
returnstrue
. Any cleared references encountered are removed as a side effect.- Specified by:
getFirst
in interfaceWeakReferenceManager<T>
- Parameters:
test
- The test to decide if a valid item should be returned- Returns:
- The first valid item that passed
test
, ornull
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 atrue
return does not guarantee that items will be encountered by subsequent methods.- Specified by:
isEmpty
in interfaceWeakReferenceManager<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 interfaceWeakReferenceManager<T>
-