Class WeakList<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
net.sourceforge.jnlp.util.WeakList<E>
- Type Parameters:
E- generic typeto be used in this list
- All Implemented Interfaces:
Iterable<E>, Collection<E>, List<E>, SequencedCollection<E>
This list stores objects automatically using weak references.
Objects are added and removed from the list as normal, but may
turn to null at any point (ie, indexOf(x) followed by get(x)
may return null). The weak references are only removed when
the trimToSize method is called so that the indices remain
constant otherwise.
- Version:
- $Revision: 1.3 $
-
Field Summary
FieldsFields inherited from class AbstractList
modCount -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidInserts the object at the specified position in the list.private Ederef(WeakReference<E> o) Extract the hard reference out of a weak reference.get(int index) hardList()remove(int index) Removes the object at the specified position and returns it or returns null if it was already collected.Sets the object at the specified position and returns the previous object at that position or null if it was already collected.intsize()voidCompacts the list by removing references to collected objects.Methods inherited from class AbstractList
add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subListMethods inherited from class AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from interface Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface List
addAll, addFirst, addLast, contains, containsAll, getFirst, getLast, isEmpty, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, sort, spliterator, toArray, toArray
-
Field Details
-
refs
-
-
Constructor Details
-
WeakList
public WeakList()Create a weak random-access list.
-
-
Method Details
-
deref
Extract the hard reference out of a weak reference. -
get
-
size
public int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceList<E>- Specified by:
sizein classAbstractCollection<E>- Returns:
- the size of the list, including already collected objects.
-
set
Sets the object at the specified position and returns the previous object at that position or null if it was already collected. -
add
Inserts the object at the specified position in the list. Automatically creates a weak reference to the object. -
remove
Removes the object at the specified position and returns it or returns null if it was already collected. -
hardList
-
trimToSize
public void trimToSize()Compacts the list by removing references to collected objects.
-