public class WeakList<E>
extends java.lang.Object
implements java.util.List<E>, java.io.Serializable
| Modifier and Type | Field and Description | 
|---|---|
protected java.lang.ref.Reference<E>[] | 
array
The list of elements. 
 | 
protected java.lang.ref.ReferenceQueue | 
queue
Reference queue for garbage-collected elements. 
 | 
protected java.util.List<E> | 
serialized_list  | 
protected int | 
size
The number of elements. 
 | 
protected int | 
state
The state (to check for modifications). 
 | 
| Constructor and Description | 
|---|
WeakList()
Create a new list. 
 | 
| Modifier and Type | Method and Description | 
|---|---|
boolean | 
add(E o)
Appends the specified element to the end of this list (optional
 operation). 
 | 
void | 
add(int index,
   java.lang.Object o)
Inserts the specified element at the specified position in this list
 (optional operation). 
 | 
boolean | 
addAll(java.util.Collection collection)
Appends all of the elements in the specified collection to the end of
 this list, in the order that they are returned by the specified
 collection's iterator (optional operation). 
 | 
boolean | 
addAll(int index,
      java.util.Collection collection)
Inserts all of the elements in the specified collection into this
 list at the specified position (optional operation). 
 | 
protected static void | 
checkForEmptySlots(java.util.List list)
Check for empty slots in list. 
 | 
void | 
clear()
Removes all of the elements from this list (optional operation). 
 | 
boolean | 
contains(java.lang.Object o)
Returns 
  | 
boolean | 
containsAll(java.util.Collection c)
Returns 
  | 
protected static java.lang.String[] | 
createTestvalues(java.lang.String teststring,
                int size)
Create some string values for testing. 
 | 
E | 
get(int index)
Returns the element at the specified position in this list. 
 | 
int | 
indexOf(java.lang.Object o)
Returns the index in this list of the first occurrence of the specified
 element, or -1 if this list does not contain this element. 
 | 
boolean | 
isEmpty()
Returns 
  | 
java.util.Iterator<E> | 
iterator()
Returns an iterator over the elements in this list in proper sequence. 
 | 
int | 
lastIndexOf(java.lang.Object o)
Returns the index in this list of the last occurrence of the specified
 element, or -1 if this list does not contain this element. 
 | 
java.util.ListIterator<E> | 
listIterator()
Returns a list iterator of the elements in this list (in proper
 sequence). 
 | 
java.util.ListIterator<E> | 
listIterator(int index)
Returns a list iterator of the elements in this list (in proper
 sequence), starting at the specified position in this list. 
 | 
static void | 
main(java.lang.String[] args)
Main method for testing. 
 | 
protected java.lang.Object | 
readResolve()
Perform special handling on deserialization. 
 | 
E | 
remove(int index)
Removes the element at the specified position in this list (optional
 operation). 
 | 
boolean | 
remove(java.lang.Object o)
Removes the first occurrence in this list of the specified element
 (optional operation). 
 | 
boolean | 
removeAll(java.util.Collection c)
Removes from this list all the elements that are contained in the
 specified collection (optional operation). 
 | 
boolean | 
retainAll(java.util.Collection c)
Retains only the elements in this list that are contained in the
 specified collection (optional operation). 
 | 
java.lang.Object | 
set(int index,
   java.lang.Object o)
Replaces the element at the specified position in this list with the
 specified element (optional operation). 
 | 
int | 
size()
Returns the number of elements in this list. 
 | 
java.util.List<E> | 
subList(int fromIndex,
       int toIndex)
Returns a view of the portion of this list between the specified
 
  | 
java.lang.Object[] | 
toArray()
Returns an array containing all of the elements in this list in proper
 sequence. 
 | 
java.lang.Object[] | 
toArray(java.lang.Object[] ret)
Returns an array containing all of the elements in this list in proper
 sequence; the runtime type of the returned array is that of the
 specified array. 
 | 
java.lang.String | 
toString()
Get the string representation. 
 | 
protected java.lang.Object | 
writeReplace()
Perform special handling on serialization. 
 | 
protected transient java.lang.ref.Reference<E>[] array
protected int size
protected int state
protected transient java.lang.ref.ReferenceQueue queue
protected java.util.List<E> serialized_list
public int size()
size in interface java.util.Collection<E>size in interface java.util.List<E>public boolean isEmpty()
isEmpty in interface java.util.Collection<E>isEmpty in interface java.util.List<E>public boolean contains(java.lang.Object o)
contains in interface java.util.Collection<E>contains in interface java.util.List<E>o - element whose presence in this list is to be tested.java.lang.ClassCastException - if the type of the specified element
 is incompatible with this list (optional).java.lang.NullPointerException - if the specified element is null.public java.util.Iterator<E> iterator()
public java.lang.Object[] toArray()
toArray in interface java.util.Collection<E>toArray in interface java.util.List<E>Arrays.asList(Object[])public java.lang.Object[] toArray(java.lang.Object[] ret)
toArray in interface java.util.Collection<E>toArray in interface java.util.List<E>ret - the array into which the elements of this list are to
 be stored, if it is big enough; otherwise, a new array of the
 same runtime type is allocated for this purpose.java.lang.ArrayStoreException - if the runtime type of the specified array
 is not a supertype of the runtime type of every element in
 this list.java.lang.NullPointerException - if the specified array is 
public boolean add(E o)
add in interface java.util.Collection<E>add in interface java.util.List<E>o - element to be appended to this list.java.lang.UnsupportedOperationException - if the 
java.lang.ClassCastException - if the class of the specified element
 prevents it from being added to this list.java.lang.NullPointerException - if the specified element is nul.java.lang.IllegalArgumentException - if some aspect of this element
 prevents it from being added to this list.public boolean remove(java.lang.Object o)
remove in interface java.util.Collection<E>remove in interface java.util.List<E>o - element to be removed from this list, if present.java.lang.ClassCastException - if the type of the specified element
 is incompatible with this list (optional).java.lang.NullPointerException - if the specified element is null.java.lang.UnsupportedOperationException - if the 
public boolean containsAll(java.util.Collection c)
containsAll in interface java.util.Collection<E>containsAll in interface java.util.List<E>c - collection to be checked for containment in this list.java.lang.ClassCastException - if the types of one or more elements
 in the specified collection are incompatible with this
 list (optional).java.lang.NullPointerException - if the specified collection contains one
 or more null elements and this list does not support null
 elements (optional).java.lang.NullPointerException - if the specified collection is
 
contains(Object)public boolean addAll(java.util.Collection collection)
addAll in interface java.util.Collection<E>addAll in interface java.util.List<E>collection - collection whose elements are to be added to this list.java.lang.UnsupportedOperationException - if the 
java.lang.ClassCastException - if the class of an element in the specified
 collection prevents it from being added to this list.java.lang.NullPointerException - if the specified collection contains one
 or more null elements and this list does not support null
 elements, or if the specified collection is 
java.lang.IllegalArgumentException - if some aspect of an element in the
 specified collection prevents it from being added to this
 list.add(Object)public boolean addAll(int index,
                      java.util.Collection collection)
addAll in interface java.util.List<E>index - index at which to insert first element from the specified
 collection.collection - elements to be inserted into this list.java.lang.UnsupportedOperationException - if the 
java.lang.ClassCastException - if the class of one of elements of the
 specified collection prevents it from being added to this
 list.java.lang.NullPointerException - if the specified collection contains one
 or more null elements and this list does not support null
 elements, or if the specified collection is 
java.lang.IllegalArgumentException - if some aspect of one of elements of
 the specified collection prevents it from being added to
 this list.java.lang.IndexOutOfBoundsException - if the index is out of range (index
 < 0 || index > size()).public boolean removeAll(java.util.Collection c)
removeAll in interface java.util.Collection<E>removeAll in interface java.util.List<E>c - collection that defines which elements will be removed from
 this list.java.lang.UnsupportedOperationException - if the 
java.lang.ClassCastException - if the types of one or more elements
 in this list are incompatible with the specified
 collection (optional).java.lang.NullPointerException - if this list contains one or more
 null elements and the specified collection does not support
 null elements (optional).java.lang.NullPointerException - if the specified collection is
 
remove(Object), 
contains(Object)public boolean retainAll(java.util.Collection c)
retainAll in interface java.util.Collection<E>retainAll in interface java.util.List<E>c - collection that defines which elements this set will retain.java.lang.UnsupportedOperationException - if the 
java.lang.ClassCastException - if the types of one or more elements
 in this list are incompatible with the specified
 collection (optional).java.lang.NullPointerException - if this list contains one or more
 null elements and the specified collection does not support
 null elements (optional).java.lang.NullPointerException - if the specified collection is
 
remove(Object), 
contains(Object)public void clear()
public E get(int index)
get in interface java.util.List<E>index - index of element to return.java.lang.IndexOutOfBoundsException - if the index is out of range (index
 < 0 || index >= size()).public java.lang.Object set(int index,
                            java.lang.Object o)
set in interface java.util.List<E>index - index of element to replace.o - element to be stored at the specified position.java.lang.UnsupportedOperationException - if the 
java.lang.ClassCastException - if the class of the specified element
 prevents it from being added to this list.java.lang.NullPointerException - if the specified element is null and
 this list does not support null elements.java.lang.IllegalArgumentException - if some aspect of the specified
 element prevents it from being added to this list.java.lang.IndexOutOfBoundsException - if the index is out of range
 (index < 0 || index >= size()).public void add(int index,
                java.lang.Object o)
add in interface java.util.List<E>index - index at which the specified element is to be inserted.o - element to be inserted.java.lang.UnsupportedOperationException - if the 
java.lang.ClassCastException - if the class of the specified element
 prevents it from being added to this list.java.lang.NullPointerException - if the specified element is null and
 this list does not support null elements.java.lang.IllegalArgumentException - if some aspect of the specified
 element prevents it from being added to this list.java.lang.IndexOutOfBoundsException - if the index is out of range
 (index < 0 || index > size()).public E remove(int index)
remove in interface java.util.List<E>index - the index of the element to removed.java.lang.UnsupportedOperationException - if the 
java.lang.IndexOutOfBoundsException - if the index is out of range (index
 < 0 || index >= size()).public int indexOf(java.lang.Object o)
indexOf in interface java.util.List<E>o - element to search for.java.lang.ClassCastException - if the type of the specified element
 is incompatible with this list (optional).java.lang.NullPointerException - if the specified element is null.public int lastIndexOf(java.lang.Object o)
lastIndexOf in interface java.util.List<E>o - element to search for.java.lang.ClassCastException - if the type of the specified element
 is incompatible with this list (optional).java.lang.NullPointerException - if the specified element is null.public java.util.ListIterator<E> listIterator()
listIterator in interface java.util.List<E>public java.util.ListIterator<E> listIterator(int index)
listIterator in interface java.util.List<E>index - index of first element to be returned from the
 list iterator (by a call to the 
java.lang.IndexOutOfBoundsException - if the index is out of range (index
 < 0 || index > size()).public java.util.List<E> subList(int fromIndex, int toIndex)
subList in interface java.util.List<E>fromIndex - low endpoint (inclusive) of the subList.toIndex - high endpoint (exclusive) of the subList.java.lang.IndexOutOfBoundsException - for an illegal endpoint index value
 (fromIndex < 0 || toIndex > size || fromIndex > toIndex).public java.lang.String toString()
toString in class java.lang.Objectprotected java.lang.Object writeReplace()
                                 throws java.io.ObjectStreamException
java.io.ObjectStreamExceptionprotected java.lang.Object readResolve()
                                throws java.io.ObjectStreamException
java.io.ObjectStreamExceptionpublic static void main(java.lang.String[] args)
protected static java.lang.String[] createTestvalues(java.lang.String teststring,
                                                     int size)
protected static void checkForEmptySlots(java.util.List list)