001/** 002 * Copyright 2010-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.common.util; 017 018/** 019 * Print a dot to the console each time we make at least 1% progress towards the total 020 * 021 * @deprecated 022 */ 023@Deprecated 024public class PercentCompleteInformer extends AbstractProgressInformer { 025 026 protected long progress; 027 028 int percentageIncrement = 1; 029 int percentCompletePrevious; 030 long total; 031 032 public PercentCompleteInformer() { 033 this(0); 034 } 035 036 public PercentCompleteInformer(long total) { 037 this(total, null); 038 } 039 040 public PercentCompleteInformer(long total, LogMsg startMessage) { 041 super(); 042 this.total = total; 043 this.startMessage = startMessage; 044 } 045 046 /** 047 * Thread safe method for incrementing progress by one 048 */ 049 public synchronized void incrementProgress() { 050 incrementProgress(1); 051 } 052 053 /** 054 * Thread safe method for incrementing progress by <code>amount</code> 055 */ 056 public synchronized void incrementProgress(long amount) { 057 // Increment the progress indicator 058 this.progress += amount; 059 060 // Calculate how far along we are 061 int percentComplete = (int) ((progress * 100) / total); 062 063 // Have we made at least 1% progress since the last time we were informed about progress occurring? 064 if (isEnoughProgress(percentComplete, percentCompletePrevious, percentageIncrement)) { 065 // If so, print a dot to the console 066 this.percentCompletePrevious = percentComplete; 067 printStream.print(progressToken); 068 } 069 } 070 071 protected boolean isEnoughProgress(int percentComplete, int percentCompletePrevious, int percentageIncrement) { 072 int needed = percentCompletePrevious + percentageIncrement; 073 return percentComplete >= needed; 074 } 075 076 public int getPercentageIncrement() { 077 return percentageIncrement; 078 } 079 080 public void setPercentageIncrement(int percentageIncrement) { 081 this.percentageIncrement = percentageIncrement; 082 } 083 084 public int getPercentCompletePrevious() { 085 return percentCompletePrevious; 086 } 087 088 public void setPercentCompletePrevious(int percentCompletePrevious) { 089 this.percentCompletePrevious = percentCompletePrevious; 090 } 091 092 public long getTotal() { 093 return total; 094 } 095 096 public void setTotal(long total) { 097 this.total = total; 098 } 099}