--- old/src/share/classes/java/time/LocalTime.java 2013-07-18 10:20:39.000000000 -0700 +++ new/src/share/classes/java/time/LocalTime.java 2013-07-18 10:20:39.000000000 -0700 @@ -470,8 +470,9 @@ * Checks if the specified field is supported. *

* This checks if this time can be queried for the specified field. - * If false, then calling the {@link #range(TemporalField) range} and - * {@link #get(TemporalField) get} methods will throw an exception. + * If false, then calling the {@link #range(TemporalField) range}, + * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)} + * methods will throw an exception. *

* If the field is a {@link ChronoField} then the query is implemented here. * The supported fields are: @@ -511,6 +512,43 @@ } /** + * Checks if the specified unit is supported. + *

+ * This checks if the specified unit can be added to, or subtracted from, this date-time. + * If false, then calling the {@link #plus(long, TemporalUnit)} and + * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. + *

+ * If the unit is a {@link ChronoUnit} then the query is implemented here. + * The supported units are: + *

+ * All other {@code ChronoUnit} instances will return false. + *

+ * If the unit is not a {@code ChronoUnit}, then the result of this method + * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)} + * passing {@code this} as the argument. + * Whether the unit is supported is determined by the unit. + * + * @param unit the unit to check, null returns false + * @return true if the unit can be added/subtracted, false if not + */ + @Override // override for Javadoc + public boolean isSupported(TemporalUnit unit) { + if (unit instanceof ChronoUnit) { + return unit.isTimeBased(); + } + return unit != null && unit.isSupportedBy(this); + } + + //----------------------------------------------------------------------- + /** * Gets the range of valid values for the specified field. *

* The range object expresses the minimum and maximum valid values for a field. @@ -628,7 +666,7 @@ case CLOCK_HOUR_OF_DAY: return (hour == 0 ? 24 : hour); case AMPM_OF_DAY: return hour / 12; } - throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName()); + throw new UnsupportedTemporalTypeException("Unsupported field: " + field); } //----------------------------------------------------------------------- @@ -803,7 +841,7 @@ case CLOCK_HOUR_OF_DAY: return withHour((int) (newValue == 24 ? 0 : newValue)); case AMPM_OF_DAY: return plusHours((newValue - (hour / 12)) * 12); } - throw new UnsupportedTemporalTypeException("Unsupported field: " + field.getName()); + throw new UnsupportedTemporalTypeException("Unsupported field: " + field); } return field.adjustInto(this, newValue); } @@ -995,8 +1033,7 @@ @Override public LocalTime plus(long amountToAdd, TemporalUnit unit) { if (unit instanceof ChronoUnit) { - ChronoUnit f = (ChronoUnit) unit; - switch (f) { + switch ((ChronoUnit) unit) { case NANOS: return plusNanos(amountToAdd); case MICROS: return plusNanos((amountToAdd % MICROS_PER_DAY) * 1000); case MILLIS: return plusNanos((amountToAdd % MILLIS_PER_DAY) * 1000_000); @@ -1005,7 +1042,7 @@ case HOURS: return plusHours(amountToAdd); case HALF_DAYS: return plusHours((amountToAdd % 2) * 12); } - throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit.getName()); + throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); } return unit.addTo(this, amountToAdd); } @@ -1295,7 +1332,7 @@ * The result will be negative if the end is before the start. * The {@code Temporal} passed to this method must be a {@code LocalTime}. * For example, the amount in hours between two times can be calculated - * using {@code startTime.periodUntil(endTime, HOURS)}. + * using {@code startTime.until(endTime, HOURS)}. *

* The calculation returns a whole number, representing the number of * complete units between the two times. @@ -1307,7 +1344,7 @@ * The second is to use {@link TemporalUnit#between(Temporal, Temporal)}: *

      *   // these two lines are equivalent
-     *   amount = start.periodUntil(end, MINUTES);
+     *   amount = start.until(end, MINUTES);
      *   amount = MINUTES.between(start, end);
      * 
* The choice should be made based on which makes the code more readable. @@ -1332,7 +1369,7 @@ * @throws ArithmeticException if numeric overflow occurs */ @Override - public long periodUntil(Temporal endTime, TemporalUnit unit) { + public long until(Temporal endTime, TemporalUnit unit) { if (endTime instanceof LocalTime == false) { Objects.requireNonNull(endTime, "endTime"); throw new DateTimeException("Unable to calculate amount as objects are of two different types"); @@ -1349,7 +1386,7 @@ case HOURS: return nanosUntil / NANOS_PER_HOUR; case HALF_DAYS: return nanosUntil / (12 * NANOS_PER_HOUR); } - throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit.getName()); + throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); } return unit.between(this, endTime); }