/[projects]/dao/FuldDaekningWorker/src/main/java/dk/daoas/fulddaekning/ProgressBar.java
ViewVC logotype

Contents of /dao/FuldDaekningWorker/src/main/java/dk/daoas/fulddaekning/ProgressBar.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2797 - (show annotations) (download)
Tue Dec 29 13:11:20 2015 UTC (8 years, 4 months ago) by torben
File size: 755 byte(s)
add progressbar
1 package dk.daoas.fulddaekning;
2
3
4
5 public class ProgressBar {
6
7 int total = 0;
8 int current = 0;
9
10
11 public ProgressBar(int total) {
12 this.total = total;
13 }
14
15 public synchronized void tick() {
16 current ++;
17
18 if ( (current%25) == 0) {
19
20 updateProgress( ((double)current) / total );
21 }
22 }
23
24 private void updateProgress(double progressPercentage) {
25 StringBuilder sb = new StringBuilder();
26
27 final int width = 50; // progress bar width in chars
28
29 sb.append("\r[");
30 int i = 0;
31 for (; i <= (int)(progressPercentage*width); i++) {
32 sb.append(".");
33 }
34 for (; i < width; i++) {
35 sb.append(" ");
36 }
37 sb.append("] ");
38 sb.append( String.format("%5.1f",progressPercentage*100) );
39 sb.append("% ");
40
41 System.out.print( sb.toString() );
42 }
43 }

  ViewVC Help
Powered by ViewVC 1.1.20