Class CalendarVariant<D extends CalendarVariant<D>>
- Type Parameters:
D
- generic type of self reference
- All Implemented Interfaces:
Serializable
,Comparable<D>
,CalendarDate
,ChronoDisplay
,Temporal<CalendarDate>
,VariantSource
- Direct Known Subclasses:
HijriCalendar
,HinduCalendar
,HistoricCalendar
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
- All subclasses must be final und immutable.
- Documentation of supported and registered elements is required.
- The natural order should be consistent with
equals()
.
- Since:
- 3.4/4.3
- Author:
- Meno Hochschild
- See Also:
Chronology
,CalendarFamily
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
Compares two calendar variants preferably by their temporal positions on the common date axis and then by their variant names.abstract boolean
Compares the whole state of this instance with given object.long
Counts the elapsed days since UTC epoch.abstract int
hashCode()
Subclasses must redefine this method corresponding to the behaviour ofequals()
.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.minus(CalendarDays days)
Subtracts given calendar days from this instance.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.withVariant(String variant)
Creates a copy of this instance with given variant.withVariant(VariantSource variantSource)
Equivalent towithVariant(variantSource.getVariant())
.Methods inherited from class net.time4j.engine.ChronoEntity
contains, get, get, getInt, getMaximum, getMinimum, getRegisteredElements, getTimezone, hasTimezone, isValid, isValid, isValid, matches, with, with, with, with
Methods inherited from interface net.time4j.engine.CalendarDate
transform, transform, transform, transform, transform, transform
Methods inherited from interface net.time4j.engine.Temporal
isAfterAll, isAfterOrEqual, isBeforeAll, isBeforeOrEqual
Methods inherited from interface net.time4j.engine.VariantSource
getVariant
-
Constructor Details
-
CalendarVariant
public CalendarVariant()
-
-
Method Details
-
withVariant
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.
- Parameters:
variant
- name of new variant- Returns:
- copy of this instance with equal epoch-day-value but different variant
- Throws:
ChronoException
- if given variant is not supported- Since:
- 3.14/4.11
-
withVariant
Equivalent to
withVariant(variantSource.getVariant())
.- Parameters:
variantSource
- source of desired calendar variant- Returns:
- copy of this instance with equal epoch-day-value but different variant
- Throws:
ChronoException
- if given variant is not supported- Since:
- 3.14/4.11
-
compareTo
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.- Specified by:
compareTo
in interfaceComparable<D extends CalendarVariant<D>>
- Parameters:
calendarVariant
- the object to be compared.- Returns:
- a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
- See Also:
equals(Object)
-
isAfter
Description copied from interface:Temporal
Queries if this object is after given object on a timeline.
- Specified by:
isAfter
in interfaceTemporal<D extends CalendarVariant<D>>
- Parameters:
other
- object this instance is compared to- Returns:
true
if this instance is temporally aftertemporal
elsefalse
-
isBefore
Description copied from interface:Temporal
Queries if this object is before given object on a timeline.
- Specified by:
isBefore
in interfaceTemporal<D extends CalendarVariant<D>>
- Parameters:
other
- object this instance is compared to- Returns:
true
if this instance is temporally beforetemporal
elsefalse
-
isSimultaneous
Description copied from interface:Temporal
Queries 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 theObject
-methodequals()
such that first the comparison type must be a temporal one and second that only temporal-only state will be considered.- Specified by:
isSimultaneous
in interfaceTemporal<D extends CalendarVariant<D>>
- Parameters:
other
- object this instance is compared to- Returns:
true
if this instance is temporally equal totemporal
elsefalse
-
plus
Adds given calendar days to this instance.
- Parameters:
days
- calendar days to be added- Returns:
- result of addition
- Throws:
ArithmeticException
- in case of numerical overflow- Since:
- 3.4/4.3
-
minus
Subtracts given calendar days from this instance.
- Parameters:
days
- calendar days to be subtracted- Returns:
- result of subtraction
- Throws:
ArithmeticException
- in case of numerical overflow- Since:
- 3.4/4.3
-
equals
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.
- Overrides:
equals
in classObject
- See Also:
compareTo(CalendarVariant)
-
hashCode
public abstract int hashCode()Subclasses must redefine this method corresponding to the behaviour of
equals()
. -
toString
Provides a complete textual representation of the state of this calendar variant.
-
getDaysSinceEpochUTC
public long getDaysSinceEpochUTC()Description copied from interface:CalendarDate
Counts the elapsed days since UTC epoch.
- Specified by:
getDaysSinceEpochUTC
in interfaceCalendarDate
- Returns:
- count of days relative to UTC epoch [1972-01-01]
- See Also:
EpochDays.UTC
-