D - generic type of self referencepublic abstract class CalendarVariant<D extends CalendarVariant<D>> extends ChronoEntity<D> implements CalendarDate, Comparable<D>, Serializable
Represents an immutable calendar variant.
Display and change chronological element values
The calendar variant consists of chronological elements. This base class
delegates the element and time arithmetic to the associated calendar family respective to
the underlying rules of elements and units. However, any concrete subclass
is required to define the state and reflect it in all get()-methods
and also to specify the serialization behaviour.
Element values can only be changed by creating a new immutable copy
of the original instance. This is done via all with()-methods.
Calendar system
Every calendar variant is a member of a calendar family. That means referring to
a calendar system via a variant name. Hence a limited day arithmetic using the
class CalendarDays is always possible.
Sorting
The sorting algorithm prefers the temporal order then the lexicographical comparison
based on variant names. In case of doubt the documentation of the subclass is leading.
Alternatively, the interface Temporal can be used to enable a pure temporal order.
Implementation notes
equals(). Chronology,
CalendarFamily| Constructor and Description |
|---|
CalendarVariant() |
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(D calendarVariant)
Compares two calendar variants preferably by their temporal positions
on the common date axis and then by their variant names.
|
abstract boolean |
equals(Object obj)
Compares the whole state of this instance with given object.
|
long |
getDaysSinceEpochUTC()
Counts the elapsed days since UTC epoch.
|
abstract String |
getVariant()
Returns the name of the associated variant of underlying calendar system.
|
abstract int |
hashCode()
Subclasses must redefine this method corresponding to the
behaviour of
equals(). |
boolean |
isAfter(CalendarDate other)
Queries if this object is after given object on a timeline.
|
boolean |
isBefore(CalendarDate other)
Queries if this object is before given object on a timeline.
|
boolean |
isSimultaneous(CalendarDate other)
Queries if this object and given object have the same position
on the time axis.
|
D |
minus(CalendarDays days)
Subtracts given calendar days from this instance.
|
D |
plus(CalendarDays days)
Adds given calendar days to this instance.
|
abstract String |
toString()
Provides a complete textual representation of the state of this calendar variant.
|
D |
withVariant(String variant)
Creates a copy of this instance with given variant.
|
D |
withVariant(VariantSource variantSource)
Equivalent to
withVariant(variantSource.getVariant()). |
contains, get, get, getInt, getMaximum, getMinimum, getRegisteredElements, getTimezone, hasTimezone, isValid, isValid, isValid, matches, with, with, with, withtransform, transform, transform, transform, transform, transformisAfterAll, isBeforeAllpublic abstract String getVariant()
Returns the name of the associated variant of underlying calendar system.
CalendarFamily.getCalendarSystem(String)public D withVariant(String variant)
Creates a copy of this instance with given variant.
If given variant is equal to the variant of this instance then the method will just return this instance.
variant - name of new variantChronoException - if given variant is not supportedpublic D withVariant(VariantSource variantSource)
Equivalent to withVariant(variantSource.getVariant()).
variantSource - source of desired calendar variantpublic int compareTo(D calendarVariant)
Compares two calendar variants preferably by their temporal positions on the common date axis and then by their variant names.
Implementation note: In order to make the natural order consistent
with equals() the whole state must be taken into account,
with preference for those attributes which define the temporal
position on the time axis.
compareTo in interface Comparable<D extends CalendarVariant<D>>calendarVariant - the object to be compared.equals(Object)public boolean isAfter(CalendarDate other)
TemporalQueries if this object is after given object on a timeline.
isAfter in interface Temporal<CalendarDate>other - object this instance is compared totrue if this instance is temporally after
temporal else falsepublic boolean isBefore(CalendarDate other)
TemporalQueries if this object is before given object on a timeline.
isBefore in interface Temporal<CalendarDate>other - object this instance is compared totrue if this instance is temporally before
temporal else falsepublic boolean isSimultaneous(CalendarDate other)
TemporalQueries if this object and given object have the same position on the time axis.
Is equivalent to !isAfter(temporal) && !isBefore(temporal).
This method differs from the Object-method equals()
such that first the comparison type must be a temporal one and second
that only temporal-only state will be considered.
isSimultaneous in interface Temporal<CalendarDate>other - object this instance is compared totrue if this instance is temporally equal
to temporal else falsepublic D plus(CalendarDays days)
Adds given calendar days to this instance.
days - calendar days to be addedArithmeticException - in case of numerical overflowpublic D minus(CalendarDays days)
Subtracts given calendar days from this instance.
days - calendar days to be subtractedArithmeticException - in case of numerical overflowpublic abstract boolean equals(Object obj)
Compares the whole state of this instance with given object.
Implementations will usually define their state based on the temporal position and the variant name. Exceptions from this rule should be explicitly documented and reasoned.
equals in class ObjectcompareTo(CalendarVariant)public abstract int hashCode()
Subclasses must redefine this method corresponding to the
behaviour of equals().
public abstract String toString()
Provides a complete textual representation of the state of this calendar variant.
public long getDaysSinceEpochUTC()
CalendarDateCounts the elapsed days since UTC epoch.
getDaysSinceEpochUTC in interface CalendarDateEpochDays.UTCCopyright © 2014–2017. All rights reserved.