Enum HistoricEra
- java.lang.Object
-
- java.lang.Enum<HistoricEra>
-
- javax.time.i18n.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. Theint
value followsCalendar
, assigning 0 to BCE and 1 to CE. It is recommended that applications use the enum rather than theint
value to ensure code clarity.Do not use
ordinal()
to obtain the numeric representation ofHistoricEra
. UsegetValue()
instead.HistoricEra is an immutable and thread-safe enum.
- Author:
- Stephen Colebourne
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
get(CalendricalRule<T> rule)
Gets the value of the specified calendrical rule.String
getShortText(Locale locale)
Gets the short textual representation of this BCE/CE, such as 'BCE' or 'CE'.String
getText(Locale locale)
Gets the short textual representation of this day-of-week, such as 'BCE' or 'CE'.int
getValue()
Gets the BCE/CEint
value.static HistoricEra
of(int era)
Obtains an instance ofHistoricEra
from anint
value.static HistoricEra
valueOf(String name)
Returns the enum constant of this type with the specified name.static HistoricEra[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
BCE
public static final HistoricEra BCE
The singleton instance for the era BCE - Before Common Era. This has the numeric value of0
.
-
CE
public static final HistoricEra CE
The singleton instance for the era CE - Common Era. This has the numeric value of1
.
-
-
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 nameNullPointerException
- if the argument is null
-
of
public static HistoricEra of(int era)
Obtains an instance ofHistoricEra
from anint
value.HistoricEra
is an enum representing the historic eras of BCE/CE. This factory allows the enum to be obtained from theint
value. Theint
value followsCalendar
, 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/CEint
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 returnnull
.- Specified by:
get
in interfaceCalendrical
- 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
-
-