com.cleancode.time
Class SimpleFormat

java.lang.Object
  extended by com.cleancode.time.SimpleFormat

public class SimpleFormat
extends Object

Provides simple elapsed time formatting.

Since:
CleanCode 0.9.01
Version:
$Revision: 9 $
Author:
Michael Sorens

Constructor Summary
SimpleFormat()
          Creates a nominal SimpleFormat object.
SimpleFormat(int speedup)
          Creates a SimpleFormat object with accelerated time.
 
Method Summary
 long elapsed()
          Returns the elapsed time since object creation as a number.
 Date getEndDate()
          Returns Date object for end of interval.
 Date getStartDate()
          Returns Date object for start of interval.
 boolean isElapsed(long val)
          Indicates whether a given time has passed since object creation.
 void lap()
          Freezes the timer value to be returned.
 String reportElapsed()
          Reports the elapsed time since creation of the SimpleFormat object.
 void resume()
          Release the lock on the timer value set by lap().
 void setFixedFormat()
          Change from minimal format (the default) to fixed format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleFormat

public SimpleFormat()
Creates a nominal SimpleFormat object.


SimpleFormat

public SimpleFormat(int speedup)
Creates a SimpleFormat object with accelerated time. Usually used for debugging purposes, when you wish to see time-related effects without having to wait hours or days.

Parameters:
speedup - time acceleration factor
Method Detail

setFixedFormat

public void setFixedFormat()
Change from minimal format (the default) to fixed format. The default format would represent 180 seconds as "3 minutes" while in fixed format, it would be "3.00 minutes", i.e. always with two decimal places.


reportElapsed

public String reportElapsed()
Reports the elapsed time since creation of the SimpleFormat object. Seconds are reported up to 2 minutes, then minutes are reported up to 2 hours, then hours are reported. reportElapsed reports on the current date at the instant it is called unless you have locked in a value with lap.

Returns:
string of "x.xx minutes" (or seconds or hours as appropriate)

isElapsed

public boolean isElapsed(long val)
Indicates whether a given time has passed since object creation.

Parameters:
val - time to check, in milliseconds
Returns:
status indicating whether time has passed.

elapsed

public long elapsed()
Returns the elapsed time since object creation as a number. elapsed reports on the current date at the instant it is called unless you have locked in a value with lap. If the object has been created with accelerated time (see SimpleFormat(int), this routine reports time multiplied by that acceleration factor.

Returns:
elapsed time in milliseconds

getStartDate

public Date getStartDate()
Returns Date object for start of interval.

Returns:
Date object

getEndDate

public Date getEndDate()
Returns Date object for end of interval. getEndDate reports on the current date at the instant it is called unless you have locked in a value with lap. Also, be aware that, if using a time accelerated object, this endDate is the actual, unmodified one.

Returns:
Date object

lap

public void lap()
Freezes the timer value to be returned. Each call to getEndDate or elapsed will normally report on the time at the current instant. Use this method to lock a value at a given moment in time. That way you can do other processing that you do not wish to be included in the timer results before actually asking for the timer results. (Also, that guarantees that both getEndDate and elapsed will be talking about exactly the same value; otherwise even if called consecutively, they will differ by a miniscule amount.) Use the corresponding resume method to unlock the timer, so that you may get a fresh value later via either getEndDate, elapsed, or lap itself.


resume

public void resume()
Release the lock on the timer value set by lap().



CleanCode Java Libraries Copyright © 2001-2012 Michael Sorens - Revised 2012.12.10 Get CleanCode at SourceForge.net. Fast, secure and Free Open Source software downloads