|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.davisor.data.CalendarFields
CalendarFields is an calendar arithmetic utility class that itself represents a range of calendar fields, sorted in their order of significance. Calendar fields provides also a set of usefull static calendar field related operations.
Each calendar field has a limited ranges of legal values. These ranges depend on other calendar field values. The order in which calendar fields are processes is therefore significant. When an operation applies to several fiels, the methods in this class always start processing from the less significant fields, and then continue to the more significant fields.
When calendar field values are added together, the field absolute
minimum value is considered to be the zero value that
will have no effect in the operatoin.
When field values are rounded up or down to an even multiple of a a field value, the field values are treated as ordinary integer values to which the rounding applies standard arithmetic operations. However, if the result is outside the range of legal field values, the value is replaced with the nearest legal value. In particular, rounding under- or overflows will not affect other field values.
Rounding calendar field values may sometimes give unexpected results. In particular, take two calendar values that define the upper and lower bounds of a calendar time pediod. If these limit values are rounded intependently to a given time field precision, the resulting range may not become an even multiple of that same precision.
add(java.lang.Object),
iterator(),
sub(java.util.Calendar, java.util.Calendar)| Nested Class Summary | |
class |
CalendarFields.FieldIterator
FieldIterator implements a calendar field iterator. |
| Field Summary | |
static int |
DAY
The index of ordered days (of month) field (4). |
static int |
ERA
The index of ordered eras field (7). |
static int |
FIELD
Calendar field code array index (0). |
protected static java.lang.Integer[][] |
FIELDS
Calender fields in their order of significance. |
static int |
FIRSTDATECODE
The index of first date code (4, the index of DAY_OF_MONTH). |
static int |
HOUR
The index of ordered hours (of day) field (3). |
protected int |
M_first
The index of first calendar field range element (inclusive). |
protected int |
M_last
The index of last calendar field range element (inclusive). |
static int |
MILLISECOND
The index of ordered milliseconds field (0). |
static int |
MINUTE
The index of ordered minutes field (2). |
static int |
MONTH
The index of ordered months field (5). |
static int |
SECOND
The index of ordered seconds field (1). |
static int |
VALUE
Calendar field value array index (1). |
static int |
YEAR
The index of ordered years field (6). |
| Constructor Summary | |
CalendarFields()
Creates a calendar field set that covers all fields. |
|
CalendarFields(java.util.Calendar calendar)
Creates a calendar field set from given calendar. |
|
CalendarFields(int last)
Creates a calendar field set from MILLISECOND to the given last field. |
|
CalendarFields(int first,
int last)
Creates a calendar field set from the given first field to the given last field. |
|
| Method Summary | |
static boolean |
add(java.util.Calendar calendar,
java.util.Calendar term)
Modifies given calendar by adding the values of another calendar to it. |
boolean |
add(java.lang.Object o)
Ensures that this collection contains the specified element. |
boolean |
addAll(java.util.Collection c)
Adds all of the elements in the specified collection to this collection. |
static boolean |
ceil(java.util.Calendar calendar,
java.util.Calendar precision)
Modifies given calendar by rounding it upwards to given precision. |
static boolean |
ceil(java.util.Calendar calendar,
CalendarField precision)
Modifies given calendar by rounding one of it's fields upwards to given precision. |
void |
clear()
Clears the field range. |
java.util.Comparator |
comparator()
Returns the comparator associated with this sorted set, or null if it uses its elements' natural ordering. |
boolean |
contains(java.lang.Object o)
Tests whether the current field range contains the given field. |
boolean |
containsAll(java.util.Collection c)
Tests if the current field range contains all of the given fields. |
static java.util.Date |
dateValue(java.lang.String stringValue,
java.text.ParsePosition status,
java.text.Format format)
Parses given date string value. |
boolean |
equals(java.lang.Object o)
Tests if this object is equal to another object. |
static java.lang.Integer |
fieldCode(int fieldIndex)
Converts the field index to a Calendar field code. |
static int |
fieldIndex(int fieldCode)
Converts Calendar field code to a field code. |
static int[] |
fieldValue(java.lang.String value,
java.text.ParsePosition status)
Parses given date field string value. |
java.lang.Object |
first()
Returns the first (lowest) element currently in this sorted set. |
static boolean |
floor(java.util.Calendar calendar,
java.util.Calendar precision)
Modifies given calendar by rounding it downwards to given precision. |
static boolean |
floor(java.util.Calendar calendar,
CalendarField precision)
Modifies given calendar by rounding one of it's fields downwards to given precision. |
int |
getFirst()
Gets range first field. |
static int |
getFirst(java.util.Calendar calendar)
Gets the index of the least significant calender field which describes a time period shorter than the time set into given calendar. |
int |
getLast()
Gets range last field. |
static int |
getLast(java.util.Calendar calendar)
Gets the index of the most significant calender field which describes a time period shorter than the time set into given calendar. |
static java.lang.String |
getPattern(int field)
Gets SimpleDateFormat pattern string for given Calendar
field. |
int |
hashCode()
Returns a hash code value for the object. |
java.util.SortedSet |
headSet(java.lang.Object toElement)
Returns a view of the portion of this sorted set whose elements are strictly less than given element. |
boolean |
isDate()
Tests if the current field range covers only fields that express dates, and not time of day. |
boolean |
isEmpty()
Tests if the current field range is empty. |
boolean |
isTime()
Tests if the current field range covers only fields that express time of day, and not dates. |
boolean |
isTimestamp()
Tests if the current field range covers fields that express both time of day and dates. |
java.util.Iterator |
iterator()
Gets the field iterator. |
java.util.Iterator |
iterator(boolean forward)
Gets the field iterator, with given iteration direction. |
java.lang.Object |
last()
Returns the last (highest) element currently in this sorted set. |
static int |
next(int fieldCode)
Gets the next more significant field of given field. |
static int |
prev(int fieldCode)
Gets the next less significant field of given field. |
boolean |
remove(java.lang.Object o)
Removes a single instance of the specified element from this collection, if it is present. |
boolean |
removeAll(java.util.Collection c)
Removes all this collection's elements that are also contained in the specified collection. |
boolean |
retainAll(java.util.Collection c)
Retains only the elements in this collection that are contained in the specified collection. |
int |
size()
Tells the number of fields in the current field range. |
static java.lang.String |
stringValue(java.util.Calendar calendar)
Gets calendar value string representation. |
static java.lang.String |
stringValue(java.util.Calendar calendar,
int field)
Gets calendar field value string representation. |
static boolean |
sub(java.util.Calendar calendar,
java.util.Calendar term)
Modifies given calendar by substracting the values of another calendar from it. |
java.util.SortedSet |
subSet(java.lang.Object fromElement,
java.lang.Object toElement)
Returns a view of the portion of this sorted set whose elements range between given inclusive and exclusive lower and upper values. |
java.util.SortedSet |
tailSet(java.lang.Object fromElement)
Returns a view of the portion of this sorted set whose elements are greater or euqal than given element. |
java.lang.Object[] |
toArray()
Converts the current field range into an array of integers. |
java.lang.Object[] |
toArray(java.lang.Object[] a)
Converts the current field range into an array of integers. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int FIELD
public static final int VALUE
public static final int FIRSTDATECODE
public static final int MILLISECOND
public static final int SECOND
public static final int MINUTE
public static final int HOUR
public static final int DAY
public static final int MONTH
public static final int YEAR
public static final int ERA
protected static final java.lang.Integer[][] FIELDS
The first element in second index gives the principal field code, Following elemensts, if any, enumerate secondary fields related to the principal field.
protected int M_first
protected int M_last
| Constructor Detail |
public CalendarFields()
public CalendarFields(int last)
last - last time field included (a Calendar time field code)fieldIndex(int)
public CalendarFields(int first,
int last)
first - first time field included (a Calendar time field code)last - last time field included (a Calendar time field code)fieldIndex(int)public CalendarFields(java.util.Calendar calendar)
For example, for a Gregorian calendar and GMT time zone, a value of 86400000 milliseconds (24h * 60min * 60s * 1000ms) that represents one Gregorian day would affect directly the day field only, and result a range of [day,day]. A value of 86401000 milliseconds (a day and a second), would result a range of [second,day].
calendar - calendar valuegetFirst(Calendar),
getLast(Calendar)| Method Detail |
public boolean add(java.lang.Object o)
CalendarFields.
add in interface java.util.Seto - element whose presence in this collection is to be ensured
true if this collection changed as a result
of the call
java.lang.ClassCastException - if the object is not an instance of
CalendarFieldspublic boolean addAll(java.util.Collection c)
addAll in interface java.util.Setc - elements to be inserted into this collection
true if this collection changed as a result
of the call
java.lang.ClassCastException - if the object is not an instance of
CalendarFieldsadd(Object)public void clear()
clear in interface java.util.Setpublic boolean contains(java.lang.Object o)
contains in interface java.util.Seto - the field to be tested, expressed as a Number
false.public boolean containsAll(java.util.Collection c)
containsAll in interface java.util.Setc - collection of fields, expressed as Number
instances.
false.contains(java.lang.Object)public boolean isEmpty()
isEmpty in interface java.util.Setpublic java.util.Iterator iterator()
iterator in interface java.util.Setpublic boolean remove(java.lang.Object o)
remove in interface java.util.Setjava.lang.UnsupportedOperationException - alwayspublic boolean removeAll(java.util.Collection c)
removeAll in interface java.util.Setjava.lang.UnsupportedOperationException - alwayspublic boolean retainAll(java.util.Collection c)
retainAll in interface java.util.Setjava.lang.UnsupportedOperationException - alwayspublic int size()
size in interface java.util.Setpublic java.lang.Object[] toArray()
toArray in interface java.util.Setpublic java.lang.Object[] toArray(java.lang.Object[] a)
toArray in interface java.util.Setpublic boolean equals(java.lang.Object o)
CalendarField objects are equal if they share the same field range.
equals in interface java.util.Setpublic int hashCode()
hashCode in interface java.util.Set
public static boolean add(java.util.Calendar calendar,
java.util.Calendar term)
term calendar
are added. Furhermore, field values are compencated by their
actual minimum values, so that adding a minimum value will have
no effect.
calendar - calendar to add to (modified)term - calendar to add from
true if calendar was modified
public static boolean ceil(java.util.Calendar calendar,
java.util.Calendar precision)
calendar - calendar to round upwards (modified)precision - calendar field precisions
true if calendar was modifiedceil(Calendar,CalendarField),
floor(Calendar,Calendar),
floor(Calendar,CalendarField)
public static boolean ceil(java.util.Calendar calendar,
CalendarField precision)
floor(Calendar,CalendarField)
method. If this modifies the calendar, the value is rounded up by
adding given field value to the rounded down value. If the
rounding down did not modify the calendar value, the value was
already at even precision boundary, and it therefore does not
need to be rounded up, either.
calendar - calendar to round upwards (modified)precision - calendar field to round off againts
true if calendar was modifiedceil(Calendar,Calendar),
floor(Calendar,Calendar),
floor(Calendar,CalendarField)
public static java.util.Date dateValue(java.lang.String stringValue,
java.text.ParsePosition status,
java.text.Format format)
throws InvalidDataException
null or empty string values result a
null date value.
stringValue - data string value (may be null)status - parse status (may be null)format - date string parser (may be null)
InvalidDataException - if value can not be interpreted as a datepublic static java.lang.Integer fieldCode(int fieldIndex)
Calendar field code.
fieldIndex(int)public static int fieldIndex(int fieldCode)
Calendar field code to a field code.
fieldCode(int)
public static int[] fieldValue(java.lang.String value,
java.text.ParsePosition status)
throws InvalidDataException
value - data string valuestatus - parse status (may be null)
InvalidDataException - if value can not be interpreted as a date
public static boolean floor(java.util.Calendar calendar,
java.util.Calendar precision)
calendar - calendar to round downwards (modified)precision - calendar field precisions
true if calendar was modifiedceil(Calendar,Calendar),
ceil(Calendar,CalendarField),
floor(Calendar,CalendarField)
public static boolean floor(java.util.Calendar calendar,
CalendarField precision)
If the rounded down value would be less or more than the actual minimum or maximum field value, the minimum or maximum value is used instead.
Clearing calendar fields is tricky business, as Calendars tend to
run back to default values whenever there is even the least
possible excuse to try to interprete incomplete or conflicting
calendar settings. In particular, in order for the rounding down
to work propertly, all fields related to a given time unit must
always be cleared as a one unit operation. In practice, calendars
may therefore be rounded down to the principal field values only.
Calendar principal fields are enumerated by FIELDS constant.
calendar - calendar to round downwards (modified)precision - calendar field to round off againts
true if calendar was modifiedceil(Calendar,Calendar),
ceil(Calendar,CalendarField),
fieldCode(int),
fieldIndex(int),
floor(Calendar,Calendar)public int getFirst()
getFirst(Calendar),
getLast()public static int getFirst(java.util.Calendar calendar)
For example, if the calendar has been set to a time of the first
day of the first month in the second year, the index of the
YEAR field is returned. If the time would have been
the second hour of that same day, the index of the
HOUR field would have been returned.
If all fields are at their minimum values, the index of the
MILLISECONDS field is returned (zero).
calendar - calendar to examine
getFirst(),
getLast(Calendar)public int getLast()
getFirst(),
getLast(Calendar)public static int getLast(java.util.Calendar calendar)
For example, if the calendar has been set to a time of the second
day of the first month in the first year, the index of the
DAY field is returned. If the time would have been
the second day of the second year, the index of the
YEAR field would have been returned.
If all fields are at their minimum values, the index of the
MILLISECONDS field is returned (zero).
calendar - calendar to examine
getFirst(Calendar),
getLast()public static java.lang.String getPattern(int field)
SimpleDateFormat pattern string for given Calendar
field.
field - Calendar field code
SimpleDateFormat pattern, or an
empty stringpublic boolean isDate()
isTime(),
isTimestamp()public boolean isTime()
isDate(),
isTimestamp()public boolean isTimestamp()
isDate(),
isTime()public java.util.Iterator iterator(boolean forward)
public static int next(int fieldCode)
prev(int),
fieldIndex(int),
fieldCode(int)public static int prev(int fieldCode)
next(int),
fieldIndex(int),
fieldCode(int)public static java.lang.String stringValue(java.util.Calendar calendar)
calendar - calendar valuestringValue(Calendar,int)
public static java.lang.String stringValue(java.util.Calendar calendar,
int field)
calendar - calendar valuefield - calendar field codestringValue(Calendar)
public static boolean sub(java.util.Calendar calendar,
java.util.Calendar term)
term calendar are substracted. Furhermore, field
values are compencated by their actual minimum values, so that
substracting a minimum value will have no effect.
calendar - calendar to add to (modified)term - calendar to add from
true if calendar was modifiedpublic java.util.Comparator comparator()
null if it uses its elements' natural ordering.
comparator in interface java.util.SortedSetnullpublic java.lang.Object first()
first in interface java.util.SortedSetgetFirst()public java.util.SortedSet headSet(java.lang.Object toElement)
This method is currently unimplemented.
headSet in interface java.util.SortedSetpublic java.lang.Object last()
last in interface java.util.SortedSetgetLast()
public java.util.SortedSet subSet(java.lang.Object fromElement,
java.lang.Object toElement)
This method is currently unimplemented.
subSet in interface java.util.SortedSetpublic java.util.SortedSet tailSet(java.lang.Object fromElement)
This method is currently unimplemented.
tailSet in interface java.util.SortedSet
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||