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
-
Method Summary
Modifier and TypeMethodDescriptionboolean
contains(ChronoElement<?> element)
Queries if the value for given chronological element can be accessed viaget(element)
.<V> V
get(ChronoElement<V> element)
Returns the partial value associated with given chronological element.<R> R
get(ChronoFunction<? super T,R> function)
Lets given query evaluate this entity.int
getInt(ChronoElement<Integer> element)
Returns the partial value associated with given chronological element.<V> V
getMaximum(ChronoElement<V> element)
Yields the maximum value of given chronological element in the current context of this object.<V> V
getMinimum(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.boolean
Queries if this entity contains a timezone for display purposes.boolean
isValid(ChronoElement<Integer> element, int value)
Tests if the value for given chronological value is invalid.boolean
isValid(ChronoElement<Long> element, long value)
Tests if the value for given chronological value is invalid.<V> boolean
isValid(ChronoElement<V> element, V value)
Tests if the value for given chronological value is invalid.boolean
matches(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> T
with(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 givenChronoOperator
using a strategy pattern approach.
-
Constructor Details
-
ChronoEntity
public ChronoEntity()
-
-
Method Details
-
contains
Description copied from interface:ChronoDisplay
Queries 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:
contains
in interfaceChronoDisplay
- Parameters:
element
- chronological element to be asked (optional)- Returns:
true
if 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:ChronoDisplay
Returns the partial value associated with given chronological element.
- Specified by:
get
in 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:ChronoDisplay
Returns the partial value associated with given chronological element.
- Specified by:
getInt
in interfaceChronoDisplay
- Parameters:
element
- element which has the value- Returns:
- associated element value as int primitive or
Integer.MIN_VALUE
if not available - See Also:
ChronoDisplay.get(ChronoElement)
-
getMinimum
Description copied from interface:ChronoDisplay
Yields 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:
getMinimum
in 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:ChronoDisplay
Yields 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
59
but 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:
getMaximum
in 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 yieldnull
or 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
null
if 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:
true
if 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:
true
if 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:
true
if 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:
true
if 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
null
value will almost ever be seen as invalid causing anIllegalArgumentException
. Subclasses which permitnull
must 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
ChronoOperator
using 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:
hasTimezone
in interfaceChronoDisplay
- Returns:
true
if 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
ChronoException
by default. Subclasses with a timezone reference intended for formatted output will override the method in a suitable way.- Specified by:
getTimezone
in 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
-