org.jscience.util
Class AbstractIterator<E>

java.lang.Object
  extended by org.jscience.util.AbstractIterator<E>
Type Parameters:
E - DOCUMENT ME!
All Implemented Interfaces:
java.util.Enumeration<E>, java.util.Iterator<E>
Direct Known Subclasses:
ObjectEnumerator, ServerLogFile.ServerLogEntryEnumerator

public abstract class AbstractIterator<E>
extends java.lang.Object
implements java.util.Enumeration<E>, java.util.Iterator<E>

makes it very easy to implement either an Enumeration or an Iterator. The only abstract method is getNextObject(). This method is to supply the next object until it either returns null or throws an exception, which marks that the last object was reached. In addition this class supplies convenient static methods to convert an Enumeration to an Iterator and vice versa.

Since:
04/16/2004

Constructor Summary
AbstractIterator()
           
 
Method Summary
static
<F> java.util.Enumeration<F>
enumerate(java.util.Iterator<F> i)
          converts an Iterator into an Enumeration
protected abstract  E getNextObject()
          if no more Element is available, this method is to return null or throw any Exception
 boolean hasMoreElements()
          DOCUMENT ME!
 boolean hasNext()
          DOCUMENT ME!
static
<F> java.util.Iterator<F>
iterate(java.util.Enumeration<F> e)
          converts an Enumeration into an Iterator
static
<F> java.util.List<F>
list(java.util.Enumeration<F> e)
          DOCUMENT ME!
static
<F> java.util.List<F>
list(java.util.Iterator<F> i)
          DOCUMENT ME!
 E next()
          DOCUMENT ME!
 E nextElement()
          DOCUMENT ME!
 void remove()
          throws UnsupportedOperationException
static
<F> java.util.Enumeration<F>
reverseEnumeration(java.util.Enumeration<F> e)
          reverses the given Enumeration
static
<F extends java.lang.Comparable<? super F>>
java.util.Enumeration<F>
sortEnumeration(java.util.Enumeration<F> e)
          sorts the given Enumeration by the natural order of its elements
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractIterator

public AbstractIterator()
Method Detail

getNextObject

protected abstract E getNextObject()
                            throws java.lang.Exception
if no more Element is available, this method is to return null or throw any Exception

Returns:
DOCUMENT ME!
Throws:
java.lang.Exception - DOCUMENT ME!

next

public E next()
DOCUMENT ME!

Specified by:
next in interface java.util.Iterator<E>
Returns:
DOCUMENT ME!

nextElement

public E nextElement()
DOCUMENT ME!

Specified by:
nextElement in interface java.util.Enumeration<E>
Returns:
DOCUMENT ME!

hasMoreElements

public boolean hasMoreElements()
DOCUMENT ME!

Specified by:
hasMoreElements in interface java.util.Enumeration<E>
Returns:
DOCUMENT ME!

hasNext

public boolean hasNext()
DOCUMENT ME!

Specified by:
hasNext in interface java.util.Iterator<E>
Returns:
DOCUMENT ME!

remove

public void remove()
throws UnsupportedOperationException

Specified by:
remove in interface java.util.Iterator<E>
Throws:
java.lang.UnsupportedOperationException - DOCUMENT ME!

iterate

public static <F> java.util.Iterator<F> iterate(java.util.Enumeration<F> e)
converts an Enumeration into an Iterator

Type Parameters:
F - DOCUMENT ME!
Parameters:
e - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.UnsupportedOperationException - DOCUMENT ME!

enumerate

public static <F> java.util.Enumeration<F> enumerate(java.util.Iterator<F> i)
converts an Iterator into an Enumeration

Type Parameters:
F - DOCUMENT ME!
Parameters:
i - DOCUMENT ME!
Returns:
DOCUMENT ME!

sortEnumeration

public static <F extends java.lang.Comparable<? super F>> java.util.Enumeration<F> sortEnumeration(java.util.Enumeration<F> e)
sorts the given Enumeration by the natural order of its elements

Type Parameters:
F - DOCUMENT ME!
Parameters:
e - DOCUMENT ME!
Returns:
DOCUMENT ME!

reverseEnumeration

public static <F> java.util.Enumeration<F> reverseEnumeration(java.util.Enumeration<F> e)
reverses the given Enumeration

Type Parameters:
F - DOCUMENT ME!
Parameters:
e - DOCUMENT ME!
Returns:
DOCUMENT ME!

list

public static <F> java.util.List<F> list(java.util.Iterator<F> i)
DOCUMENT ME!

Type Parameters:
F - DOCUMENT ME!
Parameters:
i - DOCUMENT ME!
Returns:
DOCUMENT ME!

list

public static <F> java.util.List<F> list(java.util.Enumeration<F> e)
DOCUMENT ME!

Type Parameters:
F - DOCUMENT ME!
Parameters:
e - DOCUMENT ME!
Returns:
DOCUMENT ME!