|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.util.AbstractIterator<E>
public abstract class AbstractIterator<E>
makes it very easy to implement both, Enumeration and Iterator.
The only abstract method is getNextObject().
This method is to supply the next object until it throws an exception,
which marks that the last object was reached.
By default, returning null also marks the end of the iteration;
in consequence, the next() never returns null in this case.
You can change this behavior to allow an enumeration to return null as a
valid element by calling setAllowNull(true).
In addition, this class supplies convenient static methods to convert
an Enumeration to an Iterator and vice versa.
| Constructor Summary | |
|---|---|
protected |
AbstractIterator()
|
protected |
AbstractIterator(boolean allowNull)
|
| Method Summary | ||
|---|---|---|
boolean |
allowsNull()
if false (the default), next() never returns null
(as null marks the end of the iteration). |
|
E |
currentElement()
allows to access the current element over and over again without advancing the cursor. |
|
static
|
enumerate(Iterator<F> i)
converts an Iterator into an Enumeration |
|
List<E> |
getAll()
|
|
long |
getCount()
returns the number of elements that have been returned through next so far |
|
Exception |
getEndCondition()
indicates the cause for this iterator to end |
|
Filter<E> |
getFilter()
|
|
protected abstract E |
getNextElement()
if no more Element is available, this method is to return null or throw any Exception. |
|
boolean |
hasMoreElements()
|
|
boolean |
hasNext()
|
|
static
|
iterate(Enumeration<F> e)
converts an Enumeration into an Iterator |
|
static
|
list(Enumeration<F> e)
|
|
static
|
list(Iterator<F> i)
|
|
E |
next()
|
|
E |
nextElement()
|
|
boolean |
propagatesException()
if true, an exception thrown by getNextElement() will be thrown as an IterationException back to the caller of any method of the Iterator or Enumeration interface. |
|
void |
remove()
throws UnsupportedOperationException (unless overridden, of course) |
|
static
|
reverseEnumeration(Enumeration<F> e)
reverses the given Enumeration |
|
void |
setAllowNull(boolean flag)
allows to set wether null is an allowed value for next()
or if marks the end of an iteration. |
|
void |
setFilter(Filter<E> filter)
if a non-null filter is set, only those elements that pass the filter will be returned by next(). |
|
void |
setPropagateException(boolean flag)
allows to have Exceptions thrown during getNextElement() propagated as IterationExceptions back to the caller |
|
static
|
sortEnumeration(Enumeration<F> e)
sorts the given Enumeration by the natural order of its elements |
|
static
|
sortEnumeration(Enumeration<F> e,
Comparator<F> c)
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 |
|---|
protected AbstractIterator()
protected AbstractIterator(boolean allowNull)
setAllowNull(boolean)| Method Detail |
|---|
public void setFilter(Filter<E> filter)
next().
public Filter<E> getFilter()
public boolean allowsNull()
next() never returns null
(as null marks the end of the iteration).
setAllowNull(boolean)public void setAllowNull(boolean flag)
next()
or if marks the end of an iteration.
If set to true, the iteration only ends if getNextObject()
throws an exception.
public boolean propagatesException()
IterationExceptionpublic void setPropagateException(boolean flag)
IterationException
protected abstract E getNextElement()
throws Exception
next().
Exceptionpublic E next()
next in interface Iterator<E>public long getCount()
public E currentElement()
throws IllegalStateException
IllegalStateException - if this method is called before next()
has been called the first time, it returns null.public E nextElement()
nextElement in interface Enumeration<E>public boolean hasMoreElements()
hasMoreElements in interface Enumeration<E>public boolean hasNext()
hasNext in interface Iterator<E>public List<E> getAll()
public Exception getEndCondition()
throws IllegalStateException
IllegalStateException - if hasNext() is truepublic void remove()
remove in interface Iterator<E>public static <F> Iterator<F> iterate(Enumeration<F> e)
public static <F> Enumeration<F> enumerate(Iterator<F> i)
public static <F extends Comparable<? super F>> Enumeration<F> sortEnumeration(Enumeration<F> e)
public static <F> Enumeration<F> sortEnumeration(Enumeration<F> e,
Comparator<F> c)
public static <F> Enumeration<F> reverseEnumeration(Enumeration<F> e)
public static <F> ArrayList<F> list(Iterator<F> i)
public static <F> ArrayList<F> list(Enumeration<F> e)
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||