Class ProgressIterable<E>
- Type Parameters:
E
- Type of elements to be iterated over.
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Iterable<E>
,MappableIterable<E>
public class ProgressIterable<E> extends Object implements MappableIterable<E>, Closeable
Iterable
wrapper that will start a ProgressBar
for each
iterator.
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. If the Iterable is used in a for loop the duration is started at
the beginning of the for loop and duration finishes and reports as the for
loop ends. (Not at the time the last element is provided.)
Calling iterator()
more than once is supported but could result in
mixed output if they are run at the same time.
- Author:
- Christian-B
-
Constructor Summary
Constructors Constructor Description ProgressIterable(Collection<E> things, String description)
Creates an iterable wrapper but not yet a ProgressBar.ProgressIterable(Collection<E> things, String description, PrintStream output)
Creates an iterable wrapper but not yet a ProgressBar. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface uk.ac.manchester.spinnaker.utils.MappableIterable
filter, first, first, map, nth, toCollectingMap, toCollectingMap, toCollectingMap, toCollectingMap, toList, toList, toMap, toMap, toSet, toSet
-
Constructor Details
-
ProgressIterable
Creates an iterable wrapper but not yet a ProgressBar.- Parameters:
things
- A collection to supply a size and and iterable. The type of elements returned by this iterable is also the type of elements returned by the ProgressIterable.description
- A text description to add at the start and when reporting duration.output
- The Stream to write output too. For example,System.out
.
-
ProgressIterable
Creates an iterable wrapper but not yet a ProgressBar. The progress bar will write toSystem.out
.- Parameters:
things
- A collection to supply a size and and iterable. The type of elements returned by this iterable is also the type of elements returned by the ProgressIterable.description
- A text description to add at the start and when reporting duration.
-
-
Method Details
-
iterator
Starts a ProgressBar and returns an iterator over the elements of the iterable contained within this iterable. -
close
public void close()Closes all created Iterators and their ProgressBar(s).This method allows the Iterable to be used in a
try
-with-resources statement, which guarantees the ProgressBar is closed.Note: As
hasNext() == false
automatically calls close there is no need to call this method unless you break out of the iterator early.If the bar is already closed, invoking this method has no effect.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-