Package com.quanser.common
Class Timeout
java.lang.Object
com.quanser.common.Timeout
Represents an absolute or relative time.
The
Timeout
class represents an absolute time or a relative time interval
down to nanosecond resolution. It is used throughout the Quanser Java classes for
methods that require a timeout.
Because the Timeout
class contains a flag denoting whether the time is
absolute or relative, methods using this class do not require any extra arguments to
differentiate between absolute and relative timeouts. The timeout is considered relative
by default since that is the most common usage.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
Get the total number of milliseconds in the timeout.int
Get the number of nanoseconds in the timeout.long
Get the number of seconds in the timeout.boolean
Returns true if the timeout is absolute.boolean
Returns true if the timeout is negative.boolean
isZero()
Returns true if the timeout is equal to zero.toString()
Get a string representation of the timeout.
-
Constructor Details
-
Timeout
public Timeout()Construct a zero relative timeout. -
Timeout
Construct a copy of the given timeout.- Parameters:
timeout
- TheTimeout
object to copy.
-
Timeout
public Timeout(double seconds) Construct a relative timeout of the given seconds. It has nanosecond resolution.- Parameters:
seconds
- Adouble
scalar indicating the number of seconds in the timeout. The timeout will be relative.
-
-
Method Details
-
getSeconds
public long getSeconds()Get the number of seconds in the timeout. This is only the integral part of the timeout.- Returns:
- Returns the number of seconds in the timeout as a
long
.
-
getNanoseconds
public int getNanoseconds()Get the number of nanoseconds in the timeout. This is only the fractional part of the timeout.- Returns:
- Returns the number of nanoseconds in the timeout as a
int
.
-
isAbsolute
public boolean isAbsolute()Returns true if the timeout is absolute.- Returns:
- Returns
true
if the timeout is absolute andfalse
if it is relative.
-
isNegative
public boolean isNegative()Returns true if the timeout is negative.- Returns:
- Returns
true
if the timeout is negative andfalse
if it is non-strictly positive.
-
isZero
public boolean isZero()Returns true if the timeout is equal to zero.- Returns:
- Returns
true
if the timeout is zero andfalse
otherwise.
-
getMilliseconds
public int getMilliseconds()Get the total number of milliseconds in the timeout. This combines both the seconds and nanoseconds.- Returns:
- Returns the total number of milliseconds in the timeout as an
int
.
-
toString
Get a string representation of the timeout.
-