1
2
3
4
5
6
7 package com.atlassian.core.util;
8
9
10
11
12
13 public class ProgressMeter
14 {
15 int percentageComplete;
16 private String status;
17 private int total;
18 private int currentCount;
19 private boolean completedSuccessfully = true;
20
21
22
23
24
25
26
27 public void setPercentage(int count, int total)
28 {
29 if (total < 0)
30 {
31 setPercentage(0);
32 }
33 else if (total <= count)
34 {
35 setPercentage(100);
36 }
37 else
38 {
39 int calculatedPercentage = ((int) (100 * (float) count / (float) total));
40
41 if (count < total && calculatedPercentage == 100)
42 calculatedPercentage = 99;
43
44 setPercentage(calculatedPercentage);
45 }
46 }
47
48 public synchronized void setStatus(String status)
49 {
50 this.status = status;
51 }
52
53
54
55
56 public synchronized int getPercentageComplete()
57 {
58 return percentageComplete;
59 }
60
61 public synchronized String getStatus()
62 {
63 return status;
64 }
65
66 public synchronized void setPercentage(int percentageComplete)
67 {
68 this.percentageComplete = percentageComplete;
69 }
70
71 public synchronized int getCurrentCount()
72 {
73 return currentCount;
74 }
75
76 public synchronized void setCurrentCount(int currentCount)
77 {
78 this.currentCount = currentCount;
79 updatePercentageComplete();
80 }
81
82 private void updatePercentageComplete()
83 {
84 setPercentage(getCurrentCount(),getTotal());
85 }
86
87 public synchronized int getTotal()
88 {
89 return total;
90 }
91
92 public synchronized void setTotalObjects(int total)
93 {
94 this.total = total;
95 updatePercentageComplete();
96 }
97
98
99
100
101
102
103
104
105 public synchronized boolean isCompletedSuccessfully()
106 {
107 return completedSuccessfully;
108 }
109
110 public synchronized void setCompletedSuccessfully(boolean completedSuccessfully)
111 {
112 this.completedSuccessfully = completedSuccessfully;
113 }
114 }