T - generic type of self referencepublic abstract class ChronoEntity<T extends ChronoEntity<T>> extends Object implements ChronoDisplay
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.
| Constructor and Description |
|---|
ChronoEntity() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(ChronoElement<?> element)
Queries if the value for given chronological element can be
accessed via
get(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<?>> |
getRegisteredElements()
Yields all registered elements of this instance.
|
TZID |
getTimezone()
Returns the associated timezone ID for display purposes
if available.
|
boolean |
hasTimezone()
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.
|
T |
with(ChronoElement<Integer> element,
int value)
Creates a copy of this instance with the changed element value.
|
T |
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.
|
T |
with(ChronoOperator<T> operator)
Creates a copy of this instance which is adjusted by given
ChronoOperator using a strategy pattern approach. |
public boolean contains(ChronoElement<?> element)
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.
contains in interface ChronoDisplayelement - chronological element to be asked (optional)true if the element is registered or there is an element rule for evaluating the value
else falseChronoDisplay.get(ChronoElement)public <V> V get(ChronoElement<V> element)
ChronoDisplayReturns the partial value associated with given chronological element.
get in interface ChronoDisplayV - generic type of element valueelement - element which has the valuenull)ChronoDisplay.contains(ChronoElement)public int getInt(ChronoElement<Integer> element)
ChronoDisplayReturns the partial value associated with given chronological element.
getInt in interface ChronoDisplayelement - element which has the valueInteger.MIN_VALUE if not availableChronoDisplay.get(ChronoElement)public <V> V getMinimum(ChronoElement<V> element)
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.
getMinimum in interface ChronoDisplayV - generic type of element valueelement - element whose minimum value is to be evaluatedChronoElement.getDefaultMinimum(),
ChronoDisplay.getMaximum(ChronoElement)public <V> V getMaximum(ChronoElement<V> element)
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 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.
getMaximum in interface ChronoDisplayV - generic type of element valueelement - element whose maximum value is to be evaluatedChronoElement.getDefaultMaximum(),
ChronoDisplay.getMinimum(ChronoElement)public final <R> R get(ChronoFunction<? super T,R> function)
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 is read-only access.
Users have to consult the documentation of given query to decide
if this method will yield null or throws an exception
if the result is undefined or otherwise not obtainable.
R - generic type of result of queryfunction - time querynull if undefinedChronoException - if the given query is not executablepublic boolean matches(ChronoCondition<? super T> condition)
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 of ChronoFunction.
condition - temporal conditiontrue if the given condition is matched by this
entity else falseget(ChronoFunction)public <V> boolean isValid(ChronoElement<V> element, V value)
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 an ArithmeticException) will
usually not be checked.
V - generic type of element valueelement - element the given value shall be assigned tovalue - candidate value to be validated (optional)true if the method with() can be called
without exception else falsewith(ChronoElement, V)public boolean isValid(ChronoElement<Integer> element, int value)
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 an ArithmeticException) will
usually not be checked.
element - element the given value shall be assigned tovalue - candidate value to be validatedtrue if the method with() can be called
without exception else falsewith(ChronoElement, int)public boolean isValid(ChronoElement<Long> element, long value)
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 an ArithmeticException) will
usually not be checked.
element - element the given value shall be assigned tovalue - candidate value to be validatedtrue if the method with() can be called
without exception else falsewith(ChronoElement, long)public <V> T with(ChronoElement<V> element, V value)
Creates a copy of this instance with the changed element value.
A null value will almost ever be seen as invalid causing an
IllegalArgumentException. Subclasses which permit null
must explicitly document this feature.
V - generic type of element valueelement - chronological elementvalue - new element valueChronoException - 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 overflowisValid(ChronoElement, V)public T with(ChronoElement<Integer> element, int value)
Creates a copy of this instance with the changed element value.
element - chronological elementvalue - new element valueChronoException - 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 overflowisValid(ChronoElement, V)public T with(ChronoElement<Long> element, long value)
Creates a copy of this instance with the changed element value.
element - chronological elementvalue - new element valueChronoException - 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 overflowisValid(ChronoElement, V)public T with(ChronoOperator<T> operator)
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 counterpart ChronoFunction.
operator - operator for adjusting the element valuesChronoException - if no element rule exists for setting the valuesIllegalArgumentException - if any new value is not validArithmeticException - in case of arithmetic overflowget(ChronoFunction)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.
hasTimezone in interface ChronoDisplaytrue if a timezone is available and can be achieved
with getTimezone() else falsepublic TZID 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.
getTimezone in interface ChronoDisplayChronoException - if the timezone is not availablehasTimezone()public Set<ChronoElement<?>> getRegisteredElements()
Yields all registered elements of this instance.
Note that some (external) elements can be supported but not registered.
Copyright © 2014–2017. All rights reserved.