Top Description Fields Constructors Methods
io.github.kusoroadeolu.clique.components

public Class ProgressBar

extends Object
implements Component
Class Inheritance
All Implemented Interfaces
io.github.kusoroadeolu.clique.components.Component
Annotations
@Stable
since:3.0.0
Imports
io.github.kusoroadeolu.clique.configuration.EasingConfiguration, .ProgressBarConfiguration, io.github.kusoroadeolu.clique.internal.documentation.Stable, java.io.PrintStream, java.util.Objects, java.util.concurrent.TimeUnit

A terminal progress bar component that tracks incremental progress toward a total.

Progress is advanced via tick() or tick(int), each of which re-renders the bar in place. The bar is considered complete when currentTick >= total, at which point isDone() returns true and a newline is emitted on the next render(PrintStream) call.

Rendering uses a format string from ProgressBarConfiguration that supports the following tokens:

This class is not thread-safe. Concurrent calls to tick(int) or tickAnimated(int) from multiple threads require external synchronization.

Since
3.0.0

Field Summary

Modifier and TypeField and Description
pack-priv final ProgressBarConfiguration
pack-priv final long
pack-priv int
pack-priv boolean
pack-priv final int

Constructor Summary

AccessConstructor and Description
private
ProgressBar(int currentTick, int total, boolean isDone, long creationTime, ProgressBarConfiguration configuration)

public
ProgressBar(int total, ProgressBarConfiguration configuration)

public
ProgressBar(int total)

Method Summary

Modifier and TypeMethod and Description
private String
alignRight(String text, int size)

private String
public ProgressBar

Returns:

this instance
complete
()

Advances the progress bar to completion and re-renders it to System#out.

public ProgressBar

Returns:

this instance
complete
(boolean
if the progress bar should be re-rendered to System#out
render
)

Advances the progress bar to completion.

private void
easeTick(int amount, EasingConfiguration easingConfig)

private long
public boolean
equals(Object o)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public String

Returns:

the rendered progress bar string; never null
get
()

Implements io.github.kusoroadeolu.clique.components.Component.get.

Returns the current rendered string representation of the progress bar, with all format tokens resolved.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

private String
interval(Long milliseconds)

public boolean

Returns:

true if currentTick >= total; false otherwise
isDone
()

Returns whether the progress bar has reached its total.

private int
private Long
public void
render(PrintStream
the stream to render to; must not be null
printStream
)

Overrides default io.github.kusoroadeolu.clique.components.Component.render.

Renders the progress bar to the given PrintStream in place, using a carriage return (\r) to overwrite the current line.

public ProgressBar

Returns:

this instance
tick
()

Advances the progress bar by 1 tick and re-renders it to System#out.

public ProgressBar

Returns:

this instance
tick
(int
the number of ticks to advance; must be >= 1
amount
)

Advances the progress bar by the given number of ticks and re-renders it to System#out.

public ProgressBar

Returns:

this instance
tick
(boolean
if the progress bar should be re-rendered to System#out

Equivalent to tick(1).

render
)

Advances the progress bar by 1 tick.

public ProgressBar

Returns:

this instance
tick
(int
the number of ticks to advance; must be >= 1
amount
,
boolean
if the progress bar should be re-rendered to System#out
render
)

Advances the progress bar by the given number of ticks.

public ProgressBar

Returns:

this instance
tickAnimated
(int
the number of ticks to advance; must be >= 1
amount
)

Advances the progress bar by the given amount, applying easing if configured.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

configurationback to summary
pack-priv final ProgressBarConfiguration configuration
creationTimeback to summary
pack-priv final long creationTime
currentTickback to summary
pack-priv int currentTick
isDoneback to summary
pack-priv boolean isDone
totalback to summary
pack-priv final int total

Constructor Detail

ProgressBarback to summary
private ProgressBar(int currentTick, int total, boolean isDone, long creationTime, ProgressBarConfiguration configuration)
ProgressBarback to summary
public ProgressBar(int total, ProgressBarConfiguration configuration)
ProgressBarback to summary
public ProgressBar(int total)

Method Detail

alignRightback to summary
private String alignRight(String text, int size)
barTextback to summary
private String barText()
completeback to summary
public ProgressBar complete()

Advances the progress bar to completion and re-renders it to System#out.

Equivalent to ticking by total - currentTick. If the bar is already complete, this method does not throw

Returns:ProgressBar

this instance

completeback to summary
public ProgressBar complete(boolean render)

Advances the progress bar to completion.

Equivalent to ticking by total - currentTick. If the bar is already complete, this method does not throw

Parameters
render:boolean

if the progress bar should be re-rendered to System#out

Returns:ProgressBar

this instance

easeTickback to summary
private void easeTick(int amount, EasingConfiguration easingConfig)
elapsedTimeback to summary
private long elapsedTime()
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
getback to summary
public String get()

Implements io.github.kusoroadeolu.clique.components.Component.get.

Returns the current rendered string representation of the progress bar, with all format tokens resolved.

The format string is sourced from ProgressBarConfiguration#getFormatForPercent(int) based on the current completion percentage. Markup tags in the resolved string are parsed if a parser is configured.

Returns:String

the rendered progress bar string; never null

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
intervalback to summary
private String interval(Long milliseconds)
isDoneback to summary
public boolean isDone()

Returns whether the progress bar has reached its total.

Returns:boolean

true if currentTick >= total; false otherwise

percentback to summary
private int percent()
remainingTimeback to summary
private Long remainingTime()
renderback to summary
public void render(PrintStream printStream)

Overrides default io.github.kusoroadeolu.clique.components.Component.render.

Renders the progress bar to the given PrintStream in place, using a carriage return (\r) to overwrite the current line.

When isDone() is true, a newline is appended after the final render to advance the cursor past the completed bar.

Parameters
printStream:PrintStream

the stream to render to; must not be null

Annotations
@Override
tickback to summary
public ProgressBar tick()

Advances the progress bar by 1 tick and re-renders it to System#out.

Equivalent to tick(1).

Returns:ProgressBar

this instance

tickback to summary
public ProgressBar tick(int amount)

Advances the progress bar by the given number of ticks and re-renders it to System#out.

The current tick is clamped to [0, total]. If this call causes currentTick >= total, isDone() will return true and a newline is emitted on the next render.

Parameters
amount:int

the number of ticks to advance; must be >= 1

Returns:ProgressBar

this instance

Exceptions
IllegalArgumentException:
if amount is less than 1
tickback to summary
public ProgressBar tick(boolean render)

Advances the progress bar by 1 tick.

Parameters
render:boolean

if the progress bar should be re-rendered to System#out

Equivalent to tick(1).

Returns:ProgressBar

this instance

tickback to summary
public ProgressBar tick(int amount, boolean render)

Advances the progress bar by the given number of ticks.

The current tick is clamped to [0, total]. If this call causes currentTick >= total, isDone() will return true and a newline is emitted on the next render.

Parameters
amount:int

the number of ticks to advance; must be >= 1

render:boolean

if the progress bar should be re-rendered to System#out

Returns:ProgressBar

this instance

Exceptions
IllegalArgumentException:
if amount is less than 1
tickAnimatedback to summary
public ProgressBar tickAnimated(int amount)

Advances the progress bar by the given amount, applying easing if configured.

If the active ProgressBarConfiguration has an EasingConfiguration whose shouldEase(amount) returns true, the tick is interpolated across multiple frames using the configured easing function and frame delay. Otherwise, delegates directly to tick(int).

This method blocks the calling thread for the duration of the animation when easing is applied.

Parameters
amount:int

the number of ticks to advance; must be >= 1

Returns:ProgressBar

this instance

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override