Class DateToken

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 immutable DateValued object.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final DateToken
    A null valued DateToken
    static final DateToken
    A zero valued DateToken
    static final long
    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).
    Constructs a new token with the non-null calendar date.
    Constructs a new token with the date value in the given container.
    Deprecated.
    since 6.1
    DateToken(Date date, ZoneId zoneId)
    Deprecated. 
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the contained date value.
    final Date
    Gets the contained date value as a java.sql.Date relative to the default time zone.
    final Date
    asDate(ZoneId zoneId)
    Gets the contained date value as a java.sql.Date relative to the given time zone.
    final long
    Gets the contained date value as the number of days since Java epoch (January 1, 1970).
    int
     
    boolean
    Indicates whether another object is equal to this token.
    Gets the data type of the token.
    int
    Returns a hash code for the token.
    final boolean
    Indicates whether the token is null valued.
    final boolean
    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.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface com.pervasive.datarush.tokens.DataToken

    toString

    Methods inherited from interface com.pervasive.datarush.tokens.scalar.ScalarValued

    getType, isZero

    Methods inherited from interface com.pervasive.datarush.tokens.TokenValued

    isNull
  • Field Details

    • NULL

      public static final DateToken NULL
      A null valued DateToken
    • ZERO_VALUE

      public static final long ZERO_VALUE
      The date representing a zero value, the beginning of Java epoch January 1, 1970.
      See Also:
    • ZERO

      public static final DateToken ZERO
      A zero valued DateToken
  • Constructor Details

    • DateToken

      public DateToken(DateValued value)
      Constructs a new token with the date value in the given container.
      Parameters:
      value - a DateValued 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, use NULL.
      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, use NULL.
      Parameters:
      year - the year portion of the calendar date
      monthOfYear - the month portion of the calendar date. Months start from 1, unlike java.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, use NULL.
      Parameters:
      date - the calendar date of the token
    • DateToken

      @Deprecated public DateToken(Date date)
      Deprecated.
      since 6.1
      Constructs a new token with the non-null date value specified as a java.util.Date object. The date is interpreted relative to the default zone id as returned by ZoneId.systemDefault(). If a null valued token is desired, use NULL.
      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, ZoneId zoneId)
      Deprecated.
      Constructs a new token with the non-null date value specified as a java.util.Date object interpreted relative to the given time zone. If a null valued token is desired, use NULL.
      Parameters:
      date - the date value of the token, expressed as a point in time relative to the specified time zone
      zoneId - the time zone id in which the date should be interpreted
  • Method Details

    • 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 of TokenComparator.equal(TokenValued,TokenValued) but makes it possible to store DataTokens in Maps.
      Specified by:
      equals in interface DataToken
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare
      Returns:
      true if the other object is a token of the same type and contains the same value, false otherwise.
    • 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 by TokenConverter.asHashCode(TokenValued).
      Specified by:
      hashCode in interface DataToken
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value for the token
    • compareTo

      public int compareTo(DateToken that)
      Specified by:
      compareTo in interface Comparable<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 interface ScalarTyped
      Specified by:
      getType in interface ScalarValued
      Specified by:
      getType in interface TokenTyped
      Specified by:
      getType in interface TokenValued
      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 interface DateValued
      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 a java.sql.Date relative to the default time zone. The time zone id used by {@link ZoneId.systemDefault()} is used.
      Specified by:
      asDate in interface DateValued
      Returns:
      the contained value as a java.sql.Date. If null valued, as indicated by TokenValued.isNull(), null is returned.
    • asDate

      public final Date asDate(ZoneId zoneId)
      Description copied from interface: DateValued
      Gets the contained date value as a java.sql.Date relative to the given time zone.
      Specified by:
      asDate in interface DateValued
      Parameters:
      zoneId - the time zone id in which to interpret the date
      Returns:
      the contained value as a java.sql.Date. If null valued, as indicated by TokenValued.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 interface DateValued
      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 interface ScalarValued
      Returns:
      true if the value is the zero value, false otherwise.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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 interface TokenValued
      Returns:
      true if the token is null valued, false otherwise