Skip to content

Commit

Permalink
0.5.3: int => long
Browse files Browse the repository at this point in the history
  • Loading branch information
ctongfei committed Jan 23, 2017
1 parent 629193a commit 5f4accb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Maven:
<dependency>
<groupId>me.tongfei</groupId>
<artifactId>progressbar</artifactId>
<version>0.5.1</version>
<version>0.5.3</version>
</dependency>
```

Expand All @@ -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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.tongfei</groupId>
<artifactId>progressbar</artifactId>
<version>0.5.2</version>
<version>0.5.3</version>
<name>progressbar</name>
<description>A console-based progress bar for JVM</description>
<url>http://github.com/ctongfei/progressbar</url>
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/me/tongfei/progressbar/ProgressBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();
}

Expand Down
16 changes: 8 additions & 8 deletions src/main/java/me/tongfei/progressbar/ProgressState.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/tongfei/progressbar/ProgressThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 5f4accb

Please sign in to comment.