/** * Informs all of my registered cursors that the specified * element was changed. * * @param node the node that was changed */ protected void broadcastNodeChanged(final Node<E> node) { final Iterator<WeakReference<Cursor<E>>> it = cursors.iterator(); while (it.hasNext()) { final WeakReference<Cursor<E>> ref = it.next(); final Cursor<E> cursor = ref.get(); if (cursor == null) { it.remove(); // clean up list } else { cursor.nodeChanged(node); } } }
/** * Informs all of my registered cursors that the specified * element was just added to my list. * * @param node the node that was changed */ protected void broadcastNodeInserted(final Node<E> node) { final Iterator<WeakReference<Cursor<E>>> it = cursors.iterator(); while (it.hasNext()) { final WeakReference<Cursor<E>> ref = it.next(); final Cursor<E> cursor = ref.get(); if (cursor == null) { it.remove(); // clean up list } else { cursor.nodeInserted(node); } } }
/** * Informs all of my registered cursors that the specified * element was just removed from my list. * * @param node the node that was changed */ protected void broadcastNodeRemoved(final Node<E> node) { final Iterator<WeakReference<Cursor<E>>> it = cursors.iterator(); while (it.hasNext()) { final WeakReference<Cursor<E>> ref = it.next(); final Cursor<E> cursor = ref.get(); if (cursor == null) { it.remove(); // clean up list } else { cursor.nodeRemoved(node); } } }
final Cursor<E> cursor = new Cursor<>(this, fromIndex); registerCursor(cursor); return cursor;
/** * Removes the item last returned by this iterator. * <p> * 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(). * * @throws IllegalStateException if there is no item to remove */ @Override public void remove() { // overridden, as the nodeRemoved() method updates the iterator // state in the parent.removeNode() call below if (current == null && currentRemovedByAnother) { // NOPMD // quietly ignore, as the last returned node was removed // by the list or some other iterator // by ignoring it, we keep this iterator independent from // other changes as much as possible } else { checkModCount(); parent.removeNode(getLastNodeReturned()); } currentRemovedByAnother = false; }
@Override public int nextIndex() { return super.nextIndex() - sub.offset; }
@Override public void add(final E obj) { super.add(obj); sub.expectedModCount = parent.modCount; sub.size++; }
@Override public void remove() { super.remove(); sub.expectedModCount = parent.modCount; sub.size--; } }