/** * Gets a list iterator over an object array. * * @param <E> the element type * @param array the array over which to iterate * @return a list iterator over the array * @throws NullPointerException if array is null */ public static <E> ResettableListIterator<E> arrayListIterator(final E... array) { return new ObjectArrayListIterator<>(array); }
/** * Gets the index of the item to be retrieved if {@link #previous()} is called. * * @return the index of the item to be retrieved next */ @Override public int previousIndex() { return this.index - getStartIndex() - 1; }
/** * Gets the next element from the array. * * @return the next element * @throws NoSuchElementException if there is no next element */ @Override public E next() { if (hasNext() == false) { throw new NoSuchElementException(); } this.lastItemIndex = this.index; return this.array[this.index++]; }
/** * Gets the previous element from the array. * * @return the previous element * @throws NoSuchElementException if there is no previous element */ @Override public E previous() { if (hasPrevious() == false) { throw new NoSuchElementException(); } this.lastItemIndex = --this.index; return this.array[this.index]; }
/** * Returns true if there are previous elements to return from the array. * * @return true if there is a previous element to return */ @Override public boolean hasPrevious() { return this.index > getStartIndex(); }
/** * Gets a list iterator over the end part of an object array. * * @param <E> the element type * @param array the array over which to iterate * @param start the index to start iterating at * @return a list iterator over part of the array * @throws IndexOutOfBoundsException if start is less than zero * @throws NullPointerException if array is null */ public static <E> ResettableListIterator<E> arrayListIterator(final E[] array, final int start) { return new ObjectArrayListIterator<>(array, start); }
/** * Gets the next index to be retrieved. * * @return the index of the item to be retrieved next */ @Override public int nextIndex() { return this.index - getStartIndex(); }
/** * Gets a list iterator over part of an object array. * * @param <E> the element type * @param array the array over which to iterate * @param start the index to start iterating at * @param end the index to finish iterating at * @return a list iterator over part of the array * @throws IndexOutOfBoundsException if array bounds are invalid * @throws IllegalArgumentException if end is before start * @throws NullPointerException if array is null */ public static <E> ResettableListIterator<E> arrayListIterator(final E[] array, final int start, final int end) { return new ObjectArrayListIterator<>(array, start, end); }