Enum HistoricEra

  • All Implemented Interfaces:
    Serializable, Comparable<HistoricEra>, Calendrical

    public enum HistoricEra
    extends Enum<HistoricEra>
    implements Calendrical
    An era in the historic calendar system, with the values 'BCE' and 'CE'.

    HistoricEra is an enum representing the historic era concepts of BCE and CE. BCE is defined as the time-line before historic year 1, while CE is defined as the time-line from year 1 onwards.

    The calendrical framework requires date-time fields to have an int value. The int value follows Calendar, assigning 0 to BCE and 1 to CE. It is recommended that applications use the enum rather than the int value to ensure code clarity.

    Do not use ordinal() to obtain the numeric representation of HistoricEra. Use getValue() instead.

    HistoricEra is an immutable and thread-safe enum.

    Author:
    Stephen Colebourne
    • Enum Constant Detail

      • BCE

        public static final HistoricEra BCE
        The singleton instance for the era BCE - Before Common Era. This has the numeric value of 0.
      • CE

        public static final HistoricEra CE
        The singleton instance for the era CE - Common Era. This has the numeric value of 1.
    • Method Detail

      • values

        public static HistoricEra[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (HistoricEra c : HistoricEra.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static HistoricEra valueOf​(String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null
      • of

        public static HistoricEra of​(int era)
        Obtains an instance of HistoricEra from an int value.

        HistoricEra is an enum representing the historic eras of BCE/CE. This factory allows the enum to be obtained from the int value. The int value follows Calendar, assigning 0 to BCE and 1 to CE.

        An exception is thrown if the value is invalid. The exception uses the ISOChronology BCE/CE rule to indicate the failed rule.

        Parameters:
        era - the BCE/CE value to represent, from 0 (BCE) to 1 (CE)
        Returns:
        the HistoricEra singleton, never null
        Throws:
        IllegalCalendarFieldValueException - if the value is invalid
      • getValue

        public int getValue()
        Gets the BCE/CE int value.

        The values are numbered following Calendar, assigning 0 to BCE and 1 to CE.

        Returns:
        the BCE/CE value, from 0 (BCE) to 1 (CE)
      • get

        public <T> T get​(CalendricalRule<T> rule)
        Gets the value of the specified calendrical rule.

        This returns the one of the era values if the type of the rule is HistoricEra. Other rules will return null.

        Specified by:
        get in interface Calendrical
        Parameters:
        rule - the rule to use, not null
        Returns:
        the value for the rule, null if the value cannot be returned
      • getShortText

        public String getShortText​(Locale locale)
        Gets the short textual representation of this BCE/CE, such as 'BCE' or 'CE'.

        If there is no textual mapping for the locale, then the value is returned as per Integer.toString().

        Parameters:
        locale - the locale to use, not null
        Returns:
        the short text value of the BCE/CE, never null
      • getText

        public String getText​(Locale locale)
        Gets the short textual representation of this day-of-week, such as 'BCE' or 'CE'.

        If there is no textual mapping for the locale, then the value is returned as per Integer.toString().

        Parameters:
        locale - the locale to use, not null
        Returns:
        the long text value of the BCE/CE, never null