java.time.temporal.TemporalAdjuster#adjustInto ( )源码实例Demo

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

源代码1 项目: TencentKona-8   文件: ZonedDateTime.java
/**
 * Returns an adjusted copy of this date-time.
 * <p>
 * This returns a {@code ZonedDateTime}, based on this one, with the date-time adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the date to the last day of the month.
 * A selection of common adjustments is provided in
 * {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
 * These include finding the "last day of the month" and "next Wednesday".
 * Key date-time classes also implement the {@code TemporalAdjuster} interface,
 * such as {@link Month} and {@link java.time.MonthDay MonthDay}.
 * The adjuster is responsible for handling special cases, such as the varying
 * lengths of month and leap years.
 * <p>
 * For example this code returns a date on the last day of July:
 * <pre>
 *  import static java.time.Month.*;
 *  import static java.time.temporal.TemporalAdjusters.*;
 *
 *  result = zonedDateTime.with(JULY).with(lastDayOfMonth());
 * </pre>
 * <p>
 * The classes {@link LocalDate} and {@link LocalTime} implement {@code TemporalAdjuster},
 * thus this method can be used to change the date, time or offset:
 * <pre>
 *  result = zonedDateTime.with(date);
 *  result = zonedDateTime.with(time);
 * </pre>
 * <p>
 * {@link ZoneOffset} also implements {@code TemporalAdjuster} however using it
 * as an argument typically has no effect. The offset of a {@code ZonedDateTime} is
 * controlled primarily by the time-zone. As such, changing the offset does not generally
 * make sense, because there is only one valid offset for the local date-time and zone.
 * If the zoned date-time is in a daylight savings overlap, then the offset is used
 * to switch between the two valid offsets. In all other cases, the offset is ignored.
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code ZonedDateTime} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public ZonedDateTime with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalDate) {
        return resolveLocal(LocalDateTime.of((LocalDate) adjuster, dateTime.toLocalTime()));
    } else if (adjuster instanceof LocalTime) {
        return resolveLocal(LocalDateTime.of(dateTime.toLocalDate(), (LocalTime) adjuster));
    } else if (adjuster instanceof LocalDateTime) {
        return resolveLocal((LocalDateTime) adjuster);
    } else if (adjuster instanceof OffsetDateTime) {
        OffsetDateTime odt = (OffsetDateTime) adjuster;
        return ofLocal(odt.toLocalDateTime(), zone, odt.getOffset());
    } else if (adjuster instanceof Instant) {
        Instant instant = (Instant) adjuster;
        return create(instant.getEpochSecond(), instant.getNano(), zone);
    } else if (adjuster instanceof ZoneOffset) {
        return resolveOffset((ZoneOffset) adjuster);
    }
    return (ZonedDateTime) adjuster.adjustInto(this);
}
 
源代码2 项目: dragonwell8_jdk   文件: ZonedDateTime.java
/**
 * Returns an adjusted copy of this date-time.
 * <p>
 * This returns a {@code ZonedDateTime}, based on this one, with the date-time adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the date to the last day of the month.
 * A selection of common adjustments is provided in
 * {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
 * These include finding the "last day of the month" and "next Wednesday".
 * Key date-time classes also implement the {@code TemporalAdjuster} interface,
 * such as {@link Month} and {@link java.time.MonthDay MonthDay}.
 * The adjuster is responsible for handling special cases, such as the varying
 * lengths of month and leap years.
 * <p>
 * For example this code returns a date on the last day of July:
 * <pre>
 *  import static java.time.Month.*;
 *  import static java.time.temporal.TemporalAdjusters.*;
 *
 *  result = zonedDateTime.with(JULY).with(lastDayOfMonth());
 * </pre>
 * <p>
 * The classes {@link LocalDate} and {@link LocalTime} implement {@code TemporalAdjuster},
 * thus this method can be used to change the date, time or offset:
 * <pre>
 *  result = zonedDateTime.with(date);
 *  result = zonedDateTime.with(time);
 * </pre>
 * <p>
 * {@link ZoneOffset} also implements {@code TemporalAdjuster} however using it
 * as an argument typically has no effect. The offset of a {@code ZonedDateTime} is
 * controlled primarily by the time-zone. As such, changing the offset does not generally
 * make sense, because there is only one valid offset for the local date-time and zone.
 * If the zoned date-time is in a daylight savings overlap, then the offset is used
 * to switch between the two valid offsets. In all other cases, the offset is ignored.
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code ZonedDateTime} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public ZonedDateTime with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalDate) {
        return resolveLocal(LocalDateTime.of((LocalDate) adjuster, dateTime.toLocalTime()));
    } else if (adjuster instanceof LocalTime) {
        return resolveLocal(LocalDateTime.of(dateTime.toLocalDate(), (LocalTime) adjuster));
    } else if (adjuster instanceof LocalDateTime) {
        return resolveLocal((LocalDateTime) adjuster);
    } else if (adjuster instanceof OffsetDateTime) {
        OffsetDateTime odt = (OffsetDateTime) adjuster;
        return ofLocal(odt.toLocalDateTime(), zone, odt.getOffset());
    } else if (adjuster instanceof Instant) {
        Instant instant = (Instant) adjuster;
        return create(instant.getEpochSecond(), instant.getNano(), zone);
    } else if (adjuster instanceof ZoneOffset) {
        return resolveOffset((ZoneOffset) adjuster);
    }
    return (ZonedDateTime) adjuster.adjustInto(this);
}
 
源代码3 项目: jdk1.8-source-analysis   文件: OffsetTime.java
/**
 * Returns an adjusted copy of this time.
 * <p>
 * This returns an {@code OffsetTime}, based on this one, with the time adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the hour field.
 * A more complex adjuster might set the time to the last hour of the day.
 * <p>
 * The classes {@link LocalTime} and {@link ZoneOffset} implement {@code TemporalAdjuster},
 * thus this method can be used to change the time or offset:
 * <pre>
 *  result = offsetTime.with(time);
 *  result = offsetTime.with(offset);
 * </pre>
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return an {@code OffsetTime} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public OffsetTime with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalTime) {
        return with((LocalTime) adjuster, offset);
    } else if (adjuster instanceof ZoneOffset) {
        return with(time, (ZoneOffset) adjuster);
    } else if (adjuster instanceof OffsetTime) {
        return (OffsetTime) adjuster;
    }
    return (OffsetTime) adjuster.adjustInto(this);
}
 
源代码4 项目: TencentKona-8   文件: LocalDate.java
/**
 * Returns an adjusted copy of this date.
 * <p>
 * This returns a {@code LocalDate}, based on this one, with the date adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the date to the last day of the month.
 * <p>
 * A selection of common adjustments is provided in
 * {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
 * These include finding the "last day of the month" and "next Wednesday".
 * Key date-time classes also implement the {@code TemporalAdjuster} interface,
 * such as {@link Month} and {@link java.time.MonthDay MonthDay}.
 * The adjuster is responsible for handling special cases, such as the varying
 * lengths of month and leap years.
 * <p>
 * For example this code returns a date on the last day of July:
 * <pre>
 *  import static java.time.Month.*;
 *  import static java.time.temporal.TemporalAdjusters.*;
 *
 *  result = localDate.with(JULY).with(lastDayOfMonth());
 * </pre>
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code LocalDate} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public LocalDate with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalDate) {
        return (LocalDate) adjuster;
    }
    return (LocalDate) adjuster.adjustInto(this);
}
 
源代码5 项目: jdk1.8-source-analysis   文件: OffsetDateTime.java
/**
 * Returns an adjusted copy of this date-time.
 * <p>
 * This returns an {@code OffsetDateTime}, based on this one, with the date-time adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the date to the last day of the month.
 * A selection of common adjustments is provided in
 * {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
 * These include finding the "last day of the month" and "next Wednesday".
 * Key date-time classes also implement the {@code TemporalAdjuster} interface,
 * such as {@link Month} and {@link java.time.MonthDay MonthDay}.
 * The adjuster is responsible for handling special cases, such as the varying
 * lengths of month and leap years.
 * <p>
 * For example this code returns a date on the last day of July:
 * <pre>
 *  import static java.time.Month.*;
 *  import static java.time.temporal.TemporalAdjusters.*;
 *
 *  result = offsetDateTime.with(JULY).with(lastDayOfMonth());
 * </pre>
 * <p>
 * The classes {@link LocalDate}, {@link LocalTime} and {@link ZoneOffset} implement
 * {@code TemporalAdjuster}, thus this method can be used to change the date, time or offset:
 * <pre>
 *  result = offsetDateTime.with(date);
 *  result = offsetDateTime.with(time);
 *  result = offsetDateTime.with(offset);
 * </pre>
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return an {@code OffsetDateTime} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public OffsetDateTime with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalDate || adjuster instanceof LocalTime || adjuster instanceof LocalDateTime) {
        return with(dateTime.with(adjuster), offset);
    } else if (adjuster instanceof Instant) {
        return ofInstant((Instant) adjuster, offset);
    } else if (adjuster instanceof ZoneOffset) {
        return with(dateTime, (ZoneOffset) adjuster);
    } else if (adjuster instanceof OffsetDateTime) {
        return (OffsetDateTime) adjuster;
    }
    return (OffsetDateTime) adjuster.adjustInto(this);
}
 
源代码6 项目: jdk1.8-source-analysis   文件: LocalTime.java
/**
 * Returns an adjusted copy of this time.
 * <p>
 * This returns a {@code LocalTime}, based on this one, with the time adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the hour field.
 * A more complex adjuster might set the time to the last hour of the day.
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code LocalTime} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public LocalTime with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalTime) {
        return (LocalTime) adjuster;
    }
    return (LocalTime) adjuster.adjustInto(this);
}
 
源代码7 项目: jdk1.8-source-analysis   文件: LocalDate.java
/**
 * Returns an adjusted copy of this date.
 * <p>
 * This returns a {@code LocalDate}, based on this one, with the date adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the date to the last day of the month.
 * <p>
 * A selection of common adjustments is provided in
 * {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
 * These include finding the "last day of the month" and "next Wednesday".
 * Key date-time classes also implement the {@code TemporalAdjuster} interface,
 * such as {@link Month} and {@link java.time.MonthDay MonthDay}.
 * The adjuster is responsible for handling special cases, such as the varying
 * lengths of month and leap years.
 * <p>
 * For example this code returns a date on the last day of July:
 * <pre>
 *  import static java.time.Month.*;
 *  import static java.time.temporal.TemporalAdjusters.*;
 *
 *  result = localDate.with(JULY).with(lastDayOfMonth());
 * </pre>
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code LocalDate} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public LocalDate with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalDate) {
        return (LocalDate) adjuster;
    }
    return (LocalDate) adjuster.adjustInto(this);
}
 
源代码8 项目: jdk1.8-source-analysis   文件: LocalDateTime.java
/**
 * Returns an adjusted copy of this date-time.
 * <p>
 * This returns a {@code LocalDateTime}, based on this one, with the date-time adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the date to the last day of the month.
 * <p>
 * A selection of common adjustments is provided in
 * {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
 * These include finding the "last day of the month" and "next Wednesday".
 * Key date-time classes also implement the {@code TemporalAdjuster} interface,
 * such as {@link Month} and {@link java.time.MonthDay MonthDay}.
 * The adjuster is responsible for handling special cases, such as the varying
 * lengths of month and leap years.
 * <p>
 * For example this code returns a date on the last day of July:
 * <pre>
 *  import static java.time.Month.*;
 *  import static java.time.temporal.TemporalAdjusters.*;
 *
 *  result = localDateTime.with(JULY).with(lastDayOfMonth());
 * </pre>
 * <p>
 * The classes {@link LocalDate} and {@link LocalTime} implement {@code TemporalAdjuster},
 * thus this method can be used to change the date, time or offset:
 * <pre>
 *  result = localDateTime.with(date);
 *  result = localDateTime.with(time);
 * </pre>
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code LocalDateTime} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public LocalDateTime with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalDate) {
        return with((LocalDate) adjuster, time);
    } else if (adjuster instanceof LocalTime) {
        return with(date, (LocalTime) adjuster);
    } else if (adjuster instanceof LocalDateTime) {
        return (LocalDateTime) adjuster;
    }
    return (LocalDateTime) adjuster.adjustInto(this);
}
 
源代码9 项目: dragonwell8_jdk   文件: OffsetTime.java
/**
 * Returns an adjusted copy of this time.
 * <p>
 * This returns an {@code OffsetTime}, based on this one, with the time adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the hour field.
 * A more complex adjuster might set the time to the last hour of the day.
 * <p>
 * The classes {@link LocalTime} and {@link ZoneOffset} implement {@code TemporalAdjuster},
 * thus this method can be used to change the time or offset:
 * <pre>
 *  result = offsetTime.with(time);
 *  result = offsetTime.with(offset);
 * </pre>
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return an {@code OffsetTime} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public OffsetTime with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalTime) {
        return with((LocalTime) adjuster, offset);
    } else if (adjuster instanceof ZoneOffset) {
        return with(time, (ZoneOffset) adjuster);
    } else if (adjuster instanceof OffsetTime) {
        return (OffsetTime) adjuster;
    }
    return (OffsetTime) adjuster.adjustInto(this);
}
 
源代码10 项目: dragonwell8_jdk   文件: OffsetDateTime.java
/**
 * Returns an adjusted copy of this date-time.
 * <p>
 * This returns an {@code OffsetDateTime}, based on this one, with the date-time adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the date to the last day of the month.
 * A selection of common adjustments is provided in
 * {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
 * These include finding the "last day of the month" and "next Wednesday".
 * Key date-time classes also implement the {@code TemporalAdjuster} interface,
 * such as {@link Month} and {@link java.time.MonthDay MonthDay}.
 * The adjuster is responsible for handling special cases, such as the varying
 * lengths of month and leap years.
 * <p>
 * For example this code returns a date on the last day of July:
 * <pre>
 *  import static java.time.Month.*;
 *  import static java.time.temporal.TemporalAdjusters.*;
 *
 *  result = offsetDateTime.with(JULY).with(lastDayOfMonth());
 * </pre>
 * <p>
 * The classes {@link LocalDate}, {@link LocalTime} and {@link ZoneOffset} implement
 * {@code TemporalAdjuster}, thus this method can be used to change the date, time or offset:
 * <pre>
 *  result = offsetDateTime.with(date);
 *  result = offsetDateTime.with(time);
 *  result = offsetDateTime.with(offset);
 * </pre>
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return an {@code OffsetDateTime} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public OffsetDateTime with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalDate || adjuster instanceof LocalTime || adjuster instanceof LocalDateTime) {
        return with(dateTime.with(adjuster), offset);
    } else if (adjuster instanceof Instant) {
        return ofInstant((Instant) adjuster, offset);
    } else if (adjuster instanceof ZoneOffset) {
        return with(dateTime, (ZoneOffset) adjuster);
    } else if (adjuster instanceof OffsetDateTime) {
        return (OffsetDateTime) adjuster;
    }
    return (OffsetDateTime) adjuster.adjustInto(this);
}
 
源代码11 项目: TencentKona-8   文件: OffsetDateTime.java
/**
 * Returns an adjusted copy of this date-time.
 * <p>
 * This returns an {@code OffsetDateTime}, based on this one, with the date-time adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the date to the last day of the month.
 * A selection of common adjustments is provided in
 * {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
 * These include finding the "last day of the month" and "next Wednesday".
 * Key date-time classes also implement the {@code TemporalAdjuster} interface,
 * such as {@link Month} and {@link java.time.MonthDay MonthDay}.
 * The adjuster is responsible for handling special cases, such as the varying
 * lengths of month and leap years.
 * <p>
 * For example this code returns a date on the last day of July:
 * <pre>
 *  import static java.time.Month.*;
 *  import static java.time.temporal.TemporalAdjusters.*;
 *
 *  result = offsetDateTime.with(JULY).with(lastDayOfMonth());
 * </pre>
 * <p>
 * The classes {@link LocalDate}, {@link LocalTime} and {@link ZoneOffset} implement
 * {@code TemporalAdjuster}, thus this method can be used to change the date, time or offset:
 * <pre>
 *  result = offsetDateTime.with(date);
 *  result = offsetDateTime.with(time);
 *  result = offsetDateTime.with(offset);
 * </pre>
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return an {@code OffsetDateTime} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public OffsetDateTime with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalDate || adjuster instanceof LocalTime || adjuster instanceof LocalDateTime) {
        return with(dateTime.with(adjuster), offset);
    } else if (adjuster instanceof Instant) {
        return ofInstant((Instant) adjuster, offset);
    } else if (adjuster instanceof ZoneOffset) {
        return with(dateTime, (ZoneOffset) adjuster);
    } else if (adjuster instanceof OffsetDateTime) {
        return (OffsetDateTime) adjuster;
    }
    return (OffsetDateTime) adjuster.adjustInto(this);
}
 
源代码12 项目: dragonwell8_jdk   文件: LocalDateTime.java
/**
 * Returns an adjusted copy of this date-time.
 * <p>
 * This returns a {@code LocalDateTime}, based on this one, with the date-time adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the date to the last day of the month.
 * <p>
 * A selection of common adjustments is provided in
 * {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
 * These include finding the "last day of the month" and "next Wednesday".
 * Key date-time classes also implement the {@code TemporalAdjuster} interface,
 * such as {@link Month} and {@link java.time.MonthDay MonthDay}.
 * The adjuster is responsible for handling special cases, such as the varying
 * lengths of month and leap years.
 * <p>
 * For example this code returns a date on the last day of July:
 * <pre>
 *  import static java.time.Month.*;
 *  import static java.time.temporal.TemporalAdjusters.*;
 *
 *  result = localDateTime.with(JULY).with(lastDayOfMonth());
 * </pre>
 * <p>
 * The classes {@link LocalDate} and {@link LocalTime} implement {@code TemporalAdjuster},
 * thus this method can be used to change the date, time or offset:
 * <pre>
 *  result = localDateTime.with(date);
 *  result = localDateTime.with(time);
 * </pre>
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code LocalDateTime} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public LocalDateTime with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalDate) {
        return with((LocalDate) adjuster, time);
    } else if (adjuster instanceof LocalTime) {
        return with(date, (LocalTime) adjuster);
    } else if (adjuster instanceof LocalDateTime) {
        return (LocalDateTime) adjuster;
    }
    return (LocalDateTime) adjuster.adjustInto(this);
}
 
源代码13 项目: TencentKona-8   文件: LocalDateTime.java
/**
 * Returns an adjusted copy of this date-time.
 * <p>
 * This returns a {@code LocalDateTime}, based on this one, with the date-time adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the date to the last day of the month.
 * <p>
 * A selection of common adjustments is provided in
 * {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
 * These include finding the "last day of the month" and "next Wednesday".
 * Key date-time classes also implement the {@code TemporalAdjuster} interface,
 * such as {@link Month} and {@link java.time.MonthDay MonthDay}.
 * The adjuster is responsible for handling special cases, such as the varying
 * lengths of month and leap years.
 * <p>
 * For example this code returns a date on the last day of July:
 * <pre>
 *  import static java.time.Month.*;
 *  import static java.time.temporal.TemporalAdjusters.*;
 *
 *  result = localDateTime.with(JULY).with(lastDayOfMonth());
 * </pre>
 * <p>
 * The classes {@link LocalDate} and {@link LocalTime} implement {@code TemporalAdjuster},
 * thus this method can be used to change the date, time or offset:
 * <pre>
 *  result = localDateTime.with(date);
 *  result = localDateTime.with(time);
 * </pre>
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code LocalDateTime} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public LocalDateTime with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalDate) {
        return with((LocalDate) adjuster, time);
    } else if (adjuster instanceof LocalTime) {
        return with(date, (LocalTime) adjuster);
    } else if (adjuster instanceof LocalDateTime) {
        return (LocalDateTime) adjuster;
    }
    return (LocalDateTime) adjuster.adjustInto(this);
}
 
源代码14 项目: jdk1.8-source-analysis   文件: Instant.java
/**
 * Returns an adjusted copy of this instant.
 * <p>
 * This returns an {@code Instant}, based on this one, with the instant adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return an {@code Instant} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Instant with(TemporalAdjuster adjuster) {
    return (Instant) adjuster.adjustInto(this);
}
 
源代码15 项目: jdk1.8-source-analysis   文件: Year.java
/**
 * Returns an adjusted copy of this year.
 * <p>
 * This returns a {@code Year}, based on this one, with the year adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code Year} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Year with(TemporalAdjuster adjuster) {
    return (Year) adjuster.adjustInto(this);
}
 
源代码16 项目: dragonwell8_jdk   文件: YearMonth.java
/**
 * Returns an adjusted copy of this year-month.
 * <p>
 * This returns a {@code YearMonth}, based on this one, with the year-month adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the year-month to the next month that
 * Halley's comet will pass the Earth.
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code YearMonth} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public YearMonth with(TemporalAdjuster adjuster) {
    return (YearMonth) adjuster.adjustInto(this);
}
 
源代码17 项目: dragonwell8_jdk   文件: Instant.java
/**
 * Returns an adjusted copy of this instant.
 * <p>
 * This returns an {@code Instant}, based on this one, with the instant adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return an {@code Instant} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Instant with(TemporalAdjuster adjuster) {
    return (Instant) adjuster.adjustInto(this);
}
 
源代码18 项目: TencentKona-8   文件: Instant.java
/**
 * Returns an adjusted copy of this instant.
 * <p>
 * This returns an {@code Instant}, based on this one, with the instant adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return an {@code Instant} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Instant with(TemporalAdjuster adjuster) {
    return (Instant) adjuster.adjustInto(this);
}
 
源代码19 项目: TencentKona-8   文件: Year.java
/**
 * Returns an adjusted copy of this year.
 * <p>
 * This returns a {@code Year}, based on this one, with the year adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code Year} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Year with(TemporalAdjuster adjuster) {
    return (Year) adjuster.adjustInto(this);
}
 
源代码20 项目: TencentKona-8   文件: YearMonth.java
/**
 * Returns an adjusted copy of this year-month.
 * <p>
 * This returns a {@code YearMonth}, based on this one, with the year-month adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the year-month to the next month that
 * Halley's comet will pass the Earth.
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code YearMonth} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public YearMonth with(TemporalAdjuster adjuster) {
    return (YearMonth) adjuster.adjustInto(this);
}
 
 同类方法