Package craterdog.core
Class Iterator<E>
java.lang.Object
craterdog.core.Iterator<E>
- Type Parameters:
E
- The type of the element being iterated over.
- All Implemented Interfaces:
Iterator<E>
- Direct Known Subclasses:
Manipulator
This abstract class defines a framework for each concrete iterator class
that allows iteration over a sequence's elements. The iterator
points at the slots on either side of the elements in the sequence:
[element 1] [element 2] [element 3] ... [element N] ^ ^ ^ ^ ^ ^ at start at end
- Author:
- Derk Norton
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract E
getNext()
This method returns the element after the slot where the iterator is currently pointing.abstract E
This method returns the element before the slot where the iterator is currently pointing.abstract boolean
hasNext()
This method determines if the iterator is currently pointing at a slot just before an element in this sequence.abstract boolean
This method determines if the iterator is currently pointing at a slot just after an element in this sequence.final E
next()
void
remove()
abstract void
toEnd()
This method moves the iterator to the slot just past the last element in this sequence.abstract void
toIndex
(int index) This method moves the iterator to the slot just before the specified index.abstract void
toStart()
This method moves the iterator to just before the first element in this sequence.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
Iterator
public Iterator()
-
-
Method Details
-
toStart
public abstract void toStart()This method moves the iterator to just before the first element in this sequence. The next element to be returned will the first element in this sequence. -
toIndex
public abstract void toIndex(int index) This method moves the iterator to the slot just before the specified index. The next element to be returned will then be the element with that index. The valid values for the index are in the range [1..size] where size is the number of elements in the sequence. Notice that this interface uses ordinal based indexing instead of zero-based indexing (come on, its time to get out of the 1970s!).- Parameters:
index
- The index of the element to be returned next by the iterator.
-
toEnd
public abstract void toEnd()This method moves the iterator to the slot just past the last element in this sequence. There is no next element that can be returned from this position. -
hasPrevious
public abstract boolean hasPrevious()This method determines if the iterator is currently pointing at a slot just after an element in this sequence. If the iterator is at the start of the sequence this method will returnfalse
.- Returns:
- Whether or not there is an element just before the current position of the iterator.
-
getPrevious
This method returns the element before the slot where the iterator is currently pointing. If the iterator is at the start of this sequence an exception is thrown.- Returns:
- The previous element in this sequence.
-
hasNext
public abstract boolean hasNext()This method determines if the iterator is currently pointing at a slot just before an element in this sequence. If the iterator is at the end of the sequence this method will returnfalse
. -
getNext
This method returns the element after the slot where the iterator is currently pointing. If the iterator is at the end of this sequence an exception is thrown.- Returns:
- The next element in this sequence.
-
next
-
remove
public void remove()
-