Package io.deephaven.base
Class WeakReferenceManager<T>
java.lang.Object
io.deephaven.base.WeakReferenceManager<T>
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 Summary
ConstructorsConstructorDescriptionCreate a WeakReferenceManager, withCopyOnWriteArrayListas backing structure.WeakReferenceManager(boolean useCowList) Create a WeakReferenceManager, with eitherArrayListorCopyOnWriteArrayListas backing structure. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd the specified item to the list.voidclear()Clear the list of references.voidforEachValidReference(Consumer<T> proc) Execute the provided procedure on each listener that has not been GC'd.Retrieve the first valid ref that satisfies the testbooleanisEmpty()Return true if the list is empty.voidRemove item from the list if present, and also any expired references.voidremoveAll(Collection<T> items) Remove items in the collection from the list, and also any expired references.
-
Constructor Details
-
WeakReferenceManager
public WeakReferenceManager()Create a WeakReferenceManager, withCopyOnWriteArrayListas backing structure. -
WeakReferenceManager
public WeakReferenceManager(boolean useCowList) Create a WeakReferenceManager, with eitherArrayListorCopyOnWriteArrayListas backing structure.- Parameters:
useCowList- Use CopyOnWriteArrayList if true, else ArrayList.
-
-
Method Details
-
add
Add the specified item to the list.- Parameters:
item- the item to add.
-
remove
Remove item from the list if present, and also any expired references.- Parameters:
item- the item to remove.
-
removeAll
Remove items in the collection from the list, and also any expired references.- Parameters:
items- the items to remove.
-
forEachValidReference
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
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.
-