Update arborescence 2

This commit is contained in:
Louis Calas
2019-10-10 18:01:08 +02:00
parent 29dba04efb
commit a0b8e315db
167 changed files with 3 additions and 5 deletions

View File

@@ -0,0 +1,46 @@
package progressbar;
// Source : https://masterex.github.io/archive/2011/10/23/java-cli-progress-bar.html
public class ProgressBar {
private StringBuilder progress;
/**
* initialize progress bar properties.
*/
public ProgressBar() {
init();
}
/**
* called whenever the progress bar needs to be updated.
* that is whenever progress was made.
*
* @param done an int representing the work done so far
* @param total an int representing the total work
*/
public void update(int done, int total) {
char[] workchars = {'|', '/', '-', '\\'};
String format = "\r%3d%% %s %c";
int percent = (++done * 100) / total;
int extrachars = (percent / 2) - this.progress.length();
while (extrachars-- > 0) {
progress.append('=');
}
System.out.printf(format, percent, progress,
workchars[done % workchars.length]);
if (done == total) {
System.out.flush();
System.out.println();
init();
}
}
private void init() {
this.progress = new StringBuilder(60);
}
}