mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8265746: Update java.time to use instanceof pattern variable (part II)
Reviewed-by: dfuchs, lancea, rriggs, chegar, naoto
This commit is contained in:
parent
a85f6cbbaa
commit
45c5da0fd3
20 changed files with 104 additions and 152 deletions
|
@ -703,10 +703,9 @@ public final class Instant
|
|||
*/
|
||||
@Override
|
||||
public Instant with(TemporalField field, long newValue) {
|
||||
if (field instanceof ChronoField) {
|
||||
ChronoField f = (ChronoField) field;
|
||||
f.checkValidValue(newValue);
|
||||
switch (f) {
|
||||
if (field instanceof ChronoField chronoField) {
|
||||
chronoField.checkValidValue(newValue);
|
||||
switch (chronoField) {
|
||||
case MILLI_OF_SECOND: {
|
||||
int nval = (int) newValue * 1000_000;
|
||||
return (nval != nanos ? create(seconds, nval) : this);
|
||||
|
@ -1143,9 +1142,8 @@ public final class Instant
|
|||
@Override
|
||||
public long until(Temporal endExclusive, TemporalUnit unit) {
|
||||
Instant end = Instant.from(endExclusive);
|
||||
if (unit instanceof ChronoUnit) {
|
||||
ChronoUnit f = (ChronoUnit) unit;
|
||||
switch (f) {
|
||||
if (unit instanceof ChronoUnit chronoUnit) {
|
||||
switch (chronoUnit) {
|
||||
case NANOS: return nanosUntil(end);
|
||||
case MICROS: return nanosUntil(end) / 1000;
|
||||
case MILLIS: return Math.subtractExact(end.toEpochMilli(), toEpochMilli());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue