java.time.temporal.ChronoField#checkValidValue ( )源码实例Demo

下面列出了java.time.temporal.ChronoField#checkValidValue ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: TencentKona-8   文件: CopticDate.java
@Override
public CopticDate with(TemporalField field, long newValue) {
    if (field instanceof ChronoField) {
        ChronoField f = (ChronoField) field;
        f.checkValidValue(newValue);        // TODO: validate value
        int nvalue = (int) newValue;
        switch (f) {
            case DAY_OF_WEEK: return plusDays(newValue - get(ChronoField.DAY_OF_WEEK));
            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 resolvePreviousValid(prolepticYear, month, nvalue);
            case DAY_OF_YEAR: return resolvePreviousValid(prolepticYear, ((nvalue - 1) / 30) + 1, ((nvalue - 1) % 30) + 1);
            case EPOCH_DAY: return ofEpochDay(nvalue);
            case ALIGNED_WEEK_OF_MONTH: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_MONTH)) * 7);
            case ALIGNED_WEEK_OF_YEAR: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_YEAR)) * 7);
            case MONTH_OF_YEAR: return resolvePreviousValid(prolepticYear, nvalue, day);
            case YEAR_OF_ERA: return resolvePreviousValid(prolepticYear >= 1 ? nvalue : 1 - nvalue, month, day);
            case YEAR: return resolvePreviousValid(nvalue, month, day);
            case ERA: return resolvePreviousValid(1 - prolepticYear, month, day);
        }
        throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
    }
    return field.adjustInto(this, newValue);
}
 
源代码2 项目: jdk8u60   文件: CopticDate.java
@Override
public CopticDate with(TemporalField field, long newValue) {
    if (field instanceof ChronoField) {
        ChronoField f = (ChronoField) field;
        f.checkValidValue(newValue);        // TODO: validate value
        int nvalue = (int) newValue;
        switch (f) {
            case DAY_OF_WEEK: return plusDays(newValue - get(ChronoField.DAY_OF_WEEK));
            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 resolvePreviousValid(prolepticYear, month, nvalue);
            case DAY_OF_YEAR: return resolvePreviousValid(prolepticYear, ((nvalue - 1) / 30) + 1, ((nvalue - 1) % 30) + 1);
            case EPOCH_DAY: return ofEpochDay(nvalue);
            case ALIGNED_WEEK_OF_MONTH: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_MONTH)) * 7);
            case ALIGNED_WEEK_OF_YEAR: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_YEAR)) * 7);
            case MONTH_OF_YEAR: return resolvePreviousValid(prolepticYear, nvalue, day);
            case YEAR_OF_ERA: return resolvePreviousValid(prolepticYear >= 1 ? nvalue : 1 - nvalue, month, day);
            case YEAR: return resolvePreviousValid(nvalue, month, day);
            case ERA: return resolvePreviousValid(1 - prolepticYear, month, day);
        }
        throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
    }
    return field.adjustInto(this, newValue);
}
 
源代码3 项目: jdk8u-dev-jdk   文件: CopticDate.java
@Override
public CopticDate with(TemporalField field, long newValue) {
    if (field instanceof ChronoField) {
        ChronoField f = (ChronoField) field;
        f.checkValidValue(newValue);        // TODO: validate value
        int nvalue = (int) newValue;
        switch (f) {
            case DAY_OF_WEEK: return plusDays(newValue - get(ChronoField.DAY_OF_WEEK));
            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 resolvePreviousValid(prolepticYear, month, nvalue);
            case DAY_OF_YEAR: return resolvePreviousValid(prolepticYear, ((nvalue - 1) / 30) + 1, ((nvalue - 1) % 30) + 1);
            case EPOCH_DAY: return ofEpochDay(nvalue);
            case ALIGNED_WEEK_OF_MONTH: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_MONTH)) * 7);
            case ALIGNED_WEEK_OF_YEAR: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_YEAR)) * 7);
            case MONTH_OF_YEAR: return resolvePreviousValid(prolepticYear, nvalue, day);
            case YEAR_OF_ERA: return resolvePreviousValid(prolepticYear >= 1 ? nvalue : 1 - nvalue, month, day);
            case YEAR: return resolvePreviousValid(nvalue, month, day);
            case ERA: return resolvePreviousValid(1 - prolepticYear, month, day);
        }
        throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
    }
    return field.adjustInto(this, newValue);
}
 
源代码4 项目: openjdk-8-source   文件: CopticDate.java
@Override
public CopticDate with(TemporalField field, long newValue) {
    if (field instanceof ChronoField) {
        ChronoField f = (ChronoField) field;
        f.checkValidValue(newValue);        // TODO: validate value
        int nvalue = (int) newValue;
        switch (f) {
            case DAY_OF_WEEK: return plusDays(newValue - get(ChronoField.DAY_OF_WEEK));
            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 resolvePreviousValid(prolepticYear, month, nvalue);
            case DAY_OF_YEAR: return resolvePreviousValid(prolepticYear, ((nvalue - 1) / 30) + 1, ((nvalue - 1) % 30) + 1);
            case EPOCH_DAY: return ofEpochDay(nvalue);
            case ALIGNED_WEEK_OF_MONTH: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_MONTH)) * 7);
            case ALIGNED_WEEK_OF_YEAR: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_YEAR)) * 7);
            case MONTH_OF_YEAR: return resolvePreviousValid(prolepticYear, nvalue, day);
            case YEAR_OF_ERA: return resolvePreviousValid(prolepticYear >= 1 ? nvalue : 1 - nvalue, month, day);
            case YEAR: return resolvePreviousValid(nvalue, month, day);
            case ERA: return resolvePreviousValid(1 - prolepticYear, month, day);
        }
        throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
    }
    return field.adjustInto(this, newValue);
}
 
源代码5 项目: jdk1.8-source-analysis   文件: YearMonth.java
/**
 * Returns a copy of this year-month with the specified field set to a new value.
 * <p>
 * This returns a {@code YearMonth}, based on this one, with the value
 * for the specified field changed.
 * This can be used to change any supported field, such as the year or month.
 * If it is not possible to set the value, because the field is not supported or for
 * some other reason, an exception is thrown.
 * <p>
 * If the field is a {@link ChronoField} then the adjustment is implemented here.
 * The supported fields behave as follows:
 * <ul>
 * <li>{@code MONTH_OF_YEAR} -
 *  Returns a {@code YearMonth} with the specified month-of-year.
 *  The year will be unchanged.
 * <li>{@code PROLEPTIC_MONTH} -
 *  Returns a {@code YearMonth} with the specified proleptic-month.
 *  This completely replaces the year and month of this object.
 * <li>{@code YEAR_OF_ERA} -
 *  Returns a {@code YearMonth} with the specified year-of-era
 *  The month and era will be unchanged.
 * <li>{@code YEAR} -
 *  Returns a {@code YearMonth} with the specified year.
 *  The month will be unchanged.
 * <li>{@code ERA} -
 *  Returns a {@code YearMonth} with the specified era.
 *  The month and year-of-era will be unchanged.
 * </ul>
 * <p>
 * In all cases, if the new value is outside the valid range of values for the field
 * then a {@code DateTimeException} will be thrown.
 * <p>
 * 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.adjustInto(Temporal, long)}
 * passing {@code this} as the argument. In this case, the field determines
 * whether and how to adjust the instant.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param field  the field to set in the result, not null
 * @param newValue  the new value of the field in the result
 * @return a {@code YearMonth} based on {@code this} with the specified field set, not null
 * @throws DateTimeException if the field cannot be set
 * @throws UnsupportedTemporalTypeException if the field is not supported
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public YearMonth with(TemporalField field, long newValue) {
    if (field instanceof ChronoField) {
        ChronoField f = (ChronoField) field;
        f.checkValidValue(newValue);
        switch (f) {
            case MONTH_OF_YEAR: return withMonth((int) newValue);
            case PROLEPTIC_MONTH: return plusMonths(newValue - getProlepticMonth());
            case YEAR_OF_ERA: return withYear((int) (year < 1 ? 1 - newValue : newValue));
            case YEAR: return withYear((int) newValue);
            case ERA: return (getLong(ERA) == newValue ? this : withYear(1 - year));
        }
        throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
    }
    return field.adjustInto(this, newValue);
}
 
源代码6 项目: dragonwell8_jdk   文件: YearMonth.java
/**
 * Returns a copy of this year-month with the specified field set to a new value.
 * <p>
 * This returns a {@code YearMonth}, based on this one, with the value
 * for the specified field changed.
 * This can be used to change any supported field, such as the year or month.
 * If it is not possible to set the value, because the field is not supported or for
 * some other reason, an exception is thrown.
 * <p>
 * If the field is a {@link ChronoField} then the adjustment is implemented here.
 * The supported fields behave as follows:
 * <ul>
 * <li>{@code MONTH_OF_YEAR} -
 *  Returns a {@code YearMonth} with the specified month-of-year.
 *  The year will be unchanged.
 * <li>{@code PROLEPTIC_MONTH} -
 *  Returns a {@code YearMonth} with the specified proleptic-month.
 *  This completely replaces the year and month of this object.
 * <li>{@code YEAR_OF_ERA} -
 *  Returns a {@code YearMonth} with the specified year-of-era
 *  The month and era will be unchanged.
 * <li>{@code YEAR} -
 *  Returns a {@code YearMonth} with the specified year.
 *  The month will be unchanged.
 * <li>{@code ERA} -
 *  Returns a {@code YearMonth} with the specified era.
 *  The month and year-of-era will be unchanged.
 * </ul>
 * <p>
 * In all cases, if the new value is outside the valid range of values for the field
 * then a {@code DateTimeException} will be thrown.
 * <p>
 * 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.adjustInto(Temporal, long)}
 * passing {@code this} as the argument. In this case, the field determines
 * whether and how to adjust the instant.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param field  the field to set in the result, not null
 * @param newValue  the new value of the field in the result
 * @return a {@code YearMonth} based on {@code this} with the specified field set, not null
 * @throws DateTimeException if the field cannot be set
 * @throws UnsupportedTemporalTypeException if the field is not supported
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public YearMonth with(TemporalField field, long newValue) {
    if (field instanceof ChronoField) {
        ChronoField f = (ChronoField) field;
        f.checkValidValue(newValue);
        switch (f) {
            case MONTH_OF_YEAR: return withMonth((int) newValue);
            case PROLEPTIC_MONTH: return plusMonths(newValue - getProlepticMonth());
            case YEAR_OF_ERA: return withYear((int) (year < 1 ? 1 - newValue : newValue));
            case YEAR: return withYear((int) newValue);
            case ERA: return (getLong(ERA) == newValue ? this : withYear(1 - year));
        }
        throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
    }
    return field.adjustInto(this, newValue);
}
 
源代码7 项目: jdk8u-dev-jdk   文件: YearMonth.java
/**
 * Returns a copy of this year-month with the specified field set to a new value.
 * <p>
 * This returns a {@code YearMonth}, based on this one, with the value
 * for the specified field changed.
 * This can be used to change any supported field, such as the year or month.
 * If it is not possible to set the value, because the field is not supported or for
 * some other reason, an exception is thrown.
 * <p>
 * If the field is a {@link ChronoField} then the adjustment is implemented here.
 * The supported fields behave as follows:
 * <ul>
 * <li>{@code MONTH_OF_YEAR} -
 *  Returns a {@code YearMonth} with the specified month-of-year.
 *  The year will be unchanged.
 * <li>{@code PROLEPTIC_MONTH} -
 *  Returns a {@code YearMonth} with the specified proleptic-month.
 *  This completely replaces the year and month of this object.
 * <li>{@code YEAR_OF_ERA} -
 *  Returns a {@code YearMonth} with the specified year-of-era
 *  The month and era will be unchanged.
 * <li>{@code YEAR} -
 *  Returns a {@code YearMonth} with the specified year.
 *  The month will be unchanged.
 * <li>{@code ERA} -
 *  Returns a {@code YearMonth} with the specified era.
 *  The month and year-of-era will be unchanged.
 * </ul>
 * <p>
 * In all cases, if the new value is outside the valid range of values for the field
 * then a {@code DateTimeException} will be thrown.
 * <p>
 * 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.adjustInto(Temporal, long)}
 * passing {@code this} as the argument. In this case, the field determines
 * whether and how to adjust the instant.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param field  the field to set in the result, not null
 * @param newValue  the new value of the field in the result
 * @return a {@code YearMonth} based on {@code this} with the specified field set, not null
 * @throws DateTimeException if the field cannot be set
 * @throws UnsupportedTemporalTypeException if the field is not supported
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public YearMonth with(TemporalField field, long newValue) {
    if (field instanceof ChronoField) {
        ChronoField f = (ChronoField) field;
        f.checkValidValue(newValue);
        switch (f) {
            case MONTH_OF_YEAR: return withMonth((int) newValue);
            case PROLEPTIC_MONTH: return plusMonths(newValue - getProlepticMonth());
            case YEAR_OF_ERA: return withYear((int) (year < 1 ? 1 - newValue : newValue));
            case YEAR: return withYear((int) newValue);
            case ERA: return (getLong(ERA) == newValue ? this : withYear(1 - year));
        }
        throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
    }
    return field.adjustInto(this, newValue);
}
 
源代码8 项目: openjdk-8-source   文件: YearMonth.java
/**
 * Returns a copy of this year-month with the specified field set to a new value.
 * <p>
 * This returns a {@code YearMonth}, based on this one, with the value
 * for the specified field changed.
 * This can be used to change any supported field, such as the year or month.
 * If it is not possible to set the value, because the field is not supported or for
 * some other reason, an exception is thrown.
 * <p>
 * If the field is a {@link ChronoField} then the adjustment is implemented here.
 * The supported fields behave as follows:
 * <ul>
 * <li>{@code MONTH_OF_YEAR} -
 *  Returns a {@code YearMonth} with the specified month-of-year.
 *  The year will be unchanged.
 * <li>{@code PROLEPTIC_MONTH} -
 *  Returns a {@code YearMonth} with the specified proleptic-month.
 *  This completely replaces the year and month of this object.
 * <li>{@code YEAR_OF_ERA} -
 *  Returns a {@code YearMonth} with the specified year-of-era
 *  The month and era will be unchanged.
 * <li>{@code YEAR} -
 *  Returns a {@code YearMonth} with the specified year.
 *  The month will be unchanged.
 * <li>{@code ERA} -
 *  Returns a {@code YearMonth} with the specified era.
 *  The month and year-of-era will be unchanged.
 * </ul>
 * <p>
 * In all cases, if the new value is outside the valid range of values for the field
 * then a {@code DateTimeException} will be thrown.
 * <p>
 * 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.adjustInto(Temporal, long)}
 * passing {@code this} as the argument. In this case, the field determines
 * whether and how to adjust the instant.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param field  the field to set in the result, not null
 * @param newValue  the new value of the field in the result
 * @return a {@code YearMonth} based on {@code this} with the specified field set, not null
 * @throws DateTimeException if the field cannot be set
 * @throws UnsupportedTemporalTypeException if the field is not supported
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public YearMonth with(TemporalField field, long newValue) {
    if (field instanceof ChronoField) {
        ChronoField f = (ChronoField) field;
        f.checkValidValue(newValue);
        switch (f) {
            case MONTH_OF_YEAR: return withMonth((int) newValue);
            case PROLEPTIC_MONTH: return plusMonths(newValue - getProlepticMonth());
            case YEAR_OF_ERA: return withYear((int) (year < 1 ? 1 - newValue : newValue));
            case YEAR: return withYear((int) newValue);
            case ERA: return (getLong(ERA) == newValue ? this : withYear(1 - year));
        }
        throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
    }
    return field.adjustInto(this, newValue);
}
 
源代码9 项目: Bytecoder   文件: YearMonth.java
/**
 * Returns a copy of this year-month with the specified field set to a new value.
 * <p>
 * This returns a {@code YearMonth}, based on this one, with the value
 * for the specified field changed.
 * This can be used to change any supported field, such as the year or month.
 * If it is not possible to set the value, because the field is not supported or for
 * some other reason, an exception is thrown.
 * <p>
 * If the field is a {@link ChronoField} then the adjustment is implemented here.
 * The supported fields behave as follows:
 * <ul>
 * <li>{@code MONTH_OF_YEAR} -
 *  Returns a {@code YearMonth} with the specified month-of-year.
 *  The year will be unchanged.
 * <li>{@code PROLEPTIC_MONTH} -
 *  Returns a {@code YearMonth} with the specified proleptic-month.
 *  This completely replaces the year and month of this object.
 * <li>{@code YEAR_OF_ERA} -
 *  Returns a {@code YearMonth} with the specified year-of-era
 *  The month and era will be unchanged.
 * <li>{@code YEAR} -
 *  Returns a {@code YearMonth} with the specified year.
 *  The month will be unchanged.
 * <li>{@code ERA} -
 *  Returns a {@code YearMonth} with the specified era.
 *  The month and year-of-era will be unchanged.
 * </ul>
 * <p>
 * In all cases, if the new value is outside the valid range of values for the field
 * then a {@code DateTimeException} will be thrown.
 * <p>
 * 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.adjustInto(Temporal, long)}
 * passing {@code this} as the argument. In this case, the field determines
 * whether and how to adjust the instant.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param field  the field to set in the result, not null
 * @param newValue  the new value of the field in the result
 * @return a {@code YearMonth} based on {@code this} with the specified field set, not null
 * @throws DateTimeException if the field cannot be set
 * @throws UnsupportedTemporalTypeException if the field is not supported
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public YearMonth with(TemporalField field, long newValue) {
    if (field instanceof ChronoField) {
        ChronoField f = (ChronoField) field;
        f.checkValidValue(newValue);
        switch (f) {
            case MONTH_OF_YEAR: return withMonth((int) newValue);
            case PROLEPTIC_MONTH: return plusMonths(newValue - getProlepticMonth());
            case YEAR_OF_ERA: return withYear((int) (year < 1 ? 1 - newValue : newValue));
            case YEAR: return withYear((int) newValue);
            case ERA: return (getLong(ERA) == newValue ? this : withYear(1 - year));
        }
        throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
    }
    return field.adjustInto(this, newValue);
}
 
源代码10 项目: openjdk-jdk8u-backup   文件: YearMonth.java
/**
 * Returns a copy of this year-month with the specified field set to a new value.
 * <p>
 * This returns a {@code YearMonth}, based on this one, with the value
 * for the specified field changed.
 * This can be used to change any supported field, such as the year or month.
 * If it is not possible to set the value, because the field is not supported or for
 * some other reason, an exception is thrown.
 * <p>
 * If the field is a {@link ChronoField} then the adjustment is implemented here.
 * The supported fields behave as follows:
 * <ul>
 * <li>{@code MONTH_OF_YEAR} -
 *  Returns a {@code YearMonth} with the specified month-of-year.
 *  The year will be unchanged.
 * <li>{@code PROLEPTIC_MONTH} -
 *  Returns a {@code YearMonth} with the specified proleptic-month.
 *  This completely replaces the year and month of this object.
 * <li>{@code YEAR_OF_ERA} -
 *  Returns a {@code YearMonth} with the specified year-of-era
 *  The month and era will be unchanged.
 * <li>{@code YEAR} -
 *  Returns a {@code YearMonth} with the specified year.
 *  The month will be unchanged.
 * <li>{@code ERA} -
 *  Returns a {@code YearMonth} with the specified era.
 *  The month and year-of-era will be unchanged.
 * </ul>
 * <p>
 * In all cases, if the new value is outside the valid range of values for the field
 * then a {@code DateTimeException} will be thrown.
 * <p>
 * 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.adjustInto(Temporal, long)}
 * passing {@code this} as the argument. In this case, the field determines
 * whether and how to adjust the instant.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param field  the field to set in the result, not null
 * @param newValue  the new value of the field in the result
 * @return a {@code YearMonth} based on {@code this} with the specified field set, not null
 * @throws DateTimeException if the field cannot be set
 * @throws UnsupportedTemporalTypeException if the field is not supported
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public YearMonth with(TemporalField field, long newValue) {
    if (field instanceof ChronoField) {
        ChronoField f = (ChronoField) field;
        f.checkValidValue(newValue);
        switch (f) {
            case MONTH_OF_YEAR: return withMonth((int) newValue);
            case PROLEPTIC_MONTH: return plusMonths(newValue - getProlepticMonth());
            case YEAR_OF_ERA: return withYear((int) (year < 1 ? 1 - newValue : newValue));
            case YEAR: return withYear((int) newValue);
            case ERA: return (getLong(ERA) == newValue ? this : withYear(1 - year));
        }
        throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
    }
    return field.adjustInto(this, newValue);
}
 
源代码11 项目: jdk1.8-source-analysis   文件: Year.java
/**
 * Returns a copy of this year with the specified field set to a new value.
 * <p>
 * This returns a {@code Year}, based on this one, with the value
 * for the specified field changed.
 * If it is not possible to set the value, because the field is not supported or for
 * some other reason, an exception is thrown.
 * <p>
 * If the field is a {@link ChronoField} then the adjustment is implemented here.
 * The supported fields behave as follows:
 * <ul>
 * <li>{@code YEAR_OF_ERA} -
 *  Returns a {@code Year} with the specified year-of-era
 *  The era will be unchanged.
 * <li>{@code YEAR} -
 *  Returns a {@code Year} with the specified year.
 *  This completely replaces the date and is equivalent to {@link #of(int)}.
 * <li>{@code ERA} -
 *  Returns a {@code Year} with the specified era.
 *  The year-of-era will be unchanged.
 * </ul>
 * <p>
 * In all cases, if the new value is outside the valid range of values for the field
 * then a {@code DateTimeException} will be thrown.
 * <p>
 * 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.adjustInto(Temporal, long)}
 * passing {@code this} as the argument. In this case, the field determines
 * whether and how to adjust the instant.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param field  the field to set in the result, not null
 * @param newValue  the new value of the field in the result
 * @return a {@code Year} based on {@code this} with the specified field set, not null
 * @throws DateTimeException if the field cannot be set
 * @throws UnsupportedTemporalTypeException if the field is not supported
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Year with(TemporalField field, long newValue) {
    if (field instanceof ChronoField) {
        ChronoField f = (ChronoField) field;
        f.checkValidValue(newValue);
        switch (f) {
            case YEAR_OF_ERA: return Year.of((int) (year < 1 ? 1 - newValue : newValue));
            case YEAR: return Year.of((int) newValue);
            case ERA: return (getLong(ERA) == newValue ? this : Year.of(1 - year));
        }
        throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
    }
    return field.adjustInto(this, newValue);
}
 
源代码12 项目: Java8CN   文件: Year.java
/**
 * Returns a copy of this year with the specified field set to a new value.
 * <p>
 * This returns a {@code Year}, based on this one, with the value
 * for the specified field changed.
 * If it is not possible to set the value, because the field is not supported or for
 * some other reason, an exception is thrown.
 * <p>
 * If the field is a {@link ChronoField} then the adjustment is implemented here.
 * The supported fields behave as follows:
 * <ul>
 * <li>{@code YEAR_OF_ERA} -
 *  Returns a {@code Year} with the specified year-of-era
 *  The era will be unchanged.
 * <li>{@code YEAR} -
 *  Returns a {@code Year} with the specified year.
 *  This completely replaces the date and is equivalent to {@link #of(int)}.
 * <li>{@code ERA} -
 *  Returns a {@code Year} with the specified era.
 *  The year-of-era will be unchanged.
 * </ul>
 * <p>
 * In all cases, if the new value is outside the valid range of values for the field
 * then a {@code DateTimeException} will be thrown.
 * <p>
 * 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.adjustInto(Temporal, long)}
 * passing {@code this} as the argument. In this case, the field determines
 * whether and how to adjust the instant.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param field  the field to set in the result, not null
 * @param newValue  the new value of the field in the result
 * @return a {@code Year} based on {@code this} with the specified field set, not null
 * @throws DateTimeException if the field cannot be set
 * @throws UnsupportedTemporalTypeException if the field is not supported
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Year with(TemporalField field, long newValue) {
    if (field instanceof ChronoField) {
        ChronoField f = (ChronoField) field;
        f.checkValidValue(newValue);
        switch (f) {
            case YEAR_OF_ERA: return Year.of((int) (year < 1 ? 1 - newValue : newValue));
            case YEAR: return Year.of((int) newValue);
            case ERA: return (getLong(ERA) == newValue ? this : Year.of(1 - year));
        }
        throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
    }
    return field.adjustInto(this, newValue);
}
 
源代码13 项目: jdk8u-jdk   文件: Year.java
/**
 * Returns a copy of this year with the specified field set to a new value.
 * <p>
 * This returns a {@code Year}, based on this one, with the value
 * for the specified field changed.
 * If it is not possible to set the value, because the field is not supported or for
 * some other reason, an exception is thrown.
 * <p>
 * If the field is a {@link ChronoField} then the adjustment is implemented here.
 * The supported fields behave as follows:
 * <ul>
 * <li>{@code YEAR_OF_ERA} -
 *  Returns a {@code Year} with the specified year-of-era
 *  The era will be unchanged.
 * <li>{@code YEAR} -
 *  Returns a {@code Year} with the specified year.
 *  This completely replaces the date and is equivalent to {@link #of(int)}.
 * <li>{@code ERA} -
 *  Returns a {@code Year} with the specified era.
 *  The year-of-era will be unchanged.
 * </ul>
 * <p>
 * In all cases, if the new value is outside the valid range of values for the field
 * then a {@code DateTimeException} will be thrown.
 * <p>
 * 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.adjustInto(Temporal, long)}
 * passing {@code this} as the argument. In this case, the field determines
 * whether and how to adjust the instant.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param field  the field to set in the result, not null
 * @param newValue  the new value of the field in the result
 * @return a {@code Year} based on {@code this} with the specified field set, not null
 * @throws DateTimeException if the field cannot be set
 * @throws UnsupportedTemporalTypeException if the field is not supported
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Year with(TemporalField field, long newValue) {
    if (field instanceof ChronoField) {
        ChronoField f = (ChronoField) field;
        f.checkValidValue(newValue);
        switch (f) {
            case YEAR_OF_ERA: return Year.of((int) (year < 1 ? 1 - newValue : newValue));
            case YEAR: return Year.of((int) newValue);
            case ERA: return (getLong(ERA) == newValue ? this : Year.of(1 - year));
        }
        throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
    }
    return field.adjustInto(this, newValue);
}
 
源代码14 项目: hottub   文件: Year.java
/**
 * Returns a copy of this year with the specified field set to a new value.
 * <p>
 * This returns a {@code Year}, based on this one, with the value
 * for the specified field changed.
 * If it is not possible to set the value, because the field is not supported or for
 * some other reason, an exception is thrown.
 * <p>
 * If the field is a {@link ChronoField} then the adjustment is implemented here.
 * The supported fields behave as follows:
 * <ul>
 * <li>{@code YEAR_OF_ERA} -
 *  Returns a {@code Year} with the specified year-of-era
 *  The era will be unchanged.
 * <li>{@code YEAR} -
 *  Returns a {@code Year} with the specified year.
 *  This completely replaces the date and is equivalent to {@link #of(int)}.
 * <li>{@code ERA} -
 *  Returns a {@code Year} with the specified era.
 *  The year-of-era will be unchanged.
 * </ul>
 * <p>
 * In all cases, if the new value is outside the valid range of values for the field
 * then a {@code DateTimeException} will be thrown.
 * <p>
 * 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.adjustInto(Temporal, long)}
 * passing {@code this} as the argument. In this case, the field determines
 * whether and how to adjust the instant.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param field  the field to set in the result, not null
 * @param newValue  the new value of the field in the result
 * @return a {@code Year} based on {@code this} with the specified field set, not null
 * @throws DateTimeException if the field cannot be set
 * @throws UnsupportedTemporalTypeException if the field is not supported
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Year with(TemporalField field, long newValue) {
    if (field instanceof ChronoField) {
        ChronoField f = (ChronoField) field;
        f.checkValidValue(newValue);
        switch (f) {
            case YEAR_OF_ERA: return Year.of((int) (year < 1 ? 1 - newValue : newValue));
            case YEAR: return Year.of((int) newValue);
            case ERA: return (getLong(ERA) == newValue ? this : Year.of(1 - year));
        }
        throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
    }
    return field.adjustInto(this, newValue);
}
 
源代码15 项目: JDKSourceCode1.8   文件: Year.java
/**
 * Returns a copy of this year with the specified field set to a new value.
 * <p>
 * This returns a {@code Year}, based on this one, with the value
 * for the specified field changed.
 * If it is not possible to set the value, because the field is not supported or for
 * some other reason, an exception is thrown.
 * <p>
 * If the field is a {@link ChronoField} then the adjustment is implemented here.
 * The supported fields behave as follows:
 * <ul>
 * <li>{@code YEAR_OF_ERA} -
 *  Returns a {@code Year} with the specified year-of-era
 *  The era will be unchanged.
 * <li>{@code YEAR} -
 *  Returns a {@code Year} with the specified year.
 *  This completely replaces the date and is equivalent to {@link #of(int)}.
 * <li>{@code ERA} -
 *  Returns a {@code Year} with the specified era.
 *  The year-of-era will be unchanged.
 * </ul>
 * <p>
 * In all cases, if the new value is outside the valid range of values for the field
 * then a {@code DateTimeException} will be thrown.
 * <p>
 * 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.adjustInto(Temporal, long)}
 * passing {@code this} as the argument. In this case, the field determines
 * whether and how to adjust the instant.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param field  the field to set in the result, not null
 * @param newValue  the new value of the field in the result
 * @return a {@code Year} based on {@code this} with the specified field set, not null
 * @throws DateTimeException if the field cannot be set
 * @throws UnsupportedTemporalTypeException if the field is not supported
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Year with(TemporalField field, long newValue) {
    if (field instanceof ChronoField) {
        ChronoField f = (ChronoField) field;
        f.checkValidValue(newValue);
        switch (f) {
            case YEAR_OF_ERA: return Year.of((int) (year < 1 ? 1 - newValue : newValue));
            case YEAR: return Year.of((int) newValue);
            case ERA: return (getLong(ERA) == newValue ? this : Year.of(1 - year));
        }
        throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
    }
    return field.adjustInto(this, newValue);
}
 
源代码16 项目: j2objc   文件: Year.java
/**
 * Returns a copy of this year with the specified field set to a new value.
 * <p>
 * This returns a {@code Year}, based on this one, with the value
 * for the specified field changed.
 * If it is not possible to set the value, because the field is not supported or for
 * some other reason, an exception is thrown.
 * <p>
 * If the field is a {@link ChronoField} then the adjustment is implemented here.
 * The supported fields behave as follows:
 * <ul>
 * <li>{@code YEAR_OF_ERA} -
 *  Returns a {@code Year} with the specified year-of-era
 *  The era will be unchanged.
 * <li>{@code YEAR} -
 *  Returns a {@code Year} with the specified year.
 *  This completely replaces the date and is equivalent to {@link #of(int)}.
 * <li>{@code ERA} -
 *  Returns a {@code Year} with the specified era.
 *  The year-of-era will be unchanged.
 * </ul>
 * <p>
 * In all cases, if the new value is outside the valid range of values for the field
 * then a {@code DateTimeException} will be thrown.
 * <p>
 * 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.adjustInto(Temporal, long)}
 * passing {@code this} as the argument. In this case, the field determines
 * whether and how to adjust the instant.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param field  the field to set in the result, not null
 * @param newValue  the new value of the field in the result
 * @return a {@code Year} based on {@code this} with the specified field set, not null
 * @throws DateTimeException if the field cannot be set
 * @throws UnsupportedTemporalTypeException if the field is not supported
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Year with(TemporalField field, long newValue) {
    if (field instanceof ChronoField) {
        ChronoField f = (ChronoField) field;
        f.checkValidValue(newValue);
        switch (f) {
            case YEAR_OF_ERA: return Year.of((int) (year < 1 ? 1 - newValue : newValue));
            case YEAR: return Year.of((int) newValue);
            case ERA: return (getLong(ERA) == newValue ? this : Year.of(1 - year));
        }
        throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
    }
    return field.adjustInto(this, newValue);
}
 
源代码17 项目: jdk8u-dev-jdk   文件: Year.java
/**
 * Returns a copy of this year with the specified field set to a new value.
 * <p>
 * This returns a {@code Year}, based on this one, with the value
 * for the specified field changed.
 * If it is not possible to set the value, because the field is not supported or for
 * some other reason, an exception is thrown.
 * <p>
 * If the field is a {@link ChronoField} then the adjustment is implemented here.
 * The supported fields behave as follows:
 * <ul>
 * <li>{@code YEAR_OF_ERA} -
 *  Returns a {@code Year} with the specified year-of-era
 *  The era will be unchanged.
 * <li>{@code YEAR} -
 *  Returns a {@code Year} with the specified year.
 *  This completely replaces the date and is equivalent to {@link #of(int)}.
 * <li>{@code ERA} -
 *  Returns a {@code Year} with the specified era.
 *  The year-of-era will be unchanged.
 * </ul>
 * <p>
 * In all cases, if the new value is outside the valid range of values for the field
 * then a {@code DateTimeException} will be thrown.
 * <p>
 * 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.adjustInto(Temporal, long)}
 * passing {@code this} as the argument. In this case, the field determines
 * whether and how to adjust the instant.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param field  the field to set in the result, not null
 * @param newValue  the new value of the field in the result
 * @return a {@code Year} based on {@code this} with the specified field set, not null
 * @throws DateTimeException if the field cannot be set
 * @throws UnsupportedTemporalTypeException if the field is not supported
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Year with(TemporalField field, long newValue) {
    if (field instanceof ChronoField) {
        ChronoField f = (ChronoField) field;
        f.checkValidValue(newValue);
        switch (f) {
            case YEAR_OF_ERA: return Year.of((int) (year < 1 ? 1 - newValue : newValue));
            case YEAR: return Year.of((int) newValue);
            case ERA: return (getLong(ERA) == newValue ? this : Year.of(1 - year));
        }
        throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
    }
    return field.adjustInto(this, newValue);
}
 
源代码18 项目: jdk8u-jdk   文件: Year.java
/**
 * Returns a copy of this year with the specified field set to a new value.
 * <p>
 * This returns a {@code Year}, based on this one, with the value
 * for the specified field changed.
 * If it is not possible to set the value, because the field is not supported or for
 * some other reason, an exception is thrown.
 * <p>
 * If the field is a {@link ChronoField} then the adjustment is implemented here.
 * The supported fields behave as follows:
 * <ul>
 * <li>{@code YEAR_OF_ERA} -
 *  Returns a {@code Year} with the specified year-of-era
 *  The era will be unchanged.
 * <li>{@code YEAR} -
 *  Returns a {@code Year} with the specified year.
 *  This completely replaces the date and is equivalent to {@link #of(int)}.
 * <li>{@code ERA} -
 *  Returns a {@code Year} with the specified era.
 *  The year-of-era will be unchanged.
 * </ul>
 * <p>
 * In all cases, if the new value is outside the valid range of values for the field
 * then a {@code DateTimeException} will be thrown.
 * <p>
 * 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.adjustInto(Temporal, long)}
 * passing {@code this} as the argument. In this case, the field determines
 * whether and how to adjust the instant.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param field  the field to set in the result, not null
 * @param newValue  the new value of the field in the result
 * @return a {@code Year} based on {@code this} with the specified field set, not null
 * @throws DateTimeException if the field cannot be set
 * @throws UnsupportedTemporalTypeException if the field is not supported
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Year with(TemporalField field, long newValue) {
    if (field instanceof ChronoField) {
        ChronoField f = (ChronoField) field;
        f.checkValidValue(newValue);
        switch (f) {
            case YEAR_OF_ERA: return Year.of((int) (year < 1 ? 1 - newValue : newValue));
            case YEAR: return Year.of((int) newValue);
            case ERA: return (getLong(ERA) == newValue ? this : Year.of(1 - year));
        }
        throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
    }
    return field.adjustInto(this, newValue);
}
 
源代码19 项目: Bytecoder   文件: Year.java
/**
 * Returns a copy of this year with the specified field set to a new value.
 * <p>
 * This returns a {@code Year}, based on this one, with the value
 * for the specified field changed.
 * If it is not possible to set the value, because the field is not supported or for
 * some other reason, an exception is thrown.
 * <p>
 * If the field is a {@link ChronoField} then the adjustment is implemented here.
 * The supported fields behave as follows:
 * <ul>
 * <li>{@code YEAR_OF_ERA} -
 *  Returns a {@code Year} with the specified year-of-era
 *  The era will be unchanged.
 * <li>{@code YEAR} -
 *  Returns a {@code Year} with the specified year.
 *  This completely replaces the date and is equivalent to {@link #of(int)}.
 * <li>{@code ERA} -
 *  Returns a {@code Year} with the specified era.
 *  The year-of-era will be unchanged.
 * </ul>
 * <p>
 * In all cases, if the new value is outside the valid range of values for the field
 * then a {@code DateTimeException} will be thrown.
 * <p>
 * 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.adjustInto(Temporal, long)}
 * passing {@code this} as the argument. In this case, the field determines
 * whether and how to adjust the instant.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param field  the field to set in the result, not null
 * @param newValue  the new value of the field in the result
 * @return a {@code Year} based on {@code this} with the specified field set, not null
 * @throws DateTimeException if the field cannot be set
 * @throws UnsupportedTemporalTypeException if the field is not supported
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Year with(TemporalField field, long newValue) {
    if (field instanceof ChronoField) {
        ChronoField f = (ChronoField) field;
        f.checkValidValue(newValue);
        switch (f) {
            case YEAR_OF_ERA: return Year.of((int) (year < 1 ? 1 - newValue : newValue));
            case YEAR: return Year.of((int) newValue);
            case ERA: return (getLong(ERA) == newValue ? this : Year.of(1 - year));
        }
        throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
    }
    return field.adjustInto(this, newValue);
}
 
源代码20 项目: openjdk-jdk8u-backup   文件: Year.java
/**
 * Returns a copy of this year with the specified field set to a new value.
 * <p>
 * This returns a {@code Year}, based on this one, with the value
 * for the specified field changed.
 * If it is not possible to set the value, because the field is not supported or for
 * some other reason, an exception is thrown.
 * <p>
 * If the field is a {@link ChronoField} then the adjustment is implemented here.
 * The supported fields behave as follows:
 * <ul>
 * <li>{@code YEAR_OF_ERA} -
 *  Returns a {@code Year} with the specified year-of-era
 *  The era will be unchanged.
 * <li>{@code YEAR} -
 *  Returns a {@code Year} with the specified year.
 *  This completely replaces the date and is equivalent to {@link #of(int)}.
 * <li>{@code ERA} -
 *  Returns a {@code Year} with the specified era.
 *  The year-of-era will be unchanged.
 * </ul>
 * <p>
 * In all cases, if the new value is outside the valid range of values for the field
 * then a {@code DateTimeException} will be thrown.
 * <p>
 * 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.adjustInto(Temporal, long)}
 * passing {@code this} as the argument. In this case, the field determines
 * whether and how to adjust the instant.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param field  the field to set in the result, not null
 * @param newValue  the new value of the field in the result
 * @return a {@code Year} based on {@code this} with the specified field set, not null
 * @throws DateTimeException if the field cannot be set
 * @throws UnsupportedTemporalTypeException if the field is not supported
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Year with(TemporalField field, long newValue) {
    if (field instanceof ChronoField) {
        ChronoField f = (ChronoField) field;
        f.checkValidValue(newValue);
        switch (f) {
            case YEAR_OF_ERA: return Year.of((int) (year < 1 ? 1 - newValue : newValue));
            case YEAR: return Year.of((int) newValue);
            case ERA: return (getLong(ERA) == newValue ? this : Year.of(1 - year));
        }
        throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
    }
    return field.adjustInto(this, newValue);
}