Class CursorableLinkedList
- java.lang.Object
-
- org.apache.commons.collections.list.AbstractLinkedList
-
- org.apache.commons.collections.list.CursorableLinkedList
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Iterable,java.util.Collection,java.util.List
public class CursorableLinkedList extends AbstractLinkedList implements java.io.Serializable
AListimplementation with aListIteratorthat allows concurrent modifications to the underlying list.This implementation supports all of the optional
Listoperations. It extendsAbstractLinkedListand thus provides the stack/queue/dequeue operations available inLinkedList.The main feature of this class is the ability to modify the list and the iterator at the same time. Both the
listIterator()andcursor()methods provides access to aCursorinstance which extendsListIterator. The cursor allows changes to the list concurrent with changes to the iterator. Note that theiterator()method and sublists do not provide this cursor behaviour.The
Cursorclass is provided partly for backwards compatibility and partly because it allows the cursor to be directly closed. Closing the cursor is optional because references are held via aWeakReference. For most purposes, simply modify the iterator and list at will, and then let the garbage collector to the rest.Note that this implementation is not synchronized.
- Since:
- Commons Collections 1.0
- See Also:
LinkedList, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCursorableLinkedList.CursorAn extendedListIteratorthat allows concurrent changes to the underlying list.
-
Constructor Summary
Constructors Constructor Description CursorableLinkedList()Constructor that creates.CursorableLinkedList(java.util.Collection coll)Constructor that copies the specified collection
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CursorableLinkedList.Cursorcursor()Returns aCursorableLinkedList.Cursorfor iterating through the elements of this list.CursorableLinkedList.Cursorcursor(int fromIndex)Returns aCursorableLinkedList.Cursorfor iterating through the elements of this list starting from a specified index.java.util.Iteratoriterator()Returns an iterator that does not support concurrent modification.java.util.ListIteratorlistIterator()Returns a cursor iterator that allows changes to the underlying list in parallel.java.util.ListIteratorlistIterator(int fromIndex)Returns a cursor iterator that allows changes to the underlying list in parallel.-
Methods inherited from class org.apache.commons.collections.list.AbstractLinkedList
add, add, addAll, addAll, addFirst, addLast, clear, contains, containsAll, equals, get, getFirst, getLast, hashCode, indexOf, isEmpty, lastIndexOf, remove, remove, removeAll, removeFirst, removeLast, retainAll, set, size, subList, toArray, toArray, toString
-
-
-
-
Method Detail
-
iterator
public java.util.Iterator iterator()
Returns an iterator that does not support concurrent modification.If the underlying list is modified while iterating using this iterator a ConcurrentModificationException will occur. The cursor behaviour is available via
listIterator().- Specified by:
iteratorin interfacejava.util.Collection- Specified by:
iteratorin interfacejava.lang.Iterable- Specified by:
iteratorin interfacejava.util.List- Overrides:
iteratorin classAbstractLinkedList- Returns:
- a new iterator that does not support concurrent modification
-
listIterator
public java.util.ListIterator listIterator()
Returns a cursor iterator that allows changes to the underlying list in parallel.The cursor enables iteration and list changes to occur in any order without invalidating the iterator (from one thread). When elements are added to the list, an event is fired to all active cursors enabling them to adjust to the change in the list.
When the "current" (i.e., last returned by
ListIterator.next()orListIterator.previous()) element of the list is removed, the cursor automatically adjusts to the change (invalidating the last returned value such that it cannot be removed).- Specified by:
listIteratorin interfacejava.util.List- Overrides:
listIteratorin classAbstractLinkedList- Returns:
- a new cursor iterator
-
listIterator
public java.util.ListIterator listIterator(int fromIndex)
Returns a cursor iterator that allows changes to the underlying list in parallel.The cursor enables iteration and list changes to occur in any order without invalidating the iterator (from one thread). When elements are added to the list, an event is fired to all active cursors enabling them to adjust to the change in the list.
When the "current" (i.e., last returned by
ListIterator.next()orListIterator.previous()) element of the list is removed, the cursor automatically adjusts to the change (invalidating the last returned value such that it cannot be removed).- Specified by:
listIteratorin interfacejava.util.List- Overrides:
listIteratorin classAbstractLinkedList- Parameters:
fromIndex- the index to start from- Returns:
- a new cursor iterator
-
cursor
public CursorableLinkedList.Cursor cursor()
Returns aCursorableLinkedList.Cursorfor iterating through the elements of this list.A
Cursoris aListIteratorwith an additionalclose()method. Calling this method immediately discards the references to the cursor. If it is not called, then the garbage collector will still remove the reference as it is held via aWeakReference.The cursor enables iteration and list changes to occur in any order without invalidating the iterator (from one thread). When elements are added to the list, an event is fired to all active cursors enabling them to adjust to the change in the list.
When the "current" (i.e., last returned by
ListIterator.next()orListIterator.previous()) element of the list is removed, the cursor automatically adjusts to the change (invalidating the last returned value such that it cannot be removed).The
listIterator()method returns the same as this method, and can be cast to aCursorif theclosemethod is required.- Returns:
- a new cursor iterator
-
cursor
public CursorableLinkedList.Cursor cursor(int fromIndex)
Returns aCursorableLinkedList.Cursorfor iterating through the elements of this list starting from a specified index.A
Cursoris aListIteratorwith an additionalclose()method. Calling this method immediately discards the references to the cursor. If it is not called, then the garbage collector will still remove the reference as it is held via aWeakReference.The cursor enables iteration and list changes to occur in any order without invalidating the iterator (from one thread). When elements are added to the list, an event is fired to all active cursors enabling them to adjust to the change in the list.
When the "current" (i.e., last returned by
ListIterator.next()orListIterator.previous()) element of the list is removed, the cursor automatically adjusts to the change (invalidating the last returned value such that it cannot be removed).The
listIterator(int)method returns the same as this method, and can be cast to aCursorif theclosemethod is required.- Parameters:
fromIndex- the index to start from- Returns:
- a new cursor iterator
- Throws:
java.lang.IndexOutOfBoundsException- if the index is out of range (index < 0 || index > size()).
-
-