ALox  V. 2402 R. 0
Home ALox for C++ ALox for C# ALox for Java Download
Public Static Methods | Public Methods | Private Static Fields | Protected Fields | Package Access Static Methods | List of all members
Ticks Class Reference
Collaboration diagram for Ticks:
[legend]

Class Description


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]
 

Constructor & Destructor Documentation

◆ Ticks() [1/3]

Ticks ( )

Creates a Ticks instance representing the point in time when this constructor was invoked.

◆ Ticks() [2/3]

Ticks ( long  ticks)

Creates a Ticks instance representing a given time point or time span in ticks.

Parameters
ticksThe value to copy into this.

◆ Ticks() [3/3]

Ticks ( Ticks  copy)

Creates a Ticks instance representing the same point in time or time span as the instance provided.

Parameters
copyThe instance to copy the ticks value from.

Member Function Documentation

◆ [static initializer]()

[static initializer] ( )
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).

◆ add() [1/2]

void add ( long  value)

Adds the point in time or time span represented by the given Ticks instance to this instance.

Parameters
valueThe ticks to add.

◆ add() [2/2]

void add ( Ticks  other)

Adds the point in time or time span represented by the given Ticks instance to this instance.

Parameters
otherThe instance to add the ticks value from.

◆ age() [1/2]

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 age of this instance, stored in a temporary object, not thread safe object.

◆ age() [2/2]

Ticks age ( Ticks  result)

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.

Parameters
resultThe Ticks object to store the result in. If null, this is created.
Returns
The age of this instance, stored in the given or created object.

◆ creationTime()

static Ticks creationTime ( )
static

Returns
The point in time when the ticker library (ALIB) was initialized. This might be useful to measure the time since the process was started.

◆ fromDays()

void fromDays ( long  days)

Sets the internal value to a time span provided in seconds.

Parameters
daysThe time span to set in days.

◆ fromHours()

void fromHours ( long  hours)

Sets the internal value to a time span provided in hours.

Parameters
hoursThe time span to set in hours.

◆ fromMicros()

void fromMicros ( long  micros)

Sets the internal value to a time span provided in microseconds.

Parameters
microsThe time span to set in microseconds.

◆ fromMillis()

void fromMillis ( long  millis)

Sets the internal value to a time span provided in milliseconds.

Parameters
millisThe time span to set in milliseconds.

◆ fromMinutes()

void fromMinutes ( long  mins)

Sets the internal value to a time span provided in minutes.

Parameters
minsThe time span to set in minutes.

◆ fromNanos()

void fromNanos ( long  nanos)

Sets the internal value to a time span provided in nanoseconds.

Parameters
nanosThe time span to set in nanoseconds.

◆ fromSeconds()

void fromSeconds ( long  secs)

Sets the internal value to a time span provided in seconds.

Parameters
secsThe time span to set in seconds.

◆ hasElapsed()

boolean hasElapsed ( Ticks  waitTime)

Determines if this objects' age is higher than a given time span.

Parameters
waitTimeA Ticks object representing a time span.
Returns
true if the given Ticks object representing a time span is smaller or equal than our age. false otherwise.

◆ inDays()

long inDays ( )

Converts the internal value to days.

Returns
The internal value converted to days.

◆ inEpochMillis()

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.

Returns
Milliseconds in the epoch.

◆ inHertz() [1/2]

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.

Returns
A double value representing the frequency in hertz.

◆ inHertz() [2/2]

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.

Parameters
qtyFractionalDigitsNumber of digits that the return value will be rounded to. Defaults to -1 which means no rounding.
Returns
A double value representing the frequency in hertz.

◆ inHours()

long inHours ( )

Converts the internal value to hours.

Returns
The internal value converted to hours.

◆ inJavaCalendar()

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.

Parameters
resultThe java.util.Calendar object to set. If null, this is created.
Returns
The date object given or created.

◆ inJavaDate()

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.

Parameters
resultThe java.util.Date object to set. If null, this is created.
Returns
The date object given or created.

◆ inMicros()

long inMicros ( )

Converts the internal value to microseconds.

Returns
The internal value converted to microseconds.

◆ inMillis()

long inMillis ( )

Converts the internal value to milliseconds.

Returns
The internal value converted to milliseconds.

◆ inMinutes()

long inMinutes ( )

Converts the internal value to minutes.

Returns
The internal value converted to minutes.

◆ inNanos()

long inNanos ( )

Converts the internal value to nanoseconds.

Returns
The internal value converted to nanoseconds.

◆ inSeconds()

long inSeconds ( )

Converts the internal value to seconds.

Returns
The internal value converted to seconds.

◆ internalFrequency()

static long internalFrequency ( )
static

Returns
The Frequency of the internal tick timer. The Frequency gives you an indication of the accuracy of the time (At least if the underlying system library is reasonably well working in this respect). And this is the reason why it is published with this field. This value does not necessarily correspond to the number of ticks per second that you get from this classes raw() method. (Well, in the Java implementation of ALIB it currently does.)

◆ raw()

long raw ( )

Gets the internally stored system dependent time in ticks.

Returns
The internal value

◆ set() [1/2]

void set ( )

Sets the actual point in time as the value of this instance.

◆ set() [2/2]

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.

Parameters
otherThe instance to copy the ticks value from.

◆ setFromEpochMillis()

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.

Parameters
epochMillisThe milliseconds in the epoch to convert.

◆ setFromJavaCalendar()

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.

Parameters
javaCalendarThe java.util.Date object to convert.

◆ setFromJavaDate()

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.

Parameters
javaDateThe java.util.Date object to convert.

◆ setRaw()

void setRaw ( long  value)

Sets this objects' value to the value specified in ticks.

Parameters
valueThe number of ticks this object should represent.

◆ since() [1/2]

Ticks since ( Ticks  olderTime)

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.

Parameters
olderTimeThe value to compare this instance with.
Returns
The calculated time span, stored in a temporary object, not tread safe object.

◆ since() [2/2]

Ticks since ( Ticks  olderTime,
Ticks  result 
)

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.

Parameters
olderTimeThe value to compare this instance with.
resultThe Ticks object to store the result in. If null, this is created.
Returns
The calculated time span, stored in the given or created object.

◆ sub() [1/2]

void sub ( long  value)

Subtracts the point in time or time span represented by the given Ticks instance from this instance.

Parameters
valueThe ticks to subtract.

◆ sub() [2/2]

void sub ( Ticks  other)

Subtracts the point in time or time span represented by the given Ticks instance from this instance.

Parameters
otherThe instance to subtract the ticks value from.

Member Data Documentation

◆ creationTimeDateMillis

long creationTimeDateMillis
staticprivate

The system clock milliseconds at process creation time.

◆ creationTimeTicks

Ticks creationTimeTicks
staticprivate

Ticks at process initialization.

◆ internalFrequency

long internalFrequency
staticprivate

The internal frequency of our timer.

◆ tempTicks

Ticks tempTicks
protected

A temporary ticks object. used for as a return value

◆ ticks

long ticks = 0L
protected

The value


The documentation for this class was generated from the following file: