org.tranche.timeestimator
Class TimeEstimator

java.lang.Object
  extended by org.tranche.commons.Debuggable
      extended by org.tranche.timeestimator.TimeEstimator
Direct Known Subclasses:
ContextualTimeEstimator

public class TimeEstimator
extends org.tranche.commons.Debuggable

A utility class to easily calculate the estimated completion time for work.

Author:
Jayson Falkner - jfalkner@umich.edu, James "Augie" Hill - augman85@gmail.com

Field Summary
protected  long bytesCompleted
          Represents the work done.
protected  long currentTime
          The current time for the estimator.
protected  long filesCompleted
           
protected  long startTime
          The start time for the estimator.
protected  long totalBytes
          Represented the amount of work to do.
protected  long totalFiles
           
 
Constructor Summary
TimeEstimator()
           
 
Method Summary
 void addTotalBytes(long addTotalBytes)
           
 void addTotalFiles(long addTotalFiles)
           
 long getBytesDone()
           
 long getFilesDone()
           
 long getHours()
          Returns the number of hours left to work.
 long getMinutes()
          Returns the number of minutes left to work.
 double getPercentDone()
          Returns the percentage of work complete as a number between 0 and 100, e.g.
 long getSeconds()
          Returns the number of seconds left to work.
 long getStartTime()
          Get the time the estimator started.
 java.lang.String getTimeLeftString()
           
 long getTimeRunning()
          Get the total time the estimator has been running.
 long getTotalBytes()
           
 long getTotalFiles()
           
 void subtractTotalBytes(long subtractTotalBytes)
           
 void subtractTotalFiles(long subtractTotalFiles)
           
 void update(long bytesCompleted, long totalBytes, long filesCompleted, long totalFiles)
          Updates the internal clock and provides a chance to update the amount of total work and the amount of work done.
 
Methods inherited from class org.tranche.commons.Debuggable
debugErr, debugErr, debugOut, isDebug, setDebug
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

totalBytes

protected long totalBytes

Represented the amount of work to do.


bytesCompleted

protected long bytesCompleted

Represents the work done.


totalFiles

protected long totalFiles

filesCompleted

protected long filesCompleted

startTime

protected long startTime

The start time for the estimator.


currentTime

protected long currentTime

The current time for the estimator.

Constructor Detail

TimeEstimator

public TimeEstimator()
Method Detail

update

public void update(long bytesCompleted,
                   long totalBytes,
                   long filesCompleted,
                   long totalFiles)

Updates the internal clock and provides a chance to update the amount of total work and the amount of work done.

Parameters:
bytesCompleted - An arbitrary long that represents the amount of work completed. Must be between 0 and Long.MAX_VALUE.
totalBytes - An arbitrary long that represents the amount of work to do. Must be between 0 and Long.MAX_VALUE.
filesCompleted -
totalFiles -

getBytesDone

public long getBytesDone()
Returns:

getTotalBytes

public long getTotalBytes()
Returns:

getFilesDone

public long getFilesDone()
Returns:

getTotalFiles

public long getTotalFiles()
Returns:

addTotalBytes

public void addTotalBytes(long addTotalBytes)
Parameters:
addTotalBytes -

subtractTotalBytes

public void subtractTotalBytes(long subtractTotalBytes)
Parameters:
subtractTotalBytes -

addTotalFiles

public void addTotalFiles(long addTotalFiles)
Parameters:
addTotalFiles -

subtractTotalFiles

public void subtractTotalFiles(long subtractTotalFiles)
Parameters:
subtractTotalFiles -

getPercentDone

public double getPercentDone()

Returns the percentage of work complete as a number between 0 and 100, e.g. 97.23%

Returns:
Returns a double value that is between 0 and 100.

getHours

public long getHours()

Returns the number of hours left to work. Might be more than 24.

Returns:
Returns a long value that is between 0 and Long.MAX_VALUE.

getMinutes

public long getMinutes()

Returns the number of minutes left to work. Will be 0 through 60.

Returns:
Returns a minutes value that is beteen 0 and 60.

getSeconds

public long getSeconds()

Returns the number of seconds left to work. Will be 0 through 60.

Returns:
Returns a seconds value that is between 0 and 60.

getTimeRunning

public long getTimeRunning()

Get the total time the estimator has been running.

Returns:

getStartTime

public long getStartTime()

Get the time the estimator started.

Returns:

getTimeLeftString

public java.lang.String getTimeLeftString()
Returns:


This code is free for use both commercially and non-commercially as stated in the project's license