com.metsci.glimpse.util.units.time
Class TimeStamp

java.lang.Object
  extended by com.metsci.glimpse.util.units.time.TimeStamp
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<TimeStamp>
Direct Known Subclasses:
TimeStampPosixMicrosInt64, TimeStampPosixMillisInt64, TimeStampPosixSecondsFloat64

public abstract class TimeStamp
extends java.lang.Object
implements java.lang.Comparable<TimeStamp>, java.io.Serializable

Author:
hogye
See Also:
Serialized Form

Field Summary
static TimeStampFormat defaultFormat
          The format used by the convenience methods fromString(String) and toString().
 
Method Summary
abstract  TimeStamp add(double duration)
          Creates a new TimeStamp instance offset from this timestamp by the given amount.
 int compareTo(TimeStamp o)
           
static TimeStamp currentTime()
          Creates a TimeStamp that represents the current system time.
 double durationAfter(TimeStamp o)
          Determines how long after the given timestamp this timestamp is.
 double durationBefore(TimeStamp o)
          Determines how long before the given timestamp this timestamp is.
 boolean equals(java.lang.Object o)
           
static TimeStamp fromCalendar(java.util.Calendar calendar)
          Converts a Calendar to a TimeStamp.
static TimeStamp fromDate(java.util.Date date)
          Converts a Date to a TimeStamp.
static TimeStamp fromPosixMicros(long posixMicros)
          Converts a timestamp in posix microseconds to a TimeStamp.
static TimeStamp fromPosixMillis(long posixMillis)
          Converts a timestamp in posix milliseconds to a TimeStamp.
static TimeStamp fromPosixNanos(long posixNanos)
          Converts a timestamp in posix nanoseconds to a TimeStamp.
static TimeStamp fromPosixSeconds(java.math.BigDecimal posixSeconds)
          Converts a timestamp in posix seconds to a TimeStamp.
static TimeStamp fromPosixSeconds(double posixSeconds)
          Converts a timestamp in posix seconds to a TimeStamp.
static TimeStamp fromString(java.lang.String string)
          Converts a String to a TimeStamp, using defaultFormat.
static TimeStamp fromString(java.lang.String string, TimeStampFormat format)
          Converts a String to a TimeStamp.
static TimeStamp fromTimeStamp(TimeStamp timeStamp)
          Converts a TimeStamp of any subclass to a TimeStamp of the default subclass.
 int hashCode()
           
 boolean isAfter(TimeStamp o)
          Returns true iff this timestamp is after the given timestamp.
 boolean isAfterOrEquals(TimeStamp o)
          Returns true iff this timestamp is after or equal to the given timestamp.
 boolean isBefore(TimeStamp o)
          Returns true iff this timestamp is before the given timestamp.
 boolean isBeforeOrEquals(TimeStamp o)
          Returns true iff this timestamp is before or equal to the given timestamp.
static TimeStamp posixEpoch()
          Returns a TimeStamp that represents the posix epoch.
abstract  TimeStamp subtract(double duration)
          Creates a new TimeStamp instance offset from this timestamp by the given amount.
abstract  java.util.Calendar toCalendar()
          Converts this TimeStamp to a Calendar.
abstract  java.util.Date toDate()
          Converts this TimeStamp to a Date.
abstract  long toPosixMicros()
          Converts this TimeStamp to posix microseconds.
abstract  long toPosixMillis()
          Converts this TimeStamp to posix milliseconds.
abstract  long toPosixNanos()
          Converts this TimeStamp to posix nanoseconds.
abstract  double toPosixSeconds()
          Converts this TimeStamp to posix seconds.
abstract  java.math.BigDecimal toPosixSecondsExact()
          Converts this TimeStamp to posix seconds.
 java.lang.String toString()
          Converts this timestamp to a String, according to defaultFormat.
 java.lang.String toString(TimeStampFormat format)
          Converts this timestamp to a String, according to the given format.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

defaultFormat

public static final TimeStampFormat defaultFormat
The format used by the convenience methods fromString(String) and toString(). It refers to TimeStampFormat.iso8601.

Method Detail

fromPosixSeconds

public static TimeStamp fromPosixSeconds(double posixSeconds)
Converts a timestamp in posix seconds to a TimeStamp.

Parameters:
posixSeconds - seconds since the epoch

fromPosixSeconds

public static TimeStamp fromPosixSeconds(java.math.BigDecimal posixSeconds)
Converts a timestamp in posix seconds to a TimeStamp.

Parameters:
posixSeconds - seconds since the epoch

fromPosixMillis

public static TimeStamp fromPosixMillis(long posixMillis)
Converts a timestamp in posix milliseconds to a TimeStamp.

Parameters:
posixMillis - milliseconds since the epoch

fromPosixMicros

public static TimeStamp fromPosixMicros(long posixMicros)
Converts a timestamp in posix microseconds to a TimeStamp.

Parameters:
posixMicros - microseconds since the epoch

fromPosixNanos

public static TimeStamp fromPosixNanos(long posixNanos)
Converts a timestamp in posix nanoseconds to a TimeStamp.

Parameters:
posixNanos - nanoseconds since the epoch

fromTimeStamp

public static TimeStamp fromTimeStamp(TimeStamp timeStamp)
Converts a TimeStamp of any subclass to a TimeStamp of the default subclass.

Throws:
java.lang.NullPointerException - if argument is null

fromDate

public static TimeStamp fromDate(java.util.Date date)
Converts a Date to a TimeStamp.

Throws:
java.lang.NullPointerException - if argument is null

fromCalendar

public static TimeStamp fromCalendar(java.util.Calendar calendar)
Converts a Calendar to a TimeStamp.

Throws:
java.lang.NullPointerException - if argument is null

fromString

public static TimeStamp fromString(java.lang.String string,
                                   TimeStampFormat format)
                            throws TimeStampParseException
Converts a String to a TimeStamp.

Throws:
java.lang.NullPointerException - if either argument is null
TimeStampParseException - if string parsing fails

fromString

public static TimeStamp fromString(java.lang.String string)
                            throws TimeStampParseException
Converts a String to a TimeStamp, using defaultFormat.

Throws:
java.lang.NullPointerException - if either argument is null
TimeStampParseException - if string parsing fails

posixEpoch

public static TimeStamp posixEpoch()
Returns a TimeStamp that represents the posix epoch.


currentTime

public static TimeStamp currentTime()
Creates a TimeStamp that represents the current system time. The precision may be limited by the precision of Java's access to the system clock.


add

public abstract TimeStamp add(double duration)
Creates a new TimeStamp instance offset from this timestamp by the given amount. The returned instance may or may not be of the same dynamic type as this instance.

Parameters:
duration - the amount of time to add in system-units

subtract

public abstract TimeStamp subtract(double duration)
Creates a new TimeStamp instance offset from this timestamp by the given amount. The returned instance may or may not be of the same dynamic type as this instance.

Parameters:
duration - the amount of time to subtract in system-units

durationBefore

public double durationBefore(TimeStamp o)
Determines how long before the given timestamp this timestamp is. That is: durationBefore = other - this In the base-class implementation, arithmetic is done with BigDecimal. This is quite effective at minimizing rounding error, but may be slow compared to primitive arithmetic.

Returns:
the difference, in system-units
Throws:
java.lang.NullPointerException - if argument is null

durationAfter

public double durationAfter(TimeStamp o)
Determines how long after the given timestamp this timestamp is. That is: durationAfter = this - other In the base-class implementation, arithmetic is done with BigDecimal. This is quite effective at minimizing rounding error, but may be slow compared to primitive arithmetic.

Returns:
the difference, in system-units
Throws:
java.lang.NullPointerException - if argument is null

toPosixSeconds

public abstract double toPosixSeconds()
Converts this TimeStamp to posix seconds.

Returns:
seconds since the epoch

toPosixMillis

public abstract long toPosixMillis()
Converts this TimeStamp to posix milliseconds.

Returns:
milliseconds since the epoch

toPosixMicros

public abstract long toPosixMicros()
Converts this TimeStamp to posix microseconds.

Returns:
microseconds since the epoch

toPosixNanos

public abstract long toPosixNanos()
Converts this TimeStamp to posix nanoseconds.

Returns:
nanoseconds since the epoch

toDate

public abstract java.util.Date toDate()
Converts this TimeStamp to a Date.


toCalendar

public abstract java.util.Calendar toCalendar()
Converts this TimeStamp to a Calendar.


toPosixSecondsExact

public abstract java.math.BigDecimal toPosixSecondsExact()
Converts this TimeStamp to posix seconds. The returned representation is exact (see note). NOTE: In theory, it is possible to have a subclass that stores its value in a form that cannot be exactly converted to a BigDecimal (e.g., thirds of a second). Such subclasses are discouraged. If such a subclass is unavoidable, its documentation must note prominently that it breaks the contract of the TimeStamp interface, and its implementation of this method must return values as exact as is practical.

Returns:
seconds since the epoch

isBefore

public boolean isBefore(TimeStamp o)
Returns true iff this timestamp is before the given timestamp.

Throws:
java.lang.NullPointerException - if argument is null

isBeforeOrEquals

public boolean isBeforeOrEquals(TimeStamp o)
Returns true iff this timestamp is before or equal to the given timestamp.

Throws:
java.lang.NullPointerException - if argument is null

isAfter

public boolean isAfter(TimeStamp o)
Returns true iff this timestamp is after the given timestamp.

Throws:
java.lang.NullPointerException - if argument is null

isAfterOrEquals

public boolean isAfterOrEquals(TimeStamp o)
Returns true iff this timestamp is after or equal to the given timestamp.

Throws:
java.lang.NullPointerException - if argument is null

compareTo

public int compareTo(TimeStamp o)
Specified by:
compareTo in interface java.lang.Comparable<TimeStamp>

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString(TimeStampFormat format)
Converts this timestamp to a String, according to the given format.


toString

public java.lang.String toString()
Converts this timestamp to a String, according to defaultFormat.

Overrides:
toString in class java.lang.Object


Copyright © 2012 Metron, Inc.. All Rights Reserved.