Class Chronology<T>

java.lang.Object
net.time4j.engine.Chronology<T>
Type Parameters:
T - generic type compatible to ChronoEntity
All Implemented Interfaces:
ChronoMerger<T>
Direct Known Subclasses:
BridgeChronology, CalendarFamily, TimeAxis

public class Chronology<T> extends Object implements ChronoMerger<T>

Represents a system of chronological elements which form any kind of temporal value.

Author:
Meno Hochschild
  • Method Details

    • getChronoType

      public Class<T> getChronoType()

      Returns the chronological type.

      Returns:
      type of time context
    • getRegisteredElements

      public Set<ChronoElement<?>> getRegisteredElements()

      Returns all registered chronological elements.

      Returns:
      unmodifiable set of elements without duplicates
    • isRegistered

      public boolean isRegistered(ChronoElement<?> element)

      Queries if given chronological element is registered together with its element rule.

      Parameters:
      element - element to be asked (optional)
      Returns:
      true if registered else false
    • isSupported

      public boolean isSupported(ChronoElement<?> element)

      Queries if given chronological element is supported by this chronology.

      The element will be supported if it is either registered or defines a suitable element rule for this chronology.

      Parameters:
      element - element to be asked (optional)
      Returns:
      true if supported else false
    • createFrom

      public T createFrom(TimeSource<?> clock, AttributeQuery attributes)
      Description copied from interface: ChronoMerger

      Creates a new entity which reflects current time.

      In a date-only chronology this method will create the current date using the necessary timezone contained in given attributes.

      Specified by:
      createFrom in interface ChronoMerger<T>
      Parameters:
      clock - source for current time
      attributes - configuration attributes which might contain the timezone to translate current time to local time
      Returns:
      new time context or null if given data are insufficient
    • 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 expression entity.with(ValidationElement.ERROR_MESSAGE, message.

      Specified by:
      createFrom in interface ChronoMerger<T>
      Parameters:
      entity - any chronological entity like parsed elements with their values
      attributes - configuration attributes given by parser
      lenient - controls the leniency how to interprete invalid values
      preparsing - preparsing phase active?
      Returns:
      new time context or null if given data are insufficient
      See Also:
      ValidationElement.ERROR_MESSAGE
    • preformat

      public ChronoDisplay preformat(T context, AttributeQuery attributes)
      Description copied from interface: ChronoMerger

      Transforms the current context/entity into another set of chronological values which finally shall be formatted using given attributes.

      Specified by:
      preformat in interface ChronoMerger<T>
      Parameters:
      context - actual chronological context to be formatted
      attributes - controls attributes during formatting
      Returns:
      replacement entity which will finally be used for formatting
    • preparser

      public Chronology<?> preparser()
      Description copied from interface: ChronoMerger

      This method defines a child chronology which can preparse a chronological text.

      Specified by:
      preparser in interface ChronoMerger<T>
      Returns:
      preparsing chronology or null (default)
    • getFormatPattern

      public String getFormatPattern(FormatStyle style, Locale locale)
      Description copied from interface: ChronoMerger

      Defines a CLDR-compatible localized format pattern.

      The default implementation always throws an UnsupportedOperationException.

      Specified by:
      getFormatPattern in interface ChronoMerger<T>
      Parameters:
      style - format style
      locale - language and country setting
      Returns:
      localized format pattern
      See Also:
      LocalizedPatternSupport
    • getDefaultStartOfDay

      public StartOfDay getDefaultStartOfDay()
      Description copied from interface: ChronoMerger

      Determines the default start of day.

      Specified by:
      getDefaultStartOfDay in interface ChronoMerger<T>
      Returns:
      start of day
    • getDefaultPivotYear

      public int getDefaultPivotYear()
      Description copied from interface: ChronoMerger

      Determines the default pivot year which might be calendar specific and serves for the formatting of two-digit-years.

      Most calendar chronologies should choose a pivot year 20 years in the future. The standard implementation is based on the gregorian calendar. If an implementation returns the value 100 then the formatting of two-digit-years is effectively switched off.

      Specified by:
      getDefaultPivotYear in interface ChronoMerger<T>
      Returns:
      default pivot year (must not be smaller than 100)
    • getExtensions

      public List<ChronoExtension> getExtensions()

      Returns all registered chronological extensions.

      This method will be called by format-API in order to collect all extension elements which are relevant for formatting.

      Returns:
      unmodifiable list of extensions
    • hasCalendarSystem

      public boolean hasCalendarSystem()

      Queries if this chronology has a calendar system.

      Returns:
      true if this chronology has a calendar system else false
      See Also:
      getCalendarSystem()
    • getCalendarSystem

      public CalendarSystem<T> getCalendarSystem()

      Returns the associated calendar system if available.

      Returns:
      calendar system, not null
      Throws:
      ChronoException - if the calendar system is unavailable or if there is more than one variant
      See Also:
      hasCalendarSystem()
    • getCalendarSystem

      public CalendarSystem<T> getCalendarSystem(String variant)

      Returns the calendar system for given calendar variant if available.

      Parameters:
      variant - name of calendar variant
      Returns:
      calendar system, not null
      Throws:
      ChronoException - if a calendar system is unavailable for given variant (invalid variant name)
      Since:
      3.4/4.3
      See Also:
      VariantSource.getVariant()
    • getCalendarSystem

      public final CalendarSystem<T> getCalendarSystem(VariantSource variant)

      Returns the calendar system for given calendar variant if available.

      Parameters:
      variant - name of calendar variant
      Returns:
      calendar system, not null
      Throws:
      ChronoException - if a calendar system is unavailable for given variant (invalid variant name)
      Since:
      5.0
    • lookup

      public static <T> Chronology<T> lookup(Class<T> chronoType)

      Returns a typed singleton per ChronoEntity-class.

      Type Parameters:
      T - generic type of time context
      Parameters:
      chronoType - chronological type
      Returns:
      chronology or null if not found