- java.lang.Object
-
- com.pervasive.datarush.tokens.scalar.PeriodToken
-
- All Implemented Interfaces:
DataToken
,PeriodValued
,ScalarToken
,ScalarValued
,TokenValued
,ScalarTyped
,TokenTyped
,Serializable
,Comparable<PeriodToken>
public final class PeriodToken extends Object implements ScalarToken, Comparable<PeriodToken>
An immutablePeriodValued
object.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static PeriodToken
NULL
A null valuedPeriodToken
static PeriodToken
ZERO
A zero valuedPeriodToken
static Period
ZERO_VALUE
The period zero value,0
.
-
Constructor Summary
Constructors Constructor Description PeriodToken(int years, int months, int days)
Constructs a new token with the given non-null period value.PeriodToken(PeriodValued value)
Constructs a new token with the period value in the given container.PeriodToken(Period value)
Constructs a new token with the given non-null period value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Period
asPeriod()
Gets the contained Period value as ajava.time.Period
.int
compareTo(PeriodToken that)
boolean
equals(Object obj)
Indicates whether another object is equal to this token.int
getDays()
Gets the day portion of the contained period value.int
getMonths()
Gets the month portion of the contained period value.ScalarTokenType
getType()
Gets the data type of the token.int
getYears()
Gets the year portion of the contained period value.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 PeriodToken
parse(String value)
Converts a string representation of a Period value into a token.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 PeriodToken NULL
A null valuedPeriodToken
-
ZERO_VALUE
public static final Period ZERO_VALUE
The period zero value,0
.
-
ZERO
public static final PeriodToken ZERO
A zero valuedPeriodToken
-
-
Constructor Detail
-
PeriodToken
public PeriodToken(PeriodValued value)
Constructs a new token with the period value in the given container.- Parameters:
value
- aPeriodValued
containing the desired value
-
PeriodToken
public PeriodToken(Period value)
Constructs a new token with the given non-null period value. If a null valued token is desired, useNULL
.- Parameters:
value
- the period value of the token
-
PeriodToken
public PeriodToken(int years, int months, int days)
Constructs a new token with the given non-null period value. If a null valued token is desired, useNULL
.- Parameters:
years
- the year portion of the periodmonths
- the month portion of the perioddays
- the day portion of the period
-
-
Method Detail
-
compareTo
public int compareTo(PeriodToken that)
- Specified by:
compareTo
in interfaceComparable<PeriodToken>
-
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 PeriodToken parse(String value)
Converts a string representation of a Period value into a token.- Parameters:
value
- a string value to interpret as period; seePeriod#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.
-
getYears
public int getYears()
Description copied from interface:PeriodValued
Gets the year portion of the contained period value.- Specified by:
getYears
in interfacePeriodValued
- Returns:
- the year portion of the contained value
If null valued, as indicated by
TokenValued.isNull()
,0
is returned.
-
getMonths
public int getMonths()
Description copied from interface:PeriodValued
Gets the month portion of the contained period value. This does not include the year portion.- Specified by:
getMonths
in interfacePeriodValued
- Returns:
- the month portion of the contained value
If null valued, as indicated by
TokenValued.isNull()
,0
is returned.
-
getDays
public int getDays()
Description copied from interface:PeriodValued
Gets the day portion of the contained period value. This does not include the year or month portion.- Specified by:
getDays
in interfacePeriodValued
- Returns:
- the day portion of the contained value
If null valued, as indicated by
TokenValued.isNull()
,0
is returned.
-
asPeriod
public final Period asPeriod()
Description copied from interface:PeriodValued
Gets the contained Period value as ajava.time.Period
.- Specified by:
asPeriod
in interfacePeriodValued
- Returns:
- the contained value as a
java.time.Period
. 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
-
-