|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objecttime.TimeField<V>
public final class TimeField<V>
Implements a field used in time representation.
A TimeField can be used by one or several different Chronologies. For example, Julian and Gregorian chronologies will likely share the same TimeFields. But Chinese chronology will have its own TimeField, although it may use the same TimeField for hour, minutes, second and millisecond.
TimeField objects are provided by Chronologies, and the end user should not create new ones.
A TimeField can have several values. Thoses value are defined with the TimeField itself, at TimeField creation. For example,
The TimeField object defines also an order for its possible values, and that's why it implements Comparable<V>. There are two options:
TimeField have a typical duration which is exprimed in milliseconds. The typical duration of a TimeField is the mean, or the most common duration of this TimeField. More formaly, this typical duration is the variation of time implied by the minimal change of this TimeField values.
Here some examples of typical duration:
The typical duration is only used for sorting the TimeFields together. TimeField have indeed a natural order.
TimeField are first compared by their typical duration. The greater the typical duration, the smaller the TimeField. So a TimeField like Month is before a TimeField like Days, which is before Hour. This allows to sort TimeFields with most significant TimeFields in first position. Two TimeFields objects with the same typical duration are sorted lexicographically using their name. It is suggested that a Chronology does not provide such TimeFields with the same typical duration.
As equals() method is not redefined, the natural order is not consistent with equals(): two TimeField defined by two different chronologies with the same name and duration will be equals according to compareTo() but not according to equals(). This should not be a problem as such TimeField should not be used together in the same TimeMask.
TimeMask,
Chronology| Constructor Summary | |
|---|---|
TimeField(java.lang.String name,
long typicalDuration,
java.util.Collection<V> possibleValues,
java.util.Comparator<V> comparator)
Create a new TimeField. |
|
| Method Summary | |
|---|---|
int |
compare(V o1,
V o2)
Compare two possibles values of a TimeField according to this TimeField rule. |
int |
compareTo(TimeField other)
Compare this TimeField with another one. |
java.lang.String |
getName()
Return the name of this TimeField. |
boolean |
isValueOk(V value)
Test if a value is acceptable for this TimeField. |
java.lang.String |
toString()
Convert this TimeField into a String. |
java.util.SortedSet<V> |
values()
Return all possible values of this TimeField. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Comparator |
|---|
equals |
| Constructor Detail |
|---|
public TimeField(java.lang.String name,
long typicalDuration,
java.util.Collection<V> possibleValues,
java.util.Comparator<V> comparator)
If values of this TimeField object are not Comparable, the order of the possibleValues collection is used to achieve comparaisons between values. (this collections is assumed ordered by ascending order).
The provided possibleValues set should not be changed after TimeField creation (with add or remove methods for example), as this implementation keeps a reference to this set for testing future acceptable values.
name - the name of the new TimeFieldtypicalDuration - the typical duration in millisecond of the new TimeFieldpossibleValues - all possible values of the new TimeFieldcomparator - null if the natural order of possibleValues
is used, otherwise a comparator that defines the order for possibleValues.
java.lang.NullPointerException - if name is null
java.lang.IllegalArgumentException - if possibleValues is empty.isValueOk(V)| Method Detail |
|---|
public int compareTo(TimeField other)
compareTo in interface java.lang.Comparable<TimeField<V>>java.lang.NullPointerException - if other is null.public java.lang.String getName()
public java.util.SortedSet<V> values()
public boolean isValueOk(V value)
The value is acceptable if is contained in the possible value set provided at TimeField creation.
java.lang.NullPointerException - if value is null.public java.lang.String toString()
toString in class java.lang.Object
public int compare(V o1,
V o2)
If the values are Comparable if no Comparator have been provided at TimeField creation, the natural order of the values is used.
Otherwise, the Comparator provided at TimeField creation is used.
compare in interface java.util.Comparator<V>java.lang.IllegalArgumentException - if o1 or o2 is not a legal
value for this TimeField object.
java.lang.ClassCastException - if values are not Comparable and
no Comparator have been provided
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||