Class ProgressIterator<E>
java.lang.Object
uk.ac.manchester.spinnaker.utils.progress.ProgressIterator<E>
- Type Parameters:
E- Type of Element to be iterated over.
- All Implemented Interfaces:
Closeable,AutoCloseable,Iterator<E>
An
Iterator wrapper with and an attached ProgressBar. Mainly
designed as a support class for ProgressIterable.
As items are obtained by calling next() the ProgressBar is updated.
When hasNext() returns false the ProgressBar is closed resulting in
the duration to be written out.
- Author:
- Christian-B
-
Constructor Summary
ConstructorsConstructorDescriptionProgressIterator(Collection<E> outer, String description, PrintStream output) Creates a newProgressIterableand a bar on the output stream. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the underlyingProgressBar.booleanhasNext()Returns true if the iteration has more elements.next()Returns the next element in the iteration, and updates the ProgressBar.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Constructor Details
-
ProgressIterator
Creates a newProgressIterableand a bar on the output stream.- Parameters:
outer- A Collection to supply a size and and Iterable.description- A text description to add at the start and when reporting duration.output- The Stream to write output too. For exampleSystem.out
-
-
Method Details
-
hasNext
public boolean hasNext()Returns true if the iteration has more elements. (In other words, returns true ifnext()would return an element rather than throwing an exception.)When
hasNext()returns false the ProgressBar is closed. -
next
Returns the next element in the iteration, and updates the ProgressBar.- Specified by:
nextin interfaceIterator<E>- Returns:
- The next element from the underlying iterator.
- Throws:
NoSuchElementException- if the iteration has no more elementsIllegalStateException- is the Iterator and therefore the ProgressBar have been closed.
-
close
public void close()Closes the underlyingProgressBar.Note: As
hasNext() == falseautomatically calls close there is no need to call this method unless you break out of the iterator early.If the bar is already closed then invoking this method has no effect.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-