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
ConstructorDescriptionCreate a WeakReferenceManager, withCopyOnWriteArrayList
as backing structure.WeakReferenceManager
(boolean useCowList) Create a WeakReferenceManager, with eitherArrayList
orCopyOnWriteArrayList
as backing structure. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add the specified item to the list.void
clear()
Clear the list of references.void
forEachValidReference
(Consumer<T> proc) Execute the provided procedure on each listener that has not been GC'd.Retrieve the first valid ref that satisfies the testboolean
isEmpty()
Return true if the list is empty.void
Remove item from the list if present, and also any expired references.void
removeAll
(Collection<T> items) Remove items in the collection from the list, and also any expired references.
-
Constructor Details
-
WeakReferenceManager
public WeakReferenceManager()Create a WeakReferenceManager, withCopyOnWriteArrayList
as backing structure. -
WeakReferenceManager
public WeakReferenceManager(boolean useCowList) Create a WeakReferenceManager, with eitherArrayList
orCopyOnWriteArrayList
as 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.
-