- java.lang.Object
-
- com.pervasive.datarush.tokens.scalar.DateToken
-
- All Implemented Interfaces:
DataToken
,DateValued
,ScalarToken
,ScalarValued
,TokenValued
,ScalarTyped
,TokenTyped
,Serializable
,Comparable<DateToken>
public final class DateToken extends Object implements ScalarToken, Comparable<DateToken>
An immutableDateValued
object.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static DateToken
NULL
A null valuedDateToken
static DateToken
ZERO
A zero valuedDateToken
static long
ZERO_VALUE
The date representing a zero value, the beginning of Java epoch January 1, 1970.
-
Constructor Summary
Constructors Constructor Description DateToken(int year, int monthOfYear, int dayOfMonth)
Constructs a new token with the non-null calendar date.DateToken(long epochDays)
Constructs a new token with the non-null date value specified as the number of days since Java epoch (January 1, 1970 GMT).DateToken(CalendarDate date)
Constructs a new token with the non-null calendar date.DateToken(DateValued value)
Constructs a new token with the date value in the given container.DateToken(Date date)
Deprecated.since 6.1DateToken(Date date, TimeZone tz)
Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CalendarDate
asCalendarDate()
Gets the contained date value.Date
asDate()
Gets the contained date value as ajava.sql.Date
relative to the default time zone.Date
asDate(TimeZone tz)
Gets the contained date value as ajava.sql.Date
relative to the given time zone.long
asEpochDays()
Gets the contained date value as the number of days since Java epoch (January 1, 1970).int
compareTo(DateToken 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 DateToken
parse(String value)
Converts a string representation of a date 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 DateToken NULL
A null valuedDateToken
-
ZERO_VALUE
public static final long ZERO_VALUE
The date representing a zero value, the beginning of Java epoch January 1, 1970.- See Also:
- Constant Field Values
-
ZERO
public static final DateToken ZERO
A zero valuedDateToken
-
-
Constructor Detail
-
DateToken
public DateToken(DateValued value)
Constructs a new token with the date value in the given container.- Parameters:
value
- aDateValued
containing the desired value
-
DateToken
public DateToken(long epochDays)
Constructs a new token with the non-null date value specified as the number of days since Java epoch (January 1, 1970 GMT). If a null valued token is desired, useNULL
.- Parameters:
epochDays
- the date value of the token, expressed as the number of days since Java epoch
-
DateToken
public DateToken(int year, int monthOfYear, int dayOfMonth)
Constructs a new token with the non-null calendar date. If a null valued token is desired, useNULL
.- Parameters:
year
- the year portion of the calendar datemonthOfYear
- the month portion of the calendar date. Months start from1
, unlikejava.util.Calendar
.dayOfMonth
- the day portion of the calendar date.
-
DateToken
public DateToken(CalendarDate date)
Constructs a new token with the non-null calendar date. If a null valued token is desired, useNULL
.- Parameters:
date
- the calendar date of the token
-
DateToken
@Deprecated public DateToken(Date date)
Deprecated.since 6.1Constructs a new token with the non-null date value specified as ajava.util.Date
object. The date is interpreted relative to the default time zone as returned byTimeZone.getDefault()
. If a null valued token is desired, useNULL
.- Parameters:
date
- the date value of the token, expressed as a point in time relative to the default time zone
-
DateToken
@Deprecated public DateToken(Date date, TimeZone tz)
Deprecated.Constructs a new token with the non-null date value specified as ajava.util.Date
object interpreted relative to the given time zone. If a null valued token is desired, useNULL
.- Parameters:
date
- the date value of the token, expressed as a point in time relative to the specified time zonetz
- the time zone in which the date should be interpreted
-
-
Method Detail
-
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)
.
-
compareTo
public int compareTo(DateToken that)
- Specified by:
compareTo
in interfaceComparable<DateToken>
-
parse
public static DateToken parse(String value)
Converts a string representation of a date value into a token.- Parameters:
value
- a string value to interpret as a date; this must be in ISO8601 format.- 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.
-
asEpochDays
public final long asEpochDays()
Description copied from interface:DateValued
Gets the contained date value as the number of days since Java epoch (January 1, 1970).- Specified by:
asEpochDays
in interfaceDateValued
- Returns:
- the contained value as days since Java epoch.
If null valued, as indicated by
TokenValued.isNull()
,0
is returned.
-
asDate
public final Date asDate()
Description copied from interface:DateValued
Gets the contained date value as ajava.sql.Date
relative to the default time zone. The time zone used byTimeZone.getDefault()
is used.- Specified by:
asDate
in interfaceDateValued
- Returns:
- the contained value as a
java.sql.Date
. If null valued, as indicated byTokenValued.isNull()
,null
is returned.
-
asDate
public final Date asDate(TimeZone tz)
Description copied from interface:DateValued
Gets the contained date value as ajava.sql.Date
relative to the given time zone.- Specified by:
asDate
in interfaceDateValued
- Parameters:
tz
- the time zone in which to interpret the date- Returns:
- the contained value as a
java.sql.Date
. If null valued, as indicated byTokenValued.isNull()
,null
is returned.
-
asCalendarDate
public final CalendarDate asCalendarDate()
Description copied from interface:DateValued
Gets the contained date value. This value represents the timezone free date portion of a timestamp.- Specified by:
asCalendarDate
in interfaceDateValued
- Returns:
- the contained value as a calendar date.
If null valued, as indicated by
TokenValued.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
-
-