|
|||||||||
| Home >> All >> org >> apache >> commons >> [ collections overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.commons.collections
Class CursorableLinkedList

java.lang.Objectorg.apache.commons.collections.CursorableLinkedList
- All Implemented Interfaces:
- java.util.Collection, java.lang.Iterable, java.util.List, java.io.Serializable
- Direct Known Subclasses:
- CursorableSubList
- public class CursorableLinkedList
- extends java.lang.Object
- implements java.util.List, java.io.Serializable
- extends java.lang.Object
A doubly-linked list implementation of the java.util.List interface, supporting a java.util.ListIterator that allows concurrent modifications to the underlying list.
Implements all of the optional java.util.List operations, the
stack/queue/dequeue operations available in java.util.LinkedList
and supports a java.util.ListIterator that allows concurrent modifications
to the underlying list (see cursor() 55 ).
Note that this implementation is not synchronized.
- Since:
- 1.0
- Version:
- $Id: CursorableLinkedList.java,v 1.10.2.1 2004/05/22 12:14:02 scolebourne Exp $
| Nested Class Summary | |
class |
CursorableLinkedList.Cursor
|
(package private) class |
CursorableLinkedList.Listable
|
(package private) class |
CursorableLinkedList.ListIter
|
| Field Summary | |
protected java.util.List |
_cursors
A list of the currently CursorableLinkedList.Cursors 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. |
| Constructor Summary | |
CursorableLinkedList()
|
|
| Method Summary | |
void |
add(int index,
java.lang.Object element)
Inserts the specified element at the specified position in this list. |
boolean |
add(java.lang.Object o)
Appends the specified element to the end of this list. |
boolean |
addAll(java.util.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 java.util.Collection's java.util.Iterator. |
boolean |
addAll(int index,
java.util.Collection c)
Inserts all of the elements in the specified collection into this list at the specified position. |
boolean |
addFirst(java.lang.Object o)
Inserts the specified element at the beginning of this list. |
boolean |
addLast(java.lang.Object o)
Inserts the specified element at the end of this list. |
protected void |
broadcastListableChanged(CursorableLinkedList.Listable elt)
Informs all of my registerd cursors that the specified element was changed. |
protected void |
broadcastListableInserted(CursorableLinkedList.Listable elt)
Informs all of my registered cursors tha the specifed element was just added to my list. |
protected void |
broadcastListableRemoved(CursorableLinkedList.Listable elt)
Informs all of my registered cursors tha the specifed element was just removed from my list. |
void |
clear()
Removes all of the elements from this list. |
boolean |
contains(java.lang.Object o)
Returns true if this list contains the specified element. |
boolean |
containsAll(java.util.Collection c)
Returns true if this list contains all of the elements of the specified collection. |
CursorableLinkedList.Cursor |
cursor()
Returns a java.util.ListIterator for iterating through the elements of this list. |
CursorableLinkedList.Cursor |
cursor(int i)
Returns a java.util.ListIterator for iterating through the elements of this list, initialized such that ListIterator.next()> ListIterator.next() 55 will return the element at
the specified index (if any) and ListIterator.previous()>ListIterator.previous() 55
will return the element immediately preceeding it (if any). |
boolean |
equals(java.lang.Object o)
Compares the specified object with this list for equality. |
java.lang.Object |
get(int index)
Returns the element at the specified position in this list. |
java.lang.Object |
getFirst()
Returns the element at the beginning of this list. |
java.lang.Object |
getLast()
Returns the element at the end of this list. |
protected CursorableLinkedList.Listable |
getListableAt(int index)
Returns the CursorableLinkedList.Listable at the specified index. |
int |
hashCode()
Returns the hash code value for 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. |
protected CursorableLinkedList.Listable |
insertListable(CursorableLinkedList.Listable before,
CursorableLinkedList.Listable after,
java.lang.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 registerd cursors that they are now invalid. |
boolean |
isEmpty()
Returns true if this list contains no elements. |
java.util.Iterator |
iterator()
Returns a fail-fast iterator. |
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 |
listIterator()
Returns a fail-fast ListIterator. |
java.util.ListIterator |
listIterator(int index)
Returns a fail-fast ListIterator. |
private void |
readObject(java.io.ObjectInputStream in)
|
protected void |
registerCursor(CursorableLinkedList.Cursor cur)
Registers a CursorableLinkedList.Cursor to be notified of changes to this list. |
java.lang.Object |
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. |
boolean |
removeAll(java.util.Collection c)
Removes from this list all the elements that are contained in the specified collection. |
java.lang.Object |
removeFirst()
Removes the first element of this list, if any. |
java.lang.Object |
removeLast()
Removes the last element of this list, if any. |
protected void |
removeListable(CursorableLinkedList.Listable elt)
Removes the given CursorableLinkedList.Listable from my list. |
boolean |
retainAll(java.util.Collection c)
Retains only the elements in this list that are contained in the specified collection. |
java.lang.Object |
set(int index,
java.lang.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. |
java.util.List |
subList(int i,
int j)
Returns a fail-fast sublist. |
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[] 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. |
java.lang.String |
toString()
Returns a java.lang.String representation of this list, suitable for debugging. |
protected void |
unregisterCursor(CursorableLinkedList.Cursor cur)
Removes a CursorableLinkedList.Cursor from the set of cursors to be notified of changes to this list. |
private void |
writeObject(java.io.ObjectOutputStream out)
|
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
_size
protected transient int _size
- The number of elements in me.
_head
protected transient CursorableLinkedList.Listable _head
- A sentry node.
_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 CursorableLinkedList.Listable is the first or last element in the list.
_modCount
protected int _modCount
- Tracks the number of structural modifications to me.
_cursors
protected java.util.List _cursors
- A list of the currently CursorableLinkedList.Cursors currently
open in this list.
| Constructor Detail |
CursorableLinkedList
public CursorableLinkedList()
| Method Detail |
add
public boolean add(java.lang.Object o)
- Appends the specified element to the end of this list.
- Specified by:
addin interfacejava.util.List
add
public void add(int index,
java.lang.Object element)
- Inserts the specified element at the specified position in this list.
Shifts the element currently at that position (if any) and any subsequent
elements to the right (adds one to their indices).
- Specified by:
addin interfacejava.util.List
addAll
public boolean addAll(java.util.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
java.util.Collection's java.util.Iterator. The behavior of this operation is
unspecified if the specified collection is modified while
the operation is in progress. (Note that this will occur if the
specified collection is this list, and it's nonempty.)
- Specified by:
addAllin interfacejava.util.List
addAll
public boolean addAll(int index,
java.util.Collection c)
- Inserts all of the elements in the specified collection into this
list at the specified position. Shifts the element currently at
that position (if any) and any subsequent elements to the right
(increases their indices). The new elements will appear in this
list in the order that they are returned by the specified
java.util.Collection's java.util.Iterator. The behavior of this operation is
unspecified if the specified collection is modified while the
operation is in progress. (Note that this will occur if the specified
collection is this list, and it's nonempty.)
- Specified by:
addAllin interfacejava.util.List
addFirst
public boolean addFirst(java.lang.Object o)
- Inserts the specified element at the beginning of this list.
(Equivalent to add(0,o) 55 ).
addLast
public boolean addLast(java.lang.Object o)
- Inserts the specified element at the end of this list.
(Equivalent to
add(java.lang.Object)55 ).
clear
public void clear()
- Removes all of the elements from this list. This
list will be empty after this call returns (unless
it throws an exception).
- Specified by:
clearin interfacejava.util.List
contains
public boolean contains(java.lang.Object o)
- Returns true if this list contains the specified element.
More formally, returns true if and only if this list contains
at least one element e such that
(o==null ? e==null : o.equals(e)).
- Specified by:
containsin interfacejava.util.List
containsAll
public boolean containsAll(java.util.Collection c)
- Returns true if this list contains all of the elements of the
specified collection.
- Specified by:
containsAllin interfacejava.util.List
cursor
public CursorableLinkedList.Cursor cursor()
- Returns a java.util.ListIterator for iterating through the
elements of this list. Unlike
iterator()55 , a cursor is not bothered by concurrent modifications to the underlying list.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 ListIterator.next()>
ListIterator.next()55 or ListIterator.previous()>ListIterator.previous()55 ) 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 java.util.ListIterator does not support the ListIterator.nextIndex()>
ListIterator.nextIndex()55 and ListIterator.previousIndex()>ListIterator.previousIndex()55 methods (they throw java.lang.UnsupportedOperationException when invoked.Clients must close the cursor when they are done using it. The returned java.util.ListIterator will be an instance of CursorableLinkedList.Cursor. To close the cursor, cast the java.util.ListIterator to CursorableLinkedList.Cursor and invoke the
CursorableLinkedList.Cursor.close()55 method.
cursor
public CursorableLinkedList.Cursor cursor(int i)
- Returns a java.util.ListIterator for iterating through the
elements of this list, initialized such that
ListIterator.next()>
ListIterator.next()55 will return the element at the specified index (if any) and ListIterator.previous()>ListIterator.previous()55 will return the element immediately preceeding it (if any). Unlikeiterator()55 , a cursor is not bothered by concurrent modifications to the underlying list.
equals
public boolean equals(java.lang.Object o)
- Compares the specified object with this list for equality. Returns
true if and only if the specified object is also a list, both
lists have the same size, and all corresponding pairs of elements in
the two lists are equal. (Two elements e1 and
e2 are equal if (e1==null ? e2==null :
e1.equals(e2)).) In other words, two lists are defined to be
equal if they contain the same elements in the same order. This
definition ensures that the equals method works properly across
different implementations of the List interface.
- Specified by:
equalsin interfacejava.util.List
get
public java.lang.Object get(int index)
- Returns the element at the specified position in this list.
- Specified by:
getin interfacejava.util.List
getFirst
public java.lang.Object getFirst()
- Returns the element at the beginning of this list.
getLast
public java.lang.Object getLast()
- Returns the element at the end of this list.
hashCode
public int hashCode()
- Returns the hash code value for this list. The hash code of a list
is defined to be the result of the following calculation:
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.- Specified by:
hashCodein interfacejava.util.List
indexOf
public 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.
More formally, returns the lowest index i such that
(o==null ? get(i)==null : o.equals(get(i))),
or -1 if there is no such index.
- Specified by:
indexOfin interfacejava.util.List
isEmpty
public boolean isEmpty()
- Returns true if this list contains no elements.
- Specified by:
isEmptyin interfacejava.util.List
iterator
public java.util.Iterator iterator()
- Returns a fail-fast iterator.
- Specified by:
iteratorin interfacejava.util.List
lastIndexOf
public 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.
More formally, returns the highest index i such that
(o==null ? get(i)==null : o.equals(get(i))),
or -1 if there is no such index.
- Specified by:
lastIndexOfin interfacejava.util.List
listIterator
public java.util.ListIterator listIterator()
- Returns a fail-fast ListIterator.
- Specified by:
listIteratorin interfacejava.util.List
listIterator
public java.util.ListIterator listIterator(int index)
- Returns a fail-fast ListIterator.
- Specified by:
listIteratorin interfacejava.util.List
remove
public boolean remove(java.lang.Object o)
- Removes the first occurrence in this list of the specified element.
If this list does not contain the element, it is
unchanged. More formally, removes the element with the lowest index i
such that (o==null ? get(i)==null : o.equals(get(i))) (if
such an element exists).
- Specified by:
removein interfacejava.util.List
remove
public java.lang.Object remove(int index)
- Removes the element at the specified position in this list (optional
operation). Shifts any subsequent elements to the left (subtracts one
from their indices). Returns the element that was removed from the
list.
- Specified by:
removein interfacejava.util.List
removeAll
public boolean removeAll(java.util.Collection c)
- Removes from this list all the elements that are contained in the
specified collection.
- Specified by:
removeAllin interfacejava.util.List
removeFirst
public java.lang.Object removeFirst()
- Removes the first element of this list, if any.
removeLast
public java.lang.Object removeLast()
- Removes the last element of this list, if any.
retainAll
public boolean retainAll(java.util.Collection c)
- Retains only the elements in this list that are contained in the
specified collection. In other words, removes
from this list all the elements that are not contained in the specified
collection.
- Specified by:
retainAllin interfacejava.util.List
set
public java.lang.Object set(int index, java.lang.Object element)
- Replaces the element at the specified position in this list with the
specified element.
- Specified by:
setin interfacejava.util.List
size
public int size()
- Returns the number of elements in this list.
- Specified by:
sizein interfacejava.util.List
toArray
public java.lang.Object[] toArray()
- Returns an array containing all of the elements in this list in proper
sequence. Obeys the general contract of the Collection.toArray()>
Collection.toArray()55 method.- Specified by:
toArrayin interfacejava.util.List
toArray
public java.lang.Object[] toArray(java.lang.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. Obeys the general contract of the
Collection.toArray()>
Collection.toArray()55 method.- Specified by:
toArrayin interfacejava.util.List
toString
public java.lang.String toString()
- Returns a java.lang.String representation of this list, suitable for debugging.
subList
public java.util.List subList(int i, int j)
- Returns a fail-fast sublist.
- Specified by:
subListin interfacejava.util.List
insertListable
protected CursorableLinkedList.Listable insertListable(CursorableLinkedList.Listable before, CursorableLinkedList.Listable after, java.lang.Object value)
- Inserts a new value into my
list, after the specified before element, and before the
specified after element
removeListable
protected void removeListable(CursorableLinkedList.Listable elt)
- Removes the given
CursorableLinkedList.Listable
from my list.
getListableAt
protected CursorableLinkedList.Listable getListableAt(int index)
- Returns the
CursorableLinkedList.Listable
at the specified index.
registerCursor
protected void registerCursor(CursorableLinkedList.Cursor cur)
- Registers a CursorableLinkedList.Cursor to be notified
of changes to this list.
unregisterCursor
protected void unregisterCursor(CursorableLinkedList.Cursor cur)
- Removes a CursorableLinkedList.Cursor from
the set of cursors to be notified of changes to this list.
invalidateCursors
protected void invalidateCursors()
- Informs all of my registerd cursors that they are now
invalid.
broadcastListableChanged
protected void broadcastListableChanged(CursorableLinkedList.Listable elt)
- Informs all of my registerd cursors that the specified
element was changed.
broadcastListableRemoved
protected void broadcastListableRemoved(CursorableLinkedList.Listable elt)
- Informs all of my registered cursors tha the specifed
element was just removed from my list.
broadcastListableInserted
protected void broadcastListableInserted(CursorableLinkedList.Listable elt)
- Informs all of my registered cursors tha the specifed
element was just added to my list.
writeObject
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException
readObject
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException
|
|||||||||
| Home >> All >> org >> apache >> commons >> [ collections overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
org.apache.commons.collections.CursorableLinkedList