structure5
Class AbstractIterator<E>

java.lang.Object
  extended by structure5.AbstractIterator<E>
All Implemented Interfaces:
Iterable<E>, Enumeration<E>, Iterator<E>
Direct Known Subclasses:
AbstractListIterator, ArrayIterator, DoublyLinkedListIterator

public abstract class AbstractIterator<E>
extends Object
implements Enumeration<E>, Iterator<E>, Iterable<E>

Abstract base class for portable iterator and enumeration implementation.

A general purpose iterator that implements both java.util.Iterator and java.util.Enumeration. This class also implements the value() method, providing multiple accesses, and the reset() method, which allows the user to restart the traversal.

Typical usage:

     Vector v = new Vector;
     String s = "target";
     ...
     Iterator t = v.iterator()();
     // print members of vector that are greater than s
     for (t.reset(); t.hasNext(); t.next())
     {
         if (s.compareTo(t.value()) < 0)
               System.out.println(t.value());
     }
 

Users of Java's Enumeration or Iterator may treat the AbstractIterator as an Enumeration or Iterator, respectively, without ill effect.

Appropriate care should be taken to make sure that the underlying data structure is not modified while the traversal is active. Some extensions of this class may choose to provide methods that modify the structure --- the remove method of iterator is one such possibility. Care should be taken to make sure that such modifications are carefully synchronized, or limited to one active traversal.

See Also:
Iterator, Enumeration

Constructor Summary
AbstractIterator()
          Default constructor (for base class invocation).
 
Method Summary
abstract  E get()
          Returns the value currently being considered by the AbstractIterator.
 boolean hasMoreElements()
          An Enumeration method that is equivalent to hasNext().
abstract  boolean hasNext()
          Returns true if the iterator has more elements to visit.
 Iterator<E> iterator()
          Support for for-iteration.
abstract  E next()
          Moves, bumps, or "increments" the iterator along the traversal; returns the next value considered.
 E nextElement()
          An Enumeration method that is equivalent to next().
 void remove()
          If implemented, removes the currently visited value from the structure.
abstract  void reset()
          Reset iterator to the beginning of the structure.
 E value()
          Deprecated. This method was deprecated in version 2 of the structure package. Use the get method.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractIterator

public AbstractIterator()
Default constructor (for base class invocation). Does nothing. Remind Sun (jdk-comments@java.sun.com) that automatically implemented default constructors are a silly thing.

Method Detail

reset

public abstract void reset()
Reset iterator to the beginning of the structure. This method is not required of Iterator or Enumeration implementation, but some traversals may allow efficient multi-pass implementations with little overhead. The user is encouraged to implement this method.


hasNext

public abstract boolean hasNext()
Returns true if the iterator has more elements to visit. The method hasMoreElements is an Enumeration-required call to this method. The user should override only this method.

Specified by:
hasNext in interface Iterator<E>
Returns:
true iff the iterator has more elements to visit
See Also:
hasMoreElements()

get

public abstract E get()
Returns the value currently being considered by the AbstractIterator. This method is required by neither Iterator nor Enumeration. This method should be implemented, however, to provide better support for for-loops.

Returns:
the next value to be considered in iterator

value

@Deprecated
public final E value()
Deprecated. This method was deprecated in version 2 of the structure package. Use the get method.

Returns the value currently being considered by the AbstractIterator. This method is required by neither Iterator nor Enumeration. This method should be implemented, however, to provide better support for for-loops.

Returns:
the next value to be considered in iterator

next

public abstract E next()
Moves, bumps, or "increments" the iterator along the traversal; returns the next value considered. This method should only be called if the iterator has a next value. To get a value from an iterator multiple times, use the value method.

This method is preferred over the nextElement method.

Specified by:
next in interface Iterator<E>
Returns:
the current value
See Also:
hasMoreElements(), value()

remove

public void remove()
If implemented, removes the currently visited value from the structure. remove should not be called unless it is overridden.

Specified by:
remove in interface Iterator<E>

hasMoreElements

public final boolean hasMoreElements()
An Enumeration method that is equivalent to hasNext(). Extensions to this class should provide a hasNext method.

Specified by:
hasMoreElements in interface Enumeration<E>
Returns:
returns true iff there are more elements

nextElement

public final E nextElement()
An Enumeration method that is equivalent to next(). Extensions to this class should provide a next method.

Specified by:
nextElement in interface Enumeration<E>
Returns:
the current value before iterator is incremented

iterator

public final Iterator<E> iterator()
Support for for-iteration.

Specified by:
iterator in interface Iterable<E>
Returns:
this iterator