|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractList
org.openbp.common.util.WeakArrayList
public class WeakArrayList
A weak list works pretty identical to the java.util.ArrayList class except that
it usually refers its elements using a weak reference.
Weak references enable the garbage collector to remove objects though they are
still referenced through the weak ref. In this case, the reference returns null
(i. e. through the get(int) method).
Note that the list does not change its size though the references may be garbage-collected.
However, if you invoke the trim() method, 'dead' references are removed.
Though the implementation of the java.util.List methods always add the elements
as weak references, it is also possible to insert elements as hard references using
the addHardReference(Object) method, allowing to mix weak and hard references in a
single list. This is e. g. used by the ListenerSupport
class, which stores the listeners as weak references, but the listener classes as regular
references in order to minimize object allocation.
Note the the Iterator returned by the AbstractList.iterator() method always returns
elements that are validly referenced by the list. The references in the list can be copied
to a list that contains regular (hard) references using the createHardList() method.
| Field Summary |
|---|
| Fields inherited from class java.util.AbstractList |
|---|
modCount |
| Constructor Summary | |
|---|---|
WeakArrayList()
Default constructor. |
|
WeakArrayList(int initialCapacity)
Default constructor. |
|
| Method Summary | |
|---|---|
void |
add(int index,
java.lang.Object element)
Inserts the object at the given position in the list as a weak reference. |
void |
addHardReference(int index,
java.lang.Object element)
Inserts the object at the given position in the list as a regular (hard) reference. |
void |
addHardReference(java.lang.Object element)
Adds the object at the end of the list as a regular (hard) reference. |
java.util.List |
createHardList()
Creates a list of hard references to the objects. |
java.lang.Object |
get(int index)
Gets the element at the given index. |
java.lang.Object |
remove(int index)
Removes the object at the given index. |
java.lang.Object |
set(int index,
java.lang.Object element)
Sets the object at the given index as a weak reference. |
int |
size()
Gets the size of the list. |
void |
trim()
Trims the list by removing 'dead' references, i\. e\. collected elements. |
| 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 |
| Constructor Detail |
|---|
public WeakArrayList()
public WeakArrayList(int initialCapacity)
initialCapacity - Initial capacity of the list| Method Detail |
|---|
public java.lang.Object get(int index)
get in interface java.util.Listget in class java.util.AbstractListindex - Index into the list
public int size()
size in interface java.util.Collectionsize in interface java.util.Listsize in class java.util.AbstractCollection
public java.lang.Object set(int index,
java.lang.Object element)
set in interface java.util.Listset in class java.util.AbstractListindex - List indexelement - Element to set
public void add(int index,
java.lang.Object element)
add in interface java.util.Listadd in class java.util.AbstractListindex - List indexelement - Element to addpublic java.lang.Object remove(int index)
remove in interface java.util.Listremove in class java.util.AbstractListindex - The index of the element to be removed
public void addHardReference(java.lang.Object element)
element - Element to add
public void addHardReference(int index,
java.lang.Object element)
index - List indexelement - Element to addpublic java.util.List createHardList()
public void trim()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||