|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.time.calendar.CalendricalEngine
public final class CalendricalEngine
Main processing engine to merge and interpret calendrical information.
This stateful class is a tool for manipulating a set of calendrical information. The engine typically takes some calendrical information as input and derives other information from it. For example, a date can be derived from separate year, month and day fields.
This class is mutable and not thread-safe. It must only be used from a single thread and must not be passed between threads.
Method Summary | ||
---|---|---|
void |
addError(java.lang.String error)
Adds an error to those tracked by the normalizer. |
|
|
derive(CalendricalRule<R> ruleToDerive)
|
|
static
|
derive(CalendricalRule<R> ruleToDerive,
CalendricalRule<?> ruleOfData,
Chronology chronology,
DateTimeField field)
Derives the specified rule from a the normalized set of objects. |
|
static
|
derive(CalendricalRule<R> ruleToDerive,
CalendricalRule<?> ruleOfData,
LocalDate date,
LocalTime time,
ZoneOffset offset,
ZoneId zone,
Chronology chronology,
DateTimeFields fields)
Derives the specified rule from a the normalized set of objects. |
|
|
deriveChecked(CalendricalRule<R> ruleToDerive)
|
|
Chronology |
getChronology(boolean storeErrorIfNull)
Gets the chronology. |
|
LocalDate |
getDate(boolean storeErrorIfNull)
Gets the date. |
|
java.util.Set<java.lang.String> |
getErrors()
Gets the modifiable list of errors that have occurred. |
|
DateTimeField |
getField(DateTimeRule rule,
boolean storeErrorIfNull)
Gets a field by rule. |
|
DateTimeField |
getFieldDerived(DateTimeRule ruleToDerive,
boolean storeErrorIfNull)
Gets a field by rule, deriving the value. |
|
java.util.List<Calendrical> |
getInput()
The original input provided to the merger. |
|
ZoneOffset |
getOffset(boolean storeErrorIfNull)
Gets the offset. |
|
CalendricalRule<?> |
getRule()
The single rule that defines the data in this merger. |
|
LocalTime |
getTime(boolean storeErrorIfNull)
Gets the time. |
|
ZoneId |
getZone(boolean storeErrorIfNull)
Gets the zone. |
|
static CalendricalEngine |
merge(Calendrical... calendricals)
Derives the specified rule from a set of calendricals. |
|
static CalendricalRule<CalendricalEngine> |
rule()
Gets the rule for CalendricalEngine . |
|
void |
setChronology(Chronology chronology,
boolean storeErrorIfClash)
Sets the chronology. |
|
void |
setDate(LocalDate date,
boolean storeErrorIfClash)
Sets the date. |
|
void |
setField(DateTimeField field,
boolean storeErrorIfClash)
Sets the specified field. |
|
void |
setOffset(ZoneOffset offset,
boolean storeErrorIfClash)
Sets the offset. |
|
void |
setTime(LocalTime time,
boolean storeErrorIfClash)
Sets the time. |
|
void |
setZone(ZoneId zone,
boolean storeErrorIfClash)
Sets the zone. |
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public static CalendricalRule<CalendricalEngine> rule()
CalendricalEngine
.
public static CalendricalEngine merge(Calendrical... calendricals)
This method is used to combine any number of calendrical objects into
a more meaningful form. For example, a Year
, MonthDay
and LocalTime
could be combined into a LocalDateTime
.
The returned merger will contain the combined information of the input
in a normalized form. Use derive(CalendricalRule)
or
deriveChecked(CalendricalRule)
to derive the desired values or values.
If the input cannot be combined into any sensible normalized output then an exception is thrown. For example, passing in the month January and the date 2011-06-30 will fail as the months are in conflict.
calendricals
- the calendricals to merge, not null, no nulls
CalendricalException
- if the calendricals cannot be successfully mergedpublic static <R> R derive(CalendricalRule<R> ruleToDerive, CalendricalRule<?> ruleOfData, LocalDate date, LocalTime time, ZoneOffset offset, ZoneId zone, Chronology chronology, DateTimeFields fields)
This method is designed to be called from Calendrical.get(CalendricalRule)
.
The class implementing the interface must call this method passing in
parameters to fully describe the state of the object to be derived from.
Avoid duplicating information between the date, time and fields if possible.
R
- the type of the desired ruleruleToDerive
- the rule to derive, not nullruleOfData
- the rule of the data to derive from, may be nulldate
- the date to derive from, may be nulltime
- the time to derive from, may be nulloffset
- the zone offset to derive from, may be nullzone
- the zone ID to derive from, may be nullchronology
- the chronology to derive from, may be nullfields
- the fields to derive from, may be null
public static <R> R derive(CalendricalRule<R> ruleToDerive, CalendricalRule<?> ruleOfData, Chronology chronology, DateTimeField field)
This method is designed to be called from Calendrical.get(CalendricalRule)
.
The class implementing the interface must call this method passing in
parameters to fully describe the state of the object to be derived from.
R
- the type of the desired ruleruleToDerive
- the rule to derive, not nullruleOfData
- the rule of the data to derive from, may be nullchronology
- the chronology to derive from, may be nullfield
- the field to derive from, not null
public java.util.List<Calendrical> getInput()
public CalendricalRule<?> getRule()
This will only be present if this merger is created from a single conceptual object as opposed to being merged.
public LocalDate getDate(boolean storeErrorIfNull)
The flag is set to true
if the value is required and an error
should be stored if it is not available. Note that the value is returned
whether it is null or not and no exception is thrown.
storeErrorIfNull
- true to store an error if the value is null
public LocalTime getTime(boolean storeErrorIfNull)
The flag is set to true
if the value is required and an error
should be stored if it is not available. Note that the value is returned
whether it is null or not and no exception is thrown.
storeErrorIfNull
- true to store an error if the value is null
public ZoneOffset getOffset(boolean storeErrorIfNull)
The flag is set to true
if the value is required and an error
should be stored if it is not available. Note that the value is returned
whether it is null or not and no exception is thrown.
storeErrorIfNull
- true to store an error if the value is null
public ZoneId getZone(boolean storeErrorIfNull)
The flag is set to true
if the value is required and an error
should be stored if it is not available. Note that the value is returned
whether it is null or not and no exception is thrown.
storeErrorIfNull
- true to store an error if the value is null
public Chronology getChronology(boolean storeErrorIfNull)
The flag is set to true
if the value is required and an error
should be stored if it is not available. Note that the value is returned
whether it is null or not and no exception is thrown.
storeErrorIfNull
- true to store an error if the value is null
public DateTimeField getField(DateTimeRule rule, boolean storeErrorIfNull)
The flag is set to true
if the value is required and an error
should be stored if it is not available. Note that the value is returned
whether it is null or not and no exception is thrown.
rule
- the rule to retrieve, null returns null
public DateTimeField getFieldDerived(DateTimeRule ruleToDerive, boolean storeErrorIfNull)
The flag is set to true
if the value is required and an error
should be stored if it is not available. Note that the value is returned
whether it is null or not and no exception is thrown.
ruleToDerive
- the rule to retrieve, null returns null
public void setDate(LocalDate date, boolean storeErrorIfClash)
If the flag is true, then a check is performed to see if the specified object clashes with the stored object, storing an error if it does. If the flag is false, then the current value is overwritten without further checks.
date
- the date to store, may be nullstoreErrorIfClash
- true to store an error if the date clashes with the stored valuepublic void setTime(LocalTime time, boolean storeErrorIfClash)
If the flag is true, then a check is performed to see if the specified object clashes with the stored object, storing an error if it does. If the flag is false, then the current value is overwritten without further checks.
time
- the time to store, may be nullstoreErrorIfClash
- true to store an error if the time clashes with the stored valuepublic void setOffset(ZoneOffset offset, boolean storeErrorIfClash)
If the flag is true, then a check is performed to see if the specified object clashes with the stored object, storing an error if it does. If the flag is false, then the current value is overwritten without further checks.
offset
- the offset to store, may be nullstoreErrorIfClash
- true to store an error if the offset clashes with the stored valuepublic void setZone(ZoneId zone, boolean storeErrorIfClash)
If the flag is true, then a check is performed to see if the specified object clashes with the stored object, storing an error if it does. If the flag is false, then the current value is overwritten without further checks.
zone
- the zone to store, may be nullstoreErrorIfClash
- true to store an error if the zone clashes with the stored valuepublic void setChronology(Chronology chronology, boolean storeErrorIfClash)
If the flag is true, then a check is performed to see if the specified object clashes with the stored object, storing an error if it does. If the flag is false, then the current value is overwritten without further checks.
chronology
- the chronology to store, may be nullstoreErrorIfClash
- true to store an error if the chronology clashes with the stored valuepublic void setField(DateTimeField field, boolean storeErrorIfClash)
If the flag is true, then a check is performed to see if the specified object
clashes with the stored object, storing an error if it does.
If the flag is false, then the current value is overwritten without further checks.
The flag should be set to true
to cause the method to check
if the value for the field clashes with an existing value.
A false
value simply overwrites any previous value.
field
- the field to store, null ignoredstoreErrorIfClash
- true to store an error if the field clashes with an existing fieldpublic <R> R derive(CalendricalRule<R> ruleToDerive)
public <R> R deriveChecked(CalendricalRule<R> ruleToDerive)
public java.util.Set<java.lang.String> getErrors()
Use addError(java.lang.String)
to add to this list.
public void addError(java.lang.String error)
error
- the error text, not nullpublic java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |