org.apache.commons.collections
public class CursorableLinkedList extends Object implements List, Serializable
Deprecated: Use new version in list subpackage, which has been rewritten and now returns the cursor from the listIterator method. Will be removed in v4.0
A doubly-linked list implementation of the {@link List} interface, supporting a {@link ListIterator} that allows concurrent modifications to the underlying list.Implements all of the optional {@link List} operations, the stack/queue/dequeue operations available in {@link java.util.LinkedList} and supports a {@link ListIterator} that allows concurrent modifications to the underlying list (see {@link #cursor}).
Note that this implementation is not synchronized.
Since: Commons Collections 1.0
Version: $Revision: 1.23 $ $Date: 2004/02/18 01:15:42 $
See Also: java.util.LinkedList
Nested Class Summary | |
---|---|
class | CursorableLinkedList.Cursor |
Field Summary | |
---|---|
protected List | _cursors
A list of the currently {@link CursorableLinkedList.Cursor}s currently
open in this list. |
protected CursorableLinkedList.Listable | _head
A sentry node.
|
protected int | _modCount Tracks the number of structural modifications to me. |
protected int | _size The number of elements in me. |
Method Summary | |
---|---|
boolean | add(Object o)
Appends the specified element to the end of this list.
|
void | add(int index, Object element)
Inserts the specified element at the specified position in this list.
|
boolean | addAll(Collection c)
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
{@link Collection}'s {@link Iterator}. |
boolean | addAll(int index, Collection c)
Inserts all of the elements in the specified collection into this
list at the specified position. |
boolean | addFirst(Object o)
Inserts the specified element at the beginning of this list.
|
boolean | addLast(Object o)
Inserts the specified element at the end of this list.
|
protected void | broadcastListableChanged(CursorableLinkedList.Listable elt)
Informs all of my registered cursors that the specified
element was changed. |
protected void | broadcastListableInserted(CursorableLinkedList.Listable elt)
Informs all of my registered cursors that the specified
element was just added to my list. |
protected void | broadcastListableRemoved(CursorableLinkedList.Listable elt)
Informs all of my registered cursors that the specified
element was just removed from my list. |
void | clear()
Removes all of the elements from this list. |
boolean | contains(Object o)
Returns true if this list contains the specified element.
|
boolean | containsAll(Collection c)
Returns true if this list contains all of the elements of the
specified collection.
|
CursorableLinkedList.Cursor | cursor()
Returns a {@link ListIterator} for iterating through the
elements of this list. |
CursorableLinkedList.Cursor | cursor(int i)
Returns a {@link ListIterator} for iterating through the
elements of this list, initialized such that
{@link ListIterator#next} will return the element at
the specified index (if any) and {@link ListIterator#previous}
will return the element immediately preceding it (if any).
|
boolean | equals(Object o)
Compares the specified object with this list for equality. |
Object | get(int index)
Returns the element at the specified position in this list.
|
Object | getFirst()
Returns the element at the beginning of this list. |
Object | getLast()
Returns the element at the end of this list. |
protected CursorableLinkedList.Listable | getListableAt(int index)
Returns the
{@link org.apache.commons.collections.CursorableLinkedList.Listable}
at the specified index.
|
int | hashCode()
Returns the hash code value for this list. |
int | indexOf(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.
|
protected CursorableLinkedList.Listable | insertListable(CursorableLinkedList.Listable before, CursorableLinkedList.Listable after, Object value)
Inserts a new value into my
list, after the specified before element, and before the
specified after element
|
protected void | invalidateCursors()
Informs all of my registered cursors that they are now
invalid. |
boolean | isEmpty()
Returns true if this list contains no elements. |
Iterator | iterator()
Returns a fail-fast iterator. |
int | lastIndexOf(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.
|
ListIterator | listIterator()
Returns a fail-fast ListIterator. |
ListIterator | listIterator(int index)
Returns a fail-fast ListIterator. |
protected void | registerCursor(CursorableLinkedList.Cursor cur)
Registers a {@link CursorableLinkedList.Cursor} to be notified
of changes to this list. |
boolean | remove(Object o)
Removes the first occurrence in this list of the specified element.
|
Object | remove(int index)
Removes the element at the specified position in this list (optional
operation). |
boolean | removeAll(Collection c)
Removes from this list all the elements that are contained in the
specified collection.
|
Object | removeFirst()
Removes the first element of this list, if any. |
Object | removeLast()
Removes the last element of this list, if any. |
protected void | removeListable(CursorableLinkedList.Listable elt)
Removes the given
{@link org.apache.commons.collections.CursorableLinkedList.Listable}
from my list. |
boolean | retainAll(Collection c)
Retains only the elements in this list that are contained in the
specified collection. |
Object | set(int index, Object element)
Replaces the element at the specified position in this list with the
specified element.
|
int | size()
Returns the number of elements in this list. |
List | subList(int i, int j)
Returns a fail-fast sublist. |
Object[] | toArray()
Returns an array containing all of the elements in this list in proper
sequence. |
Object[] | toArray(Object[] a)
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. |
String | toString()
Returns a {@link String} representation of this list, suitable for debugging. |
protected void | unregisterCursor(CursorableLinkedList.Cursor cur)
Removes a {@link CursorableLinkedList.Cursor} from
the set of cursors to be notified of changes to this list. |
_head.next() points to the first element in the list, _head.prev() to the last. Note that it is possible for _head.next().prev() and _head.prev().next() to be non-null, as when I am a sublist for some larger list. Use == _head.next() and == _head.prev() to determine if a given {@link org.apache.commons.collections.CursorableLinkedList.Listable} is the first or last element in the list.
Parameters: o element to be appended to this list.
Returns: true
Parameters: index index at which the specified element is to be inserted. element element to be inserted.
Throws: ClassCastException if the class of the specified element prevents it from being added to this list. IllegalArgumentException if some aspect of the specified element prevents it from being added to this list. IndexOutOfBoundsException if the index is out of range (index < 0 || index > size()).
Parameters: c collection whose elements are to be added to this list.
Returns: true if this list changed as a result of the call.
Throws: ClassCastException if the class of an element in the specified collection prevents it from being added to this list. IllegalArgumentException if some aspect of an element in the specified collection prevents it from being added to this list.
Parameters: index index at which to insert first element from the specified collection. c elements to be inserted into this list.
Returns: true if this list changed as a result of the call.
Throws: ClassCastException if the class of one of elements of the specified collection prevents it from being added to this list. IllegalArgumentException if some aspect of one of elements of the specified collection prevents it from being added to this list. IndexOutOfBoundsException if the index is out of range (index < 0 || index > size()).
Parameters: o element to be prepended to this list.
Returns: true
Parameters: o element to be appended to this list.
Returns: true
See Also: CursorableLinkedList
Parameters: o element whose presence in this list is to be tested.
Returns: true if this list contains the specified element.
Parameters: c collection to be checked for containment in this list.
Returns: true if this list contains all of the elements of the specified collection.
Specifically, when elements are added to the list before or after the cursor, the cursor simply picks them up automatically. When the "current" (i.e., last returned by {@link ListIterator#next} or {@link ListIterator#previous}) element of the list is removed, the cursor automatically adjusts to the change (invalidating the last returned value--i.e., it cannot be removed).
Note that the returned {@link ListIterator} does not support the {@link ListIterator#nextIndex} and {@link ListIterator#previousIndex} methods (they throw {@link UnsupportedOperationException} when invoked.
Historical Note: In previous versions of this class, the object returned from this method was required to be explicitly closed. This is no longer necessary.
See Also: CursorableLinkedList CursorableLinkedList Cursor
Throws: IndexOutOfBoundsException if the index is out of range (index < 0 || index > size()).
See Also: CursorableLinkedList CursorableLinkedList Cursor
Parameters: o the object to be compared for equality with this list.
Returns: true if the specified object is equal to this list.
Parameters: index index of element to return.
Returns: the element at the specified position in this list.
Throws: IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()).
Throws: IndexOutOfBoundsException if index is less than zero or greater than or equal to the size of this list.
hashCode = 1; Iterator i = list.iterator(); while (i.hasNext()) { Object obj = i.next(); hashCode = 31*hashCode + (obj==null ? 0 : obj.hashCode()); }This ensures that list1.equals(list2) implies that list1.hashCode()==list2.hashCode() for any two lists, list1 and list2, as required by the general contract of Object.hashCode.
Returns: the hash code value for this list.
See Also: Object#hashCode() Object#equals(Object) equals
Parameters: o element to search for.
Returns: the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.
Returns: the newly created {@link org.apache.commons.collections.CursorableLinkedList.Listable}
Returns: true if this list contains no elements.
See Also: List#iterator
Parameters: o element to search for.
Returns: the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element.
See Also: List#listIterator
See Also: List#listIterator(int)
Parameters: o element to be removed from this list, if present.
Returns: true if this list contained the specified element.
Parameters: index the index of the element to removed.
Returns: the element previously at the specified position.
Throws: IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()).
Parameters: c collection that defines which elements will be removed from this list.
Returns: true if this list changed as a result of the call.
Parameters: c collection that defines which elements this set will retain.
Returns: true if this list changed as a result of the call.
Parameters: index index of element to replace. element element to be stored at the specified position.
Returns: the element previously at the specified position.
Throws: ClassCastException if the class of the specified element prevents it from being added to this list. IllegalArgumentException if some aspect of the specified element prevents it from being added to this list. IndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()).
Returns: the number of elements in this list.
See Also: List#subList(int,int)
Returns: an array containing all of the elements in this list in proper sequence.
Parameters: a 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.
Returns: an array containing the elements of this list.
Throws: ArrayStoreException if the runtime type of the specified array is not a supertype of the runtime type of every element in this list.
Returns: a {@link String} representation of this list, suitable for debugging.