From 5f4accb2dd7039b8e8e60614bbf55e56c86e699f Mon Sep 17 00:00:00 2001 From: ctongfei Date: Mon, 23 Jan 2017 12:33:56 -0500 Subject: [PATCH] 0.5.3: int => long --- README.md | 5 ++++- pom.xml | 2 +- .../me/tongfei/progressbar/ProgressBar.java | 18 +++++++++--------- .../me/tongfei/progressbar/ProgressState.java | 16 ++++++++-------- .../me/tongfei/progressbar/ProgressThread.java | 2 +- 5 files changed, 23 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 4a7b8e4..8e525d7 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Maven: me.tongfei progressbar - 0.5.1 + 0.5.3 ``` @@ -24,6 +24,8 @@ Usage: ProgressBar pb = new ProgressBar("Test", 100); // name, initial max // Use ProgressBar("Test", 100, ProgressBarStyle.ASCII) if you want ASCII output style pb.start(); // the progress bar starts timing +// Or you could combine these two lines like this: +// ProgressBar pb = new ProgressBar("Test", 100).start(); some loop { ... pb.step(); // step by 1 @@ -42,6 +44,7 @@ pb.stop() // stops the progress bar #### Changelog + - 0.5.3: Type of max/current of a progress bar is changed from `int` to `long`. Thanks @vitobellini ! - 0.5.2: Methods now returns `this`. This simplifies the initialization: Now you can do `pb = new ProgressBar(...).start()`. Extra messages that are too long are trimmed properly. Thanks @mattcg ! - 0.5.1: Fixed the refresh problem when progress ended. Added style (Unicode block characters / pure ASCII) support. diff --git a/pom.xml b/pom.xml index 18b5ee4..9277db3 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.tongfei progressbar - 0.5.2 + 0.5.3 progressbar A console-based progress bar for JVM http://github.com/ctongfei/progressbar diff --git a/src/main/java/me/tongfei/progressbar/ProgressBar.java b/src/main/java/me/tongfei/progressbar/ProgressBar.java index f3b8e89..77b63f9 100644 --- a/src/main/java/me/tongfei/progressbar/ProgressBar.java +++ b/src/main/java/me/tongfei/progressbar/ProgressBar.java @@ -20,15 +20,15 @@ public class ProgressBar { * @param task Task name * @param initialMax Initial maximum value */ - public ProgressBar(String task, int initialMax) { + public ProgressBar(String task, long initialMax) { this(task, initialMax, 1000, System.err, ProgressBarStyle.UNICODE_BLOCK); } - public ProgressBar(String task, int initialMax, ProgressBarStyle style) { + public ProgressBar(String task, long initialMax, ProgressBarStyle style) { this(task, initialMax, 1000, System.err, style); } - public ProgressBar(String task, int initialMax, int updateIntervalMillis) { + public ProgressBar(String task, long initialMax, int updateIntervalMillis) { this(task, initialMax, updateIntervalMillis, System.err, ProgressBarStyle.UNICODE_BLOCK); } @@ -41,7 +41,7 @@ public ProgressBar(String task, int initialMax, int updateIntervalMillis) { * @param os Print stream (default value System.err) * @param style Output style (default value ProgresBarStyle.UNICODE_BLOCK) */ - public ProgressBar(String task, int initialMax, int updateIntervalMillis, PrintStream os, ProgressBarStyle style) { + public ProgressBar(String task, long initialMax, int updateIntervalMillis, PrintStream os, ProgressBarStyle style) { this.progress = new ProgressState(task, initialMax); this.target = new ProgressThread(progress, style, updateIntervalMillis, os); this.thread = new Thread(target); @@ -60,7 +60,7 @@ public ProgressBar start() { * Advances this progress bar by a specific amount. * @param n Step size */ - public ProgressBar stepBy(int n) { + public ProgressBar stepBy(long n) { progress.stepBy(n); return this; } @@ -69,7 +69,7 @@ public ProgressBar stepBy(int n) { * Advances this progress bar to the specific progress value. * @param n New progress value */ - public ProgressBar stepTo(int n) { + public ProgressBar stepTo(long n) { progress.stepTo(n); return this; } @@ -86,7 +86,7 @@ public ProgressBar step() { * Gives a hint to the maximum value of the progress bar. * @param n Hint of the maximum value */ - public ProgressBar maxHint(int n) { + public ProgressBar maxHint(long n) { progress.maxHint(n); return this; } @@ -117,14 +117,14 @@ public ProgressBar setExtraMessage(String msg) { /** * Returns the current progress. */ - public int getCurrent() { + public long getCurrent() { return progress.getCurrent(); } /** * Returns the maximum value of this progress bar. */ - public int getMax() { + public long getMax() { return progress.getMax(); } diff --git a/src/main/java/me/tongfei/progressbar/ProgressState.java b/src/main/java/me/tongfei/progressbar/ProgressState.java index aa517d1..b04a71b 100644 --- a/src/main/java/me/tongfei/progressbar/ProgressState.java +++ b/src/main/java/me/tongfei/progressbar/ProgressState.java @@ -11,28 +11,28 @@ class ProgressState { String task; - int current = 0; - int max = 0; + long current = 0; + long max = 0; LocalDateTime startTime = null; String extraMessage = ""; - ProgressState(String task, int initialMax) { + ProgressState(String task, long initialMax) { this.task = task; this.max = initialMax; } - synchronized void maxHint(int n) { + synchronized void maxHint(long n) { max = n; } - synchronized void stepBy(int n) { + synchronized void stepBy(long n) { current += n; if (current > max) max = current; } - synchronized void stepTo(int n) { + synchronized void stepTo(long n) { current = n; if (current > max) max = current; } @@ -49,11 +49,11 @@ synchronized String getExtraMessage() { return extraMessage; } - synchronized int getCurrent() { + synchronized long getCurrent() { return current; } - synchronized int getMax() { + synchronized long getMax() { return max; } diff --git a/src/main/java/me/tongfei/progressbar/ProgressThread.java b/src/main/java/me/tongfei/progressbar/ProgressThread.java index d447939..d7d12db 100644 --- a/src/main/java/me/tongfei/progressbar/ProgressThread.java +++ b/src/main/java/me/tongfei/progressbar/ProgressThread.java @@ -30,7 +30,7 @@ public class ProgressThread implements Runnable { // between 0 and 1 double progress() { - if (progress.max == 0) return 0.0; + if (progress.max == 0l) return 0.0; else return ((double)progress.current) / progress.max; }