|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
public interface Chronology
This class represents a system used by humans to describe time.
A chronology provides several TimeField that have a meaning in this chronology. One can merge several TimeField to create TimeMask objects.
Those TimeMask objects define time format that can be used to describe a precise Time object.
If a Time object is well defined, it will describe a peace of time (for example, with a TimeMask with YEAR, MONTH and DAY). Such a Time object is said consistent for interval as it can be safely converted in an Interval object.
A Time object does not necessary have to be consistent for interval. For example, it is possible to define a Time object like "9 hour and 15 minutes". This Time object is not consistent for interval, because it does not define a precise day, just a time in a day. But it still can be usefull, as it may be used to build other Time objects. Indeed, you can combinate it with another Time object that only defines a day, and the combinaison of both gives a Time object that defines day and hour/minute.
Please note that having a good TimeMask is not sufficient for beeing consistent for interval. For example, a Time object which value is [31st February of 2006] is not consistent for interval.
If a Time object provide enough information to be millisecond accurate, it is said consistent for instant as it can be safely converted in an Instant object. Generally, being consistent for instant implies to be consistent for interval (which one millisecond interval duration).
A Chronology provides the following services:
| Method Summary | |
|---|---|
java.util.List<Time> |
asList(Time startingTime,
int startingPosition)
Return a immutable view of some Time objects of this chronology starting at a specified Time. |
java.util.List<Time> |
asList(TimeMask mask)
Return a immutable view of all Time objects of this chronology with a specified TimeMask. |
java.util.SortedSet<Time> |
asSortedSet(TimeMask mask)
Return a immutable view of all Time objects of this chronology with a specified TimeMask. |
Instant |
getInstant(Time time)
Convert a Time object into Instant according to this chronology object. |
Interval |
getInterval(Time time)
Convert a Time object into an Interval object, according to this chronology. |
Time |
getTime(Instant instant)
Convert an Instant object into a Time object with all known TimeField of this chronology. |
Time |
getTime(Instant instant,
TimeMask mask)
Convert an Instant object into a Time object with a precise TimeMask according to this chronology. |
Time |
getTime(Interval interval)
Convert an Interval object into a Time object with all known TimeField of this chronology. |
Time |
getTime(Interval interval,
TimeMask mask)
Convert an Interval object into a Time object with a precise TimeMask according to this chronology. |
boolean |
isConsistentForInstant(Time time)
Test if a Time object is consistent for instant. |
boolean |
isConsistentForInterval(Time time)
Test if a Time object is consistent for interval. |
java.util.SortedSet<TimeField> |
knownFields()
Return all TimeField of this chronology. |
Time |
next(Time time)
Return the next Time object that directly follows a specified Time object according to this chronology. |
Time |
previous(Time time)
Return the previous Time object that is just before a specified Time object according to this chronology. |
java.util.SortedSet<Time> |
split(Time timeToSplit,
TimeField... fieldsToAdd)
Return a immutable view with Time objects by adding some TimeField to an existing Time object. |
| Method Detail |
|---|
java.util.SortedSet<TimeField> knownFields()
All TimeMask and Time object used with this chronology should only use one or several of thoses TimeField objects, otherwise a ClassCastException will be thrown by the other methods of this chronology when such an unappropriate TimeField will be used.
boolean isConsistentForInstant(Time time)
A Time object is consistent for instant if it provides enough information to point a unique Instant in the whole Time.
time - the Time object to be tested.
java.lang.NullPointerException - if time is nullboolean isConsistentForInterval(Time time)
A Time object is consistent for interval, if it provides enough information to point a unique Interval in the whole Time (for example, a day, a week, a month...).
time - the Time object to be tested.
java.lang.NullPointerException - if time is nullTime getTime(Instant instant)
instant - the Instant object to be converted.
Time getTime(Instant instant,
TimeMask mask)
throws java.lang.ClassCastException
Calling this method should be equivalent as the following:
getTime(instant).subMap(mask)
instant - the Instant object to be converted.mask - the TimeMask to use.
java.lang.ClassCastException - if mask is not compatible
with this chronology.
java.lang.NullPointerException - if instant or mask is nullTime getTime(Interval interval)
interval - the Interval object to be converted.
java.lang.IllegalArgumentException - if interval cannot be converted into
a Time object according to this chronology.
java.lang.NullPointerException - if interval is null
Time getTime(Interval interval,
TimeMask mask)
throws java.lang.ClassCastException
Calling this method should be equivalent as the following:
getTime(interval).subMap(mask)
interval - the Interval object to be converted.mask - the TimeMask to use.
java.lang.IllegalArgumentException - if interval cannot be converted into
a Time object according to this chronology.
java.lang.ClassCastException - if mask is not compatible
with this chronology.
java.lang.NullPointerException - if interval or mask is null
Instant getInstant(Time time)
throws java.lang.ClassCastException
time - the Time object to be converted.
java.lang.ClassCastException - if time does not have a TimeMask
compatible with this Chronology object.
java.lang.IllegalArgumentException - if time is not consistent for instant.
java.lang.NullPointerException - if time is null
Interval getInterval(Time time)
throws java.lang.ClassCastException
time - the Time object to be converted
java.lang.ClassCastException - if time is not compatible
with this chronology.
java.lang.IllegalArgumentException - if time is not consistent for
interval.
java.lang.NullPointerException - if time is nulljava.util.SortedSet<Time> asSortedSet(TimeMask mask)
For example, assuming that myTime is a Time object,
calling:
asSortedSet(myTime.getTimeMask()).contains(myTime)
Another example, assuming that dayMask is a TimeMask
object like [YEAR, MONTH, DAY_OF_MONTH], and that day1 and
day2 are two differents days,
calling:
asSortedSet(dayMask).subSet(day1, day2).size()
To have the day following day1,
call:
Iterator
To have the day before day1,
call:
asSortedSet(dayMask).headSet(day1).last()
mask - the specified TimeMask
java.lang.NullPointerException - if mask is null
java.lang.ClassCastException - if mask is not compatible with this chronology
java.lang.IllegalArgumentException - if mask is not consistent with intervaljava.util.List<Time> asList(TimeMask mask)
For example, assuming that myTime is a Time object,
calling:
asList(myTime.getTimeMask()).contains(myTime)
To have the 100th day following day1,
call:
int idx = asList(dayMask).indexOf(day1);
asList(dayMask).get(idx+100);
mask - the specified TimeMask
java.lang.NullPointerException - if mask is null
java.lang.ClassCastException - if mask is not compatible with this chronology
java.lang.IllegalArgumentException - if mask is not consistent with interval
java.lang.IndexOutOfBoundsException - if the returned List would have more than
Integer.MAX_VALUE elements.
java.util.List<Time> asList(Time startingTime,
int startingPosition)
All Time objects of the returned list have the same TimeMask
as startingTime.
The first element of the list is startingTime if
startingPosition=0.
Otherwise, if startingPosition>0, it specifies the position
of startingTime in the returned list.
So we have:
asList(myTime, x).get(x).equals(myTime)==true
To sumurize, startingPosition is always the logically (even if it's negative) position of startingTime in the returned list.
To have the 100th day following day1,
call:
asList(day1, 0).get(100);
or:
asList(day1, 100).get(0);
startingTime - an absolute reference for TimestartingPosition - the logical position of startingTime
in the returned list
java.lang.NullPointerException - if startingTime is null
java.lang.ClassCastException - if startingTime is not compatible with this chronology
java.lang.IllegalArgumentException - if startingTime is not consistent with interval
java.lang.IndexOutOfBoundsException - if the returned List would have more than
Integer.MAX_VALUE elements.
java.util.SortedSet<Time> split(Time timeToSplit,
TimeField... fieldsToAdd)
The provided timeToSplit must be consistent for interval. The returned set is a view of timeToSplit as set of its component. For example:
The returned set contains Time objects whose TimeMask is the time mask of timeToExplode merged with all fieldsToAdd. All possibles values are contained in the returned set.
For example, if one have:
timeToSplit = new Time(DAY_MASK, 2005, Month.NOVEMBER, 11);
split(timeToSplit, HOUR, MINUTE);
Time myMonth = new Time(MONTH_MASK, 2005, Month.DECEMBER);
int nbDays = myChronology.split(myMonth, DAY_OF_MONTH).size();
timeToSplit - the time to split.fieldsToAdd - all TimeField to add.
Time next(Time time)
throws java.lang.IllegalArgumentException,
java.lang.ClassCastException
More formally, this method returns a Time object that have the same TimeMask than time, with the following property: the ending instant (according to this chronoloy) of time is the starting instant (according to this chronology) of the resulted Time object.
If no exception is thrown, the following test is always true:
getInterval(time).getEnd().equals(next(time).getStart())
This is equivalent of the following call:
Iterator
time - the time whose next time is return
java.lang.ClassCastException - if time does not have a TimeMask
compatible with this Chronology object.
java.lang.IllegalArgumentException - if time does not have a following
Time.
Time previous(Time time)
throws java.lang.IllegalArgumentException,
java.lang.ClassCastException
More formally, this method returns a Time object that have the same TimeMask than time, with the following property: the starting instant (according to this chronoloy) of time is the ending instant (according to this chronology) of the resulted Time object.
If no exception is thrown, the following test is always true:
getInterval(time).getStart().equals(previous(time).getEnd())
This is equivalent of the following call:
asSortedSet(time.getTimeMask()).headSet(time).last()
time - the time whose previous time is return
java.lang.ClassCastException - if time does not have a TimeMask
compatible with this Chronology object.
java.lang.IllegalArgumentException - if time does not have a previous
Time.
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||