|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.calendar.Stopwatch
public class Stopwatch
Stopwatch is a convenient implementation to bench just about anything. By default, this class uses the machine's internal clock, but by setting a custom TimeSystem, it can also be clocked by an atomic clock or any other time measurement system.
HourFormat,
Serialized Form| Field Summary |
|---|
| Fields inherited from interface com.antelmann.calendar.Timed |
|---|
COMPARATOR, DATE_EXTRACTOR |
| Constructor Summary | |
|---|---|
Stopwatch()
initializes a running Stopwatch starting now |
|
Stopwatch(boolean isRunning)
If the boolean parameter is true, this call is equivalent to the default constructor; if the parameter is false, the StopWach will be initialized but is halted with no elapsed time so far. |
|
Stopwatch(Date time)
This constructor starts a Stopwatch starting at the given point in time. |
|
Stopwatch(long milliseconds)
This constructor starts a Stopwatch starting at the current time minus the milliseconds given. |
|
Stopwatch(long milliseconds,
boolean isRunning)
|
|
Stopwatch(long milliseconds,
TimeSystem system)
|
|
Stopwatch(Stopwatch timer)
This constructor generates a new Stopwatch synchronized with the given timer |
|
| Method Summary | |
|---|---|
String |
display()
displays the elapsed time as timeAsStringShort(elapsed()) |
long |
elapsed()
returns the elapsed time in milliseconds |
String |
elapsedAsString()
returns a string representing the elapsed time with - if applicable - days, hours, minutes and seconds (down to the milliseconds). |
String |
elapsedAsStringShort()
returns a short string representing the elapsed time with - if applicable - days, hours, minutes and seconds (down to the milliseconds). |
protected long |
getEnd()
|
protected long |
getHalted()
|
Date |
getStartDate()
returns the initial start time of the Stopwatch. |
long |
getStartTime()
returns the time this Stopwatch was constructed or when any of the reset() or restart() methods were called last |
long |
getTime()
|
TimeSystem |
getTimeSystem()
returns the time measurement system in place |
static String |
hourMinuteString(long milliSecs)
formats a String with hours as the largest entity in the format h:mm |
boolean |
isPaused()
returns true if Stopwatch is paused. |
boolean |
isRunning()
returns true if Stopwatch is running. |
static long |
parse(String s)
assumes the format h:m:s; can parse a String created by timeAsStringShort(long) |
void |
pause()
pause() stops the timer and maintains the elapsed time; it does nothing if the timer is already paused. |
void |
reset()
reset() will set the start to the current time and set the halted time to zero. |
void |
reset(long milliseconds)
sets the given time as elapsed time; run/pause status remains and halted time is reset |
void |
restart()
restart() reinitializes the timer equivalent to it just being construced with the default constructor (time is running). |
void |
restart(long milliseconds)
restart() reinitializes the timer with the passed milliseconds interpreted as already elapsed time. |
void |
resume()
resume() will reactivate a suspended timer (suspended through either stop() or pause()). |
void |
setTimeSystem(TimeSystem system)
allows to use a customized measurement for time |
void |
start()
start() maintains the beginning time and sets the elapsed time to zero (through halted time); time will be running. |
long |
stop()
stop() returns the elapsed time and also performs a reset(). |
void |
synchronize(Stopwatch timer)
synchronize() will make this Stopwatch equivalent to the passed timer |
static String |
timeAsHourString(long milliSecs)
formats a String with hours as the largest entity and down to the minute |
static String |
timeAsHourStringShort(long milliSecs)
formats a String with hours as the largest entity in the format h:mm with an 'h' at the end |
static String |
timeAsString(long milliSecs)
|
static String |
timeAsString(long milliSecs,
Locale locale)
takes milliseconds and converts them into a localized String using all relevant time measures from millisecs to days |
static String |
timeAsStringShort(long milliSecs)
takes milliseconds and converts them into a short String of the format h:mm:ss. |
String |
toString()
returns the elapsed time in a convenient format including elapsedAsString() and tells whether the Stopwatch is currently running or not |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Stopwatch()
public Stopwatch(long milliseconds)
public Stopwatch(long milliseconds,
TimeSystem system)
public Stopwatch(Date time)
public Stopwatch(Stopwatch timer)
public Stopwatch(boolean isRunning)
public Stopwatch(long milliseconds,
boolean isRunning)
| Method Detail |
|---|
public void synchronize(Stopwatch timer)
public TimeSystem getTimeSystem()
public void setTimeSystem(TimeSystem system)
public long getStartTime()
public Date getStartDate()
public boolean isPaused()
public boolean isRunning()
public void pause()
public void resume()
public void start()
public long stop()
public void reset()
public void reset(long milliseconds)
public void restart()
public void restart(long milliseconds)
public long elapsed()
public long getTime()
getTime in interface Timedpublic String elapsedAsString()
timeAsString(long)public String elapsedAsStringShort()
timeAsStringShort(long)public String display()
timeAsStringShort(long)public static String timeAsString(long milliSecs)
public static String timeAsString(long milliSecs,
Locale locale)
public static String timeAsStringShort(long milliSecs)
h:mm:ss. As opposed to
SimpleDateFormat, this format will also show the full hours even
though there may be more than 24.
HourFormat
public static long parse(String s)
throws FormatException
timeAsStringShort(long)
FormatExceptionHourFormatpublic static String timeAsHourString(long milliSecs)
public static String timeAsHourStringShort(long milliSecs)
public static String hourMinuteString(long milliSecs)
public String toString()
toString in class Objectprotected long getHalted()
protected long getEnd()
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||