netx.jnlp.util

Class WeakList


public class WeakList
extends 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.3 $
Author:
Jon A. Maxwell (JAM) - initial author

Constructor Summary

WeakList()
Create a weak random-access list.

Method Summary

void
add(int index, Object element)
Inserts the object at the specified position in the list.
Object
get(int index)
Returns the object at the specified index, or null if the object has been collected.
List
hardList()
Returns a list of hard references to the objects.
Object
remove(int index)
Removes the object at the specified position and returns it or returns null if it was already collected.
Object
set(int index, 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.

Constructor Details

WeakList

public WeakList()
Create a weak random-access list.

Method Details

add

public void add(int index,
                Object element)
Inserts the object at the specified position in the list. Automatically creates a weak reference to the object.

get

public Object get(int index)
Returns the object at the specified index, or null if the object has been collected.

hardList

public 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.

remove

public Object remove(int index)
Removes the object at the specified position and returns it or returns null if it was already collected.

set

public Object set(int index,
                  Object element)
Sets the object at the specified position and returns the previous object at that position or null if it was already collected.

size

public int size()
Returns the size of the list, including already collected objects.

trimToSize

public void trimToSize()
Compacts the list by removing references to collected objects.