|
JTemporal Home Tutorial |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Instant
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
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 |
---|
int compareTo(java.lang.Object i)
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)).
compareTo
in interface java.lang.Comparable
i
- the other instant to be compared to.
java.lang.ClassCastException
- if the specified object's type prevents it
from being compared to this Object.boolean isPositiveInfinity()
The properties of the positive infinity are:
positiveInfinity.compareTo(positiveInfinity) == 0
positiveInfinity.equals(positiveInfinity) == true
positiveInfinity.compareTo(anyOtherInstant) > 0
boolean isNegativeInfinity()
The properties of the negative infinity are:
negativeInfinity.compareTo(negativeInfinity) == 0
negativeInfinity.equals(negativeInfinity) == true
negativeInfinity.compareTo(anyOtherInstant) < 0
|
JTemporal Home Tutorial |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |