- java.lang.Object
-
- com.pervasive.datarush.tokens.scalar.DurationToken
-
- All Implemented Interfaces:
DataToken
,DurationValued
,ScalarToken
,ScalarValued
,TokenValued
,ScalarTyped
,TokenTyped
,Serializable
,Comparable<DurationToken>
public final class DurationToken extends Object implements ScalarToken, Comparable<DurationToken>
An immutableDurationValued
object.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static DurationToken
NULL
A null valuedDurationToken
static DurationToken
ZERO
A zero valuedDurationToken
static Duration
ZERO_VALUE
The duration zero value,0
.
-
Constructor Summary
Constructors Constructor Description DurationToken(long seconds, int nanos)
Constructs a new token with the given non-null duration value.DurationToken(DurationValued value)
Constructs a new token with the duration value in the given container.DurationToken(Duration value)
Constructs a new token with the given non-null duration value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Duration
asDuration()
Gets the contained Duration value as ajava.time.Duration
.long
asSeconds()
Get the contained duration value as the number of seconds.int
compareTo(DurationToken that)
boolean
equals(Object obj)
Indicates whether another object is equal to this token.ScalarTokenType
getType()
Gets the data type of the token.int
hashCode()
Returns a hash code for the token.boolean
isNull()
Indicates whether the token is null valued.boolean
isZero()
Indicates whether the value is the zero value for the type.static DurationToken
parse(String value)
Converts a string representation of a Duration value into a token.int
subsecNanos()
Get the subsecond portion of the contained duration value.String
toString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.pervasive.datarush.tokens.scalar.ScalarValued
getType, isZero
-
Methods inherited from interface com.pervasive.datarush.tokens.TokenValued
isNull
-
-
-
-
Field Detail
-
NULL
public static final DurationToken NULL
A null valuedDurationToken
-
ZERO_VALUE
public static final Duration ZERO_VALUE
The duration zero value,0
.
-
ZERO
public static final DurationToken ZERO
A zero valuedDurationToken
-
-
Constructor Detail
-
DurationToken
public DurationToken(DurationValued value)
Constructs a new token with the duration value in the given container.- Parameters:
value
- aDurationValued
containing the desired value
-
DurationToken
public DurationToken(Duration value)
Constructs a new token with the given non-null duration value. If a null valued token is desired, useNULL
.- Parameters:
value
- the duration value of the token
-
DurationToken
public DurationToken(long seconds, int nanos)
Constructs a new token with the given non-null duration value. If a null valued token is desired, useNULL
.- Parameters:
seconds
- the second portion of the durationnanos
- the subsecond portion of the duration
-
-
Method Detail
-
compareTo
public int compareTo(DurationToken that)
- Specified by:
compareTo
in interfaceComparable<DurationToken>
-
equals
public boolean equals(Object obj)
Description copied from interface:DataToken
Indicates whether another object is equal to this token. Two null valued tokens are considered equal. This differs from the behavior ofTokenComparator.equal(TokenValued,TokenValued)
but makes it possible to storeDataToken
s inMap
s.
-
hashCode
public int hashCode()
Description copied from interface:DataToken
Returns a hash code for the token. This value is guaranteed to be consistent with that returned byTokenConverter.asHashCode(TokenValued)
.
-
parse
public static DurationToken parse(String value)
Converts a string representation of a Duration value into a token.- Parameters:
value
- a string value to interpret as duration; seeDuration#parse(String)
- Returns:
- a token with the specified value
-
getType
public final ScalarTokenType getType()
Description copied from interface:TokenValued
Gets the data type of the token. This type will dictate the valid values that can be contained.- Specified by:
getType
in interfaceScalarTyped
- Specified by:
getType
in interfaceScalarValued
- Specified by:
getType
in interfaceTokenTyped
- Specified by:
getType
in interfaceTokenValued
- Returns:
- the token type.
-
asSeconds
public long asSeconds()
Description copied from interface:DurationValued
Get the contained duration value as the number of seconds.- Specified by:
asSeconds
in interfaceDurationValued
- Returns:
- the contained value as seconds.
If null valued, as indicated by
TokenValued.isNull()
,0
is returned. - See Also:
DurationValued.subsecNanos()
-
subsecNanos
public int subsecNanos()
Description copied from interface:DurationValued
Get the subsecond portion of the contained duration value.- Specified by:
subsecNanos
in interfaceDurationValued
- Returns:
- the subsecond portion of the contained value, in
nanoseconds. If null valued, as indicated by
TokenValued.isNull()
,0
is returned. - See Also:
DurationValued.asSeconds()
-
asDuration
public final Duration asDuration()
Description copied from interface:DurationValued
Gets the contained Duration value as ajava.time.Duration
.- Specified by:
asDuration
in interfaceDurationValued
- Returns:
- the contained value as a
java.time.Duration
. If null valued, as indicated byTokenValued.isNull()
,null
is returned.
-
isZero
public final boolean isZero()
Description copied from interface:ScalarValued
Indicates whether the value is the zero value for the type. Zero values are not stored in sparse representation formats.- Specified by:
isZero
in interfaceScalarValued
- Returns:
true
if the value is the zero value,false
otherwise.
-
isNull
public final boolean isNull()
Description copied from interface:TokenValued
Indicates whether the token is null valued. Tokens support null values analogous to SQL. Before accessing the value of the container, it is usually best to ensure it is not null valued using this method.- Specified by:
isNull
in interfaceTokenValued
- Returns:
true
if the token is null valued,false
otherwise
-
-