public class WeakList extends AbstractList implements List, Serializable
This is a list with weak references to all the add objects. When this list is the only one that has a reference to an object the object will be garbage collected, and the element will be removed from the list.
NOTE: You must be aware of that there might be some rear possibility that some of the methods can return null.
modCount
Constructor and Description |
---|
WeakList()
Constructs an empty WeakList.
|
WeakList(Collection c)
Constructs a WeakList containing the elements of the specified
collection, in the order they are returned by the collection's
iterator.
|
WeakList(int initialCapacity)
Constructs an empty WeakList with the specified initial capacity.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
Object element) |
boolean |
add(Object element) |
protected Object |
castObject(Object o) |
protected Object |
create(Object element)
Creates the weak reference object to put in the list
|
Object |
get(int index) |
protected void |
processQueue()
Here we go through the ReferenceQueue and remove garbage
collected WeakRefernce objects from the List by looking them
up using the WeakReference.
|
Object |
remove(int index) |
boolean |
remove(Object element) |
Object |
set(int index,
Object element) |
int |
size() |
addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList
addAll, contains, containsAll, isEmpty, removeAll, retainAll, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addAll, addAll, clear, contains, containsAll, equals, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, removeAll, replaceAll, retainAll, sort, spliterator, subList, toArray, toArray
parallelStream, removeIf, stream
public WeakList()
public WeakList(int initialCapacity)
initialCapacity
- the initial capacity of the list.public WeakList(Collection c)
c
- the collection whose elements are to be placed into this list.protected void processQueue()
protected Object create(Object element)
element
- the element we want a weak reference topublic void add(int index, Object element)
add
in interface List
add
in class AbstractList
public boolean add(Object element)
add
in interface Collection
add
in interface List
add
in class AbstractList
public Object get(int index)
get
in interface List
get
in class AbstractList
public Object remove(int index)
remove
in interface List
remove
in class AbstractList
public boolean remove(Object element)
remove
in interface Collection
remove
in interface List
remove
in class AbstractCollection
public Object set(int index, Object element)
set
in interface List
set
in class AbstractList
public int size()
size
in interface Collection
size
in interface List
size
in class AbstractCollection
© 1998- 2018 Stibo DX