Ticks

public final class Ticks


A value type for tracking elapsed time without committing to specific epoch baseline value or relationship to physical seconds, specifically SI seconds.

The value held by a Ticks is a reading from a Ticker, and can be converted to and from a value in seconds. The seconds values calculated may be inaccurate depending on the accuracy and precision of the underlying ticker.

Each object holds a reference to an originTicker which is intended to prevent comparisons between, and calculations using ticks originating from different tickers.

Summary

Public methods

Duration
@RequiresApi(api = VERSION_CODES.O)
durationUntil(Ticks other)

Calculates the Duration between this ticks and another ticks.

boolean
@Nullable Long

Calculates the absolute error estimate between this ticks and another ticks in milliseconds, or null if the error cannot be computed.

Ticker

Returns the Ticker that this ticks originated from.

int
boolean

Returns true if this ticks was generated after the specified ticks.

boolean

Returns true if this ticks was generated before the specified ticks.

long

Returns the duration in milliseconds between this ticks and another ticks.

String

Public methods

durationUntil

@RequiresApi(api = VERSION_CODES.O)
public Duration durationUntil(Ticks other)

Calculates the Duration between this ticks and another ticks.

The accuracy and precision of the Duration will depend on the accuracy and precision of the origin Ticker. If the origin Ticker has low accuracy, the resulting Duration will be inaccurate. If the ticks do not originate from the same ticker, then an IllegalArgumentException is thrown.

Parameters
Ticks other

the other ticks, not null

Returns
Duration

a non null Duration that is the period of time between the two ticks. If this was read after the specified ticks then the return value will be a negative period else it is positive.

Throws
java.lang.IllegalArgumentException

if the ticks do not originate from the same ticker

java.lang.ArithmeticException

if the calculation results in an overflow

equals

public boolean equals(@Nullable Object o)

estimatedErrorMillisUntil

public @Nullable Long estimatedErrorMillisUntil(Ticks other)

Calculates the absolute error estimate between this ticks and another ticks in milliseconds, or null if the error cannot be computed.

This value can be null if the behavior of the local device clock used to track ticks is not yet known, or has been detected to be unpredictable.

Parameters
Ticks other

the other ticks, not null

Throws
java.lang.IllegalArgumentException

if the ticks does not originate from the same ticker

java.lang.ArithmeticException

if the calculation results in an overflow

getOriginTicker

public Ticker getOriginTicker()

Returns the Ticker that this ticks originated from.

hashCode

public int hashCode()

isAfter

public boolean isAfter(Ticks t1)

Returns true if this ticks was generated after the specified ticks. The determination of ordering is dependent on the precision of the origin ticker.

Parameters
Ticks t1

the ticks to compare to

Throws
java.lang.IllegalArgumentException

if the ticks do not originate from the same ticker

isBefore

public boolean isBefore(Ticks t1)

Returns true if this ticks was generated before the specified ticks. The determination of ordering is dependent on the precision of the origin ticker.

Parameters
Ticks t1

the ticks to compare to

Throws
java.lang.IllegalArgumentException

if the ticks do not originate from the same ticker

millisUntil

public long millisUntil(Ticks other)

Returns the duration in milliseconds between this ticks and another ticks.

The accuracy and precision of the duration will depend on the accuracy and precision of the origin Ticker. If the origin Ticker has low accuracy, the resulting duration will be inaccurate. If the ticks do not originate from the same ticker, then an IllegalArgumentException is thrown.

Parameters
Ticks other

the end ticks, not null

Returns
long

a long that is the period of time between the two ticks in milliseconds. If this was read after the specified ticks then the return value will be a negative period else it is positive.

Throws
java.lang.IllegalArgumentException

if the ticks do not originate from the same ticker

java.lang.ArithmeticException

if the calculation results in an overflow

toString

public String toString()