Class ProgressBar
java.lang.Object
uk.ac.manchester.spinnaker.utils.progress.ProgressBar
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class ProgressBar extends Object implements Closeable
Progress bar for telling the user where a task is up to and for reporting the
duration.
The timer is started and the header of the bar is written during
construction. The dash line is terminated when the last expected update
arrives. (or if close()
is called before that update). The timer is
stopped and the duration written when close()
is called. If
close()
is not called the duration is never written out.
- Author:
- Christian-B
-
Constructor Summary
Constructors Constructor Description ProgressBar(int numberOfThings, String description)
Creates a Progress bar which outputs toSystem.out
.ProgressBar(int numberOfThings, String description, PrintStream output)
Creates a progress bar which outputs to the givenPrintStream
. -
Method Summary
-
Constructor Details
-
ProgressBar
Creates a progress bar which outputs to the givenPrintStream
.- Parameters:
numberOfThings
- The number of items to progress overdescription
- A text description to add at the start and when reporting duration.output
- The stream to write output too. For exampleSystem.out
.
-
ProgressBar
Creates a Progress bar which outputs toSystem.out
.- Parameters:
numberOfThings
- The number of items to progress overdescription
- A text description to add at the start and when reporting duration.
-
-
Method Details
-
update
public void update(int amountToAdd)Update the progress bar by a given amount.- Parameters:
amountToAdd
- Amount of things to update by.- Throws:
IllegalStateException
- Throws if the bar is updated too often or updated after it was closed.
-
update
public void update()Update the progress bar by a one unit.- Throws:
IllegalStateException
- Throws if the bar is updated too often or updated after it was closed.
-
close
public void close()Ends the Progress bar line and prints a duration line.If the bar is already closed then invoking this method has no effect.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
isClosed
public boolean isClosed()- Returns:
- True if the progress bar is closed
-