1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util;
17
18
19
20
21 public class PercentCompleteInformer extends AbstractProgressInformer {
22
23 protected long progress;
24
25 int percentageIncrement = 1;
26 int percentCompletePrevious;
27 long total;
28
29 public PercentCompleteInformer() {
30 this(0);
31 }
32
33 public PercentCompleteInformer(long total) {
34 this(total, null);
35 }
36
37 public PercentCompleteInformer(long total, LogMsg startMessage) {
38 super();
39 this.total = total;
40 this.startMessage = startMessage;
41 }
42
43
44
45
46 public synchronized void incrementProgress() {
47 incrementProgress(1);
48 }
49
50
51
52
53 public synchronized void incrementProgress(long amount) {
54
55 this.progress += amount;
56
57
58 int percentComplete = (int) ((progress * 100) / total);
59
60
61 if (isEnoughProgress(percentComplete, percentCompletePrevious, percentageIncrement)) {
62 this.percentCompletePrevious = percentComplete;
63 printStream.print(progressToken);
64 }
65 }
66
67 protected boolean isEnoughProgress(int percentComplete, int percentCompletePrevious, int percentageIncrement) {
68 int needed = percentCompletePrevious + percentageIncrement;
69 return percentComplete >= needed;
70 }
71
72 public int getPercentageIncrement() {
73 return percentageIncrement;
74 }
75
76 public void setPercentageIncrement(int percentageIncrement) {
77 this.percentageIncrement = percentageIncrement;
78 }
79
80 public int getPercentCompletePrevious() {
81 return percentCompletePrevious;
82 }
83
84 public void setPercentCompletePrevious(int percentCompletePrevious) {
85 this.percentCompletePrevious = percentCompletePrevious;
86 }
87
88 public long getTotal() {
89 return total;
90 }
91
92 public void setTotal(long total) {
93 this.total = total;
94 }
95 }