8204444: java.time cleanup
authormartin
Fri, 08 Jun 2018 09:36:10 -0700
changeset 50473 bef0ed237504
parent 50472 ee1a0ddb2590
child 50474 5d905cc4c358
8204444: java.time cleanup Reviewed-by: scolebourne, rriggs
src/java.base/share/classes/java/time/Clock.java
src/java.base/share/classes/java/time/Duration.java
src/java.base/share/classes/java/time/Instant.java
src/java.base/share/classes/java/time/LocalTime.java
src/java.base/share/classes/java/time/chrono/ChronoLocalDateImpl.java
src/java.base/share/classes/java/time/chrono/ChronoLocalDateTime.java
src/java.base/share/classes/java/time/chrono/Chronology.java
src/java.base/share/classes/java/time/chrono/IsoChronology.java
src/java.base/share/classes/java/time/chrono/JapaneseChronology.java
src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java
src/java.base/share/classes/java/time/format/DecimalStyle.java
src/java.base/share/classes/java/time/zone/ZoneRulesProvider.java
--- a/src/java.base/share/classes/java/time/Clock.java	Fri Jun 08 18:15:58 2018 +0200
+++ b/src/java.base/share/classes/java/time/Clock.java	Fri Jun 08 09:36:10 2018 -0700
@@ -586,7 +586,7 @@
      * This is typically used for testing.
      */
     static final class FixedClock extends Clock implements Serializable {
-       private static final long serialVersionUID = 7430389292664866958L;
+        private static final long serialVersionUID = 7430389292664866958L;
         private final Instant instant;
         private final ZoneId zone;
 
@@ -636,7 +636,7 @@
      * Implementation of a clock that adds an offset to an underlying clock.
      */
     static final class OffsetClock extends Clock implements Serializable {
-       private static final long serialVersionUID = 2007484719125426256L;
+        private static final long serialVersionUID = 2007484719125426256L;
         private final Clock baseClock;
         private final Duration offset;
 
--- a/src/java.base/share/classes/java/time/Duration.java	Fri Jun 08 18:15:58 2018 +0200
+++ b/src/java.base/share/classes/java/time/Duration.java	Fri Jun 08 09:36:10 2018 -0700
@@ -231,7 +231,7 @@
      * This method allows an arbitrary number of nanoseconds to be passed in.
      * The factory will alter the values of the second and nanosecond in order
      * to ensure that the stored nanosecond is in the range 0 to 999,999,999.
-     * For example, the following will result in the exactly the same duration:
+     * For example, the following will result in exactly the same duration:
      * <pre>
      *  Duration.ofSeconds(3, 1);
      *  Duration.ofSeconds(4, -999_999_999);
@@ -1357,12 +1357,14 @@
      * Truncating the duration returns a copy of the original with conceptual fields
      * smaller than the specified unit set to zero.
      * For example, truncating with the {@link ChronoUnit#MINUTES MINUTES} unit will
-     * round down to the nearest minute, setting the seconds and nanoseconds to zero.
+     * round down towards zero to the nearest minute, setting the seconds and
+     * nanoseconds to zero.
      * <p>
      * The unit must have a {@linkplain TemporalUnit#getDuration() duration}
      * that divides into the length of a standard day without remainder.
-     * This includes all supplied time units on {@link ChronoUnit} and
-     * {@link ChronoUnit#DAYS DAYS}. Other ChronoUnits throw an exception.
+     * This includes all
+     * {@linkplain ChronoUnit#isTimeBased() time-based units on {@code ChronoUnit}}
+     * and {@link ChronoUnit#DAYS DAYS}. Other ChronoUnits throw an exception.
      * <p>
      * This instance is immutable and unaffected by this method call.
      *
@@ -1388,7 +1390,7 @@
             throw new UnsupportedTemporalTypeException("Unit must divide into a standard day without remainder");
         }
         long nod = (seconds % LocalTime.SECONDS_PER_DAY) * LocalTime.NANOS_PER_SECOND + nanos;
-        long result = (nod / dur) * dur ;
+        long result = (nod / dur) * dur;
         return plusNanos(result - nod);
     }
 
--- a/src/java.base/share/classes/java/time/Instant.java	Fri Jun 08 18:15:58 2018 +0200
+++ b/src/java.base/share/classes/java/time/Instant.java	Fri Jun 08 09:36:10 2018 -0700
@@ -311,7 +311,7 @@
      * This method allows an arbitrary number of nanoseconds to be passed in.
      * The factory will alter the values of the second and nanosecond in order
      * to ensure that the stored nanosecond is in the range 0 to 999,999,999.
-     * For example, the following will result in the exactly the same instant:
+     * For example, the following will result in exactly the same instant:
      * <pre>
      *  Instant.ofEpochSecond(3, 1);
      *  Instant.ofEpochSecond(4, -999_999_999);
@@ -757,7 +757,7 @@
             throw new UnsupportedTemporalTypeException("Unit must divide into a standard day without remainder");
         }
         long nod = (seconds % LocalTime.SECONDS_PER_DAY) * LocalTime.NANOS_PER_SECOND + nanos;
-        long result = Math.floorDiv(nod, dur) * dur ;
+        long result = Math.floorDiv(nod, dur) * dur;
         return plusNanos(result - nod);
     }
 
--- a/src/java.base/share/classes/java/time/LocalTime.java	Fri Jun 08 18:15:58 2018 +0200
+++ b/src/java.base/share/classes/java/time/LocalTime.java	Fri Jun 08 09:36:10 2018 -0700
@@ -356,14 +356,14 @@
      * @return the local time, not null
      * @since 9
      */
-     public static LocalTime ofInstant(Instant instant, ZoneId zone) {
-         Objects.requireNonNull(instant, "instant");
-         Objects.requireNonNull(zone, "zone");
-         ZoneOffset offset = zone.getRules().getOffset(instant);
-         long localSecond = instant.getEpochSecond() + offset.getTotalSeconds();
-         int secsOfDay = Math.floorMod(localSecond, SECONDS_PER_DAY);
-         return ofNanoOfDay(secsOfDay * NANOS_PER_SECOND + instant.getNano());
-     }
+    public static LocalTime ofInstant(Instant instant, ZoneId zone) {
+        Objects.requireNonNull(instant, "instant");
+        Objects.requireNonNull(zone, "zone");
+        ZoneOffset offset = zone.getRules().getOffset(instant);
+        long localSecond = instant.getEpochSecond() + offset.getTotalSeconds();
+        int secsOfDay = Math.floorMod(localSecond, SECONDS_PER_DAY);
+        return ofNanoOfDay(secsOfDay * NANOS_PER_SECOND + instant.getNano());
+    }
 
     //-----------------------------------------------------------------------
     /**
--- a/src/java.base/share/classes/java/time/chrono/ChronoLocalDateImpl.java	Fri Jun 08 18:15:58 2018 +0200
+++ b/src/java.base/share/classes/java/time/chrono/ChronoLocalDateImpl.java	Fri Jun 08 09:36:10 2018 -0700
@@ -110,7 +110,7 @@
  *        int year = date.get(ChronoField.YEAR);
  *        System.out.printf("  Today is %s %s %d-%s-%d%n", date.getChronology().getID(),
  *                dow, day, month, year);
-
+ *
  *        // Print today's date and the last day of the year
  *        ChronoLocalDate now1 = Chronology.of("Hijrah").dateNow();
  *        ChronoLocalDate first = now1.with(ChronoField.DAY_OF_MONTH, 1)
--- a/src/java.base/share/classes/java/time/chrono/ChronoLocalDateTime.java	Fri Jun 08 18:15:58 2018 +0200
+++ b/src/java.base/share/classes/java/time/chrono/ChronoLocalDateTime.java	Fri Jun 08 09:36:10 2018 -0700
@@ -201,7 +201,7 @@
      *
      * @return the date part of this date-time, not null
      */
-    D toLocalDate() ;
+    D toLocalDate();
 
     /**
      * Gets the local time part of this date-time.
--- a/src/java.base/share/classes/java/time/chrono/Chronology.java	Fri Jun 08 18:15:58 2018 +0200
+++ b/src/java.base/share/classes/java/time/chrono/Chronology.java	Fri Jun 08 09:36:10 2018 -0700
@@ -736,8 +736,8 @@
      * @throws DateTimeException if any of the values are out of range
      * @since 9
      */
-     public default long epochSecond(int prolepticYear, int month, int dayOfMonth,
-                                     int hour, int minute, int second, ZoneOffset zoneOffset) {
+    public default long epochSecond(int prolepticYear, int month, int dayOfMonth,
+                                    int hour, int minute, int second, ZoneOffset zoneOffset) {
         Objects.requireNonNull(zoneOffset, "zoneOffset");
         HOUR_OF_DAY.checkValidValue(hour);
         MINUTE_OF_HOUR.checkValidValue(minute);
@@ -765,8 +765,8 @@
      * @throws DateTimeException if any of the values are out of range
      * @since 9
      */
-     public default long epochSecond(Era era, int yearOfEra, int month, int dayOfMonth,
-                                     int hour, int minute, int second, ZoneOffset zoneOffset) {
+    public default long epochSecond(Era era, int yearOfEra, int month, int dayOfMonth,
+                                    int hour, int minute, int second, ZoneOffset zoneOffset) {
         Objects.requireNonNull(era, "era");
         return epochSecond(prolepticYear(era, yearOfEra), month, dayOfMonth, hour, minute, second, zoneOffset);
     }
--- a/src/java.base/share/classes/java/time/chrono/IsoChronology.java	Fri Jun 08 18:15:58 2018 +0200
+++ b/src/java.base/share/classes/java/time/chrono/IsoChronology.java	Fri Jun 08 09:36:10 2018 -0700
@@ -287,9 +287,9 @@
      *         or if the day-of-month is invalid for the month-of-year
      * @since 9
      */
-     @Override
-     public long epochSecond(int prolepticYear, int month, int dayOfMonth,
-                             int hour, int minute, int second, ZoneOffset zoneOffset) {
+    @Override
+    public long epochSecond(int prolepticYear, int month, int dayOfMonth,
+                            int hour, int minute, int second, ZoneOffset zoneOffset) {
         YEAR.checkValidValue(prolepticYear);
         MONTH_OF_YEAR.checkValidValue(month);
         DAY_OF_MONTH.checkValidValue(dayOfMonth);
--- a/src/java.base/share/classes/java/time/chrono/JapaneseChronology.java	Fri Jun 08 18:15:58 2018 +0200
+++ b/src/java.base/share/classes/java/time/chrono/JapaneseChronology.java	Fri Jun 08 09:36:10 2018 -0700
@@ -459,38 +459,38 @@
         return era.getPrivateEra().getSinceDate().getYear() + yearOfEra - 1;
     }
 
-     private ChronoLocalDate resolveYMD(JapaneseEra era, int yoe, Map<TemporalField,Long> fieldValues, ResolverStyle resolverStyle) {
-         fieldValues.remove(ERA);
-         fieldValues.remove(YEAR_OF_ERA);
-         if (resolverStyle == ResolverStyle.LENIENT) {
-             int y = prolepticYearLenient(era, yoe);
-             long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
-             long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
-             return date(y, 1, 1).plus(months, MONTHS).plus(days, DAYS);
-         }
-         int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
-         int dom = range(DAY_OF_MONTH).checkValidIntValue(fieldValues.remove(DAY_OF_MONTH), DAY_OF_MONTH);
-         if (resolverStyle == ResolverStyle.SMART) {  // previous valid
-             if (yoe < 1) {
-                 throw new DateTimeException("Invalid YearOfEra: " + yoe);
-             }
-             int y = prolepticYearLenient(era, yoe);
-             JapaneseDate result;
-             try {
-                 result = date(y, moy, dom);
-             } catch (DateTimeException ex) {
-                 result = date(y, moy, 1).with(TemporalAdjusters.lastDayOfMonth());
-             }
-             // handle the era being changed
-             // only allow if the new date is in the same Jan-Dec as the era change
-             // determine by ensuring either original yoe or result yoe is 1
-             if (result.getEra() != era && result.get(YEAR_OF_ERA) > 1 && yoe > 1) {
-                 throw new DateTimeException("Invalid YearOfEra for Era: " + era + " " + yoe);
-             }
-             return result;
-         }
-         return date(era, yoe, moy, dom);
-     }
+    private ChronoLocalDate resolveYMD(JapaneseEra era, int yoe, Map<TemporalField,Long> fieldValues, ResolverStyle resolverStyle) {
+        fieldValues.remove(ERA);
+        fieldValues.remove(YEAR_OF_ERA);
+        if (resolverStyle == ResolverStyle.LENIENT) {
+            int y = prolepticYearLenient(era, yoe);
+            long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
+            long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
+            return date(y, 1, 1).plus(months, MONTHS).plus(days, DAYS);
+        }
+        int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
+        int dom = range(DAY_OF_MONTH).checkValidIntValue(fieldValues.remove(DAY_OF_MONTH), DAY_OF_MONTH);
+        if (resolverStyle == ResolverStyle.SMART) {  // previous valid
+            if (yoe < 1) {
+                throw new DateTimeException("Invalid YearOfEra: " + yoe);
+            }
+            int y = prolepticYearLenient(era, yoe);
+            JapaneseDate result;
+            try {
+                result = date(y, moy, dom);
+            } catch (DateTimeException ex) {
+                result = date(y, moy, 1).with(TemporalAdjusters.lastDayOfMonth());
+            }
+            // handle the era being changed
+            // only allow if the new date is in the same Jan-Dec as the era change
+            // determine by ensuring either original yoe or result yoe is 1
+            if (result.getEra() != era && result.get(YEAR_OF_ERA) > 1 && yoe > 1) {
+                throw new DateTimeException("Invalid YearOfEra for Era: " + era + " " + yoe);
+            }
+            return result;
+        }
+        return date(era, yoe, moy, dom);
+    }
 
     private ChronoLocalDate resolveYD(JapaneseEra era, int yoe, Map <TemporalField,Long> fieldValues, ResolverStyle resolverStyle) {
         fieldValues.remove(ERA);
--- a/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java	Fri Jun 08 18:15:58 2018 +0200
+++ b/src/java.base/share/classes/java/time/format/DateTimeFormatterBuilder.java	Fri Jun 08 09:36:10 2018 -0700
@@ -3049,7 +3049,7 @@
      * Prints and parses a numeric date-time field with optional padding.
      */
     static final class FractionPrinterParser extends NumberPrinterParser {
-       private final boolean decimalPoint;
+        private final boolean decimalPoint;
 
         /**
          * Constructor.
--- a/src/java.base/share/classes/java/time/format/DecimalStyle.java	Fri Jun 08 18:15:58 2018 +0200
+++ b/src/java.base/share/classes/java/time/format/DecimalStyle.java	Fri Jun 08 09:36:10 2018 -0700
@@ -216,7 +216,6 @@
      *
      * @param zeroDigit  the character for zero
      * @return  a copy with a new character that represents zero, not null
-
      */
     public DecimalStyle withZeroDigit(char zeroDigit) {
         if (zeroDigit == this.zeroDigit) {
--- a/src/java.base/share/classes/java/time/zone/ZoneRulesProvider.java	Fri Jun 08 18:15:58 2018 +0200
+++ b/src/java.base/share/classes/java/time/zone/ZoneRulesProvider.java	Fri Jun 08 09:36:10 2018 -0700
@@ -119,7 +119,7 @@
  * Providers must ensure that once a rule has been seen by the application, the
  * rule must continue to be available.
  * <p>
-*  Providers are encouraged to implement a meaningful {@code toString} method.
+ * Providers are encouraged to implement a meaningful {@code toString} method.
  * <p>
  * Many systems would like to update time-zone rules dynamically without stopping the JVM.
  * When examined in detail, this is a complex problem.