JTemporal Home
Tutorial

net.sf.jtemporal
Interface Instant

All Superinterfaces:
java.lang.Comparable

public interface Instant
extends java.lang.Comparable

You must implement this interface (basically a Comparable) to represent time.
You can write a little adapter wrapping java.util.Date. Some users prefer instead using "pure" dates, to avoid issues with timezones and avoid performances losses with milliseconds conversions. There are many open source implementations of Julian and Gregorian date. Any object implementing this interface is required to be immutable. This is part of the contract.
Do not forget to implement equals and hashCode properly, as defined in the Object documentation: this is necessary. Also, the equals method must be consistent with the compareTo method.

Please note that the performances of the whole JTemporal heavily depend on the performance of the methods implementing this interface. Therefore, you should try to avoid instantiating new objects during these method calls (and also the methods equals and hashcode).

Given that Instants are immutable, it usually makes sense to share the implementing instances: there are never millions of different dates in a system. This can be done easily using for example a LightLRUCache

Version:
$Id: Instant.java,v 1.12 2007/09/15 18:52:55 tabeck Exp $

Method Summary
 int compareTo(java.lang.Object i)
          Compares this object with the specified object for order.
 boolean isNegativeInfinity()
          Tells whether this Instant is the negative infinity.
 boolean isPositiveInfinity()
          Tells whether this Instant is the positive infinity.
 

Method Detail

compareTo

int compareTo(java.lang.Object i)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception iff y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y)>0 && y.compareTo(z)>0) implies x.compareTo(z)>0.

Finally, the implementer must ensure that x.compareTo(y)==0 implies that sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for all z.

It is required that (x.compareTo(y)==0) == (x.equals(y)).

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
i - the other instant to be compared to.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
Throws:
java.lang.ClassCastException - if the specified object's type prevents it from being compared to this Object.

isPositiveInfinity

boolean isPositiveInfinity()
Tells whether this Instant is the positive infinity.

The properties of the positive infinity are:
positiveInfinity.compareTo(positiveInfinity) == 0
positiveInfinity.equals(positiveInfinity) == true
positiveInfinity.compareTo(anyOtherInstant) > 0

Returns:
true if this instance is the positive infinity

isNegativeInfinity

boolean isNegativeInfinity()
Tells whether this Instant is the negative infinity.

The properties of the negative infinity are:
negativeInfinity.compareTo(negativeInfinity) == 0
negativeInfinity.equals(negativeInfinity) == true
negativeInfinity.compareTo(anyOtherInstant) < 0

Returns:
true if this instance is the positive infinity

JTemporal Home
Tutorial