xmlBlaster 2.2.0 client API

org.xmlBlaster.util
Class Timestamp

java.lang.Object
  extended by org.xmlBlaster.util.Timestamp
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable
Direct Known Subclasses:
QueueEntryId, RcvTimestamp

public class Timestamp
extends java.lang.Object
implements java.lang.Comparable, java.io.Serializable

High performing timestamp class, time elapsed since 1970, the nanos are simulated as a unique counter.
The counter is rewound on any millisecond step.
Timestamp objects are immutable - a Timstamp can not be changed once it is created.
Guarantees that any created Timestamp instance is unique in the current Java Virtual Machine (and Classloader).

Fails only if

A typical output is:
Performance hints (600 MHz Intel PC, Linux 2.4.10, JDK 1.3.1):
XML representation:
  <timestamp nanos='1013346248150000001'>
     2002-02-10 14:04:08.150000001
  </timestamp>
 
or
  <timestamp nanos='1013346248150000001'/>
 

Author:
Marcel Ruff
See Also:
org.xmlBlaster.test.classtest.TimestampTest, Serialized Form

Field Summary
static int BILLION
           
static int MILLION
           
protected  java.lang.String tagName
          You may overwrite the tag name for XML dumps in derived classes, defaults to <timestamp ...
 
Constructor Summary
Timestamp()
          Constructs a current timestamp which is guaranteed to be unique in time for this JVM
Timestamp(long nanos)
          Create a Timestamp with given nanoseconds since 1970
 
Method Summary
 int compareTo(java.lang.Object obj)
          Compares two Timestamps for ordering.
 boolean equals(java.lang.Object obj)
          Compares this object against the specified object.
 boolean equals(Timestamp ts)
          Tests to see if this Timestamp object is equal to the given Timestamp object.
 long getMillis()
          You can use this value for java.util.Date(millis)
 int getMillisOnly()
          The milli part only
 int getNanosOnly()
          The nano part only
 long getTime()
          You can use this value for java.util.Date(millis)
 long getTimestamp()
           
 java.lang.Long getTimestampLong()
          We cache a Long object for reuse (helpful when used as a key in a map).
static void main(java.lang.String[] args)
          Test only.
static java.lang.String millisToNice(long millis)
          Convert milliseconds to some more human readable representation.
static void sleep(long millis)
          Stop execution for some given milliseconds.
 java.lang.String toString()
          Timestamp in JDBC Timestamp escape format (human readable).
 java.lang.String toXml()
           
 java.lang.String toXml(java.lang.String extraOffset)
           
 java.lang.String toXml(java.lang.String extraOffset, boolean literal)
          Dump state of this object into a XML ASCII string.
static Timestamp valueOf(java.lang.String s)
          Converts a String object in JDBC timestamp escape format to a Timestamp value.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MILLION

public static final int MILLION
See Also:
Constant Field Values

BILLION

public static final int BILLION
See Also:
Constant Field Values

tagName

protected java.lang.String tagName
You may overwrite the tag name for XML dumps in derived classes, defaults to <timestamp ...

Constructor Detail

Timestamp

public Timestamp()
Constructs a current timestamp which is guaranteed to be unique in time for this JVM

Throws:
java.lang.RuntimeException - on overflow (never happens :-=)

Timestamp

public Timestamp(long nanos)
Create a Timestamp with given nanoseconds since 1970

See Also:
Date
Method Detail

getTimestamp

public final long getTimestamp()
Returns:
The exact timestamp in nanoseconds

getTimestampLong

public final java.lang.Long getTimestampLong()
We cache a Long object for reuse (helpful when used as a key in a map).

Returns:
The exact timestamp in nanoseconds

getNanosOnly

public final int getNanosOnly()
The nano part only

Returns:
The nano part only

getMillisOnly

public final int getMillisOnly()
The milli part only

Returns:
The milli part only

getMillis

public final long getMillis()
You can use this value for java.util.Date(millis)

Returns:
Rounded to millis
See Also:
getTime(), Date

getTime

public final long getTime()
You can use this value for java.util.Date(millis)

Returns:
Rounded to millis
See Also:
getMillis(), Date

toString

public java.lang.String toString()
Timestamp in JDBC Timestamp escape format (human readable).

Overrides:
toString in class java.lang.Object
Returns:
The Timestamp in JDBC Timestamp escape format: "2002-02-10 10:52:40.879456789"

valueOf

public static Timestamp valueOf(java.lang.String s)
Converts a String object in JDBC timestamp escape format to a Timestamp value.

Parameters:
s - timestamp in format yyyy-mm-dd hh:mm:ss.fffffffff
Returns:
corresponding Timestamp value
Throws:
java.lang.IllegalArgumentException - if the given argument does not have the format yyyy-mm-dd hh:mm:ss.fffffffff

compareTo

public int compareTo(java.lang.Object obj)
Compares two Timestamps for ordering.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
ts - The Timestamp to be compared.
Returns:
the value 0 if the argument Timestamp is equal to this Timestamp; a value less than 0 if this Timestamp is before the Timestamp argument; and a value greater than 0 if this Timestamp is after the Timestamp argument.

equals

public boolean equals(Timestamp ts)
Tests to see if this Timestamp object is equal to the given Timestamp object.

Parameters:
stamp - the Timestamp value to compare with
Returns:
true if the given Timestamp object is equal to this Timestamp object; false otherwise

equals

public boolean equals(java.lang.Object obj)
Compares this object against the specified object. The result is true if and only if the argument is not null and is a Long object that contains the same long value as this object.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to compare with.
Returns:
true if the objects are the same; false otherwise.

toXml

public final java.lang.String toXml()
Returns:
internal state of the Timestamp as an XML ASCII string

toXml

public final java.lang.String toXml(java.lang.String extraOffset)
Returns:
internal state of the Timestamp as an XML ASCII string without human readable JDBC formatting

toXml

public final java.lang.String toXml(java.lang.String extraOffset,
                                    boolean literal)
Dump state of this object into a XML ASCII string.

Parameters:
extraOffset - indenting of tags for nice output
literal - true -> show human readable format as well (JDBC escape format) "2002-02-10 10:52:40.879456789"
Returns:
internal state of the Timestamp as a XML ASCII string

millisToNice

public static final java.lang.String millisToNice(long millis)
Convert milliseconds to some more human readable representation.

Parameters:
millis - An amount of elapsed milliseconds
Returns:
A human readable time string

sleep

public static void sleep(long millis)
Stop execution for some given milliseconds. Returns earlier on Interrupted exception

Parameters:
millis - amount of milliseconds to wait

main

public static void main(java.lang.String[] args)
Test only.
 javac -g -d $XMLBLASTER_HOME/classes Timestamp.java

   java org.xmlBlaster.util.Timestamp

 Dump a nanosecond 'long' to a string representation:
    
   java org.xmlBlaster.util.Timestamp 1076677832527000001

 Dump a a string representation to a nanosecond 'long':

   java org.xmlBlaster.util.Timestamp "2004-02-13 14:10:32.527000001"
 


xmlBlaster 2.2.0 client API

Copyright © 1999-2014 The xmlBlaster.org contributers.