/** * Returns a cursor iterator that allows changes to the underlying list in parallel. * <p> * 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. * <p> * 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 such that it cannot be removed). * * @return a new cursor iterator */ @Override public ListIterator<E> listIterator() { return cursor(0); }
/** * Deserializes the data held in this object to the stream specified. * * @param in the input stream * @throws IOException if an error occurs while reading from the stream * @throws ClassNotFoundException if an object read from the stream can not be loaded */ private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); doReadObject(in); }
/** * Serializes the data held in this object to the stream specified. * * @param out the output stream * @throws IOException if an error occurs while writing to the stream */ private void writeObject(final ObjectOutputStream out) throws IOException { out.defaultWriteObject(); doWriteObject(out); }
/** * Creates a list iterator for the sublist. * * @param subList the sublist to get an iterator for * @param fromIndex the index to start from, relative to the sublist * @return the list iterator for the sublist */ @Override protected ListIterator<E> createSubListListIterator(final LinkedSubList<E> subList, final int fromIndex) { final SubCursor<E> cursor = new SubCursor<>(subList, fromIndex); registerCursor(cursor); return cursor; }
/** * Constructor that creates. */ public CursorableLinkedList() { super(); init(); // must call init() as use super(); }
/** * Removes the specified node from the list. * * @param node the node to remove * @throws NullPointerException if <code>node</code> is null */ @Override protected void removeNode(final Node<E> node) { super.removeNode(node); broadcastNodeRemoved(node); }
/** * Inserts a new node into the list. * * @param nodeToInsert new node to insert * @param insertBeforeNode node to insert before * @throws NullPointerException if either node is null */ @Override protected void addNode(final Node<E> nodeToInsert, final Node<E> insertBeforeNode) { super.addNode(nodeToInsert, insertBeforeNode); broadcastNodeInserted(nodeToInsert); }
/** * Updates the node with a new value. * This implementation sets the value on the node. * Subclasses can override this to record the change. * * @param node node to update * @param value new value of the node */ @Override protected void updateNode(final Node<E> node, final E value) { super.updateNode(node, value); broadcastNodeChanged(node); }
registerCursor(cursor); return cursor;
/** * Returns a cursor iterator that allows changes to the underlying list in parallel. * <p> * 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. * <p> * 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 such that it cannot be removed). * * @param fromIndex the index to start from * @return a new cursor iterator */ @Override public ListIterator<E> listIterator(final int fromIndex) { return cursor(fromIndex); }
/** * Returns a {@link Cursor} for iterating through the elements of this list. * <p> * A <code>Cursor</code> is a <code>ListIterator</code> with an additional * <code>close()</code> 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 a <code>WeakReference</code>. * <p> * 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. * <p> * 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 such that it cannot be removed). * <p> * The {@link #listIterator()} method returns the same as this method, and can * be cast to a <code>Cursor</code> if the <code>close</code> method is required. * * @return a new cursor iterator */ public CursorableLinkedList.Cursor<E> cursor() { return cursor(0); }