Class ChronoEntity<T extends ChronoEntity<T>>
- Type Parameters:
T- generic type of self reference
- All Implemented Interfaces:
ChronoDisplay
- Direct Known Subclasses:
AnnualDate,CalendarVariant,FixedCalendarInterval,SpanOfWeekdays,TimePoint
Represents a temporal object which associates partial temporal values with chronological elements and also allows some manipulations of these element values.
A ChronoEntity is usually a TimePoint, where the
(primary) element values determine the position on a time axis such
that a time arithmetic is possible. Alternatively a ChronoEntity
can also represent a partial information like the combination of month
and day-of-month for a simple display of a birthday.
Chronological elements are either statically registered such that
a direct access is enabled, or there is an (external) rule which
enables read- and write-access. If no element rule can be found a
RuleNotFoundException will be thrown.
Note: All public implementations must be immutable.
- Author:
- Meno Hochschild
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(ChronoElement<?> element)Queries if the value for given chronological element can be accessed viaget(element).<V> Vget(ChronoElement<V> element)Returns the partial value associated with given chronological element.<R> Rget(ChronoFunction<? super T,R> function)Lets given query evaluate this entity.intgetInt(ChronoElement<Integer> element)Returns the partial value associated with given chronological element.<V> VgetMaximum(ChronoElement<V> element)Yields the maximum value of given chronological element in the current context of this object.<V> VgetMinimum(ChronoElement<V> element)Yields the minimum value of given chronological element in the current context of this object.Set<ChronoElement<?>>Yields all registered elements of this instance.Returns the associated timezone ID for display purposes if available.booleanQueries if this entity contains a timezone for display purposes.booleanisValid(ChronoElement<Integer> element, int value)Tests if the value for given chronological value is invalid.booleanisValid(ChronoElement<Long> element, long value)Tests if the value for given chronological value is invalid.<V> booleanisValid(ChronoElement<V> element, V value)Tests if the value for given chronological value is invalid.booleanmatches(ChronoCondition<? super T> condition)Queries if this entity matches given condition.with(ChronoElement<Integer> element, int value)Creates a copy of this instance with the changed element value.with(ChronoElement<Long> element, long value)Creates a copy of this instance with the changed element value.<V> Twith(ChronoElement<V> element, V value)Creates a copy of this instance with the changed element value.with(ChronoOperator<T> operator)Creates a copy of this instance which is adjusted by givenChronoOperatorusing a strategy pattern approach.
-
Constructor Details
-
ChronoEntity
public ChronoEntity()
-
-
Method Details
-
contains
Description copied from interface:ChronoDisplayQueries if the value for given chronological element can be accessed via
get(element).If the argument is missing then this method will yield
false. Note: Elements which are not registered but define a suitable rule are also accessible.- Specified by:
containsin interfaceChronoDisplay- Parameters:
element- chronological element to be asked (optional)- Returns:
trueif the element is registered or there is an element rule for evaluating the value elsefalse- See Also:
ChronoDisplay.get(ChronoElement)
-
get
Description copied from interface:ChronoDisplayReturns the partial value associated with given chronological element.
- Specified by:
getin interfaceChronoDisplay- Type Parameters:
V- generic type of element value- Parameters:
element- element which has the value- Returns:
- associated element value as object (never
null) - See Also:
ChronoDisplay.contains(ChronoElement)
-
getInt
Description copied from interface:ChronoDisplayReturns the partial value associated with given chronological element.
- Specified by:
getIntin interfaceChronoDisplay- Parameters:
element- element which has the value- Returns:
- associated element value as int primitive or
Integer.MIN_VALUEif not available - See Also:
ChronoDisplay.get(ChronoElement)
-
getMinimum
Description copied from interface:ChronoDisplayYields the minimum value of given chronological element in the current context of this object.
The definition of a minimum and a maximum does generally not imply that every intermediate value between minimum and maximum is valid in this context. For example in the timezone Europe/Berlin the hour [T02:00] will be invalid if switching to summer time.
In most cases the minimum value is not dependent on this context.
- Specified by:
getMinimumin interfaceChronoDisplay- Type Parameters:
V- generic type of element value- Parameters:
element- element whose minimum value is to be evaluated- Returns:
- minimum maybe context-dependent element value
- See Also:
ChronoElement.getDefaultMinimum(),ChronoDisplay.getMaximum(ChronoElement)
-
getMaximum
Description copied from interface:ChronoDisplayYields the maximum value of given chronological element in the current context of this object.
Maximum values are different from minimum case often dependent on the context. An example is the element SECOND_OF_MINUTE whose maximum is normally
59but can differ in UTC-context with leap seconds. Another more common example is the maximum of the element DAY_OF_MONTH (28-31) which is dependent on the month and year of this context (leap years!).Note: In timezone-related timestamps possible offset jumps inducing gaps on the local timeline will be conserved. That means that minimum and maximum do not guarantee a continuum of valid intermediate values.
- Specified by:
getMaximumin interfaceChronoDisplay- Type Parameters:
V- generic type of element value- Parameters:
element- element whose maximum value is to be evaluated- Returns:
- maximum maybe context-dependent element value
- See Also:
ChronoElement.getDefaultMaximum(),ChronoDisplay.getMinimum(ChronoElement)
-
get
Lets given query evaluate this entity.
Is equivalent to
function.apply(this). The applied strategy pattern hereby enables the externalization of querying the interpretation and evaluation of this entity, consequently enabling user-defined queries with arbitrary result types R. Main difference to chronological elements are lack of formattability and read-only access. Users have to consult the documentation of given query to decide if this method will yieldnullor throws an exception if the result is undefined or otherwise not obtainable.- Type Parameters:
R- generic type of result of query- Parameters:
function- time query- Returns:
- result of query or
nullif undefined - Throws:
ChronoException- if the given query is not executable
-
matches
Queries if this entity matches given condition.
Is equivalent to
condition.test(this). This method will never throw an exception. This behaviour is in contrast to that ofChronoFunction.- Parameters:
condition- temporal condition- Returns:
trueif the given condition is matched by this entity elsefalse- See Also:
get(ChronoFunction)
-
isValid
Tests if the value for given chronological value is invalid.
Notes: This method tests if given value to be in question can be set via the expression
with(element, value). A numerical overflow situation (causing anArithmeticException) will usually not be checked.- Type Parameters:
V- generic type of element value- Parameters:
element- element the given value shall be assigned tovalue- candidate value to be validated (optional)- Returns:
trueif the methodwith()can be called without exception elsefalse- See Also:
with(ChronoElement, V)
-
isValid
Tests if the value for given chronological value is invalid.
Notes: This method tests if given value to be in question can be set via the expression
with(element, value). A numerical overflow situation (causing anArithmeticException) will usually not be checked.- Parameters:
element- element the given value shall be assigned tovalue- candidate value to be validated- Returns:
trueif the methodwith()can be called without exception elsefalse- See Also:
with(ChronoElement, int)
-
isValid
Tests if the value for given chronological value is invalid.
Notes: This method tests if given value to be in question can be set via the expression
with(element, value). A numerical overflow situation (causing anArithmeticException) will usually not be checked.- Parameters:
element- element the given value shall be assigned tovalue- candidate value to be validated- Returns:
trueif the methodwith()can be called without exception elsefalse- See Also:
with(ChronoElement, long)
-
with
Creates a copy of this instance with the changed element value.
A
nullvalue will almost ever be seen as invalid causing anIllegalArgumentException. Subclasses which permitnullmust explicitly document this feature.- Type Parameters:
V- generic type of element value- Parameters:
element- chronological elementvalue- new element value- Returns:
- changed copy of the same type, this instance remains unaffected
- Throws:
ChronoException- if the element is not registered and there is no element rule for setting the valueIllegalArgumentException- if the value is not validArithmeticException- in case of arithmetic overflow- See Also:
isValid(ChronoElement, V)
-
with
Creates a copy of this instance with the changed element value.
- Parameters:
element- chronological elementvalue- new element value- Returns:
- changed copy of the same type, this instance remains unaffected
- Throws:
ChronoException- if the element is not registered and there is no element rule for setting the valueIllegalArgumentException- if the value is not validArithmeticException- in case of arithmetic overflow- See Also:
isValid(ChronoElement, V)
-
with
Creates a copy of this instance with the changed element value.
- Parameters:
element- chronological elementvalue- new element value- Returns:
- changed copy of the same type, this instance remains unaffected
- Throws:
ChronoException- if the element is not registered and there is no element rule for setting the valueIllegalArgumentException- if the value is not validArithmeticException- in case of arithmetic overflow- See Also:
isValid(ChronoElement, V)
-
with
Creates a copy of this instance which is adjusted by given
ChronoOperatorusing a strategy pattern approach.Is equivalent to
operator.apply(this). Hereby a user-defined manipulation will be externalized and is semantically similar to the reading counterpartChronoFunction.- Parameters:
operator- operator for adjusting the element values- Returns:
- changed copy of the same type, this instance remains unaffected
- Throws:
ChronoException- if no element rule exists for setting the valuesIllegalArgumentException- if any new value is not validArithmeticException- in case of arithmetic overflow- See Also:
get(ChronoFunction)
-
hasTimezone
public boolean hasTimezone()Queries if this entity contains a timezone for display purposes.
This implementation has no timezone by default and yields
false. Subclasses with a timezone reference intended for formatted output will override the method in a suitable way.- Specified by:
hasTimezonein interfaceChronoDisplay- Returns:
trueif a timezone is available and can be achieved withgetTimezone()elsefalse
-
getTimezone
Returns the associated timezone ID for display purposes if available.
This implementation throws a
ChronoExceptionby default. Subclasses with a timezone reference intended for formatted output will override the method in a suitable way.- Specified by:
getTimezonein interfaceChronoDisplay- Returns:
- timezone identifier if available
- Throws:
ChronoException- if the timezone is not available- See Also:
hasTimezone()
-
getRegisteredElements
Yields all registered elements of this instance.
Note that some (external) elements can be supported but not registered.
- Returns:
- unmodifiable set of internally registered elements
- Since:
- 3.13/4.10
-