T - generic type of self referencepublic abstract class ChronoEntity<T extends ChronoEntity<T>> extends Object
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.
|
<V> V |
getMaximum(ChronoElement<V> element)
Yields the maximum value of given chronological element in the
current context of this entity.
|
<V> V |
getMinimum(ChronoElement<V> element)
Yields the minimum value of given chronological element in the
current context of this entity.
|
TZID |
getTimezone()
Returns the associated timezone ID if available.
|
boolean |
hasTimezone()
Ermittelt, ob eine Zeitzone vorhanden ist.
|
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)
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.
element - chronological element to be asked (optional)true if the method get(ChronoElement) can
be called without exception else falseget(ChronoElement)public <V> V get(ChronoElement<V> element)
Returns the partial value associated with given chronological element.
V - generic type of element valueelement - element which has the valuenull)ChronoException - if the element is not registered and there
is no element rule for evaluating the valuecontains(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 <V> V getMinimum(ChronoElement<V> element)
Yields the minimum value of given chronological element in the current context of this entity.
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.
V - generic type of element valueelement - element whose minimum value is to be evaluatedChronoException - if the element is not registered and there
is no element rule for getting the minimum valueChronoElement.getDefaultMinimum(),
getMaximum(ChronoElement)public <V> V getMaximum(ChronoElement<V> element)
Yields the maximum value of given chronological element in the current context of this entity.
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/entity (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.
V - generic type of element valueelement - element whose maximum value is to be evaluatedChronoException - if the element is not registered and there
is no element rule for getting the maximum valueChronoElement.getDefaultMaximum(),
getMinimum(ChronoElement)public boolean hasTimezone()
Ermittelt, ob eine Zeitzone vorhanden ist.
Diese Implementierung kennt standardmäßig keine Zeitzone
und liefert false. Subklassen mit Zeitzonenbezug werden die
Methode in geeigneter Weise überschreiben.
true if a timezone is available and can be achieved
with getTimezone() else falsepublic TZID getTimezone()
Returns the associated timezone ID if available.
This implementation throws a ChronoException
by default. Subclasses with timezone reference will override
the method in a suitable way.
ChronoException - if the timezone is not availablehasTimezone()Copyright © 2014. All rights reserved.