Ticks

Kotlin|Java

public final classTicks


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 aTicks is a reading from aTicker, 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 underlyingticker.

Each object holds a reference to anoriginTicker which is intended to prevent comparisons between, and calculations usingticks originating from differenttickers.

Summary

Public methods

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

Calculates theDuration between this ticks and another ticks.

boolean
@NullableLong

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

Ticker

Returns theTicker that this ticks originated from.

int
boolean

Returnstrue if this ticks was generated after the specified ticks.

boolean

Returnstrue 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 theDuration between this ticks and another ticks.

The accuracy and precision of theDuration will depend on the accuracy and precision of the originTicker. If the originTicker has low accuracy, the resultingDuration will be inaccurate. If the ticks do not originate from the same ticker, then anIllegalArgumentException is thrown.

Parameters
Ticks other

the other ticks, not null

Returns
Duration

a non nullDuration 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(@NullableObject o)

estimatedErrorMillisUntil

public @NullableLong estimatedErrorMillisUntil(Ticks other)

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

This value can benull 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 theTicker that this ticks originated from.

hashCode

public int hashCode()

isAfter

public boolean isAfter(Ticks t1)

Returnstrue 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)

Returnstrue 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 originTicker. If the originTicker has low accuracy, the resulting duration will be inaccurate. If the ticks do not originate from the same ticker, then anIllegalArgumentException 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()

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-12-10 UTC.