예제 #1
0
 /**
  * Gets the range of valid values for the specified field.
  *
  * <p>The range object expresses the minimum and maximum valid values for a field. This
  * day-of-week is used to enhance the accuracy of the returned range. If it is not possible to
  * return the range, because the field is not supported or for some other reason, an exception is
  * thrown.
  *
  * <p>If the field is {@link ChronoField#DAY_OF_WEEK DAY_OF_WEEK} then the range of the
  * day-of-week, from 1 to 7, will be returned. All other {@code ChronoField} instances will throw
  * an {@code UnsupportedTemporalTypeException}.
  *
  * <p>If the field is not a {@code ChronoField}, then the result of this method 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
  * @throws DateTimeException if the range for the field cannot be obtained
  * @throws UnsupportedTemporalTypeException if the field is not supported
  */
 @Override
 public ValueRange range(TemporalField field) {
   if (field == DAY_OF_WEEK) {
     return field.range();
   }
   return TemporalAccessor.super.range(field);
 }
예제 #2
0
 /**
  * Checks if the specified field is supported.
  *
  * <p>This checks if this day-of-week 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.
  *
  * <p>If the field is {@link ChronoField#DAY_OF_WEEK DAY_OF_WEEK} then this method 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.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 day-of-week, false if not
  */
 @Override
 public boolean isSupported(TemporalField field) {
   if (field instanceof ChronoField) {
     return field == DAY_OF_WEEK;
   }
   return field != null && field.isSupportedBy(this);
 }
예제 #3
0
 /**
  * Gets the value of the specified field from this day-of-week as a {@code long}.
  *
  * <p>This queries this day-of-week for the value for the specified field. If it is not possible
  * to return the value, because the field is not supported or for some other reason, an exception
  * is thrown.
  *
  * <p>If the field is {@link ChronoField#DAY_OF_WEEK DAY_OF_WEEK} then the value of the
  * day-of-week, from 1 to 7, will be returned. All other {@code ChronoField} instances will throw
  * an {@code UnsupportedTemporalTypeException}.
  *
  * <p>If the field is not a {@code ChronoField}, then the result of this method 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
  * @throws DateTimeException if a value for the field cannot be obtained
  * @throws UnsupportedTemporalTypeException if the field is not supported
  * @throws ArithmeticException if numeric overflow occurs
  */
 @Override
 public long getLong(TemporalField field) {
   if (field == DAY_OF_WEEK) {
     return getValue();
   } else if (field instanceof ChronoField) {
     throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
   }
   return field.getFrom(this);
 }
예제 #4
0
 // -----------------------------------------------------------------------
 @Override
 public ValueRange range(TemporalField field) {
   if (field instanceof ChronoField) {
     if (isSupported(field)) {
       return rangeChrono((ChronoField) field);
     }
     throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
   }
   return field.rangeRefinedBy(this);
 }
예제 #5
0
 // -------------------------------------------------------------------------
 @Override
 public AbstractDate with(TemporalField field, long newValue) {
   if (field instanceof ChronoField) {
     ChronoField f = (ChronoField) field;
     getChronology().range(f).checkValidValue(newValue, f);
     int nvalue = (int) newValue;
     switch (f) {
       case DAY_OF_WEEK:
         return plusDays(newValue - getDayOfWeek());
       case ALIGNED_DAY_OF_WEEK_IN_MONTH:
         return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_MONTH));
       case ALIGNED_DAY_OF_WEEK_IN_YEAR:
         return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_YEAR));
       case DAY_OF_MONTH:
         return resolvePrevious(getProlepticYear(), getMonth(), nvalue);
       case DAY_OF_YEAR:
         return withDayOfYear(nvalue);
       case EPOCH_DAY:
         return resolveEpochDay(newValue);
       case ALIGNED_WEEK_OF_MONTH:
         return plusDays((newValue - getLong(ALIGNED_WEEK_OF_MONTH)) * lengthOfWeek());
       case ALIGNED_WEEK_OF_YEAR:
         return plusDays((newValue - getLong(ALIGNED_WEEK_OF_YEAR)) * lengthOfWeek());
       case MONTH_OF_YEAR:
         return resolvePrevious(getProlepticYear(), nvalue, getDayOfMonth());
       case PROLEPTIC_MONTH:
         return plusMonths(newValue - getProlepticMonth());
       case YEAR_OF_ERA:
         return resolvePrevious(
             getProlepticYear() >= 1 ? nvalue : 1 - nvalue, getMonth(), getDayOfMonth());
       case YEAR:
         return resolvePrevious(nvalue, getMonth(), getDayOfMonth());
       case ERA:
         return newValue == getLong(ERA)
             ? this
             : resolvePrevious(1 - getProlepticYear(), getMonth(), getDayOfMonth());
       default:
         break;
     }
     throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
   }
   return field.adjustInto(this, newValue);
 }
예제 #6
0
 // -----------------------------------------------------------------------
 @Override
 public long getLong(TemporalField field) {
   if (field instanceof ChronoField) {
     switch ((ChronoField) field) {
       case DAY_OF_WEEK:
         return getDayOfWeek();
       case ALIGNED_DAY_OF_WEEK_IN_MONTH:
         return getAlignedDayOfWeekInMonth();
       case ALIGNED_DAY_OF_WEEK_IN_YEAR:
         return getAlignedDayOfWeekInYear();
       case DAY_OF_MONTH:
         return getDayOfMonth();
       case DAY_OF_YEAR:
         return getDayOfYear();
       case EPOCH_DAY:
         return toEpochDay();
       case ALIGNED_WEEK_OF_MONTH:
         return getAlignedWeekOfMonth();
       case ALIGNED_WEEK_OF_YEAR:
         return getAlignedWeekOfYear();
       case MONTH_OF_YEAR:
         return getMonth();
       case PROLEPTIC_MONTH:
         return getProlepticMonth();
       case YEAR_OF_ERA:
         return getYearOfEra();
       case YEAR:
         return getProlepticYear();
       case ERA:
         return (getProlepticYear() >= 1 ? 1 : 0);
       default:
         break;
     }
     throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
   }
   return field.getFrom(this);
 }