Class TimeAxis<U,T extends TimePoint<U,T>>
- Type Parameters:
U
- generic type of time unitsT
- generic type of time context compatible toTimePoint
- All Implemented Interfaces:
Comparator<T>
,ChronoMerger<T>
,TimeLine<T>
A time axis is a dynamic view on a chronology where a system of registered time units is used to define a time arithmetic for any time points belonging to this time axis respective chronology.
- Author:
- Meno Hochschild
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
Compares points in time by their temporal position on the timeline.createFrom(ChronoEntity<?> entity, AttributeQuery attributes, boolean lenient, boolean preparsing)
Creates a new entity of type T based on given chronological data.element()
Yields this time axis as chronological self-referencing element.getBaseUnit(ChronoElement<?> element)
Returns the base unit of given element if available.Returns the associated calendar system if available.getCalendarSystem(String variant)
Returns the calendar system for given calendar variant if available.double
Returns the length of given time unit in seconds as it is usual or estimated on this time axis.Yields the maximum of this time axis.Yields the minimum of this time axis.Returns all registered time units.Returns the type of supported time units.boolean
hasBaseUnit(ChronoElement<?> element)
Queries if given element has a base unit.boolean
Queries if this chronology has a calendar system.boolean
Determines if this timeline is calendrical or not.boolean
isConvertible(U unit1, U unit2)
Queries if given time units are convertible.boolean
isRegistered(U unit)
Queries if given time unit is registered.boolean
isSupported(U unit)
Queries if given time unit is supported.stepBackwards(T timepoint)
Move given point in time backwards by one step.stepForward(T timepoint)
Move given point in time forward by one step.Comparator<? super U>
Compares time units by ascending precision (that is descending length).Methods inherited from class net.time4j.engine.Chronology
createFrom, getCalendarSystem, getChronoType, getDefaultPivotYear, getDefaultStartOfDay, getExtensions, getFormatPattern, getRegisteredElements, isRegistered, isSupported, lookup, preformat, preparser
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.time4j.engine.ChronoMerger
getFormatPattern
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Method Details
-
getUnitType
Returns the type of supported time units.
- Returns:
- reified type of time unit
-
getRegisteredUnits
Returns all registered time units.
- Returns:
- unmodifiable set of registered units without duplicates
-
isRegistered
Queries if given time unit is registered.
- Parameters:
unit
- time unit (optional)- Returns:
true
if registered elsefalse
-
isSupported
Queries if given time unit is supported.
A time unit is supported if it is either registered or if it defines a suitable rule.
- Parameters:
unit
- time unit (optional)- Returns:
true
if supported elsefalse
- See Also:
BasicUnit.derive(Chronology)
-
getLength
Returns the length of given time unit in seconds as it is usual or estimated on this time axis.
Example: In ISO-systems the year has
365.2425 * 86400
seconds by default (mean average), in a julian calender365.25 * 86400
seconds however. Daylight-saving-transitions or UTC-leapseconds are not counted here.Note: If given time unit is not registered then Time4J tries to interprete the unit as
ChronoUnit
. If this fails, too, then the length is not calculatable.- Parameters:
unit
- time unit- Returns:
- estimated standard length in seconds or
Double.NaN
if not calculatable - See Also:
ChronoUnit
-
isConvertible
Queries if given time units are convertible.
Convertibility means that there exists a fixed integer factor for conversion between the units. Examples for convertible units are weeks/days (factor 7) or years/months (factor 12) in ISO-systems. Otherwise minutes and seconds will only be convertible with factor
60
if there is no UTC-context with possible leap seconds.If two time units are convertible then the length of a time unit (
getLength()
) can be used to convert time units by applying the rounded quotient of lengths of units.- Parameters:
unit1
- first time unitunit2
- second time unit- Returns:
true
if convertible elsefalse
- See Also:
getLength(U)
-
hasBaseUnit
Queries if given element has a base unit.
- Parameters:
element
- chronological element (optional)- Returns:
true
if given element has a base unit elsefalse
- See Also:
getBaseUnit(ChronoElement)
-
getBaseUnit
Returns the base unit of given element if available.
Only registred elements can have a base unit unless the element is a
BasicElement
and refers another registered element with a base unit.- Parameters:
element
- chronological element- Returns:
- found base unit
- Throws:
ChronoException
- if there is no base unit- See Also:
hasBaseUnit(ChronoElement)
,BasicElement.getParent()
-
unitComparator
Compares time units by ascending precision (that is descending length).
Note: Before release v4.21, the time axis implemented
Comparator<U>
, notComparator<T>
. This new method serves as the replacement for the old comparator method.- Returns:
- Comparator
- Since:
- 3.25/4.21
- See Also:
compare(TimePoint, TimePoint)
-
compare
Compares points in time by their temporal position on the timeline.
- Specified by:
compare
in interfaceComparator<U>
- Parameters:
first
- the first point in comparisonsecond
- the second point in comparison- Returns:
- positive, zero or negative number if
first
is later, simultaneous or earlier thansecond
- Since:
- 3.25/4.21
-
getMinimum
Yields the minimum of this time axis.
- Specified by:
getMinimum
in interfaceTimeLine<U>
- Returns:
- earliest possible time point
-
getMaximum
Yields the maximum of this time axis.
- Specified by:
getMaximum
in interfaceTimeLine<U>
- Returns:
- latest possible time point
-
isCalendrical
public boolean isCalendrical()Description copied from interface:TimeLine
Determines if this timeline is calendrical or not.- Specified by:
isCalendrical
in interfaceTimeLine<U>
- Returns:
- boolean
- See Also:
CalendarDate
-
hasCalendarSystem
public boolean hasCalendarSystem()Description copied from class:Chronology
Queries if this chronology has a calendar system.
- Overrides:
hasCalendarSystem
in classChronology<T extends TimePoint<U,T>>
- Returns:
true
if this chronology has a calendar system elsefalse
- See Also:
Chronology.getCalendarSystem()
-
getCalendarSystem
Description copied from class:Chronology
Returns the associated calendar system if available.
- Overrides:
getCalendarSystem
in classChronology<T extends TimePoint<U,T>>
- Returns:
- calendar system, not
null
- See Also:
Chronology.hasCalendarSystem()
-
getCalendarSystem
Description copied from class:Chronology
Returns the calendar system for given calendar variant if available.
- Overrides:
getCalendarSystem
in classChronology<T extends TimePoint<U,T>>
- Parameters:
variant
- name of calendar variant- Returns:
- calendar system, not
null
- See Also:
VariantSource.getVariant()
-
createFrom
public T createFrom(ChronoEntity<?> entity, AttributeQuery attributes, boolean lenient, boolean preparsing)Description copied from interface:ChronoMerger
Creates a new entity of type T based on given chronological data.
Typically the method will query the given
entity
with different priorities for elements which can compose a new chronological entity (per group). For example a calendar date can be composed either by epoch days or the group (year)-(month)-(day-of-month) or the group (year)-(day-of-year) etc.A text parser will call this method after having resolved a text into single chronological elements and values. Implementations should always validate the parsed values. In case of error, they are free to either throw an
IllegalArgumentException
or to generate and to save an error message by mean of the expressionentity.with(ValidationElement.ERROR_MESSAGE, message
.- Specified by:
createFrom
in interfaceChronoMerger<U>
- Overrides:
createFrom
in classChronology<T extends TimePoint<U,T>>
- Parameters:
entity
- any chronological entity like parsed elements with their valuesattributes
- configuration attributes given by parserlenient
- controls the leniency how to interprete invalid valuespreparsing
- preparsing phase active?- Returns:
- new time context or
null
if given data are insufficient - See Also:
ValidationElement.ERROR_MESSAGE
-
element
Yields this time axis as chronological self-referencing element.
- Returns:
- self-referencing element
-
stepForward
Description copied from interface:TimeLine
Move given point in time forward by one step.
- Specified by:
stepForward
in interfaceTimeLine<U>
- Parameters:
timepoint
- point in time to be moved forward- Returns:
- new point in time one step after given argument
or
null
if applied on the maximum of timeline
-
stepBackwards
Description copied from interface:TimeLine
Move given point in time backwards by one step.
- Specified by:
stepBackwards
in interfaceTimeLine<U>
- Parameters:
timepoint
- point in time to be moved backwards- Returns:
- new point in time one step before given argument
or
null
if applied on the minimum of timeline
-