< prev index next >
src/java.base/share/classes/java/time/chrono/JapaneseEra.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 71,85 ****
--- 71,87 ----
import java.io.ObjectInputStream;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.time.DateTimeException;
import java.time.LocalDate;
+ import java.time.format.TextStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalField;
import java.time.temporal.UnsupportedTemporalTypeException;
import java.time.temporal.ValueRange;
import java.util.Arrays;
+ import java.util.Locale;
import java.util.Objects;
import sun.util.calendar.CalendarDate;
/**
*** 123,134 ****
* The singleton instance for the 'Heisei' era (1989-01-08 - current)
* which has the value 2.
*/
public static final JapaneseEra HEISEI = new JapaneseEra(2, LocalDate.of(1989, 1, 8));
! // the number of defined JapaneseEra constants.
! // There could be an extra era defined in its configuration.
private static final int N_ERA_CONSTANTS = HEISEI.getValue() + ERA_OFFSET;
/**
* Serialization version.
*/
--- 125,136 ----
* The singleton instance for the 'Heisei' era (1989-01-08 - current)
* which has the value 2.
*/
public static final JapaneseEra HEISEI = new JapaneseEra(2, LocalDate.of(1989, 1, 8));
! // The number of predefined JapaneseEra constants.
! // There may be a supplemental era defined by the property.
private static final int N_ERA_CONSTANTS = HEISEI.getValue() + ERA_OFFSET;
/**
* Serialization version.
*/
*** 235,244 ****
--- 237,272 ----
*/
public static JapaneseEra[] values() {
return Arrays.copyOf(KNOWN_ERAS, KNOWN_ERAS.length);
}
+ /**
+ * Gets the textual representation of this era.
+ * <p>
+ * This returns the textual name used to identify the era,
+ * suitable for presentation to the user.
+ * The parameters control the style of the returned text and the locale.
+ * <p>
+ * If no textual mapping is found then the {@link #getValue() numeric value}
+ * is returned.
+ *
+ * @param style the style of the text required, not null
+ * @param locale the locale to use, not null
+ * @return the text value of the era, not null
+ * @since 9
+ */
+ @Override
+ public String getDisplayName(TextStyle style, Locale locale) {
+ // If this JapaneseEra is a supplemental one, obtain the name from
+ // the era definition.
+ if (getValue() > N_ERA_CONSTANTS - ERA_OFFSET) {
+ Objects.requireNonNull(locale, "locale");
+ return style == TextStyle.FULL ? getName() : getAbbreviation();
+ }
+ return Era.super.getDisplayName(style, locale);
+ }
+
//-----------------------------------------------------------------------
/**
* Obtains an instance of {@code JapaneseEra} from a date.
*
* @param date the date, not null
*** 336,350 ****
return Era.super.range(field);
}
//-----------------------------------------------------------------------
String getAbbreviation() {
! int index = ordinal(getValue());
! if (index == 0) {
! return "";
! }
! return ERA_CONFIG[index].getAbbreviation();
}
String getName() {
return ERA_CONFIG[ordinal(getValue())].getName();
}
--- 364,374 ----
return Era.super.range(field);
}
//-----------------------------------------------------------------------
String getAbbreviation() {
! return ERA_CONFIG[ordinal(getValue())].getAbbreviation();
}
String getName() {
return ERA_CONFIG[ordinal(getValue())].getName();
}
< prev index next >