org.scijava.util
Class IteratorPlus<E>
java.lang.Object
org.scijava.util.IteratorPlus<E>
- All Implemented Interfaces:
- Iterable<E>, Enumeration<E>, Iterator<E>
public class IteratorPlus<E>
- extends Object
- implements Enumeration<E>, Iterator<E>, Iterable<E>
A class that provides more thorough support for iteration. Any
Enumeration
, Iterator
or Iterable
object can be
provided to the constructor, and the resultant IteratorPlus
will
provide all three access mechanisms. In the case of iterator()
it
simply returns this
, for more convenient usage with for-each loops. Note, however, that because of this fact, multiple calls
to {#iterator()} will produce the same Iterator
every time (in fact,
the IteratorPlus
object itself).
For example, let's say you have an Enumeration<String>
and you want
to loop over it with the for-each syntax. You could write:
final Enumeration<String> en = ...;
for (final String s : new IteratorPlus(en))
// do something with the string
The same technique works with Iterator
.
- Author:
- Curtis Rueden
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
IteratorPlus
public IteratorPlus(Iterable<E> iterable)
IteratorPlus
public IteratorPlus(Enumeration<E> enumeration)
IteratorPlus
public IteratorPlus(Iterator<E> iterator)
hasMoreElements
public boolean hasMoreElements()
- Specified by:
hasMoreElements
in interface Enumeration<E>
nextElement
public E nextElement()
- Specified by:
nextElement
in interface Enumeration<E>
hasNext
public boolean hasNext()
- Specified by:
hasNext
in interface Iterator<E>
next
public E next()
- Specified by:
next
in interface Iterator<E>
remove
public void remove()
- Specified by:
remove
in interface Iterator<E>
iterator
public Iterator<E> iterator()
- Specified by:
iterator
in interface Iterable<E>
Copyright © 2009–2014 SciJava. All rights reserved.