Package com.github.tommyettinger.ds
Class CharDeque.CharDequeIterator
java.lang.Object
com.github.tommyettinger.ds.CharList.CharListIterator
com.github.tommyettinger.ds.CharDeque.CharDequeIterator
- All Implemented Interfaces:
CharIterator,Iterator<Character>
- Enclosing class:
- CharDeque
public static class CharDeque.CharDequeIterator
extends CharList.CharListIterator
implements CharIterator
A
CharIterator over the elements of a CharDeque.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final intprotected intprotected intprotected booleanFields inherited from class com.github.tommyettinger.ds.CharList.CharListIterator
list -
Constructor Summary
ConstructorsConstructorDescriptionCharDequeIterator(CharDeque deque) CharDequeIterator(CharDeque deque, boolean descendingOrder) CharDequeIterator(CharDeque deque, int index, boolean descendingOrder) -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(char t) Inserts 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 typechar.charnextChar()Returns the nextcharelement in the iteration.intReturns the index of the element that would be returned by a subsequent call toCharIterator.next().charprevious()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 byCharIterator.next()orprevious()(optional operation).voidreset()voidreset(int index) voidset(char t) Replaces the last element returned byCharIterator.next()orprevious()with the specified element (optional operation).Methods inherited from class com.github.tommyettinger.ds.CharList.CharListIterator
previousCharMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.github.tommyettinger.ds.support.util.CharIterator
forEachRemaining, nextMethods inherited from interface java.util.Iterator
forEachRemaining
-
Field Details
-
index
protected int index -
latest
protected int latest -
valid
protected boolean valid -
direction
protected final int direction
-
-
Constructor Details
-
CharDequeIterator
-
CharDequeIterator
-
CharDequeIterator
-
-
Method Details
-
nextChar
public char nextChar()Returns the nextcharelement in the iteration.- Specified by:
nextCharin interfaceCharIterator- Overrides:
nextCharin classCharList.CharListIterator- Returns:
- the next
charelement 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, returnstrueifCharIterator.next()would return an element rather than throwing an exception.)- Specified by:
hasNextin interfaceIterator<Character>- Overrides:
hasNextin classCharList.CharListIterator- Returns:
trueif the iteration has more elements
-
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.)- Overrides:
hasPreviousin classCharList.CharListIterator- Returns:
trueif the list iterator has more elements when traversing the list in the reverse direction
-
previous
public char 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 toCharIterator.next()to go back and forth. (Note that alternating calls tonextandpreviouswill return the same element repeatedly.)- 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 toCharIterator.next(). (Returns list size if the list iterator is at the end of the list.)- Overrides:
nextIndexin classCharList.CharListIterator- 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.)- Overrides:
previousIndexin classCharList.CharListIterator- 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 byCharIterator.next()orprevious()(optional operation). This call can only be made once per call tonextorprevious. It can be made only ifadd(char)has not been called after the last call tonextorprevious.- Specified by:
removein interfaceIterator<Character>- Overrides:
removein classCharList.CharListIterator- Throws:
UnsupportedOperationException- if theremoveoperation is not supported by this list iteratorIllegalStateException- if neithernextnorprevioushave been called, orremoveoraddhave been called after the last call tonextorprevious
-
set
public void set(char t) Replaces the last element returned byCharIterator.next()orprevious()with the specified element (optional operation). This call can be made only if neitherremove()noradd(char)have been called after the last call tonextorprevious.- Overrides:
setin classCharList.CharListIterator- 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
public void add(char t) Inserts the specified element into the list (optional operation). The element is inserted immediately before the element that would be returned byCharIterator.next(), 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.)- Overrides:
addin classCharList.CharListIterator- 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()- Overrides:
resetin classCharList.CharListIterator
-
reset
public void reset(int index) - Overrides:
resetin classCharList.CharListIterator
-
iterator
Returns an iterator over elements of typechar.- Overrides:
iteratorin classCharList.CharListIterator- Returns:
- a CharIterator; really this same CharDequeIterator.
-