Package com.pnfsoftware.jeb.util.collect
Class WeakPseudoList<T>
java.lang.Object
com.pnfsoftware.jeb.util.collect.WeakPseudoList<T>
- Type Parameters:
T- element type
- All Implemented Interfaces:
Iterable<T>
A list of weak references. Holding objects in this list will not prevent them from being GC'ed.
This interface does not abide by the usual Java
List interface, hence the "pseudo".-
Constructor Summary
ConstructorsConstructorDescriptionCreate an empty weak pseudo-list.WeakPseudoList(int initialCapacity) Create an empty weak pseudo-list with an initial capacity.WeakPseudoList(Iterable<T> l) Create a weak pseudo-list from an iterable. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
WeakPseudoList
public WeakPseudoList()Create an empty weak pseudo-list. -
WeakPseudoList
public WeakPseudoList(int initialCapacity) Create an empty weak pseudo-list with an initial capacity.- Parameters:
initialCapacity- initial capacity
-
WeakPseudoList
Create a weak pseudo-list from an iterable.- Parameters:
l- elements to add
-
-
Method Details
-
iterator
-
size
public int size()- Returns:
- number of weak references in the list
-
isEmpty
public boolean isEmpty()- Returns:
- true if no weak reference is stored
-
clear
public void clear()Remove all weak references. -
get
Retrieve an element.- Parameters:
index- element index- Returns:
- referenced element, or null if it was collected
-
add
Add an element.- Parameters:
e- element to weakly reference- Returns:
- true if the list changed
-
add
Insert an element.- Parameters:
index- insertion indexe- element to weakly reference
-
addAll
Add all elements from an iterable.- Parameters:
l- elements to add
-
set
Replace an element.- Parameters:
index- element indexe- new element to weakly reference- Returns:
- previous referenced element, or null if it was collected
-
remove
Remove an element.- Parameters:
index- element index- Returns:
- removed referenced element, or null if it was collected
-