tyrex.util
public class WeakList extends Object
The base assumption about this list is that it holds objects used by the application that require extra processing. When the application releases object, we are no longer interested in processing it. This list has preference to not hold or return objects that have been garbage collected (even if not finalized yet).
There is no direct access to the list, the only way to retrieve entries is through WeakList. Since unreferenced entires may be removed at any time, implementing indexed access is a bit hard. Instead, WeakList produces an array that points to all the referenced elements, and that array can be accessed by index. For as long as this array is referenced, no entries will be claimed.
Certain optimization decisions have been made in this list based on its projected usage, in particular:
This object is not thread-safe.
Version: $Revision: 1.5 $ $Date: 2001/03/12 19:20:21 $
Field Summary | |
---|---|
static int | INITIAL_SIZE
This is the initial size of the array. |
Method Summary | |
---|---|
void | add(Object object)
Adds a new object to the list.
|
void | clear()
Clears the contents of this list. |
boolean | contains(Object object)
Returns true if the element is contained in the list and has not
been garbage collected yet.
|
Object[] | list()
Returns an array representing the contents of this list.
|
Object[] | list(Class type)
Returns an array representing the contents of this list.
|
static void | main(String[] args) |
Object | remove(Object object)
Removes an object from the list. |
Parameters: object The object to add
Parameters: object The object to test
Returns: True if the object is contained in the list
Only objects that are referenced will be returned in the array, and these objects will be referenced by the array and not discarded for as long as the returned array is referenced.
This is the only way to access the list by index and operate on it without safety checks.
The returned array is a sparse array, it may contain null entries for objects that no longer exist.
Returns: An array representing the contents of the list
Only objects that are referenced will be returned in the array, and these objects will be referenced by the array and not discarded for as long as the returned array is referenced.
This is the only way to access the list by index and operate on it without safety checks.
The returned array is a sparse array, it may contain null entries for objects that no longer exist.
Parameters: type The object type requested
Returns: An array representing the contents of the list
Parameters: object The object to remove
Returns: The removed object, null if the object was not there