src/share/classes/java/time/chrono/Era.java

Print this page

        

@@ -57,29 +57,37 @@
  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-package java.time.temporal;
+package java.time.chrono;
 
 import static java.time.temporal.ChronoField.ERA;
 import static java.time.temporal.ChronoUnit.ERAS;
 
 import java.time.DateTimeException;
 import java.time.format.DateTimeFormatterBuilder;
 import java.time.format.TextStyle;
+import java.time.temporal.ChronoField;
+import java.time.temporal.Queries;
+import java.time.temporal.Temporal;
+import java.time.temporal.TemporalAccessor;
+import java.time.temporal.TemporalAdjuster;
+import java.time.temporal.TemporalField;
+import java.time.temporal.TemporalQuery;
+import java.time.temporal.ValueRange;
 import java.util.Locale;
 
 /**
  * An era of the time-line.
  * <p>
  * Most calendar systems have a single epoch dividing the time-line into two eras.
  * However, some calendar systems, have multiple eras, such as one for the reign
  * of each leader.
  * In all cases, the era is conceptually the largest division of the time-line.
  * Each chronology defines the Era's that are known Eras and a
- * {@link Chrono#eras Chrono.eras} to get the valid eras.
+ * {@link Chronology#eras Chronology.eras} to get the valid eras.
  * <p>
  * For example, the Thai Buddhist calendar system divides time into two eras,
  * before and after a single date. By contrast, the Japanese calendar system
  * has one era for the reign of each Emperor.
  * <p>

@@ -88,14 +96,13 @@
  * <h3>Specification for implementors</h3>
  * This interface must be implemented with care to ensure other classes operate correctly.
  * All implementations must be singletons - final, immutable and thread-safe.
  * It is recommended to use an enum whenever possible.
  *
- * @param <C> the chronology of the era
  * @since 1.8
  */
-public interface Era<C extends Chrono<C>> extends TemporalAccessor, TemporalAdjuster {
+public interface Era extends TemporalAccessor, TemporalAdjuster {
 
     /**
      * Gets the numeric value associated with the era as defined by the chronology.
      * Each chronology defines the predefined Eras and methods to list the Eras
      * of the chronology.

@@ -114,54 +121,54 @@
     int getValue();
 
     /**
      * Gets the chronology of this era.
      * <p>
-     * The {@code Chrono} represents the calendar system in use.
+     * The {@code Chronology} represents the calendar system in use.
      * This always returns the standard form of the chronology.
      *
      * @return the chronology, not null
      */
-    C getChrono();
+    Chronology getChronology();
 
     //-----------------------------------------------------------------------
     /**
      * Obtains a date in this era given the year-of-era, month, and day.
      * <p>
      * This era is combined with the given date fields to form a date.
      * The year specified must be the year-of-era.
-     * Methods to create a date from the proleptic-year are on {@code Chrono}.
+     * Methods to create a date from the proleptic-year are on {@code Chronology}.
      * This always uses the standard form of the chronology.
      * <p>
-     * This default implementation invokes the factory method on {@link Chrono}.
+     * This default implementation invokes the factory method on {@link Chronology}.
      *
      * @param yearOfEra  the calendar system year-of-era
      * @param month  the calendar system month-of-year
      * @param day  the calendar system day-of-month
      * @return a local date based on this era and the specified year-of-era, month and day
      */
-    public default ChronoLocalDate<C> date(int yearOfEra, int month, int day) {
-        return getChrono().date(this, yearOfEra, month, day);
+    public default ChronoLocalDate date(int yearOfEra, int month, int day) {
+        return getChronology().date(this, yearOfEra, month, day);
     }
 
 
     /**
      * Obtains a date in this era given year-of-era and day-of-year fields.
      * <p>
      * This era is combined with the given date fields to form a date.
      * The year specified must be the year-of-era.
-     * Methods to create a date from the proleptic-year are on {@code Chrono}.
+     * Methods to create a date from the proleptic-year are on {@code Chronology}.
      * This always uses the standard form of the chronology.
      * <p>
-     * This default implementation invokes the factory method on {@link Chrono}.
+     * This default implementation invokes the factory method on {@link Chronology}.
      *
      * @param yearOfEra  the calendar system year-of-era
      * @param dayOfYear  the calendar system day-of-year
      * @return a local date based on this era and the specified year-of-era and day-of-year
      */
-    public default ChronoLocalDate<C> dateYearDay(int yearOfEra, int dayOfYear) {
-        return getChrono().dateYearDay(this, yearOfEra, dayOfYear);
+    public default ChronoLocalDate dateYearDay(int yearOfEra, int dayOfYear) {
+        return getChronology().dateYearDay(this, yearOfEra, dayOfYear);
     }
 
     //-----------------------------------------------------------------------
     /**
      * Checks if the specified field is supported.

@@ -173,11 +180,11 @@
      * If the field is a {@link ChronoField} then the query is implemented here.
      * The {@code ERA} field returns true.
      * All other {@code ChronoField} instances will return false.
      * <p>
      * If the field is not a {@code ChronoField}, then the result of this method
-     * is obtained by invoking {@code TemporalField.doIsSupported(TemporalAccessor)}
+     * is obtained by invoking {@code TemporalField.isSupportedBy(TemporalAccessor)}
      * passing {@code this} as the argument.
      * Whether the field is supported is determined by the field.
      *
      * @param field  the field to check, null returns false
      * @return true if the field is supported on this era, false if not

@@ -185,11 +192,11 @@
     @Override
     public default boolean isSupported(TemporalField field) {
         if (field instanceof ChronoField) {
             return field == ERA;
         }
-        return field != null && field.doIsSupported(this);
+        return field != null && field.isSupportedBy(this);
     }
 
     /**
      * Gets the range of valid values for the specified field.
      * <p>

@@ -201,11 +208,11 @@
      * If the field is a {@link ChronoField} then the query is implemented here.
      * The {@code ERA} field returns the range.
      * All other {@code ChronoField} instances will throw a {@code DateTimeException}.
      * <p>
      * If the field is not a {@code ChronoField}, then the result of this method
-     * is obtained by invoking {@code TemporalField.doRange(TemporalAccessor)}
+     * is obtained by invoking {@code TemporalField.rangeRefinedBy(TemporalAccessor)}
      * passing {@code this} as the argument.
      * Whether the range can be obtained is determined by the field.
      *
      * @param field  the field to query the range for, not null
      * @return the range of valid values for the field, not null

@@ -227,11 +234,11 @@
      * If the field is a {@link ChronoField} then the query is implemented here.
      * The {@code ERA} field returns the value of the era.
      * All other {@code ChronoField} instances will throw a {@code DateTimeException}.
      * <p>
      * If the field is not a {@code ChronoField}, then the result of this method
-     * is obtained by invoking {@code TemporalField.doGet(TemporalAccessor)}
+     * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)}
      * passing {@code this} as the argument. Whether the value can be obtained,
      * and what the value represents, is determined by the field.
      *
      * @param field  the field to get, not null
      * @return the value for the field

@@ -256,11 +263,11 @@
      * If the field is a {@link ChronoField} then the query is implemented here.
      * The {@code ERA} field returns the value of the era.
      * All other {@code ChronoField} instances will throw a {@code DateTimeException}.
      * <p>
      * If the field is not a {@code ChronoField}, then the result of this method
-     * is obtained by invoking {@code TemporalField.doGet(TemporalAccessor)}
+     * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)}
      * passing {@code this} as the argument. Whether the value can be obtained,
      * and what the value represents, is determined by the field.
      *
      * @param field  the field to get, not null
      * @return the value for the field

@@ -272,11 +279,11 @@
         if (field == ERA) {
             return getValue();
         } else if (field instanceof ChronoField) {
             throw new DateTimeException("Unsupported field: " + field.getName());
         }
-        return field.doGet(this);
+        return field.getFrom(this);
     }
 
     //-----------------------------------------------------------------------
     /**
      * Queries this era using the specified query.

@@ -297,12 +304,12 @@
      * @throws ArithmeticException if numeric overflow occurs (defined by the query)
      */
     @SuppressWarnings("unchecked")
     @Override
     public default <R> R query(TemporalQuery<R> query) {
-        if (query == Queries.chrono()) {
-            return (R) getChrono();
+        if (query == Queries.chronology()) {
+            return (R) getChronology();
         } else if (query == Queries.precision()) {
             return (R) ERAS;
         }
         return TemporalAccessor.super.query(query);
     }

@@ -338,22 +345,23 @@
 
     //-----------------------------------------------------------------------
     /**
      * Gets the textual representation of this era.
      * <p>
-     * This returns the textual name used to identify the era.
+     * 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.
      * <p>
      * This default implementation is suitable for all implementations.
      *
      * @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
      */
-    public default String getText(TextStyle style, Locale locale) {
-        return new DateTimeFormatterBuilder().appendText(ERA, style).toFormatter(locale).print(this);
+    public default String getDisplayName(TextStyle style, Locale locale) {
+        return new DateTimeFormatterBuilder().appendText(ERA, style).toFormatter(locale).format(this);
     }
 
     // NOTE: methods to convert year-of-era/proleptic-year cannot be here as they may depend on month/day (Japanese)
 }