Interface ElementRule<T,V>
- Type Parameters:
T
- generic type of time context compatible toChronoEntity
V
- generic type of elment value
- All Known Subinterfaces:
IntElementRule<T>
Represents the rule of a chronological element how to calculate or to manipulate its context-dependent temporal value.
Element rules will be searched by Time4J according to following criteria:
- An element rule will be registered in the
Chronology
together with its associated chronological element. For each chronology and each element instance there is exactly one rule instance. In most cases it is an inner class of the temporal type in question. - If there is no registered rule for an element in a given chronology
then Time4J checks if the associated element is a
BasicElement
and if the element supports the chronology. If yes then its internal rule will be evaluated. - If the search did not yield any result then a
RuleNotFoundException
will be thrown.
Note: All implementations must be immutable.
- Author:
- Meno Hochschild
- See Also:
Chronology.Builder.appendElement(ChronoElement,ElementRule)
,BasicElement.derive(Chronology)
-
Method Summary
Modifier and TypeMethodDescriptiongetChildAtCeiling(T context)
Yields the child element whose value is to be set to the maximum value.getChildAtFloor(T context)
Yields the child element whose value is to be set to the minimum value.getMaximum(T context)
Yields the maximum value suitable for given chronological context.getMinimum(T context)
Yields the minimum value suitable for given chronological context.Yields the current value of associated element in given chronological context.boolean
Queries if given value is valid for the element associated with this rule in given context.Determines the new value of the associated element in given chronological context and yields the result.
-
Method Details
-
getValue
Yields the current value of associated element in given chronological context.
Will be called by
ChronoEntity.get(ChronoElement)
.If the element associated with this rule is a primary element which directly represents a part of the state of an entity then any implementation will request the value directly from the state, otherwise derive from context using a specific logic. The term primary refers to if the context itself stores the value.
- Parameters:
context
- time context to be evaluated- Returns:
- current element value as object (never
null
) - Throws:
ChronoException
- if the associated element value cannot be evaluated
-
getMinimum
Yields the minimum value suitable for given chronological context.
Will be called by
ChronoEntity.getMinimum(ChronoElement)
.ATTENTION: Defining a minimum and maximum does not imply a continuum between minimum and maximum without any gaps, see for example summer time switches or hebrew leap months. Furthermore, a chronologically ascending order cannot be guaranteed.
- Parameters:
context
- time context to be evaluated- Returns:
- minimum legal and sometimes context-dependent value
- Throws:
ChronoException
- if the associated minimum value cannot be evaluated- See Also:
getMaximum(T)
-
getMaximum
Yields the maximum value suitable for given chronological context.
Will be called by
ChronoEntity.getMaximum(ChronoElement)
.ATTENTION: Defining a minimum and maximum does not imply a continuum between minimum and maximum without any gaps, see for example summer time switches or hebrew leap months. Furthermore, a chronologically ascending order cannot be guaranteed.
- Parameters:
context
- time context to be evaluated- Returns:
- maximum legal and sometimes context-dependent value
- Throws:
ChronoException
- if the associated maximum value cannot be evaluated- See Also:
getMinimum(T)
-
isValid
Queries if given value is valid for the element associated with this rule in given context.
Will be called by
ChronoEntity.isValid(ChronoElement, V)
. A numerical overflow causing anArithmeticException
will usually not be checked.- Parameters:
context
- time context to be evaluatedvalue
- candidate value to be validated (optional)- Returns:
true
if valid elsefalse
-
withValue
Determines the new value of the associated element in given chronological context and yields the result.
Will be called by
ChronoEntity.with(ChronoElement, V)
. The third parameter is in most cases only relevant if the value type is no enum type but for example an integer type. The lenient mode causes the tolerant interpretation of invalid values like 31st of April as 1st of May. This mode is only active if an element is either explicitly declared as lenient or if the methodStdOperator.setLenient()
is used.- Parameters:
context
- time context to be evaluatedvalue
- new element value (optional)lenient
- leniency mode- Returns:
- changed copy of context which itself remains unaffected
- Throws:
IllegalArgumentException
- if given value is out of range or not valid dependent on the given time contextArithmeticException
- in case of numerical overflow- See Also:
isValid(T, V)
,StdOperator.setLenient(Object, ChronoElement)
,ChronoElement.isLenient()
,ProportionalElement.setLenient(Number)
-
getChildAtFloor
Yields the child element whose value is to be set to the minimum value.
The access to this method only happens indirectly in the class
StdOperator
.- Parameters:
context
- time context to be evaluated- Returns:
- child element or
null
if not available - See Also:
StdOperator.atFloor(ChronoElement)
-
getChildAtCeiling
Yields the child element whose value is to be set to the maximum value.
The access to this method only happens indirectly in the class
StdOperator
.- Parameters:
context
- time context to be evaluated- Returns:
- child element or
null
if not available - See Also:
StdOperator.atCeiling(ChronoElement)
-