|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objecttime.Time
public final class Time
Time is a representation of a piece of time. This is the main class of this API. This class provides a good replacement for java.util.Date . But its usage is larger than simply a date, as it can represent thinks like:
It is possible to merge several Time objects in one. For example, you can have in one side Time objects that represents a day (like the 20th of October 2005). In one other side, Time objects that represents hour and minutes (for example 9:00). If you want to merge those two Time objects to speak about the 20th of October 2005 9:00, simply use the appropriate constructor.
This class is immutable, so it can itself be used as key in java.util.Map. It is also thread-safe.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface java.util.Map |
|---|
java.util.Map.Entry<K,V> |
| Constructor Summary | |
|---|---|
Time(java.util.Map<TimeField,java.lang.Object> map)
Create new Time from a map of TimeField. |
|
Time(Time... otherTimes)
Create a new Time object by merging existing other Time objects. |
|
Time(TimeMask mask,
java.lang.Object... values)
Create a new Time from a TimeMask and some values. |
|
| Method Summary | ||
|---|---|---|
void |
clear()
As TimeField are immutable, throws a UnsupportedOperationException. |
|
java.util.Comparator<? super TimeField> |
comparator()
As the naturel order if TimeField is used, returns null. |
|
int |
compareTo(Time other)
Compares this Time with the specified Time for order. |
|
boolean |
containsKey(java.lang.Object key)
Returns true if this Time object contains a mapping for the specified key. |
|
boolean |
containsValue(java.lang.Object value)
Returns true if this Time object maps one or more keys to the specified value. |
|
java.util.Set<java.util.Map.Entry<TimeField,java.lang.Object>> |
entrySet()
Returns a set view of the mappings contained in this Time object. |
|
boolean |
equals(java.lang.Object o)
Compare two Time for equality. |
|
TimeField |
firstKey()
Return the most significant TimeField in this Time object. |
|
java.lang.Object |
get(java.lang.Object field)
Return the value of a TimeField of this Time. |
|
|
get(TimeField<V> field)
Return the value of a TimeField of this Time. |
|
TimeMask |
getTimeMask()
Return the format of this Time object. |
|
Time |
headMap(TimeField toKey)
Return a new Time object that contains all TimeField more significant than toKey (excluding). |
|
boolean |
isEmpty()
Returns true if this Time object contains no key-value mappings. |
|
java.util.Set<TimeField> |
keySet()
Returns a Set view of the keys contained in this Time object. |
|
TimeField |
lastKey()
Return the less significant TimeField in this Time object. |
|
java.lang.Comparable |
put(TimeField key,
java.lang.Object value)
As TimeField are immutable, throws a UnsupportedOperationException. |
|
void |
putAll(java.util.Map<? extends TimeField,? extends java.lang.Object> t)
As TimeField are immutable, throws a UnsupportedOperationException. |
|
java.lang.Comparable |
remove(java.lang.Object key)
As TimeField are immutable, throws a UnsupportedOperationException. |
|
boolean |
sameTimeMask(Time other)
Test if two Time objects use the same TimeMask. |
|
boolean |
sameTimeMask(TimeMask mask)
Test if this Time object uses a certain TimeMask. |
|
int |
size()
Return the number of TimeField in this Time object. |
|
Time |
subMap(java.util.Collection<TimeField> fields)
Return a new Time object that contains only some TimeField of this Time object. |
|
Time |
subMap(TimeField fromKey,
TimeField toKey)
Return a new Time object that contains all TimeField less significant than fromKey (including) and more significant than toKey (excluding). |
|
Time |
tailMap(TimeField fromKey)
Return a new Time object that contains all TimeField less significant than fromKey (including). |
|
java.lang.String |
toString()
Convert this Time object in a string. |
|
Time |
update(TimeField field,
java.lang.Object value)
Create a new Time by updating or adding a new TimeField in this Time object. |
|
java.util.Collection<java.lang.Object> |
values()
Returns a collection view of the values contained in this Time object. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Map |
|---|
hashCode |
| Constructor Detail |
|---|
public Time(java.util.Map<TimeField,java.lang.Object> map)
map - the map whose keys are TimeField and values the values
of the TimeFields.
public Time(TimeMask mask,
java.lang.Object... values)
mask - the TimeMask which defines the formatvalues - all values of the TimeFields contained in the TimeMask.
java.lang.IllegalArgumentException - if mask and values do not have the
same size.
java.lang.IllegalArgumentException - if a value is incompatible with the mask.public Time(Time... otherTimes)
java.lang.IllegalArgumentException - if two or more Time objects has the same
TimeField with different values.| Method Detail |
|---|
public TimeMask getTimeMask()
public java.lang.Object get(java.lang.Object field)
You should consider the get(TimeField<V>) methods instead, as it avoid casting.
get in interface java.util.Map<TimeField,java.lang.Object>java.lang.NullPointerException - if field is null.
java.lang.ClassCastException - if field is not a TimeField.
java.lang.IllegalArgumentException - if the field is not in this Time
object keys'.get(TimeField)public <V> V get(TimeField<V> field)
java.lang.NullPointerException - if field is null.
java.lang.IllegalArgumentException - if the field is not in this Time
object keys'.
public Time update(TimeField field,
java.lang.Object value)
java.lang.IllegalArgumentException - if value is not a valid value for fieldpublic int compareTo(Time other)
compareTo in interface java.lang.Comparable<Time>java.lang.IllegalArgumentException - if both Time objects do not have the same
TimeMask.public boolean equals(java.lang.Object o)
equals in interface java.util.Map<TimeField,java.lang.Object>equals in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean sameTimeMask(TimeMask mask)
mask - the TimeMask to be tested
public boolean sameTimeMask(Time other)
other - the Time to test with
public java.util.Set<java.util.Map.Entry<TimeField,java.lang.Object>> entrySet()
This method is can be useful to test in an instant is part of another instant.
Example:
Time myMonth = new Time(MONTH_MASK, 2005, Month.DECEMBER);
Time other = new Time(...);
boolean test = other.entrySet().containsAll(myMonth.entrySet());
entrySet in interface java.util.Map<TimeField,java.lang.Object>public java.util.Collection<java.lang.Object> values()
The collection's iterator will return the values in the order that their corresponding keys appear in this Time object.
values in interface java.util.Map<TimeField,java.lang.Object>public java.util.Set<TimeField> keySet()
keySet in interface java.util.Map<TimeField,java.lang.Object>public boolean containsValue(java.lang.Object value)
containsValue in interface java.util.Map<TimeField,java.lang.Object>java.lang.NullPointerException - if value is null.public boolean containsKey(java.lang.Object key)
containsKey in interface java.util.Map<TimeField,java.lang.Object>java.lang.NullPointerException - if value is null.
java.lang.ClassCastException - if value is not a TimeField.public boolean isEmpty()
isEmpty in interface java.util.Map<TimeField,java.lang.Object>public int size()
size in interface java.util.Map<TimeField,java.lang.Object>public void clear()
clear in interface java.util.Map<TimeField,java.lang.Object>public void putAll(java.util.Map<? extends TimeField,? extends java.lang.Object> t)
putAll in interface java.util.Map<TimeField,java.lang.Object>public java.lang.Comparable remove(java.lang.Object key)
remove in interface java.util.Map<TimeField,java.lang.Object>
public java.lang.Comparable put(TimeField key,
java.lang.Object value)
put in interface java.util.Map<TimeField,java.lang.Object>public TimeField lastKey()
lastKey in interface java.util.SortedMap<TimeField,java.lang.Object>public TimeField firstKey()
firstKey in interface java.util.SortedMap<TimeField,java.lang.Object>public java.util.Comparator<? super TimeField> comparator()
comparator in interface java.util.SortedMap<TimeField,java.lang.Object>public Time tailMap(TimeField fromKey)
tailMap in interface java.util.SortedMap<TimeField,java.lang.Object>public Time headMap(TimeField toKey)
headMap in interface java.util.SortedMap<TimeField,java.lang.Object>
public Time subMap(TimeField fromKey,
TimeField toKey)
subMap in interface java.util.SortedMap<TimeField,java.lang.Object>public Time subMap(java.util.Collection<TimeField> fields)
fields - the TimeField to be kept.
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||