Package com.github.tommyettinger.ds
Class ObjectDeque.ObjectDequeIterator<T>
java.lang.Object
com.github.tommyettinger.ds.ObjectDeque.ObjectDequeIterator<T>
- Type Parameters:
T- the generic type for the ObjectDeque this iterates over
- All Implemented Interfaces:
Iterable<T>,Iterator<T>,ListIterator<T>
- Enclosing class:
- ObjectDeque<T>
public static class ObjectDeque.ObjectDequeIterator<T>
extends Object
implements Iterable<T>, ListIterator<T>
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal intintintintboolean -
Constructor Summary
ConstructorsConstructorDescriptionObjectDequeIterator(ObjectDeque<T> deque) ObjectDequeIterator(ObjectDeque<T> deque, boolean descendingOrder) ObjectDequeIterator(ObjectDeque<T> deque, int index, boolean descendingOrder) -
Method Summary
Modifier and TypeMethodDescriptionvoidInserts the specified element into the list (optional operation).booleanhasNext()Returnstrueif the iteration has more elements.booleanReturnstrueif this list iterator has more elements when traversing the list in the reverse direction.iterator()Returns an iterator over elements of typeT.final voidmodCheck()Checks if this iterator's expected amount of modifications to the deque matches what the deque reports.next()Returns the nextTelement in the iteration.intReturns the index of the element that would be returned by a subsequent call tonext().previous()Returns the previous element in the list and moves the cursor position backwards.intReturns the index of the element that would be returned by a subsequent call toprevious().voidremove()Removes from the list the last element that was returned bynext()orprevious()(optional operation).voidreset()voidreset(int index) voidReplaces the last element returned bynext()orprevious()with the specified element (optional operation).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface java.util.Iterator
forEachRemaining
-
Field Details
-
index
public int index -
latest
public int latest -
deque
-
valid
public boolean valid -
direction
public final int direction -
expectedModCount
public int expectedModCount
-
-
Constructor Details
-
ObjectDequeIterator
-
ObjectDequeIterator
-
ObjectDequeIterator
-
-
Method Details
-
modCheck
public final void modCheck()Checks if this iterator's expected amount of modifications to the deque matches what the deque reports. This is used to ensure theObjectDeque.iterator()andObjectDeque.listIterator()are both fail-fast iterators.- Throws:
ConcurrentModificationException- if the check fails
-
next
Returns the nextTelement in the iteration.- Specified by:
nextin interfaceIterator<T>- Specified by:
nextin interfaceListIterator<T>- Returns:
- the next
Telement in the iteration - Throws:
NoSuchElementException- if the iteration has no more elements
-
hasNext
public boolean hasNext()Returnstrueif the iteration has more elements. (In other words, returnstrueifnext()would return an element rather than throwing an exception.) -
hasPrevious
public boolean hasPrevious()Returnstrueif this list iterator has more elements when traversing the list in the reverse direction. (In other words, returnstrueifprevious()would return an element rather than throwing an exception.)- Specified by:
hasPreviousin interfaceListIterator<T>- Returns:
trueif the list iterator has more elements when traversing the list in the reverse direction
-
previous
Returns the previous element in the list and moves the cursor position backwards. This method may be called repeatedly to iterate through the list backwards, or intermixed with calls tonext()to go back and forth. (Note that alternating calls tonextandpreviouswill return the same element repeatedly.)- Specified by:
previousin interfaceListIterator<T>- Returns:
- the previous element in the list
- Throws:
NoSuchElementException- if the iteration has no previous element
-
nextIndex
public int nextIndex()Returns the index of the element that would be returned by a subsequent call tonext(). (Returns list size if the list iterator is at the end of the list.)- Specified by:
nextIndexin interfaceListIterator<T>- Returns:
- the index of the element that would be returned by a
subsequent call to
next, or list size if the list iterator is at the end of the list
-
previousIndex
public int previousIndex()Returns the index of the element that would be returned by a subsequent call toprevious(). (Returns -1 if the list iterator is at the beginning of the list.)- Specified by:
previousIndexin interfaceListIterator<T>- Returns:
- the index of the element that would be returned by a
subsequent call to
previous, or -1 if the list iterator is at the beginning of the list
-
remove
public void remove()Removes from the list the last element that was returned bynext()orprevious()(optional operation). This call can only be made once per call tonextorprevious. It can be made only ifadd(T)has not been called after the last call tonextorprevious.- Specified by:
removein interfaceIterator<T>- Specified by:
removein interfaceListIterator<T>- Throws:
UnsupportedOperationException- if theremoveoperation is not supported by this list iteratorIllegalStateException- if neithernextnorprevioushave been called, orremoveoraddhave been called after the last call tonextorprevious
-
set
Replaces the last element returned bynext()orprevious()with the specified element (optional operation). This call can be made only if neitherremove()noradd(T)have been called after the last call tonextorprevious.- Specified by:
setin interfaceListIterator<T>- Parameters:
t- the element with which to replace the last element returned bynextorprevious- Throws:
UnsupportedOperationException- if thesetoperation is not supported by this list iteratorClassCastException- if the class of the specified element prevents it from being added to this listIllegalArgumentException- if some aspect of the specified element prevents it from being added to this listIllegalStateException- if neithernextnorprevioushave been called, orremoveoraddhave been called after the last call tonextorprevious
-
add
Inserts the specified element into the list (optional operation). The element is inserted immediately before the element that would be returned bynext(), if any, and after the element that would be returned byprevious(), if any. (If the list contains no elements, the new element becomes the sole element on the list.) The new element is inserted before the implicit cursor: a subsequent call tonextwould be unaffected, and a subsequent call topreviouswould return the new element. (This call increases by one the value that would be returned by a call tonextIndexorpreviousIndex.)- Specified by:
addin interfaceListIterator<T>- Parameters:
t- the element to insert- Throws:
UnsupportedOperationException- if theaddmethod is not supported by this list iteratorClassCastException- if the class of the specified element prevents it from being added to this listIllegalArgumentException- if some aspect of this element prevents it from being added to this list
-
reset
public void reset() -
reset
public void reset(int index) -
iterator
Returns an iterator over elements of typeT.
-