Class JapaneseEra
- java.lang.Object
-
- org.threeten.bp.jdk8.DefaultInterfaceTemporalAccessor
-
- org.threeten.bp.jdk8.DefaultInterfaceEra
-
- org.threeten.bp.chrono.JapaneseEra
-
- All Implemented Interfaces:
java.io.Serializable,Era,TemporalAccessor,TemporalAdjuster
public final class JapaneseEra extends DefaultInterfaceEra implements java.io.Serializable
An era in the Japanese Imperial calendar system.This class defines the valid eras for the Japanese chronology. Japan introduced the Gregorian calendar starting with Meiji 6. Only Meiji and later eras are supported; dates before Meiji 6, January 1 are not supported.
The four supported eras are hard-coded. A single additional era may be registered using
registerEra(LocalDate, String).Specification for implementors
This class is immutable and thread-safe.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static intADDITIONAL_VALUEThe value of the additional era.(package private) static intERA_OFFSETprivate interaValueThe era value.static JapaneseEraHEISEIThe singleton instance for the 'Heisei' era (1989-01-08 - 2019-04-30) which has the value 2.private static java.util.concurrent.atomic.AtomicReference<JapaneseEra[]>KNOWN_ERASstatic JapaneseEraMEIJIThe singleton instance for the 'Meiji' era (1868-09-08 - 1912-07-29) which has the value -1.private java.lang.Stringnamestatic JapaneseEraREIWAThe singleton instance for the 'Reiwa' era (2019-05-01 - current) which has the value 3.private static longserialVersionUIDSerialization version.static JapaneseEraSHOWAThe singleton instance for the 'Showa' era (1926-12-25 - 1989-01-07) which has the value 1.private LocalDatesincestatic JapaneseEraTAISHOThe singleton instance for the 'Taisho' era (1912-07-30 - 1926-12-24) which has the value 0.
-
Constructor Summary
Constructors Modifier Constructor Description privateJapaneseEra(int eraValue, LocalDate since, java.lang.String name)Creates an instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) LocalDateendDate()Returns the end date of the era.(package private) static JapaneseErafrom(LocalDate date)Obtains an instance ofJapaneseErafrom a date.intgetValue()Returns the numeric value of thisJapaneseEra.static JapaneseEraof(int japaneseEra)Obtains an instance ofJapaneseErafrom anintvalue.private static intordinal(int eraValue)Returns the index into the arrays from the Era value.ValueRangerange(TemporalField field)Gets the range of valid values for the specified field.(package private) static JapaneseErareadExternal(java.io.DataInput in)private java.lang.ObjectreadResolve()Returns the singletonJapaneseEracorresponding to this object.static JapaneseEraregisterEra(LocalDate since, java.lang.String name)Registers an additional instance ofJapaneseEra.(package private) LocalDatestartDate()Returns the start date of the era.java.lang.StringtoString()static JapaneseEravalueOf(java.lang.String japaneseEra)Returns theJapaneseErawith the name.static JapaneseEra[]values()Returns an array of JapaneseEras.(package private) voidwriteExternal(java.io.DataOutput out)private java.lang.ObjectwriteReplace()-
Methods inherited from class org.threeten.bp.jdk8.DefaultInterfaceEra
adjustInto, get, getDisplayName, getLong, isSupported, query
-
-
-
-
Field Detail
-
ERA_OFFSET
static final int ERA_OFFSET
- See Also:
- Constant Field Values
-
MEIJI
public static final JapaneseEra MEIJI
The singleton instance for the 'Meiji' era (1868-09-08 - 1912-07-29) which has the value -1.
-
TAISHO
public static final JapaneseEra TAISHO
The singleton instance for the 'Taisho' era (1912-07-30 - 1926-12-24) which has the value 0.
-
SHOWA
public static final JapaneseEra SHOWA
The singleton instance for the 'Showa' era (1926-12-25 - 1989-01-07) which has the value 1.
-
HEISEI
public static final JapaneseEra HEISEI
The singleton instance for the 'Heisei' era (1989-01-08 - 2019-04-30) which has the value 2.
-
REIWA
public static final JapaneseEra REIWA
The singleton instance for the 'Reiwa' era (2019-05-01 - current) which has the value 3.
-
ADDITIONAL_VALUE
private static final int ADDITIONAL_VALUE
The value of the additional era.- See Also:
- Constant Field Values
-
serialVersionUID
private static final long serialVersionUID
Serialization version.- See Also:
- Constant Field Values
-
KNOWN_ERAS
private static final java.util.concurrent.atomic.AtomicReference<JapaneseEra[]> KNOWN_ERAS
-
eraValue
private final int eraValue
The era value.
-
since
private final transient LocalDate since
-
name
private final transient java.lang.String name
-
-
Constructor Detail
-
JapaneseEra
private JapaneseEra(int eraValue, LocalDate since, java.lang.String name)Creates an instance.- Parameters:
eraValue- the era value, validatedsince- the date representing the first date of the era, validated not nullname- the name
-
-
Method Detail
-
readResolve
private java.lang.Object readResolve() throws java.io.ObjectStreamExceptionReturns the singletonJapaneseEracorresponding to this object. It's possible that this version ofJapaneseEradoesn't support the latest era value. In that case, this method throws anObjectStreamException.- Returns:
- the singleton
JapaneseErafor this object - Throws:
java.io.ObjectStreamException- if the deserialized object has any unknown numeric era value.
-
registerEra
public static JapaneseEra registerEra(LocalDate since, java.lang.String name)
Registers an additional instance ofJapaneseEra.A new Japanese era can begin at any time. This method allows one new era to be registered without the need for a new library version. If needed, callers should assign the result to a static variable accessible across the application. This must be done once, in early startup code.
NOTE: This method does not exist in Java SE 8.
- Parameters:
since- the date representing the first date of the era, validated not nullname- the name- Returns:
- the
JapaneseErasingleton, not null - Throws:
DateTimeException- if an additional era has already been registered
-
of
public static JapaneseEra of(int japaneseEra)
Obtains an instance ofJapaneseErafrom anintvalue.The
SHOWAera that contains 1970-01-01 (ISO calendar system) has the value 1 Later era is numbered 2 (HEISEI). Earlier eras are numbered 0 (TAISHO), -1 (MEIJI), only Meiji and later eras are supported.- Parameters:
japaneseEra- the era to represent- Returns:
- the
JapaneseErasingleton, not null - Throws:
DateTimeException- if the value is invalid
-
valueOf
public static JapaneseEra valueOf(java.lang.String japaneseEra)
Returns theJapaneseErawith the name.The string must match exactly the name of the era. (Extraneous whitespace characters are not permitted.)
- Parameters:
japaneseEra- the japaneseEra name; non-null- Returns:
- the
JapaneseErasingleton, never null - Throws:
java.lang.IllegalArgumentException- if there is not JapaneseEra with the specified name
-
values
public static JapaneseEra[] values()
Returns an array of JapaneseEras.This method may be used to iterate over the JapaneseEras as follows:
for (JapaneseEra c : JapaneseEra.values()) System.out.println(c);- Returns:
- an array of JapaneseEras
-
from
static JapaneseEra from(LocalDate date)
Obtains an instance ofJapaneseErafrom a date.- Parameters:
date- the date, not null- Returns:
- the Era singleton, never null
-
ordinal
private static int ordinal(int eraValue)
Returns the index into the arrays from the Era value. the eraValue is a valid Era number, -999, -1..2.- Parameters:
eraValue- the era value to convert to the index- Returns:
- the index of the current Era
-
startDate
LocalDate startDate()
Returns the start date of the era.- Returns:
- the start date
-
endDate
LocalDate endDate()
Returns the end date of the era.- Returns:
- the end date
-
getValue
public int getValue()
-
range
public ValueRange range(TemporalField field)
Description copied from interface:TemporalAccessorGets the range of valid values for the specified field.All fields can be expressed as a
longinteger. This method returns an object that describes the valid range for that value. The value of this temporal object is used to enhance the accuracy of the returned range. If the date-time cannot return the range, because the field is unsupported or for some other reason, an exception will be thrown.Note that the result only describes the minimum and maximum valid values and it is important not to read too much into them. For example, there could be values within the range that are invalid for the field.
Specification for implementors
Implementations must check and handle all fields defined inChronoField. If the field is supported, then the range of the field must be returned. If unsupported, then aDateTimeExceptionmust be thrown.If the field is not a
ChronoField, then the result of this method is obtained by invokingTemporalField.rangeRefinedBy(TemporalAccessorl)passingthisas the argument.Implementations must not alter either this object.
- Specified by:
rangein interfaceTemporalAccessor- Overrides:
rangein classDefaultInterfaceTemporalAccessor- Parameters:
field- the field to query the range for, not null- Returns:
- the range of valid values for the field, not null
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
writeReplace
private java.lang.Object writeReplace()
-
writeExternal
void writeExternal(java.io.DataOutput out) throws java.io.IOException- Throws:
java.io.IOException
-
readExternal
static JapaneseEra readExternal(java.io.DataInput in) throws java.io.IOException
- Throws:
java.io.IOException
-
-