|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object tyrex.util.WeakList
List of weak references allows objects to be tracked and claimed by
the garbage collector. This is a simple implementation based on an
array and users WeakReference
for its entries.
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 list()
. Since unreferenced entires may be
removed at any time, implementing indexed access is a bit hard.
Instead, list()
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:
INITIAL_SIZE
entries whiche seems a good compromise.This object is not thread-safe.
Field Summary | |
static int |
INITIAL_SIZE
This is the initial size of the array. |
Constructor Summary | |
WeakList()
|
Method Summary | |
void |
add(java.lang.Object object)
Adds a new object to the list. |
void |
clear()
Clears the contents of this list. |
boolean |
contains(java.lang.Object object)
Returns true if the element is contained in the list and has not been garbage collected yet. |
java.lang.Object[] |
list()
Returns an array representing the contents of this list. |
java.lang.Object[] |
list(java.lang.Class type)
Returns an array representing the contents of this list. |
static void |
main(java.lang.String[] args)
|
java.lang.Object |
remove(java.lang.Object object)
Removes an object from the list. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int INITIAL_SIZE
Constructor Detail |
public WeakList()
Method Detail |
public void add(java.lang.Object object)
object
- The object to addpublic java.lang.Object remove(java.lang.Object object)
object
- The object to remove
public void clear()
public boolean contains(java.lang.Object object)
object
- The object to test
public java.lang.Object[] 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.
public java.lang.Object[] list(java.lang.Class type)
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.
type
- The object type requested
public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |