xbn.util
Class TimerUnits

java.lang.Object
  |
  +--xbn.XBNObject
        |
        +--xbn.util.TimerUnits
Direct Known Subclasses:
TimerSeconds

public class TimerUnits
extends XBNObject

For keeping track of things that have a delay, or expire within a given number of units.

Source code:  TimerUnits.java.  Example code  See the example code for TimerSeconds.


Fields inherited from class xbn.XBNObject
bFALSE_IN_PRODUCTION, bTRUE_IN_PRODUCTION, sCNSTR, sES, sLINE_SEP
 
Constructor Summary
TimerUnits()
          Create a TimerUnits that does not expire.
TimerUnits(long l_millsMultiplier, int i_unitsToExpire)
          Create a TimerUnits.
TimerUnits(long l_millsMultiplier, int i_unitsToExpire, boolean b_crashIfMidStartOrStop)
          Create a TimerUnits.
TimerUnits(long l_millsMultiplier, int i_unitsToExpire, boolean b_crashIfStartStart, boolean b_crashIfStopStop)
          Create a TimerUnits.
 
Method Summary
 boolean doCrashIfStartStart()
          When the timer is already started, is it legal to start it again?
 boolean doCrashIfStopStop()
          When the timer is already stopped, is it legal to stop it again?
 boolean doesExpire()
          Does this timer ever expire?
 Date getDateStarted()
          Get the date representing the moment the timer was started.
 long getMillsMultiplier()
          Get the millesecond multiplier for this TimerUnits.
 long getMillsToExpire()
          Get the number of milleseconds until expiration.
 int getUnitsToExpire()
          Get the total number of units until expiration.
 boolean hasExpired()
          Have the number of units to expiration gone a went?
 boolean isStarted()
          Has the timer been started?
 boolean isStopped()
          Has the timer been stopped?
 void start()
          Start the timer.
 void stop()
          Stop the timer.
 String toString()
          Get some information about this TimerUnits.
 
Methods inherited from class xbn.XBNObject
getXMsgPrefix, sop, sopl, sopl, throwAX, throwAXIfBadStr, throwAXIfNull, throwAXSpoof
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TimerUnits

public TimerUnits()

Create a TimerUnits that does not expire.

Equal to TimerUnits(0, -1)


TimerUnits

public TimerUnits(long l_millsMultiplier,
                  int i_unitsToExpire)

Create a TimerUnits.

Equal to TimerUnits(l_millsMultiplier, i_unitsToExpire, false)


TimerUnits

public TimerUnits(long l_millsMultiplier,
                  int i_unitsToExpire,
                  boolean b_crashIfMidStartOrStop)

Create a TimerUnits.

Equal to TimerUnits(l_millsMultiplier, i_unitsToExpire, b_crashIfMidStartOrStop, b_crashIfMidStartOrStop)


TimerUnits

public TimerUnits(long l_millsMultiplier,
                  int i_unitsToExpire,
                  boolean b_crashIfStartStart,
                  boolean b_crashIfStopStop)

Create a TimerUnits.

Parameters:
l_millsMultiplier - This number times i_unitsToExpire is the number of milleseconds until expiration. See getMillsMultiplier.
i_unitsToExpire - The number of units for the delay/until expiration. If -1, then there is no delay (expiration never occurs). Otherwise, must be greater than or equal to one. See getSeconds.
b_crashIfStartStart - Is it legal to start the timer when already started? See doCrashIfStartStart.
b_crashIfStopStop - Is it legal to stop the timer when already stopped? See doCrashIfStopStop.
Method Detail

start

public void start()

Start the timer. getSeconds, from the moment when this function is called, is when isReady will return true.

See stop.

Throws:
AssertException - If already started and doCrashIfStartStart equals true.

stop

public void stop()

Stop the timer.

See start.

Throws:
AssertException - If already stopped and doCrashIfStopStop equals true.

doCrashIfStartStart

public boolean doCrashIfStartStart()

When the timer is already started, is it legal to start it again?

Returns:
true If it is only legal to start the timer when it is stopped.
false If it is legal to start the timer at any time...even when it is already started.

doCrashIfStopStop

public boolean doCrashIfStopStop()

When the timer is already stopped, is it legal to stop it again?

Returns:
true If it is only legal to stop the timer when it is started.
false If it is legal to stop the timer at any time...even when it is already stopped.

getUnitsToExpire

public int getUnitsToExpire()

Get the total number of units until expiration. This number, multiplied by getMillsMultiplier, is the number of milliseconds until expiration.

This number represents the units from the moment this TimerUnits is started, to the moment it expires. It does not change during the life of this object.


getMillsMultiplier

public long getMillsMultiplier()

Get the millesecond multiplier for this TimerUnits. This number, multiplied by getUnitsToExpire, is the number of milliseconds until expiration.


getMillsToExpire

public long getMillsToExpire()

Get the number of milleseconds until expiration.

Returns:
(getUnitsToExpire() * getMillsMultiplier())

doesExpire

public boolean doesExpire()

Does this timer ever expire?

Returns:
(getUnitsToExpire() != -1)

isStarted

public boolean isStarted()

Has the timer been started?

Returns:
(getDateStarted() != null)

isStopped

public boolean isStopped()

Has the timer been stopped?

Returns:
!isStarted()

getDateStarted

public Date getDateStarted()

Get the date representing the moment the timer was started.

Returns:
A Date If the timer was started.
null If the timer was not started.

hasExpired

public boolean hasExpired()

Have the number of units to expiration gone a went?

When this function returns true, the timer is stopped.

Returns:
true If the timer has not yet been started.
Otherwise return [UtilDate].getNowMinusYUnits(getDateStarted(), getMillsMultiplier()) >= getUnitsToExpire())

toString

public String toString()

Get some information about this TimerUnits.

Overrides:
toString in class Object



Copyright 1997-2003, Jeff Epstein, All Rights Reserved. See top of source code files for copyright notice.

 

http://sourceforge.net/projects/xbnjava

 

SourceForge.net Logo