Top Description Inners Fields Constructors Methods
io.github.kusoroadeolu.clique.configuration

public final Class ProgressBarConfiguration

extends Object
Class Inheritance
Annotations
@Stable
since:3.2.0
Imports
io.github.kusoroadeolu.clique.internal.documentation.InternalApi, .Stable, io.github.kusoroadeolu.clique.parser.MarkupParser, java.util.*, java.util.function.Predicate

Immutable configuration for a io.github.kusoroadeolu.clique.components.ProgressBar.

Instances are obtained via builder() or fromPreset(ProgressBarPreset). The DEFAULT constant is equivalent to ProgressBarPreset#BLOCKS. The default values are:

The format string controls how the bar is rendered. The following tokens are supported:

Per-range format overrides can be registered via ProgressBarConfigurationBuilder#styleWhen(Predicate, String) or ProgressBarConfigurationBuilder#styleRange(int, int, String). When the current completion percentage matches a registered predicate, its format is used in place of the default. Predicates are evaluated in registration order; the first match wins.

This class is immutable and thread-safe. ProgressBarConfigurationBuilder is not thread-safe; external synchronization is required if a builder instance is shared across threads.

Example:

ProgressBarConfiguration config = ProgressBarConfiguration.builder()
    .length(50)
    .complete('=')
    .incomplete('-')
    .styleRange(0, 49, "[red]:bar :percent%[/]")
    .styleRange(50, 99, "[yellow]:bar :percent%[/]")
    .styleRange(100, 100, "[green]:bar :percent%[/]")
    .build();
Since
3.0.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private final char
public static final ProgressBarConfiguration
DEFAULT

A default ProgressBarConfiguration equivalent to ProgressBarPreset#BLOCKS.

private final EasingConfiguration
private final String
private final char
private final int
private final MarkupParser
private final List<ProgressBarPredicate>
private final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ProgressBarConfiguration.ProgressBarConfigurationBuilder
builder()

Returns a new builder for constructing a ProgressBarConfiguration.

public boolean
equals(Object o)

Overrides java.lang.Object.equals.

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

public static ProgressBarConfiguration
public static ProgressBarConfiguration.ProgressBarConfigurationBuilder

Returns:

a new ProgressBarConfigurationBuilder seeded from the preset
fromPreset
(ProgressBarPreset
the preset to derive initial values from; must not be null
preset
)

Returns a builder pre-populated with the values of the given preset.

public char

Returns:

the completion character
getComplete
()

Returns the character used to represent completed progress in the bar segment.

public EasingConfiguration

Returns:

the easing configuration; never null
getEasing
()

Returns the easing configuration applied during animated ticks.

public String

Returns:

the format string; never null
getFormat
()

Returns the default format string used when no style predicate matches.

public String
getFormatForPercent(int percent)

public char

Returns:

the incomplete character
getIncomplete
()

Returns the character used to represent remaining progress in the bar segment.

public int

Returns:

the bar length; always >= 0
getLength
()

Returns the total character length of the bar segment rendered for :bar.

public MarkupParser

Returns:

the parser; never null
getParser
()

Returns the markup parser used to interpret inline style tags in the rendered output.

public int

Returns:

the ticks-per-unit value; always >= 1
getTicksPerUnit
()

Returns the number of ticks that represent one logical unit of progress.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

completeback to summary
private final char complete
DEFAULTback to summary
public static final ProgressBarConfiguration DEFAULT

A default ProgressBarConfiguration equivalent to ProgressBarPreset#BLOCKS.

easingConfigurationback to summary
private final EasingConfiguration easingConfiguration
formatback to summary
private final String format
incompleteback to summary
private final char incomplete
lengthback to summary
private final int length
parserback to summary
private final MarkupParser parser
stylesback to summary
private final List<ProgressBarPredicate> styles
ticksPerUnitback to summary
private final int ticksPerUnit

Constructor Detail

ProgressBarConfigurationback to summary
private ProgressBarConfiguration(ProgressBarConfiguration.ProgressBarConfigurationBuilder builder)

Method Detail

builderback to summary
public static ProgressBarConfiguration.ProgressBarConfigurationBuilder builder()

Returns a new builder for constructing a ProgressBarConfiguration.

Returns:ProgressBarConfiguration.ProgressBarConfigurationBuilder

a new ProgressBarConfigurationBuilder

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
fromEasingback to summary
public static ProgressBarConfiguration fromEasing(EasingConfiguration easing)
Annotations
@InternalApi
since:3.2.1
fromPresetback to summary
public static ProgressBarConfiguration.ProgressBarConfigurationBuilder fromPreset(ProgressBarPreset preset)

Returns a builder pre-populated with the values of the given preset.

The returned builder can be further customized before calling ProgressBarConfigurationBuilder#build(). The preset's easing and style predicates are not copied; only length, complete, incomplete, and format are transferred.

Parameters
preset:ProgressBarPreset

the preset to derive initial values from; must not be null

Returns:ProgressBarConfiguration.ProgressBarConfigurationBuilder

a new ProgressBarConfigurationBuilder seeded from the preset

Annotations
@Stable
since:3.2.1
Exceptions
NullPointerException:
if preset is null
Since
3.2.1
getCompleteback to summary
public char getComplete()

Returns the character used to represent completed progress in the bar segment.

Returns:char

the completion character

getEasingback to summary
public EasingConfiguration getEasing()

Returns the easing configuration applied during animated ticks.

Returns:EasingConfiguration

the easing configuration; never null

getFormatback to summary
public String getFormat()

Returns the default format string used when no style predicate matches.

See the class-level documentation for the list of supported tokens.

Returns:String

the format string; never null

getFormatForPercentback to summary
public String getFormatForPercent(int percent)
Annotations
@InternalApi
since:3.2.1
getIncompleteback to summary
public char getIncomplete()

Returns the character used to represent remaining progress in the bar segment.

Returns:char

the incomplete character

getLengthback to summary
public int getLength()

Returns the total character length of the bar segment rendered for :bar.

Returns:int

the bar length; always >= 0

getParserback to summary
public MarkupParser getParser()

Returns the markup parser used to interpret inline style tags in the rendered output.

Returns:MarkupParser

the parser; never null

getTicksPerUnitback to summary
public int getTicksPerUnit()

Returns the number of ticks that represent one logical unit of progress.

Used to compute the :units and :total-units format tokens, which display progress scaled to a user-defined unit rather than raw ticks.

Returns:int

the ticks-per-unit value; always >= 1

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
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
io.github.kusoroadeolu.clique.configuration back to summary

public Class ProgressBarConfiguration.ProgressBarConfigurationBuilder

extends Object
Class Inheritance
  • java.lang.Object
  • io.github.kusoroadeolu.clique.configuration.ProgressBarConfiguration.ProgressBarConfigurationBuilder

Builder for ProgressBarConfiguration.

This builder is not thread-safe.

Field Summary

Modifier and TypeField and Description
private char
private EasingConfiguration
private String
private static final String
private char
private int
private MarkupParser
private final List<ProgressBarPredicate>
private int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public ProgressBarConfiguration

Returns:

a new ProgressBarConfiguration
build
()

Builds and returns a new ProgressBarConfiguration from the current builder state.

public ProgressBarConfiguration.ProgressBarConfigurationBuilder

Returns:

this builder
complete
(char
the completion character
complete
)

Sets the character used to represent completed progress in the bar segment.

public ProgressBarConfiguration.ProgressBarConfigurationBuilder

Returns:

this builder
easing
(EasingConfiguration
the easing configuration; must not be null
easing
)

Sets the easing configuration applied during animated ticks.

public ProgressBarConfiguration.ProgressBarConfigurationBuilder

Returns:

this builder
format
(String
the format string; must not be null
format
)

Sets the default format string used to render the progress bar.

public ProgressBarConfiguration.ProgressBarConfigurationBuilder

Returns:

this builder
incomplete
(char
the incomplete character
incomplete
)

Sets the character used to represent remaining progress in the bar segment.

public ProgressBarConfiguration.ProgressBarConfigurationBuilder

Returns:

this builder
length
(int
the bar length; must be >= 0
length
)

Sets the character length of the bar segment rendered for :bar.

public ProgressBarConfiguration.ProgressBarConfigurationBuilder

Returns:

this builder
parser
(MarkupParser
the parser to use; must not be null
parser
)

Sets the markup parser used to interpret inline style tags in progress bar

public ProgressBarConfiguration.ProgressBarConfigurationBuilder

Returns:

this builder
styleRange
(int
the lower bound of the percentage range; must be >= 0
min
,
int
the upper bound of the percentage range
max
,
String
the format string to use within this range; must not be null
format
)

Registers a conditional format applied when the completion percentage falls within [min, max], inclusive.

public ProgressBarConfiguration.ProgressBarConfigurationBuilder

Returns:

this builder
styles
(Collection<ProgressBarPredicate>
the style predicates to add; must not be null
formats
)

Adds a collection of ProgressBarPredicate style entries to this builder.

public ProgressBarConfiguration.ProgressBarConfigurationBuilder

Returns:

this builder
styleWhen
(Predicate<Integer>
a predicate over the completion percentage [0, 100]; must not be null
condition
,
String
the format string to use when the condition matches; must not be null
format
)

Registers a conditional format that is applied when condition matches the current completion percentage.

public ProgressBarConfiguration.ProgressBarConfigurationBuilder

Returns:

this builder
ticksPerUnit
(int
the ticks-per-unit value; must be >= 1
ticksPerUnit
)

Sets the number of ticks that represent one logical unit of progress.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

completeback to summary
private char complete
easingback to summary
private EasingConfiguration easing
formatback to summary
private String format
FORMAT_ERR_MESSAGEback to summary
private static final String FORMAT_ERR_MESSAGE
incompleteback to summary
private char incomplete
lengthback to summary
private int length
parserback to summary
private MarkupParser parser
stylesback to summary
private final List<ProgressBarPredicate> styles
tickPerUnitback to summary
private int tickPerUnit

Constructor Detail

ProgressBarConfigurationBuilderback to summary
public ProgressBarConfigurationBuilder()

Method Detail

buildback to summary
public ProgressBarConfiguration build()

Builds and returns a new ProgressBarConfiguration from the current builder state.

Returns:ProgressBarConfiguration

a new ProgressBarConfiguration

completeback to summary
public ProgressBarConfiguration.ProgressBarConfigurationBuilder complete(char complete)

Sets the character used to represent completed progress in the bar segment.

Parameters
complete:char

the completion character

Returns:ProgressBarConfiguration.ProgressBarConfigurationBuilder

this builder

easingback to summary
public ProgressBarConfiguration.ProgressBarConfigurationBuilder easing(EasingConfiguration easing)

Sets the easing configuration applied during animated ticks.

Parameters
easing:EasingConfiguration

the easing configuration; must not be null

Returns:ProgressBarConfiguration.ProgressBarConfigurationBuilder

this builder

Exceptions
NullPointerException:
if easing is null
formatback to summary
public ProgressBarConfiguration.ProgressBarConfigurationBuilder format(String format)

Sets the default format string used to render the progress bar.

See ProgressBarConfiguration for the list of supported tokens.

Parameters
format:String

the format string; must not be null

Returns:ProgressBarConfiguration.ProgressBarConfigurationBuilder

this builder

Exceptions
NullPointerException:
if format is null
incompleteback to summary
public ProgressBarConfiguration.ProgressBarConfigurationBuilder incomplete(char incomplete)

Sets the character used to represent remaining progress in the bar segment.

Parameters
incomplete:char

the incomplete character

Returns:ProgressBarConfiguration.ProgressBarConfigurationBuilder

this builder

lengthback to summary
public ProgressBarConfiguration.ProgressBarConfigurationBuilder length(int length)

Sets the character length of the bar segment rendered for :bar.

Parameters
length:int

the bar length; must be >= 0

Returns:ProgressBarConfiguration.ProgressBarConfigurationBuilder

this builder

Exceptions
IllegalArgumentException:
if length is negative
parserback to summary
public ProgressBarConfiguration.ProgressBarConfigurationBuilder parser(MarkupParser parser)

Sets the markup parser used to interpret inline style tags in progress bar

Parameters
parser:MarkupParser

the parser to use; must not be null

Returns:ProgressBarConfiguration.ProgressBarConfigurationBuilder

this builder

Exceptions
NullPointerException:
if parser is null
styleRangeback to summary
public ProgressBarConfiguration.ProgressBarConfigurationBuilder styleRange(int min, int max, String format)

Registers a conditional format applied when the completion percentage falls within [min, max], inclusive.

Delegates to styleWhen(Predicate, String).

Parameters
min:int

the lower bound of the percentage range; must be >= 0

max:int

the upper bound of the percentage range

format:String

the format string to use within this range; must not be null

Returns:ProgressBarConfiguration.ProgressBarConfigurationBuilder

this builder

Exceptions
IllegalArgumentException:
if min is negative
NullPointerException:
if format is null
stylesback to summary
public ProgressBarConfiguration.ProgressBarConfigurationBuilder styles(Collection<ProgressBarPredicate> formats)

Adds a collection of ProgressBarPredicate style entries to this builder.

Predicates are appended in iteration order and evaluated after any previously registered styles.

Parameters
formats:Collection<ProgressBarPredicate>

the style predicates to add; must not be null

Returns:ProgressBarConfiguration.ProgressBarConfigurationBuilder

this builder

Exceptions
NullPointerException:
if formats is null
styleWhenback to summary
public ProgressBarConfiguration.ProgressBarConfigurationBuilder styleWhen(Predicate<Integer> condition, String format)

Registers a conditional format that is applied when condition matches the current completion percentage.

Predicates are evaluated in registration order; the first match wins. If no predicate matches, the default format set via format(String) is used.

Parameters
condition:Predicate<Integer>

a predicate over the completion percentage [0, 100]; must not be null

format:String

the format string to use when the condition matches; must not be null

Returns:ProgressBarConfiguration.ProgressBarConfigurationBuilder

this builder

Exceptions
NullPointerException:
if condition or format is null
ticksPerUnitback to summary
public ProgressBarConfiguration.ProgressBarConfigurationBuilder ticksPerUnit(int ticksPerUnit)

Sets the number of ticks that represent one logical unit of progress.

For example, if each tick represents one byte and you want to display progress in kilobytes, set this to 1024.

Parameters
ticksPerUnit:int

the ticks-per-unit value; must be >= 1

Returns:ProgressBarConfiguration.ProgressBarConfigurationBuilder

this builder

Exceptions
IllegalArgumentException:
if tickPerUnit is less than 1