List implementation with a ListIterator that
allows concurrent modifications to the underlying list.
This implementation supports all of the optional List operations.
It extends AbstractLinkedList and thus provides the
stack/queue/dequeue operations available in java..
The main feature of this class is the ability to modify the list and the
iterator at the same time. Both the listIterator() and cursor()
methods provides access to a Cursor instance which extends
ListIterator. The cursor allows changes to the list concurrent
with changes to the iterator. Note that the iterator() method and
sublists do not provide this cursor behaviour.
The Cursor class 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 a WeakReference.
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.
java.util.LinkedList
| Modifier and Type | Class and Description |
|---|---|
| public static class | CursorableLinkedList.Cursor<E>
An extended |
| protected static class |
| Modifier and Type | Field and Description |
|---|---|
| private transient List | cursors
A list of the cursor currently open on this list |
| private static final long | serialVersionUID
Ensure serialization compatibility |
| Access | Constructor and Description |
|---|---|
| public | |
| public | CursorableLinkedList(final Collection<? extends E>
the collection to copy coll)Constructor that copies the specified collection |
| Modifier and Type | Method and Description |
|---|---|
| protected void | addNode(final AbstractLinkedList.
new node to insert nodeToInsert,node to insert before insertBeforeNodeOverrides org. |
| protected void | broadcastNodeChanged(final AbstractLinkedList.
the node that was changed nodeInforms all of my registered cursors that the specified element was changed. |
| protected void | broadcastNodeInserted(final AbstractLinkedList.
the node that was changed nodeInforms all of my registered cursors that the specified element was just added to my list. |
| protected void | broadcastNodeRemoved(final AbstractLinkedList.
the node that was changed nodeInforms all of my registered cursors that the specified element was just removed from my list. |
| protected ListIterator | Returns: the list iterator for the sublistthe sublist to get an iterator for subList,the index to start from, relative to the sublist fromIndex)Overrides org. |
| public CursorableLinkedList. | |
| public CursorableLinkedList. | |
| protected void | init()
Overrides org. readObject.
|
| public Iterator | Returns: a new iterator that does not support concurrent modificationOverrides org. Implements java. |
| public ListIterator | Returns: a new cursor iteratorOverrides org. Implements java. |
| public ListIterator | Returns: a new cursor iteratorthe index to start from fromIndex)Overrides org. Implements java. |
| private void | readObject(final ObjectInputStream
the input stream in)Deserializes the data held in this object to the stream specified. |
| protected void | registerCursor(final CursorableLinkedList.
the cursor to register cursorRegisters a cursor to be notified of changes to this list. |
| protected void | removeAllNodes()
Overrides org. |
| protected void | removeNode(final AbstractLinkedList.
the node to remove nodeOverrides org. |
| protected void | unregisterCursor(final CursorableLinkedList.
the cursor to deregister cursorDeregisters a cursor from the list to be notified of changes. |
| protected void | updateNode(final AbstractLinkedList.
node to update node,new value of the node value)Overrides org. |
| private void | writeObject(final ObjectOutputStream
the output stream out)Serializes the data held in this object to the stream specified. |
| cursors | back to summary |
|---|---|
| private transient List<WeakReference<CursorableLinkedList. A list of the cursor currently open on this list | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Ensure serialization compatibility | |
| CursorableLinkedList | back to summary |
|---|---|
| public CursorableLinkedList() Constructor that creates. | |
| CursorableLinkedList | back to summary |
|---|---|
| public CursorableLinkedList(final Collection<? extends E> coll) Constructor that copies the specified collection
| |
| addNode | back to summary |
|---|---|
| protected void addNode(final AbstractLinkedList. Overrides org. Inserts a new node into the list.
| |
| broadcastNodeChanged | back to summary |
|---|---|
| protected void broadcastNodeChanged(final AbstractLinkedList. Informs all of my registered cursors that the specified element was changed.
| |
| broadcastNodeInserted | back to summary |
|---|---|
| protected void broadcastNodeInserted(final AbstractLinkedList. Informs all of my registered cursors that the specified element was just added to my list.
| |
| broadcastNodeRemoved | back to summary |
|---|---|
| protected void broadcastNodeRemoved(final AbstractLinkedList. Informs all of my registered cursors that the specified element was just removed from my list.
| |
| createSubListListIterator | back to summary |
|---|---|
| protected ListIterator Overrides org. Creates a list iterator for the sublist.
| |
| cursor | back to summary |
|---|---|
| public CursorableLinkedList. Returns a
A 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
The
| |
| cursor | back to summary |
|---|---|
| public CursorableLinkedList. Returns a
A 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
The
| |
| init | back to summary |
|---|---|
| protected void init() Overrides org. The equivalent of a default constructor called
by any constructor and by
| |
| iterator | back to summary |
|---|---|
| public Iterator Overrides org. Implements java. 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 | back to summary |
|---|---|
| public ListIterator Overrides org. Implements java. 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 | back to summary |
|---|---|
| public ListIterator Overrides org. Implements java. 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
| |
| readObject | back to summary |
|---|---|
| private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException Deserializes the data held in this object to the stream specified.
| |
| registerCursor | back to summary |
|---|---|
| protected void registerCursor(final CursorableLinkedList. Registers a cursor to be notified of changes to this list.
| |
| removeAllNodes | back to summary |
|---|---|
| protected void removeAllNodes() Overrides org. Removes all nodes by iteration.
| |
| removeNode | back to summary |
|---|---|
| protected void removeNode(final AbstractLinkedList. Overrides org. Removes the specified node from the list.
| |
| unregisterCursor | back to summary |
|---|---|
| protected void unregisterCursor(final CursorableLinkedList. Deregisters a cursor from the list to be notified of changes.
| |
| updateNode | back to summary |
|---|---|
| protected void updateNode(final AbstractLinkedList. Overrides org. Updates the node with a new value. This implementation sets the value on the node. Subclasses can override this to record the change.
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(final ObjectOutputStream out) throws IOException Serializes the data held in this object to the stream specified.
| |
ListIterator that allows concurrent changes to
the underlying list.
| Modifier and Type | Field and Description |
|---|---|
| pack-priv boolean | currentRemovedByAnother
Flag to indicate if the current element was removed by another object. |
| pack-priv boolean | nextIndexValid
Is the next index valid |
| pack-priv boolean | valid
Is the cursor valid (not closed) |
| Access | Constructor and Description |
|---|---|
| protected | Cursor(final CursorableLinkedList<E>
the parent list parent, final int the index to start from index)Constructs a new cursor. |
| Modifier and Type | Method and Description |
|---|---|
| public void | add(final E
the object to add obj)Overrides org. Implements java. |
| protected void | checkModCount()
Overrides org. |
| public void | |
| public int | Returns: the next indexOverrides org. Implements java. |
| protected void | nodeChanged(final AbstractLinkedList.
the node that changed nodeHandle event from the list when a node has changed. |
| protected void | nodeInserted(final AbstractLinkedList.
the node that was added nodeHandle event from the list when a node has been added. |
| protected void | nodeRemoved(final AbstractLinkedList.
the node that was removed nodeHandle event from the list when a node has been removed. |
| public void | remove()
Overrides org. Overrides default java. Implements java. |
| currentRemovedByAnother | back to summary |
|---|---|
| pack-priv boolean currentRemovedByAnother Flag to indicate if the current element was removed by another object. | |
| nextIndexValid | back to summary |
|---|---|
| pack-priv boolean nextIndexValid Is the next index valid | |
| valid | back to summary |
|---|---|
| pack-priv boolean valid Is the cursor valid (not closed) | |
| Cursor | back to summary |
|---|---|
| protected Cursor(final CursorableLinkedList<E> parent, final int index) Constructs a new cursor.
| |
| add | back to summary |
|---|---|
| public void add(final E obj) Overrides org. Implements java. Adds an object to the list. The object added here will be the new 'previous' in the iterator.
| |
| checkModCount | back to summary |
|---|---|
| protected void checkModCount() Overrides org. Override superclass modCount check, and replace it with our valid flag.
| |
| close | back to summary |
|---|---|
| public void close() Mark this cursor as no longer being needed. Any resources associated with this cursor are immediately released. In previous versions of this class, it was mandatory to close all cursor objects to avoid memory leaks. It is no longer necessary to call this close method; an instance of this class can now be treated exactly like a normal iterator. | |
| nextIndex | back to summary |
|---|---|
| public int nextIndex() Overrides org. Implements java. Gets the index of the next element to be returned.
| |
| nodeChanged | back to summary |
|---|---|
| protected void nodeChanged(final AbstractLinkedList. Handle event from the list when a node has changed.
| |
| nodeInserted | back to summary |
|---|---|
| protected void nodeInserted(final AbstractLinkedList. Handle event from the list when a node has been added.
| |
| nodeRemoved | back to summary |
|---|---|
| protected void nodeRemoved(final AbstractLinkedList. Handle event from the list when a node has been removed.
| |
| remove | back to summary |
|---|---|
| public void remove() Overrides org. Overrides default java. Implements java. Removes the item last returned by this iterator. There may have been subsequent alterations to the list since you obtained this item, however you can still remove it. You can even remove it if the item is no longer in the main list. However, you can't call this method on the same iterator more than once without calling next() or previous().
| |
| Modifier and Type | Field and Description |
|---|---|
| protected final AbstractLinkedList. | sub
The parent list |
| Access | Constructor and Description |
|---|---|
| protected | SubCursor(final AbstractLinkedList.
the sub list sub,the index to start from index)Constructs a new cursor. |
| sub | back to summary |
|---|---|
| protected final AbstractLinkedList. The parent list | |
| SubCursor | back to summary |
|---|---|
| protected SubCursor(final AbstractLinkedList. Constructs a new cursor.
| |
| add | back to summary |
|---|---|
| public void add(final E obj) Overrides org. Implements java. Doc from org. Adds an object to the list. The object added here will be the new 'previous' in the iterator.
| |
| hasNext | back to summary |
|---|---|
| public boolean hasNext() Overrides org. Implements java. Doc from java. Returns
| |
| hasPrevious | back to summary |
|---|---|
| public boolean hasPrevious() Overrides org. Implements java. Doc from java. Returns
| |
| nextIndex | back to summary |
|---|---|
| public int nextIndex() Overrides org. Implements java. Doc from org. Gets the index of the next element to be returned.
| |
| remove | back to summary |
|---|---|
| public void remove() Overrides org. Overrides default java. Implements java. Doc from org. Removes the item last returned by this iterator. There may have been subsequent alterations to the list since you obtained this item, however you can still remove it. You can even remove it if the item is no longer in the main list. However, you can't call this method on the same iterator more than once without calling next() or previous().
| |