@Override public E next() { checkModCount(); if (!hasNext()) { throw new NoSuchElementException("No element at index " + nextIndex + "."); } if (next == null) { next = parent.root.get(nextIndex); } final E value = next.getValue(); current = next; currentIndex = nextIndex++; next = next.next(); return value; }
@Override public E previous() { checkModCount(); if (!hasPrevious()) { throw new NoSuchElementException("Already at start of list."); } if (next == null) { next = parent.root.get(nextIndex - 1); } else { next = next.previous(); } final E value = next.getValue(); current = next; currentIndex = --nextIndex; return value; }
/** * Sets the element at the specified index. * * @param index the index to set * @param obj the object to store at the specified index * @return the previous object at that index * @throws IndexOutOfBoundsException if the index is invalid */ @Override public E set(final int index, final E obj) { checkInterval(index, 0, size() - 1); final AVLNode<E> node = root.get(index); final E result = node.value; node.setValue(obj); return result; }
/** * Locate the element with the given index relative to the * offset of the parent of this node. */ AVLNode<E> get(final int index) { final int indexRelativeToMe = index - relativePosition; if (indexRelativeToMe == 0) { return this; } final AVLNode<E> nextNode = indexRelativeToMe < 0 ? getLeftSubTree() : getRightSubTree(); if (nextNode == null) { return null; } return nextNode.get(indexRelativeToMe); }
/** * Create a ListIterator for a list. * * @param parent the parent list * @param fromIndex the index to start at */ protected TreeListIterator(final TreeList<E> parent, final int fromIndex) throws IndexOutOfBoundsException { super(); this.parent = parent; this.expectedModCount = parent.modCount; this.next = parent.root == null ? null : parent.root.get(fromIndex); this.nextIndex = fromIndex; this.currentIndex = -1; }
/** * Gets the element at the specified index. * * @param index the index to retrieve * @return the element at the specified index */ @Override public E get(final int index) { checkInterval(index, 0, size() - 1); return root.get(index).getValue(); }