Class BridgeChronology<S,​T extends ChronoEntity<T>>

java.lang.Object
net.time4j.engine.Chronology<S>
net.time4j.engine.BridgeChronology<S,​T>
Type Parameters:
S - generic type of foreign temporal type
T - generic type compatible to ChronoEntity
All Implemented Interfaces:
ChronoMerger<S>

public final class BridgeChronology<S,​T extends ChronoEntity<T>> extends Chronology<S>

Represents a foreign chronology which delegates formatting and parsing to a chronology in Time4J.

A ChronoFormatter can be created by help of this chronology such that the formatter can be adjusted to any foreign type without external conversion.

Important to know: This chronology does not register any elements and is also not registered itself so Chronology.lookup(...) will inevitably fail to find this chronology.

Since:
3.24/4.20
Author:
Meno Hochschild
See Also:
TemporalType
  • Constructor Details

    • BridgeChronology

      public BridgeChronology(Converter<S,​T> converter, Chronology<T> delegate)

      Constructs a new instance.

      Parameters:
      converter - used in any type conversion, should be stateless
      delegate - delegate chronology in Time4J
  • Method Details

    • createFrom

      public S 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<S>
      Overrides:
      createFrom in class Chronology<S>
      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 S 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<S>
      Overrides:
      createFrom in class Chronology<S>
      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(S 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<S>
      Overrides:
      preformat in class Chronology<S>
      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<S>
      Overrides:
      preparser in class Chronology<S>
      Returns:
      preparsing chronology or null (default)
    • getFormatPattern

      public String getFormatPattern(FormatStyle style, Locale locale)

      Not supported for foreign types.

      Specified by:
      getFormatPattern in interface ChronoMerger<S>
      Overrides:
      getFormatPattern in class Chronology<S>
      Parameters:
      style - format style
      locale - language and country setting
      Returns:
      nothing
      Throws:
      UnsupportedOperationException - always
      See Also:
      LocalizedPatternSupport
    • getDefaultStartOfDay

      public StartOfDay getDefaultStartOfDay()
      Description copied from interface: ChronoMerger

      Determines the default start of day.

      Specified by:
      getDefaultStartOfDay in interface ChronoMerger<S>
      Overrides:
      getDefaultStartOfDay in class Chronology<S>
      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<S>
      Overrides:
      getDefaultPivotYear in class Chronology<S>
      Returns:
      default pivot year (must not be smaller than 100)
    • hasCalendarSystem

      public boolean hasCalendarSystem()
      Description copied from class: Chronology

      Queries if this chronology has a calendar system.

      Overrides:
      hasCalendarSystem in class Chronology<S>
      Returns:
      true if this chronology has a calendar system else false
      See Also:
      Chronology.getCalendarSystem()
    • getCalendarSystem

      public CalendarSystem<S> getCalendarSystem()
      Description copied from class: Chronology

      Returns the associated calendar system if available.

      Overrides:
      getCalendarSystem in class Chronology<S>
      Returns:
      calendar system, not null
      See Also:
      Chronology.hasCalendarSystem()
    • getCalendarSystem

      public CalendarSystem<S> getCalendarSystem(String variant)
      Description copied from class: Chronology

      Returns the calendar system for given calendar variant if available.

      Overrides:
      getCalendarSystem in class Chronology<S>
      Parameters:
      variant - name of calendar variant
      Returns:
      calendar system, not null
      See Also:
      VariantSource.getVariant()
    • isSupported

      public boolean isSupported(ChronoElement<?> element)

      This chronology does not itself support any elements.

      Only its delegate chronology might support given element.

      Overrides:
      isSupported in class Chronology<S>
      Parameters:
      element - element to be asked (optional)
      Returns:
      false
    • getRegisteredElements

      public Set<ChronoElement<?>> getRegisteredElements()
      Description copied from class: Chronology

      Returns all registered chronological elements.

      Overrides:
      getRegisteredElements in class Chronology<S>
      Returns:
      unmodifiable set of elements without duplicates
    • getExtensions

      public List<ChronoExtension> getExtensions()
      Description copied from class: Chronology

      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.

      Overrides:
      getExtensions in class Chronology<S>
      Returns:
      unmodifiable list of extensions