org.nakedobjects.applib.fixtures
Class FixtureClock

java.lang.Object
  extended by org.nakedobjects.applib.clock.Clock
      extended by org.nakedobjects.applib.fixtures.FixtureClock

public class FixtureClock
extends Clock

This clock, for use by fixtures, can be set to specific time.

If not set it will provide the time provided by the system clock.

Note that - by design - it does not provide any mechanism to advance the time (eg automatic ticking of the clock). That is, the time returned is always explicitly under the control of the programmer (it can be moved forward or back as required).


Method Summary
 void addDate(int years, int months, int days)
          Adjusts the time by the specified number of years, months or days.
 void addTime(int hours, int minutes)
          Adjusts the time by the specified number of hours and minutes.
 void clear()
          Sets the clock to epoch, that is midnight, 1 Jan 1970 UTC.
static FixtureClock initialize()
          Configures the system to use a FixtureClock rather than the in-built system clock.
static boolean remove()
          Makes Clock.remove() visible.
 void reset()
          Go back to just returning the system's time.
 void setDate(int year, int month, int day)
          Sets the date, but the time portion is left unchanged.
 void setTime(int hour, int min)
          Sets the hours and minutes as specified, and sets the seconds and milliseconds to zero, but the date portion is left unchanged.
protected  long time()
          Access via Clock.getTime().
 java.lang.String toString()
           
 
Methods inherited from class org.nakedobjects.applib.clock.Clock
getInstance, getTime, getTimeAsCalendar, isInitialized, timeAsCalendar
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

initialize

public static FixtureClock initialize()
Configures the system to use a FixtureClock rather than the in-built system clock. Can be called multiple times.

Must call before any other call to Clock.getInstance().

Throws:
java.lang.IllegalStateException - if Clock singleton already initialized with some other implementation.

remove

public static boolean remove()
Makes Clock.remove() visible.


time

protected long time()
Access via Clock.getTime().

Will just return the system time until setDate(int, int, int) or setTime(int, int) (or one of the overloads) has been called.

Specified by:
time in class Clock

clear

public void clear()
Sets the clock to epoch, that is midnight, 1 Jan 1970 UTC.

This is typically called before either setDate(int, int, int) (so that time is set to midnight) and/or setTime(int, int) (so that date is set to a well known value).


setTime

public void setTime(int hour,
                    int min)
Sets the hours and minutes as specified, and sets the seconds and milliseconds to zero, but the date portion is left unchanged.

See Also:
setDate(int, int, int), addTime(int, int)

setDate

public void setDate(int year,
                    int month,
                    int day)
Sets the date, but the time portion is left unchanged.

See Also:
setTime(int, int), addDate(int, int, int)

addTime

public void addTime(int hours,
                    int minutes)
Adjusts the time by the specified number of hours and minutes.

Typically called after setTime(int, int), to move the clock forward or perhaps back.

See Also:
addDate(int, int, int)

addDate

public void addDate(int years,
                    int months,
                    int days)
Adjusts the time by the specified number of years, months or days.

Typically called after setDate(int, int, int), to move the clock forward or perhaps back.

See Also:
addTime(int, int)

reset

public void reset()
Go back to just returning the system's time.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2001-2009 Naked Objects Group Ltd.. All Rights Reserved.