View Javadoc

1   /*
2    * Created by IntelliJ IDEA.
3    * User: Mike
4    * Date: Mar 5, 2004
5    * Time: 12:57:20 PM
6    */
7   package com.atlassian.core.util;
8   
9   public class ProgressMeter
10  {
11      int percentageComplete;
12      private String status;
13      private int total;
14      private int currentCount;
15      private boolean completedSuccessfully = true;
16  
17      /**
18       * Use this method to set the completion %age to object 10 of 30 etc.
19       *
20       * @param count The current object count in progress
21       * @param total The total number of objects to be processed
22       */
23      public void setPercentage(int count, int total)
24      {
25          if (total < 0)
26          {
27              percentageComplete = 0;
28          }
29          else if (total <= count)
30          {
31              percentageComplete = 100;
32          }
33          else
34          {
35              percentageComplete = ((int) (100 * (float) count / (float) total));
36  
37              if (count < total && percentageComplete == 100)
38                  percentageComplete = 99;
39          }
40      }
41  
42      public void setStatus(String status)
43      {
44          this.status = status;
45      }
46  
47      public int getPercentageComplete()
48      {
49          return percentageComplete;
50      }
51  
52      public String getStatus()
53      {
54          return status;
55      }
56  
57      public void setPercentage(int percentageComplete)
58      {
59          this.percentageComplete = percentageComplete;
60      }
61  
62      public int getCurrentCount()
63      {
64          return currentCount;
65      }
66  
67      public void setCurrentCount(int currentCount)
68      {
69          this.currentCount = currentCount;
70          updatePercentageComplete();
71      }
72  
73      private void updatePercentageComplete()
74      {
75          setPercentage(getCurrentCount(),getTotal());
76      }
77  
78      public int getTotal()
79      {
80          return total;
81      }
82  
83      public void setTotalObjects(int total)
84      {
85          this.total = total;
86          updatePercentageComplete();
87      }
88  
89      public boolean isCompletedSuccessfully()
90      {
91          return completedSuccessfully;
92      }
93  
94      public void setCompletedSuccessfully(boolean completedSuccessfully)
95      {
96          this.completedSuccessfully = completedSuccessfully;
97      }
98  }