me.tongfei.progressbar.ProgressBarBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of progressbar Show documentation
Show all versions of progressbar Show documentation
A terminal-based progress bar for JVM
package me.tongfei.progressbar;
import java.io.PrintStream;
import java.text.DecimalFormat;
/**
* Builder class for {@link ProgressBar}s.
* @author Tongfei Chen
* @since 0.7.0
*/
public class ProgressBarBuilder {
private String task = "";
private long initialMax = 0;
private ProgressBarStyle style = ProgressBarStyle.COLORFUL_UNICODE_BLOCK;
private int updateIntervalMillis = 1000;
private PrintStream stream = System.err;
private String unitName = "";
private long unitSize = 1;
private boolean showSpeed = false;
private DecimalFormat speedFormat;
public ProgressBarBuilder() { }
public ProgressBarBuilder setTaskName(String task) {
this.task = task;
return this;
}
public ProgressBarBuilder setInitialMax(long initialMax) {
this.initialMax = initialMax;
return this;
}
public ProgressBarBuilder setStyle(ProgressBarStyle style) {
this.style = style;
return this;
}
public ProgressBarBuilder setUpdateIntervalMillis(int updateIntervalMillis) {
this.updateIntervalMillis = updateIntervalMillis;
return this;
}
public ProgressBarBuilder setPrintStream(PrintStream stream) {
this.stream = stream;
return this;
}
public ProgressBarBuilder setUnit(String unitName, long unitSize) {
this.unitName = unitName;
this.unitSize = unitSize;
return this;
}
public ProgressBarBuilder showSpeed() {
return showSpeed(new DecimalFormat("#.#"));
}
public ProgressBarBuilder showSpeed(DecimalFormat speedFormat) {
this.showSpeed = true;
this.speedFormat = speedFormat;
return this;
}
public ProgressBar build() {
return new ProgressBar(
task,
initialMax,
updateIntervalMillis,
stream,
style,
unitName,
unitSize,
showSpeed,
speedFormat
);
}
}