This class provides an interface into system dependent timer values (usually 64 bit tick counters) that we call ticks. Ticks and this class allow to store and calculate time values in an efficient and highly accurate way.
Ticks generated by this class can be added and subtracted:
Conversion functions to milliseconds, microseconds and nanoseconds accept ticks and span values in ticks in the same manner.
As Ticks are system dependent, they should not be stored in system independent data files or otherwise shared between systems. In general such values should only be used by methods of this class and classes TickWatch and TickSpan.
The resolution and accuracy of the values is platform dependent. Especially nanoseconds are deemed to be not accurate and above 100 ns (this was written and fact in 2013).
Public Static Methods | |
static Ticks | creationTime () |
static long | internalFrequency () |
Public Methods | |
Ticks () | |
Ticks (long ticks) | |
Ticks (Ticks copy) | |
void | add (long value) |
void | add (Ticks other) |
Ticks | age () |
Ticks | age (Ticks result) |
void | fromDays (long days) |
void | fromHours (long hours) |
void | fromMicros (long micros) |
void | fromMillis (long millis) |
void | fromMinutes (long mins) |
void | fromNanos (long nanos) |
void | fromSeconds (long secs) |
boolean | hasElapsed (Ticks waitTime) |
long | inDays () |
long | inEpochMillis () |
double | inHertz () |
double | inHertz (int qtyFractionalDigits) |
long | inHours () |
Calendar | inJavaCalendar (Calendar result) |
Date | inJavaDate (Date result) |
long | inMicros () |
long | inMillis () |
long | inMinutes () |
long | inNanos () |
long | inSeconds () |
long | raw () |
void | set () |
void | set (Ticks other) |
void | setFromEpochMillis (long epochMillis) |
void | setFromJavaCalendar (Calendar javaCalendar) |
void | setFromJavaDate (Date javaDate) |
void | setRaw (long value) |
Ticks | since (Ticks olderTime) |
Ticks | since (Ticks olderTime, Ticks result) |
void | sub (long value) |
void | sub (Ticks other) |
Private Static Fields | |
static long | creationTimeDateMillis |
static Ticks | creationTimeTicks |
static long | internalFrequency |
Protected Fields | |
Ticks | tempTicks |
long | ticks = 0L |
Package Access Static Methods | |
[static initializer] | |
Ticks | ( | ) |
Creates a Ticks instance representing the point in time when this constructor was invoked.
Ticks | ( | long | ticks | ) |
Creates a Ticks instance representing a given time point or time span in ticks.
ticks | The value to copy into this. |
Creates a Ticks instance representing the same point in time or time span as the instance provided.
copy | The instance to copy the ticks value from. |
|
staticpackage |
This static constructor is called once at the beginning of the lifecycle of this library. We use it to get
a) the milliseconds in the epoch in the moment this class was statically initialized b) the system nanoseconds in the moment this class was statically initialized
These values are used later to avoid creating a new Date() object (speed optimization).
void add | ( | long | value | ) |
Adds the point in time or time span represented by the given Ticks instance to this instance.
value | The ticks to add. |
void add | ( | Ticks | other | ) |
Adds the point in time or time span represented by the given Ticks instance to this instance.
other | The instance to add the ticks value from. |
Ticks age | ( | ) |
Returns the time span between value represented by this instance and the current time. If the internal value represents a historic point in time, the result is positive.
Note: Attention: The object returned is a temporary object, deemed to be reused by other interface methods of this instance. Therefore, it must be used only until subsequent method invocations on this instance are performed (hence, also not thread safe!) Use age(Ticks result) to provide a dedicated external result instance.
Returns the time span between value represented by this instance and the current system time. If the internal value represents a historic point in time, the result is positive.
result | The Ticks object to store the result in. If null, this is created. |
|
static |
void fromDays | ( | long | days | ) |
Sets the internal value to a time span provided in seconds.
days | The time span to set in days. |
void fromHours | ( | long | hours | ) |
Sets the internal value to a time span provided in hours.
hours | The time span to set in hours. |
void fromMicros | ( | long | micros | ) |
Sets the internal value to a time span provided in microseconds.
micros | The time span to set in microseconds. |
void fromMillis | ( | long | millis | ) |
Sets the internal value to a time span provided in milliseconds.
millis | The time span to set in milliseconds. |
void fromMinutes | ( | long | mins | ) |
Sets the internal value to a time span provided in minutes.
mins | The time span to set in minutes. |
void fromNanos | ( | long | nanos | ) |
Sets the internal value to a time span provided in nanoseconds.
nanos | The time span to set in nanoseconds. |
void fromSeconds | ( | long | secs | ) |
Sets the internal value to a time span provided in seconds.
secs | The time span to set in seconds. |
boolean hasElapsed | ( | Ticks | waitTime | ) |
Determines if this objects' age is higher than a given time span.
waitTime | A Ticks object representing a time span. |
true
if the given Ticks object representing a time span is smaller or equal than our age. false
otherwise. long inDays | ( | ) |
Converts the internal value to days.
long inEpochMillis | ( | ) |
Converts the internal value into milliseconds since January 1, 1970, 00:00:00 GMT. The conversion is dependent on time zone and system clock setting of the host.
double inHertz | ( | ) |
Returns 1 divided by internal value in seconds, hence the number of Hertz that this Ticks object represents when interpreted as a time span.
double inHertz | ( | int | qtyFractionalDigits | ) |
Returns 1 divided by internal value in seconds, hence the number of Hertz that this Ticks object represents when interpreted as a time span.
qtyFractionalDigits | Number of digits that the return value will be rounded to. Defaults to -1 which means no rounding. |
long inHours | ( | ) |
Converts the internal value to hours.
Calendar inJavaCalendar | ( | Calendar | result | ) |
Converts the internal value to java.util.Calendar. The conversion is dependent on time zone and system clock setting of the host.
result | The java.util.Calendar object to set. If null, this is created. |
Date inJavaDate | ( | Date | result | ) |
Converts the internal value to java.util.Date. The conversion is dependent on time zone and system clock setting of the host.
result | The java.util.Date object to set. If null, this is created. |
long inMicros | ( | ) |
Converts the internal value to microseconds.
long inMillis | ( | ) |
Converts the internal value to milliseconds.
long inMinutes | ( | ) |
Converts the internal value to minutes.
long inNanos | ( | ) |
Converts the internal value to nanoseconds.
long inSeconds | ( | ) |
Converts the internal value to seconds.
|
static |
long raw | ( | ) |
Gets the internally stored system dependent time in ticks.
void set | ( | ) |
Sets the actual point in time as the value of this instance.
void set | ( | Ticks | other | ) |
Sets the point in time or time span represented by this instance to the value represented by the given Ticks instance.
other | The instance to copy the ticks value from. |
void setFromEpochMillis | ( | long | epochMillis | ) |
Sets the internal value by converting the given milliseconds since January 1, 1970, 00:00:00 GMT. The conversion is dependent on time zone and system clock setting of the host.
epochMillis | The milliseconds in the epoch to convert. |
void setFromJavaCalendar | ( | Calendar | javaCalendar | ) |
Sets the internal value by converting the given java.util.Calendar. The conversion is dependent on time zone and system clock setting of the host.
javaCalendar | The java.util.Date object to convert. |
void setFromJavaDate | ( | Date | javaDate | ) |
Sets the internal value by converting the given java.util.Date. The conversion is dependent on time zone and system clock setting of the host.
javaDate | The java.util.Date object to convert. |
void setRaw | ( | long | value | ) |
Sets this objects' value to the value specified in ticks.
value | The number of ticks this object should represent. |
Returns the time span between the value represented by this instance and the given one. If the given Ticks represents an earlier point in time, the result is positive.
Note: Attention: The object returned is a temporary object, deemed to be reused by other interface methods of this instance. Therefore, it must be used only until subsequent method invocations on this instance are performed (hence, also not thread safe!) Use since(Ticks olderTime, Ticks result) to provide a dedicated external result instance.
olderTime | The value to compare this instance with. |
Returns the time span between the value represented by this instance and the given one. If the given Ticks represents an earlier point in time, the result is positive.
olderTime | The value to compare this instance with. |
result | The Ticks object to store the result in. If null, this is created. |
void sub | ( | long | value | ) |
Subtracts the point in time or time span represented by the given Ticks instance from this instance.
value | The ticks to subtract. |
void sub | ( | Ticks | other | ) |
Subtracts the point in time or time span represented by the given Ticks instance from this instance.
other | The instance to subtract the ticks value from. |
|
staticprivate |
The system clock milliseconds at process creation time.
|
staticprivate |
The internal frequency of our timer.
|
protected |
A temporary ticks object. used for as a return value
|
protected |
The value