Class Seq.SeqIterator
java.lang.Object
Seq.SeqIterator
- All Implemented Interfaces:
- java.util.Iterator
- Enclosing class:
- Seq<T>
public class Seq.SeqIterator
- extends java.lang.Object
- implements java.util.Iterator
An iterator class capable of mutating the sequence.
See the
state of the Seq class.
Method Summary |
int |
count()
Counts the elements already returned by next(). |
boolean |
hasNext()
For use with next(). |
T |
next()
Returns the next element in the iteration. |
Seq<T> |
peek()
Shows the sequence yet to be iterated over. |
void |
remove()
not implemented |
void |
replaceRecent(T first)
Alters the element of the sequence that was most recently
returned by next() |
void |
splice(Seq<T> addMe)
Splices a sequence into the new sequence--between the
subsequences that would be separated with split(). |
Seq.SeqIterator |
split()
Splits off the part of the sequence that peek() shows. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
next
public T next()
- Returns the next element in the iteration.
Calling this method repeatedly until the hasNext() method
returns false will return each element in the sequence
exactly once. Does not change the sequence.
- Specified by:
next
in interface java.util.Iterator
- Returns:
- the next element in the sequence
hasNext
public boolean hasNext()
- For use with next().
Does not change the underlying sequence.
- Specified by:
hasNext
in interface java.util.Iterator
- Returns:
- a boolean, true iff next() will provide another
element
remove
public void remove()
- not implemented
- Specified by:
remove
in interface java.util.Iterator
count
public int count()
- Counts the elements already returned by next().
- Returns:
- a count of the elements already returned by next()
replaceRecent
public void replaceRecent(T first)
- Alters the element of the sequence that was most recently
returned by next()
- Parameters:
first
- the value to replace the count() position in the
sequence
peek
public Seq<T> peek()
- Shows the sequence yet to be iterated over. The returned
sequence is not a copy and includes only elements as yet
unseen of the sequence the iterator is passing over.
- Returns:
- returns a sequence, namely that sequence yet
to be iterated over.
split
public Seq.SeqIterator split()
- Splits off the part of the sequence that peek() shows.
The original sequence will end with the most recent element
to be returned by next. The current iterator becomes a
newly created iterator for the sequence that is split off
which is to say the sequence which peek() would show.
When the cursor is iterating over an empty sequence, the
split method has no effect.
- Returns:
- A new iterator that has passed over the shortened
original sequence. (Valuable for splicing other sequences
to the end of that sequence.)
splice
public void splice(Seq<T> addMe)
- Splices a sequence into the new sequence--between the
subsequences that would be separated with split().
The original sequence is increased in length by the length
of the sequence being spliced in. Splicing occurs just
before the element, if any, that next() would return next.
That element will still be returned by next() after the
splicing.
The sequence to be spliced in is also changed because the
sequence you would get with peek() is added to the end of
it.
The splice method still works if either of the two sequences
involved is empty.
- Parameters:
addMe
- the sequence to be splice in Gotcha:
When you splice to the front of a sequence, you must then use
addMe to represent the whole sequence.