View Javadoc
1   /**
2    * Copyright 2010-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.util;
17  
18  /**
19   * Print a dot to the console each time we make at least 1% progress towards the total
20   * 
21   * @deprecated
22   */
23  @Deprecated
24  public class PercentCompleteInformer extends AbstractProgressInformer {
25  
26  	protected long progress;
27  
28  	int percentageIncrement = 1;
29  	int percentCompletePrevious;
30  	long total;
31  
32  	public PercentCompleteInformer() {
33  		this(0);
34  	}
35  
36  	public PercentCompleteInformer(long total) {
37  		this(total, null);
38  	}
39  
40  	public PercentCompleteInformer(long total, LogMsg startMessage) {
41  		super();
42  		this.total = total;
43  		this.startMessage = startMessage;
44  	}
45  
46  	/**
47  	 * Thread safe method for incrementing progress by one
48  	 */
49  	public synchronized void incrementProgress() {
50  		incrementProgress(1);
51  	}
52  
53  	/**
54  	 * Thread safe method for incrementing progress by <code>amount</code>
55  	 */
56  	public synchronized void incrementProgress(long amount) {
57  		// Increment the progress indicator
58  		this.progress += amount;
59  
60  		// Calculate how far along we are
61  		int percentComplete = (int) ((progress * 100) / total);
62  
63  		// Have we made at least 1% progress since the last time we were informed about progress occurring?
64  		if (isEnoughProgress(percentComplete, percentCompletePrevious, percentageIncrement)) {
65  			// If so, print a dot to the console
66  			this.percentCompletePrevious = percentComplete;
67  			printStream.print(progressToken);
68  		}
69  	}
70  
71  	protected boolean isEnoughProgress(int percentComplete, int percentCompletePrevious, int percentageIncrement) {
72  		int needed = percentCompletePrevious + percentageIncrement;
73  		return percentComplete >= needed;
74  	}
75  
76  	public int getPercentageIncrement() {
77  		return percentageIncrement;
78  	}
79  
80  	public void setPercentageIncrement(int percentageIncrement) {
81  		this.percentageIncrement = percentageIncrement;
82  	}
83  
84  	public int getPercentCompletePrevious() {
85  		return percentCompletePrevious;
86  	}
87  
88  	public void setPercentCompletePrevious(int percentCompletePrevious) {
89  		this.percentCompletePrevious = percentCompletePrevious;
90  	}
91  
92  	public long getTotal() {
93  		return total;
94  	}
95  
96  	public void setTotal(long total) {
97  		this.total = total;
98  	}
99  }