netx.jnlp.util
Class WeakList
java.lang.Object
|
+--java.util.AbstractCollection
|
+--java.util.AbstractList
|
+--netx.jnlp.util.WeakList
- All Implemented Interfaces:
- java.util.Collection, java.util.List
- public class WeakList
- extends java.util.AbstractList
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.1 $
- Author:
- Jon A. Maxwell (JAM) - initial author
Fields inherited from class java.util.AbstractList |
modCount |
Constructor Summary |
WeakList()
Create a weak random-access list. |
Method Summary |
void |
add(int index,
java.lang.Object element)
Inserts the object at the specified position in the list. |
java.lang.Object |
get(int index)
Returns the object at the specified index, or null if the
object has been collected. |
java.util.List |
hardList()
Returns a list of hard references to the objects. |
java.lang.Object |
remove(int index)
Removes the object at the specified position and returns it
or returns null if it was already collected. |
java.lang.Object |
set(int index,
java.lang.Object element)
Sets the object at the specified position and returns the
previous object at that position or null if it was already
collected. |
int |
size()
Returns the size of the list, including already collected
objects. |
void |
trimToSize()
Compacts the list by removing references to collected
objects. |
Methods inherited from class java.util.AbstractList |
add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList |
Methods inherited from class java.util.AbstractCollection |
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray |
WeakList
public WeakList()
- Create a weak random-access list.
get
public java.lang.Object get(int index)
- Returns the object at the specified index, or null if the
object has been collected.
- Overrides:
get
in class java.util.AbstractList
size
public int size()
- Returns the size of the list, including already collected
objects.
- Overrides:
size
in class java.util.AbstractCollection
set
public java.lang.Object set(int index,
java.lang.Object element)
- Sets the object at the specified position and returns the
previous object at that position or null if it was already
collected.
- Overrides:
set
in class java.util.AbstractList
add
public void add(int index,
java.lang.Object element)
- Inserts the object at the specified position in the list.
Automatically creates a weak reference to the object.
- Overrides:
add
in class java.util.AbstractList
remove
public java.lang.Object remove(int index)
- Removes the object at the specified position and returns it
or returns null if it was already collected.
- Overrides:
remove
in class java.util.AbstractList
hardList
public java.util.List hardList()
- Returns a list of hard references to the objects. The
returned list does not include the collected elements, so its
indices do not necessarily correlate with those of this list.
trimToSize
public void trimToSize()
- Compacts the list by removing references to collected
objects.