1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util;
17
18 import java.io.PrintStream;
19
20
21
22
23 public class PercentCompleteInformer {
24
25 PrintStream out = System.out;
26 long count = 0;
27 long total = 0;
28 int percentageIncrement = 1;
29 int percentCompletePrevious;
30 String startToken = "[INFO] Progress: ";
31 String progressToken = ".";
32 String completeToken = "\n";
33
34 public void setTotal(long total) {
35 this.total = total;
36 }
37
38 public synchronized void progressOccurred() {
39
40 if (count == 0) {
41 out.print(startToken);
42 }
43
44
45 this.count++;
46
47
48 int percentComplete = (int) ((count * 100) / total);
49 if (enoughProgress(percentComplete)) {
50 this.percentCompletePrevious = percentComplete;
51 out.print(progressToken);
52 }
53
54
55 if (count == total) {
56 out.print(completeToken);
57 }
58 }
59
60 protected boolean enoughProgress(int percentComplete) {
61 int needed = percentCompletePrevious + percentageIncrement;
62 return percentComplete >= needed;
63 }
64
65 public PrintStream getOut() {
66 return out;
67 }
68
69 public void setOut(PrintStream out) {
70 this.out = out;
71 }
72
73 public long getCount() {
74 return count;
75 }
76
77 public void setCount(long count) {
78 this.count = count;
79 }
80
81 public int getPercentageIncrement() {
82 return percentageIncrement;
83 }
84
85 public void setPercentageIncrement(int percentageIncrement) {
86 this.percentageIncrement = percentageIncrement;
87 }
88
89 public String getStartToken() {
90 return startToken;
91 }
92
93 public void setStartToken(String startToken) {
94 this.startToken = startToken;
95 }
96
97 public String getCompleteToken() {
98 return completeToken;
99 }
100
101 public void setCompleteToken(String completeToken) {
102 this.completeToken = completeToken;
103 }
104
105 public String getProgressToken() {
106 return progressToken;
107 }
108
109 public void setProgressToken(String progressToken) {
110 this.progressToken = progressToken;
111 }
112
113 public long getTotal() {
114 return total;
115 }
116
117 }