mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
classlib: get rid of Math polyfill in java.time implementation
This commit is contained in:
parent
cd14ece14c
commit
6e46ae8eec
|
@ -51,7 +51,6 @@ import static org.threeten.bp.LocalTime.NANOS_PER_SECOND;
|
|||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
import java.util.TimeZone;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
|
||||
/**
|
||||
* A clock providing access to the current instant, date and time using a time-zone.
|
||||
|
@ -527,7 +526,7 @@ public abstract class Clock {
|
|||
}
|
||||
@Override
|
||||
public long millis() {
|
||||
return Jdk8Methods.safeAdd(baseClock.millis(), offset.toMillis());
|
||||
return Math.addExact(baseClock.millis(), offset.toMillis());
|
||||
}
|
||||
@Override
|
||||
public Instant instant() {
|
||||
|
@ -577,17 +576,17 @@ public abstract class Clock {
|
|||
@Override
|
||||
public long millis() {
|
||||
long millis = baseClock.millis();
|
||||
return millis - Jdk8Methods.floorMod(millis, tickNanos / 1000000L);
|
||||
return millis - Math.floorMod(millis, tickNanos / 1000000L);
|
||||
}
|
||||
@Override
|
||||
public Instant instant() {
|
||||
if ((tickNanos % 1000000) == 0) {
|
||||
long millis = baseClock.millis();
|
||||
return Instant.ofEpochMilli(millis - Jdk8Methods.floorMod(millis, tickNanos / 1000000L));
|
||||
return Instant.ofEpochMilli(millis - Math.floorMod(millis, tickNanos / 1000000L));
|
||||
}
|
||||
Instant instant = baseClock.instant();
|
||||
long nanos = instant.getNano();
|
||||
long adjust = Jdk8Methods.floorMod(nanos, tickNanos);
|
||||
long adjust = Math.floorMod(nanos, tickNanos);
|
||||
return instant.minusNanos(adjust);
|
||||
}
|
||||
@Override
|
||||
|
|
|
@ -62,7 +62,6 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.threeten.bp.format.DateTimeParseException;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
import org.threeten.bp.temporal.ChronoField;
|
||||
import org.threeten.bp.temporal.ChronoUnit;
|
||||
import org.threeten.bp.temporal.Temporal;
|
||||
|
@ -147,7 +146,7 @@ public final class Duration
|
|||
* @throws ArithmeticException if the input days exceeds the capacity of {@code Duration}
|
||||
*/
|
||||
public static Duration ofDays(long days) {
|
||||
return create(Jdk8Methods.safeMultiply(days, 86400), 0);
|
||||
return create(Math.multiplyExact(days, 86400), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -162,7 +161,7 @@ public final class Duration
|
|||
* @throws ArithmeticException if the input hours exceeds the capacity of {@code Duration}
|
||||
*/
|
||||
public static Duration ofHours(long hours) {
|
||||
return create(Jdk8Methods.safeMultiply(hours, 3600), 0);
|
||||
return create(Math.multiplyExact(hours, 3600), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -177,7 +176,7 @@ public final class Duration
|
|||
* @throws ArithmeticException if the input minutes exceeds the capacity of {@code Duration}
|
||||
*/
|
||||
public static Duration ofMinutes(long minutes) {
|
||||
return create(Jdk8Methods.safeMultiply(minutes, 60), 0);
|
||||
return create(Math.multiplyExact(minutes, 60), 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -213,8 +212,8 @@ public final class Duration
|
|||
* @throws ArithmeticException if the adjustment causes the seconds to exceed the capacity of {@code Duration}
|
||||
*/
|
||||
public static Duration ofSeconds(long seconds, long nanoAdjustment) {
|
||||
long secs = Jdk8Methods.safeAdd(seconds, Jdk8Methods.floorDiv(nanoAdjustment, NANOS_PER_SECOND));
|
||||
int nos = Jdk8Methods.floorMod(nanoAdjustment, NANOS_PER_SECOND);
|
||||
long secs = Math.addExact(seconds, Math.floorDiv(nanoAdjustment, NANOS_PER_SECOND));
|
||||
int nos = Math.floorMod(nanoAdjustment, NANOS_PER_SECOND);
|
||||
return create(secs, nos);
|
||||
}
|
||||
|
||||
|
@ -550,8 +549,8 @@ public final class Duration
|
|||
|
||||
private static Duration create(boolean negate, long daysAsSecs, long hoursAsSecs, long minsAsSecs,
|
||||
long secs, int nanos) {
|
||||
long seconds = Jdk8Methods.safeAdd(daysAsSecs, Jdk8Methods.safeAdd(hoursAsSecs,
|
||||
Jdk8Methods.safeAdd(minsAsSecs, secs)));
|
||||
long seconds = Math.addExact(daysAsSecs, Math.addExact(hoursAsSecs,
|
||||
Math.addExact(minsAsSecs, secs)));
|
||||
if (negate) {
|
||||
return ofSeconds(seconds, nanos).negated();
|
||||
}
|
||||
|
@ -730,7 +729,7 @@ public final class Duration
|
|||
public Duration plus(long amountToAdd, TemporalUnit unit) {
|
||||
Objects.requireNonNull(unit, "unit");
|
||||
if (unit == DAYS) {
|
||||
return plus(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_DAY), 0);
|
||||
return plus(Math.multiplyExact(amountToAdd, SECONDS_PER_DAY), 0);
|
||||
}
|
||||
if (unit.isDurationEstimated()) {
|
||||
throw new DateTimeException("Unit must not have an estimated duration");
|
||||
|
@ -750,7 +749,7 @@ public final class Duration
|
|||
case SECONDS:
|
||||
return plusSeconds(amountToAdd);
|
||||
}
|
||||
return plusSeconds(Jdk8Methods.safeMultiply(unit.getDuration().seconds, amountToAdd));
|
||||
return plusSeconds(Math.multiplyExact(unit.getDuration().seconds, amountToAdd));
|
||||
}
|
||||
Duration duration = unit.getDuration().multipliedBy(amountToAdd);
|
||||
return plusSeconds(duration.getSeconds()).plusNanos(duration.getNano());
|
||||
|
@ -767,7 +766,7 @@ public final class Duration
|
|||
* @throws ArithmeticException if numeric overflow occurs
|
||||
*/
|
||||
public Duration plusDays(long daysToAdd) {
|
||||
return plus(Jdk8Methods.safeMultiply(daysToAdd, SECONDS_PER_DAY), 0);
|
||||
return plus(Math.multiplyExact(daysToAdd, SECONDS_PER_DAY), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -780,7 +779,7 @@ public final class Duration
|
|||
* @throws ArithmeticException if numeric overflow occurs
|
||||
*/
|
||||
public Duration plusHours(long hoursToAdd) {
|
||||
return plus(Jdk8Methods.safeMultiply(hoursToAdd, SECONDS_PER_HOUR), 0);
|
||||
return plus(Math.multiplyExact(hoursToAdd, SECONDS_PER_HOUR), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -793,7 +792,7 @@ public final class Duration
|
|||
* @throws ArithmeticException if numeric overflow occurs
|
||||
*/
|
||||
public Duration plusMinutes(long minutesToAdd) {
|
||||
return plus(Jdk8Methods.safeMultiply(minutesToAdd, SECONDS_PER_MINUTE), 0);
|
||||
return plus(Math.multiplyExact(minutesToAdd, SECONDS_PER_MINUTE), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -849,8 +848,8 @@ public final class Duration
|
|||
if ((secondsToAdd | nanosToAdd) == 0) {
|
||||
return this;
|
||||
}
|
||||
long epochSec = Jdk8Methods.safeAdd(seconds, secondsToAdd);
|
||||
epochSec = Jdk8Methods.safeAdd(epochSec, nanosToAdd / NANOS_PER_SECOND);
|
||||
long epochSec = Math.addExact(seconds, secondsToAdd);
|
||||
epochSec = Math.addExact(epochSec, nanosToAdd / NANOS_PER_SECOND);
|
||||
nanosToAdd = nanosToAdd % NANOS_PER_SECOND;
|
||||
long nanoAdjustment = nanos + nanosToAdd; // safe int+NANOS_PER_SECOND
|
||||
return ofSeconds(epochSec, nanoAdjustment);
|
||||
|
@ -1211,8 +1210,8 @@ public final class Duration
|
|||
* @throws ArithmeticException if numeric overflow occurs
|
||||
*/
|
||||
public long toMillis() {
|
||||
long result = Jdk8Methods.safeMultiply(seconds, 1000);
|
||||
result = Jdk8Methods.safeAdd(result, nanos / NANOS_PER_MILLI);
|
||||
long result = Math.multiplyExact(seconds, 1000);
|
||||
result = Math.addExact(result, nanos / NANOS_PER_MILLI);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1226,8 +1225,8 @@ public final class Duration
|
|||
* @throws ArithmeticException if numeric overflow occurs
|
||||
*/
|
||||
public long toNanos() {
|
||||
long result = Jdk8Methods.safeMultiply(seconds, NANOS_PER_SECOND);
|
||||
result = Jdk8Methods.safeAdd(result, nanos);
|
||||
long result = Math.multiplyExact(seconds, NANOS_PER_SECOND);
|
||||
result = Math.addExact(result, nanos);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,6 @@ import org.threeten.bp.format.DateTimeFormatter;
|
|||
import org.threeten.bp.format.DateTimeFormatterBuilder;
|
||||
import org.threeten.bp.format.DateTimeParseException;
|
||||
import org.threeten.bp.format.DateTimePrintContext;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
import org.threeten.bp.temporal.ChronoField;
|
||||
import org.threeten.bp.temporal.ChronoUnit;
|
||||
import org.threeten.bp.temporal.Temporal;
|
||||
|
@ -302,8 +301,8 @@ public final class Instant
|
|||
* @throws ArithmeticException if numeric overflow occurs
|
||||
*/
|
||||
public static Instant ofEpochSecond(long epochSecond, long nanoAdjustment) {
|
||||
long secs = Jdk8Methods.safeAdd(epochSecond, Jdk8Methods.floorDiv(nanoAdjustment, NANOS_PER_SECOND));
|
||||
int nos = Jdk8Methods.floorMod(nanoAdjustment, NANOS_PER_SECOND);
|
||||
long secs = Math.addExact(epochSecond, Math.floorDiv(nanoAdjustment, NANOS_PER_SECOND));
|
||||
int nos = Math.floorMod(nanoAdjustment, NANOS_PER_SECOND);
|
||||
return create(secs, nos);
|
||||
}
|
||||
|
||||
|
@ -318,8 +317,8 @@ public final class Instant
|
|||
* @throws DateTimeException if the instant exceeds the maximum or minimum instant
|
||||
*/
|
||||
public static Instant ofEpochMilli(long epochMilli) {
|
||||
long secs = Jdk8Methods.floorDiv(epochMilli, 1000);
|
||||
int mos = Jdk8Methods.floorMod(epochMilli, 1000);
|
||||
long secs = Math.floorDiv(epochMilli, 1000);
|
||||
int mos = Math.floorMod(epochMilli, 1000);
|
||||
return create(secs, mos * NANOS_PER_MILLI);
|
||||
}
|
||||
|
||||
|
@ -694,7 +693,7 @@ public final class Instant
|
|||
throw new DateTimeException("Unit must divide into a standard day without remainder");
|
||||
}
|
||||
long nod = (seconds % LocalTime.SECONDS_PER_DAY) * LocalTime.NANOS_PER_SECOND + nanos;
|
||||
long result = Jdk8Methods.floorDiv(nod, dur) * dur;
|
||||
long result = Math.floorDiv(nod, dur) * dur;
|
||||
return plusNanos(result - nod);
|
||||
}
|
||||
|
||||
|
@ -722,10 +721,10 @@ public final class Instant
|
|||
case MICROS: return plus(amountToAdd / 1000000, (amountToAdd % 1000000) * 1000);
|
||||
case MILLIS: return plusMillis(amountToAdd);
|
||||
case SECONDS: return plusSeconds(amountToAdd);
|
||||
case MINUTES: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_MINUTE));
|
||||
case HOURS: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_HOUR));
|
||||
case HALF_DAYS: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_DAY / 2));
|
||||
case DAYS: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_DAY));
|
||||
case MINUTES: return plusSeconds(Math.multiplyExact(amountToAdd, SECONDS_PER_MINUTE));
|
||||
case HOURS: return plusSeconds(Math.multiplyExact(amountToAdd, SECONDS_PER_HOUR));
|
||||
case HALF_DAYS: return plusSeconds(Math.multiplyExact(amountToAdd, SECONDS_PER_DAY / 2));
|
||||
case DAYS: return plusSeconds(Math.multiplyExact(amountToAdd, SECONDS_PER_DAY));
|
||||
}
|
||||
throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
|
||||
}
|
||||
|
@ -790,8 +789,8 @@ public final class Instant
|
|||
if ((secondsToAdd | nanosToAdd) == 0) {
|
||||
return this;
|
||||
}
|
||||
long epochSec = Jdk8Methods.safeAdd(seconds, secondsToAdd);
|
||||
epochSec = Jdk8Methods.safeAdd(epochSec, nanosToAdd / NANOS_PER_SECOND);
|
||||
long epochSec = Math.addExact(seconds, secondsToAdd);
|
||||
epochSec = Math.addExact(epochSec, nanosToAdd / NANOS_PER_SECOND);
|
||||
nanosToAdd = nanosToAdd % NANOS_PER_SECOND;
|
||||
long nanoAdjustment = nanos + nanosToAdd; // safe int+NANOS_PER_SECOND
|
||||
return ofEpochSecond(epochSec, nanoAdjustment);
|
||||
|
@ -985,7 +984,7 @@ public final class Instant
|
|||
switch (f) {
|
||||
case NANOS: return nanosUntil(end);
|
||||
case MICROS: return nanosUntil(end) / 1000;
|
||||
case MILLIS: return Jdk8Methods.safeSubtract(end.toEpochMilli(), toEpochMilli());
|
||||
case MILLIS: return Math.subtractExact(end.toEpochMilli(), toEpochMilli());
|
||||
case SECONDS: return secondsUntil(end);
|
||||
case MINUTES: return secondsUntil(end) / SECONDS_PER_MINUTE;
|
||||
case HOURS: return secondsUntil(end) / SECONDS_PER_HOUR;
|
||||
|
@ -998,13 +997,13 @@ public final class Instant
|
|||
}
|
||||
|
||||
private long nanosUntil(Instant end) {
|
||||
long secsDiff = Jdk8Methods.safeSubtract(end.seconds, seconds);
|
||||
long totalNanos = Jdk8Methods.safeMultiply(secsDiff, NANOS_PER_SECOND);
|
||||
return Jdk8Methods.safeAdd(totalNanos, end.nanos - nanos);
|
||||
long secsDiff = Math.subtractExact(end.seconds, seconds);
|
||||
long totalNanos = Math.multiplyExact(secsDiff, NANOS_PER_SECOND);
|
||||
return Math.addExact(totalNanos, end.nanos - nanos);
|
||||
}
|
||||
|
||||
private long secondsUntil(Instant end) {
|
||||
long secsDiff = Jdk8Methods.safeSubtract(end.seconds, seconds);
|
||||
long secsDiff = Math.subtractExact(end.seconds, seconds);
|
||||
long nanosDiff = end.nanos - nanos;
|
||||
if (secsDiff > 0 && nanosDiff < 0) {
|
||||
secsDiff--;
|
||||
|
@ -1067,8 +1066,8 @@ public final class Instant
|
|||
*/
|
||||
public long toEpochMilli() {
|
||||
if (seconds >= 0) {
|
||||
long millis = Jdk8Methods.safeMultiply(seconds, MILLIS_PER_SEC);
|
||||
return Jdk8Methods.safeAdd(millis, nanos / NANOS_PER_MILLI);
|
||||
long millis = Math.multiplyExact(seconds, MILLIS_PER_SEC);
|
||||
return Math.addExact(millis, nanos / NANOS_PER_MILLI);
|
||||
} else {
|
||||
// prevent an overflow in seconds * 1000
|
||||
// instead of going form the second farther away from 0
|
||||
|
@ -1076,8 +1075,8 @@ public final class Instant
|
|||
// we go from the second closer to 0 away from 0
|
||||
// that way we always stay in the valid long range
|
||||
// seconds + 1 can not overflow because it is negative
|
||||
long millis = Jdk8Methods.safeMultiply(seconds + 1, MILLIS_PER_SEC);
|
||||
return Jdk8Methods.safeSubtract(millis, MILLIS_PER_SEC - nanos / NANOS_PER_MILLI);
|
||||
long millis = Math.multiplyExact(seconds + 1, MILLIS_PER_SEC);
|
||||
return Math.subtractExact(millis, MILLIS_PER_SEC - nanos / NANOS_PER_MILLI);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,6 @@ import org.threeten.bp.chrono.Era;
|
|||
import org.threeten.bp.chrono.IsoChronology;
|
||||
import org.threeten.bp.format.DateTimeFormatter;
|
||||
import org.threeten.bp.format.DateTimeParseException;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
import org.threeten.bp.temporal.ChronoField;
|
||||
import org.threeten.bp.temporal.ChronoUnit;
|
||||
import org.threeten.bp.temporal.Temporal;
|
||||
|
@ -192,7 +191,7 @@ public final class LocalDate
|
|||
final Instant now = clock.instant(); // called once
|
||||
ZoneOffset offset = clock.getZone().getRules().getOffset(now);
|
||||
long epochSec = now.getEpochSecond() + offset.getTotalSeconds(); // overflow caught later
|
||||
long epochDay = Jdk8Methods.floorDiv(epochSec, SECONDS_PER_DAY);
|
||||
long epochDay = Math.floorDiv(epochSec, SECONDS_PER_DAY);
|
||||
return LocalDate.ofEpochDay(epochDay);
|
||||
}
|
||||
|
||||
|
@ -717,7 +716,7 @@ public final class LocalDate
|
|||
* @return the day-of-week, not null
|
||||
*/
|
||||
public DayOfWeek getDayOfWeek() {
|
||||
int dow0 = Jdk8Methods.floorMod(toEpochDay() + 3, 7);
|
||||
int dow0 = Math.floorMod(toEpochDay() + 3, 7);
|
||||
return DayOfWeek.of(dow0 + 1);
|
||||
}
|
||||
|
||||
|
@ -1072,10 +1071,10 @@ public final class LocalDate
|
|||
case WEEKS: return plusWeeks(amountToAdd);
|
||||
case MONTHS: return plusMonths(amountToAdd);
|
||||
case YEARS: return plusYears(amountToAdd);
|
||||
case DECADES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 10));
|
||||
case CENTURIES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 100));
|
||||
case MILLENNIA: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 1000));
|
||||
case ERAS: return with(ERA, Jdk8Methods.safeAdd(getLong(ERA), amountToAdd));
|
||||
case DECADES: return plusYears(Math.multiplyExact(amountToAdd, 10));
|
||||
case CENTURIES: return plusYears(Math.multiplyExact(amountToAdd, 100));
|
||||
case MILLENNIA: return plusYears(Math.multiplyExact(amountToAdd, 1000));
|
||||
case ERAS: return with(ERA, Math.addExact(getLong(ERA), amountToAdd));
|
||||
}
|
||||
throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
|
||||
}
|
||||
|
@ -1137,8 +1136,8 @@ public final class LocalDate
|
|||
}
|
||||
long monthCount = year * 12L + (month - 1);
|
||||
long calcMonths = monthCount + monthsToAdd; // safe overflow
|
||||
int newYear = YEAR.checkValidIntValue(Jdk8Methods.floorDiv(calcMonths, 12));
|
||||
int newMonth = Jdk8Methods.floorMod(calcMonths, 12) + 1;
|
||||
int newYear = YEAR.checkValidIntValue(Math.floorDiv(calcMonths, 12));
|
||||
int newMonth = Math.floorMod(calcMonths, 12) + 1;
|
||||
return resolvePreviousValid(newYear, newMonth, day);
|
||||
}
|
||||
|
||||
|
@ -1158,7 +1157,7 @@ public final class LocalDate
|
|||
* @throws DateTimeException if the result exceeds the supported date range
|
||||
*/
|
||||
public LocalDate plusWeeks(long weeksToAdd) {
|
||||
return plusDays(Jdk8Methods.safeMultiply(weeksToAdd, 7));
|
||||
return plusDays(Math.multiplyExact(weeksToAdd, 7));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1180,7 +1179,7 @@ public final class LocalDate
|
|||
if (daysToAdd == 0) {
|
||||
return this;
|
||||
}
|
||||
long mjDay = Jdk8Methods.safeAdd(toEpochDay(), daysToAdd);
|
||||
long mjDay = Math.addExact(toEpochDay(), daysToAdd);
|
||||
return LocalDate.ofEpochDay(mjDay);
|
||||
}
|
||||
|
||||
|
@ -1501,7 +1500,7 @@ public final class LocalDate
|
|||
}
|
||||
long years = totalMonths / 12; // safe
|
||||
int months = (int) (totalMonths % 12); // safe
|
||||
return Period.of(Jdk8Methods.safeToInt(years), months, days);
|
||||
return Period.of(Math.toIntExact(years), months, days);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
|
@ -60,7 +60,6 @@ import java.util.Objects;
|
|||
import org.threeten.bp.chrono.ChronoLocalDateTime;
|
||||
import org.threeten.bp.format.DateTimeFormatter;
|
||||
import org.threeten.bp.format.DateTimeParseException;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
import org.threeten.bp.temporal.ChronoField;
|
||||
import org.threeten.bp.temporal.ChronoUnit;
|
||||
import org.threeten.bp.temporal.Temporal;
|
||||
|
@ -372,8 +371,8 @@ public final class LocalDateTime
|
|||
public static LocalDateTime ofEpochSecond(long epochSecond, int nanoOfSecond, ZoneOffset offset) {
|
||||
Objects.requireNonNull(offset, "offset");
|
||||
long localSecond = epochSecond + offset.getTotalSeconds(); // overflow caught later
|
||||
long localEpochDay = Jdk8Methods.floorDiv(localSecond, SECONDS_PER_DAY);
|
||||
int secsOfDay = Jdk8Methods.floorMod(localSecond, SECONDS_PER_DAY);
|
||||
long localEpochDay = Math.floorDiv(localSecond, SECONDS_PER_DAY);
|
||||
int secsOfDay = Math.floorMod(localSecond, SECONDS_PER_DAY);
|
||||
LocalDate date = LocalDate.ofEpochDay(localEpochDay);
|
||||
LocalTime time = LocalTime.ofSecondOfDay(secsOfDay, nanoOfSecond);
|
||||
return new LocalDateTime(date, time);
|
||||
|
@ -1421,8 +1420,8 @@ public final class LocalDateTime
|
|||
+ (hours % HOURS_PER_DAY) * NANOS_PER_HOUR; // max 86400000000000
|
||||
long curNoD = time.toNanoOfDay(); // max 86400000000000
|
||||
totNanos = totNanos * sign + curNoD; // total 432000000000000
|
||||
totDays += Jdk8Methods.floorDiv(totNanos, NANOS_PER_DAY);
|
||||
long newNoD = Jdk8Methods.floorMod(totNanos, NANOS_PER_DAY);
|
||||
totDays += Math.floorDiv(totNanos, NANOS_PER_DAY);
|
||||
long newNoD = Math.floorMod(totNanos, NANOS_PER_DAY);
|
||||
LocalTime newTime = newNoD == curNoD ? time : LocalTime.ofNanoOfDay(newNoD);
|
||||
return with(newDate.plusDays(totDays), newTime);
|
||||
}
|
||||
|
@ -1548,26 +1547,26 @@ public final class LocalDateTime
|
|||
long amount = daysUntil;
|
||||
switch (f) {
|
||||
case NANOS:
|
||||
amount = Jdk8Methods.safeMultiply(amount, NANOS_PER_DAY);
|
||||
return Jdk8Methods.safeAdd(amount, timeUntil);
|
||||
amount = Math.multiplyExact(amount, NANOS_PER_DAY);
|
||||
return Math.addExact(amount, timeUntil);
|
||||
case MICROS:
|
||||
amount = Jdk8Methods.safeMultiply(amount, MICROS_PER_DAY);
|
||||
return Jdk8Methods.safeAdd(amount, timeUntil / 1000);
|
||||
amount = Math.multiplyExact(amount, MICROS_PER_DAY);
|
||||
return Math.addExact(amount, timeUntil / 1000);
|
||||
case MILLIS:
|
||||
amount = Jdk8Methods.safeMultiply(amount, MILLIS_PER_DAY);
|
||||
return Jdk8Methods.safeAdd(amount, timeUntil / 1000000);
|
||||
amount = Math.multiplyExact(amount, MILLIS_PER_DAY);
|
||||
return Math.addExact(amount, timeUntil / 1000000);
|
||||
case SECONDS:
|
||||
amount = Jdk8Methods.safeMultiply(amount, SECONDS_PER_DAY);
|
||||
return Jdk8Methods.safeAdd(amount, timeUntil / NANOS_PER_SECOND);
|
||||
amount = Math.multiplyExact(amount, SECONDS_PER_DAY);
|
||||
return Math.addExact(amount, timeUntil / NANOS_PER_SECOND);
|
||||
case MINUTES:
|
||||
amount = Jdk8Methods.safeMultiply(amount, MINUTES_PER_DAY);
|
||||
return Jdk8Methods.safeAdd(amount, timeUntil / NANOS_PER_MINUTE);
|
||||
amount = Math.multiplyExact(amount, MINUTES_PER_DAY);
|
||||
return Math.addExact(amount, timeUntil / NANOS_PER_MINUTE);
|
||||
case HOURS:
|
||||
amount = Jdk8Methods.safeMultiply(amount, HOURS_PER_DAY);
|
||||
return Jdk8Methods.safeAdd(amount, timeUntil / NANOS_PER_HOUR);
|
||||
amount = Math.multiplyExact(amount, HOURS_PER_DAY);
|
||||
return Math.addExact(amount, timeUntil / NANOS_PER_HOUR);
|
||||
case HALF_DAYS:
|
||||
amount = Jdk8Methods.safeMultiply(amount, 2);
|
||||
return Jdk8Methods.safeAdd(amount, timeUntil / (NANOS_PER_HOUR * 12));
|
||||
amount = Math.multiplyExact(amount, 2);
|
||||
return Math.addExact(amount, timeUntil / (NANOS_PER_HOUR * 12));
|
||||
}
|
||||
throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
|
||||
}
|
||||
|
|
|
@ -59,7 +59,6 @@ import org.threeten.bp.chrono.ChronoPeriod;
|
|||
import org.threeten.bp.chrono.Chronology;
|
||||
import org.threeten.bp.chrono.IsoChronology;
|
||||
import org.threeten.bp.format.DateTimeParseException;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
import org.threeten.bp.temporal.ChronoUnit;
|
||||
import org.threeten.bp.temporal.Temporal;
|
||||
import org.threeten.bp.temporal.TemporalAmount;
|
||||
|
@ -159,7 +158,7 @@ public final class Period
|
|||
* @return the period of days, not null
|
||||
*/
|
||||
public static Period ofWeeks(int weeks) {
|
||||
return create(0, 0, Jdk8Methods.safeMultiply(weeks, 7));
|
||||
return create(0, 0, Math.multiplyExact(weeks, 7));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -226,11 +225,11 @@ public final class Period
|
|||
for (TemporalUnit unit : amount.getUnits()) {
|
||||
long unitAmount = amount.get(unit);
|
||||
if (unit == ChronoUnit.YEARS) {
|
||||
years = Jdk8Methods.safeToInt(unitAmount);
|
||||
years = Math.toIntExact(unitAmount);
|
||||
} else if (unit == ChronoUnit.MONTHS) {
|
||||
months = Jdk8Methods.safeToInt(unitAmount);
|
||||
months = Math.toIntExact(unitAmount);
|
||||
} else if (unit == ChronoUnit.DAYS) {
|
||||
days = Jdk8Methods.safeToInt(unitAmount);
|
||||
days = Math.toIntExact(unitAmount);
|
||||
} else {
|
||||
throw new DateTimeException("Unit must be Years, Months or Days, but was " + unit);
|
||||
}
|
||||
|
@ -314,7 +313,7 @@ public final class Period
|
|||
parser.weeks = -parser.weeks;
|
||||
parser.days = -parser.days;
|
||||
}
|
||||
int days = Jdk8Methods.safeAdd(parser.days, Jdk8Methods.safeMultiply(parser.weeks, 7));
|
||||
int days = Math.addExact(parser.days, Math.multiplyExact(parser.weeks, 7));
|
||||
return create(parser.years, parser.months, days);
|
||||
}
|
||||
|
||||
|
@ -642,9 +641,9 @@ public final class Period
|
|||
public Period plus(TemporalAmount amountToAdd) {
|
||||
Period amount = Period.from(amountToAdd);
|
||||
return create(
|
||||
Jdk8Methods.safeAdd(years, amount.years),
|
||||
Jdk8Methods.safeAdd(months, amount.months),
|
||||
Jdk8Methods.safeAdd(days, amount.days));
|
||||
Math.addExact(years, amount.years),
|
||||
Math.addExact(months, amount.months),
|
||||
Math.addExact(days, amount.days));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -664,7 +663,7 @@ public final class Period
|
|||
if (yearsToAdd == 0) {
|
||||
return this;
|
||||
}
|
||||
return create(Jdk8Methods.safeToInt(Jdk8Methods.safeAdd(years, yearsToAdd)), months, days);
|
||||
return create(Math.toIntExact(Math.addExact(years, yearsToAdd)), months, days);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -684,7 +683,7 @@ public final class Period
|
|||
if (monthsToAdd == 0) {
|
||||
return this;
|
||||
}
|
||||
return create(years, Jdk8Methods.safeToInt(Jdk8Methods.safeAdd(months, monthsToAdd)), days);
|
||||
return create(years, Math.toIntExact(Math.addExact(months, monthsToAdd)), days);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -704,7 +703,7 @@ public final class Period
|
|||
if (daysToAdd == 0) {
|
||||
return this;
|
||||
}
|
||||
return create(years, months, Jdk8Methods.safeToInt(Jdk8Methods.safeAdd(days, daysToAdd)));
|
||||
return create(years, months, Math.toIntExact(Math.addExact(days, daysToAdd)));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -727,9 +726,9 @@ public final class Period
|
|||
public Period minus(TemporalAmount amountToSubtract) {
|
||||
Period amount = Period.from(amountToSubtract);
|
||||
return create(
|
||||
Jdk8Methods.safeSubtract(years, amount.years),
|
||||
Jdk8Methods.safeSubtract(months, amount.months),
|
||||
Jdk8Methods.safeSubtract(days, amount.days));
|
||||
Math.subtractExact(years, amount.years),
|
||||
Math.subtractExact(months, amount.months),
|
||||
Math.subtractExact(days, amount.days));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -807,9 +806,9 @@ public final class Period
|
|||
return this;
|
||||
}
|
||||
return create(
|
||||
Jdk8Methods.safeMultiply(years, scalar),
|
||||
Jdk8Methods.safeMultiply(months, scalar),
|
||||
Jdk8Methods.safeMultiply(days, scalar));
|
||||
Math.multiplyExact(years, scalar),
|
||||
Math.multiplyExact(months, scalar),
|
||||
Math.multiplyExact(days, scalar));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -852,7 +851,7 @@ public final class Period
|
|||
if (splitYears == years && splitMonths == months) {
|
||||
return this;
|
||||
}
|
||||
return create(Jdk8Methods.safeToInt(splitYears), splitMonths, days);
|
||||
return create(Math.toIntExact(splitYears), splitMonths, days);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -62,7 +62,6 @@ import org.threeten.bp.format.DateTimeFormatter;
|
|||
import org.threeten.bp.format.DateTimeFormatterBuilder;
|
||||
import org.threeten.bp.format.DateTimeParseException;
|
||||
import org.threeten.bp.format.SignStyle;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
import org.threeten.bp.temporal.ChronoField;
|
||||
import org.threeten.bp.temporal.ChronoUnit;
|
||||
import org.threeten.bp.temporal.Temporal;
|
||||
|
@ -591,10 +590,10 @@ public final class Year
|
|||
if (unit instanceof ChronoUnit) {
|
||||
switch ((ChronoUnit) unit) {
|
||||
case YEARS: return plusYears(amountToAdd);
|
||||
case DECADES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 10));
|
||||
case CENTURIES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 100));
|
||||
case MILLENNIA: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 1000));
|
||||
case ERAS: return with(ERA, Jdk8Methods.safeAdd(getLong(ERA), amountToAdd));
|
||||
case DECADES: return plusYears(Math.multiplyExact(amountToAdd, 10));
|
||||
case CENTURIES: return plusYears(Math.multiplyExact(amountToAdd, 100));
|
||||
case MILLENNIA: return plusYears(Math.multiplyExact(amountToAdd, 1000));
|
||||
case ERAS: return with(ERA, Math.addExact(getLong(ERA), amountToAdd));
|
||||
}
|
||||
throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
|
||||
}
|
||||
|
|
|
@ -65,7 +65,6 @@ import org.threeten.bp.format.DateTimeFormatter;
|
|||
import org.threeten.bp.format.DateTimeFormatterBuilder;
|
||||
import org.threeten.bp.format.DateTimeParseException;
|
||||
import org.threeten.bp.format.SignStyle;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
import org.threeten.bp.temporal.ChronoField;
|
||||
import org.threeten.bp.temporal.ChronoUnit;
|
||||
import org.threeten.bp.temporal.Temporal;
|
||||
|
@ -686,10 +685,10 @@ public final class YearMonth
|
|||
switch ((ChronoUnit) unit) {
|
||||
case MONTHS: return plusMonths(amountToAdd);
|
||||
case YEARS: return plusYears(amountToAdd);
|
||||
case DECADES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 10));
|
||||
case CENTURIES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 100));
|
||||
case MILLENNIA: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 1000));
|
||||
case ERAS: return with(ERA, Jdk8Methods.safeAdd(getLong(ERA), amountToAdd));
|
||||
case DECADES: return plusYears(Math.multiplyExact(amountToAdd, 10));
|
||||
case CENTURIES: return plusYears(Math.multiplyExact(amountToAdd, 100));
|
||||
case MILLENNIA: return plusYears(Math.multiplyExact(amountToAdd, 1000));
|
||||
case ERAS: return with(ERA, Math.addExact(getLong(ERA), amountToAdd));
|
||||
}
|
||||
throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
|
||||
}
|
||||
|
@ -728,8 +727,8 @@ public final class YearMonth
|
|||
}
|
||||
long monthCount = year * 12L + (month - 1);
|
||||
long calcMonths = monthCount + monthsToAdd; // safe overflow
|
||||
int newYear = YEAR.checkValidIntValue(Jdk8Methods.floorDiv(calcMonths, 12));
|
||||
int newMonth = Jdk8Methods.floorMod(calcMonths, 12) + 1;
|
||||
int newYear = YEAR.checkValidIntValue(Math.floorDiv(calcMonths, 12));
|
||||
int newMonth = Math.floorMod(calcMonths, 12) + 1;
|
||||
return with(newYear, newMonth);
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,6 @@ import java.io.Serializable;
|
|||
import org.threeten.bp.DateTimeException;
|
||||
import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.LocalTime;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
import org.threeten.bp.temporal.ChronoUnit;
|
||||
import org.threeten.bp.temporal.Temporal;
|
||||
import org.threeten.bp.temporal.TemporalAdjuster;
|
||||
|
@ -140,12 +139,12 @@ abstract class ChronoDateImpl<D extends ChronoLocalDate>
|
|||
ChronoUnit f = (ChronoUnit) unit;
|
||||
switch (f) {
|
||||
case DAYS: return plusDays(amountToAdd);
|
||||
case WEEKS: return plusDays(Jdk8Methods.safeMultiply(amountToAdd, 7));
|
||||
case WEEKS: return plusDays(Math.multiplyExact(amountToAdd, 7));
|
||||
case MONTHS: return plusMonths(amountToAdd);
|
||||
case YEARS: return plusYears(amountToAdd);
|
||||
case DECADES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 10));
|
||||
case CENTURIES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 100));
|
||||
case MILLENNIA: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 1000));
|
||||
case DECADES: return plusYears(Math.multiplyExact(amountToAdd, 10));
|
||||
case CENTURIES: return plusYears(Math.multiplyExact(amountToAdd, 100));
|
||||
case MILLENNIA: return plusYears(Math.multiplyExact(amountToAdd, 1000));
|
||||
// case ERAS: throw new DateTimeException("Unable to add era,
|
||||
// standard calendar system only has one era");
|
||||
// case FOREVER: return (period == 0 ? this : (period > 0 ? LocalDate.MAX_DATE : LocalDate.MIN_DATE));
|
||||
|
@ -204,7 +203,7 @@ abstract class ChronoDateImpl<D extends ChronoLocalDate>
|
|||
* @throws DateTimeException if the result exceeds the supported date range
|
||||
*/
|
||||
ChronoDateImpl<D> plusWeeks(long weeksToAdd) {
|
||||
return plusDays(Jdk8Methods.safeMultiply(weeksToAdd, 7));
|
||||
return plusDays(Math.multiplyExact(weeksToAdd, 7));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,7 +51,6 @@ import java.io.Serializable;
|
|||
import java.util.Objects;
|
||||
import org.threeten.bp.LocalTime;
|
||||
import org.threeten.bp.ZoneId;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
import org.threeten.bp.temporal.ChronoField;
|
||||
import org.threeten.bp.temporal.ChronoUnit;
|
||||
import org.threeten.bp.temporal.Temporal;
|
||||
|
@ -317,8 +316,8 @@ final class ChronoLocalDateTimeImpl<D extends ChronoLocalDate>
|
|||
+ (hours % HOURS_PER_DAY) * NANOS_PER_HOUR; // max 86400000000000
|
||||
long curNoD = time.toNanoOfDay(); // max 86400000000000
|
||||
totNanos = totNanos + curNoD; // total 432000000000000
|
||||
totDays += Jdk8Methods.floorDiv(totNanos, NANOS_PER_DAY);
|
||||
long newNoD = Jdk8Methods.floorMod(totNanos, NANOS_PER_DAY);
|
||||
totDays += Math.floorDiv(totNanos, NANOS_PER_DAY);
|
||||
long newNoD = Math.floorMod(totNanos, NANOS_PER_DAY);
|
||||
LocalTime newTime = newNoD == curNoD ? time : LocalTime.ofNanoOfDay(newNoD);
|
||||
return with(newDate.plus(totDays, ChronoUnit.DAYS), newTime);
|
||||
}
|
||||
|
@ -339,15 +338,15 @@ final class ChronoLocalDateTimeImpl<D extends ChronoLocalDate>
|
|||
if (f.isTimeBased()) {
|
||||
long amount = end.getLong(EPOCH_DAY) - date.getLong(EPOCH_DAY);
|
||||
switch (f) {
|
||||
case NANOS: amount = Jdk8Methods.safeMultiply(amount, NANOS_PER_DAY); break;
|
||||
case MICROS: amount = Jdk8Methods.safeMultiply(amount, MICROS_PER_DAY); break;
|
||||
case MILLIS: amount = Jdk8Methods.safeMultiply(amount, MILLIS_PER_DAY); break;
|
||||
case SECONDS: amount = Jdk8Methods.safeMultiply(amount, SECONDS_PER_DAY); break;
|
||||
case MINUTES: amount = Jdk8Methods.safeMultiply(amount, MINUTES_PER_DAY); break;
|
||||
case HOURS: amount = Jdk8Methods.safeMultiply(amount, HOURS_PER_DAY); break;
|
||||
case HALF_DAYS: amount = Jdk8Methods.safeMultiply(amount, 2); break;
|
||||
case NANOS: amount = Math.multiplyExact(amount, NANOS_PER_DAY); break;
|
||||
case MICROS: amount = Math.multiplyExact(amount, MICROS_PER_DAY); break;
|
||||
case MILLIS: amount = Math.multiplyExact(amount, MILLIS_PER_DAY); break;
|
||||
case SECONDS: amount = Math.multiplyExact(amount, SECONDS_PER_DAY); break;
|
||||
case MINUTES: amount = Math.multiplyExact(amount, MINUTES_PER_DAY); break;
|
||||
case HOURS: amount = Math.multiplyExact(amount, HOURS_PER_DAY); break;
|
||||
case HALF_DAYS: amount = Math.multiplyExact(amount, 2); break;
|
||||
}
|
||||
return Jdk8Methods.safeAdd(amount, time.until(end.toLocalTime(), unit));
|
||||
return Math.addExact(amount, time.until(end.toLocalTime(), unit));
|
||||
}
|
||||
ChronoLocalDate endDate = end.toLocalDate();
|
||||
if (end.toLocalTime().isBefore(time)) {
|
||||
|
|
|
@ -55,7 +55,6 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.threeten.bp.DateTimeException;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
import org.threeten.bp.temporal.ChronoField;
|
||||
import org.threeten.bp.temporal.Temporal;
|
||||
import org.threeten.bp.temporal.TemporalAmount;
|
||||
|
@ -115,9 +114,9 @@ final class ChronoPeriodImpl
|
|||
if (amount.getChronology().equals(getChronology())) {
|
||||
return new ChronoPeriodImpl(
|
||||
chronology,
|
||||
Jdk8Methods.safeAdd(years, amount.years),
|
||||
Jdk8Methods.safeAdd(months, amount.months),
|
||||
Jdk8Methods.safeAdd(days, amount.days));
|
||||
Math.addExact(years, amount.years),
|
||||
Math.addExact(months, amount.months),
|
||||
Math.addExact(days, amount.days));
|
||||
}
|
||||
}
|
||||
throw new DateTimeException("Unable to add amount: " + amountToAdd);
|
||||
|
@ -130,9 +129,9 @@ final class ChronoPeriodImpl
|
|||
if (amount.getChronology().equals(getChronology())) {
|
||||
return new ChronoPeriodImpl(
|
||||
chronology,
|
||||
Jdk8Methods.safeSubtract(years, amount.years),
|
||||
Jdk8Methods.safeSubtract(months, amount.months),
|
||||
Jdk8Methods.safeSubtract(days, amount.days));
|
||||
Math.subtractExact(years, amount.years),
|
||||
Math.subtractExact(months, amount.months),
|
||||
Math.subtractExact(days, amount.days));
|
||||
}
|
||||
}
|
||||
throw new DateTimeException("Unable to subtract amount: " + amountToSubtract);
|
||||
|
@ -142,9 +141,9 @@ final class ChronoPeriodImpl
|
|||
public ChronoPeriod multipliedBy(int scalar) {
|
||||
return new ChronoPeriodImpl(
|
||||
chronology,
|
||||
Jdk8Methods.safeMultiply(years, scalar),
|
||||
Jdk8Methods.safeMultiply(months, scalar),
|
||||
Jdk8Methods.safeMultiply(days, scalar));
|
||||
Math.multiplyExact(years, scalar),
|
||||
Math.multiplyExact(months, scalar),
|
||||
Math.multiplyExact(days, scalar));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -153,8 +152,8 @@ final class ChronoPeriodImpl
|
|||
long monthLength = chronology.range(ChronoField.MONTH_OF_YEAR).getMaximum()
|
||||
- chronology.range(ChronoField.MONTH_OF_YEAR).getMinimum() + 1;
|
||||
long total = years * monthLength + months;
|
||||
int years = Jdk8Methods.safeToInt(total / monthLength);
|
||||
int months = Jdk8Methods.safeToInt(total % monthLength);
|
||||
int years = Math.toIntExact(total / monthLength);
|
||||
int months = Math.toIntExact(total % monthLength);
|
||||
return new ChronoPeriodImpl(chronology, years, months, days);
|
||||
}
|
||||
return this;
|
||||
|
|
|
@ -78,7 +78,6 @@ import org.threeten.bp.Instant;
|
|||
import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.ZoneId;
|
||||
import org.threeten.bp.format.ResolverStyle;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
import org.threeten.bp.temporal.ChronoField;
|
||||
import org.threeten.bp.temporal.TemporalAccessor;
|
||||
import org.threeten.bp.temporal.TemporalField;
|
||||
|
@ -385,8 +384,8 @@ public final class HijrahChronology extends Chronology implements Serializable {
|
|||
if (resolverStyle != ResolverStyle.LENIENT) {
|
||||
PROLEPTIC_MONTH.checkValidValue(prolepticMonth);
|
||||
}
|
||||
updateResolveMap(fieldValues, MONTH_OF_YEAR, Jdk8Methods.floorMod(prolepticMonth, 12) + 1);
|
||||
updateResolveMap(fieldValues, YEAR, Jdk8Methods.floorDiv(prolepticMonth, 12));
|
||||
updateResolveMap(fieldValues, MONTH_OF_YEAR, Math.floorMod(prolepticMonth, 12) + 1);
|
||||
updateResolveMap(fieldValues, YEAR, Math.floorDiv(prolepticMonth, 12));
|
||||
}
|
||||
|
||||
// eras
|
||||
|
@ -401,7 +400,7 @@ public final class HijrahChronology extends Chronology implements Serializable {
|
|||
if (resolverStyle == ResolverStyle.STRICT) {
|
||||
// do not invent era if strict, but do cross-check with year
|
||||
if (year != null) {
|
||||
updateResolveMap(fieldValues, YEAR, year > 0 ? yoeLong : Jdk8Methods.safeSubtract(1, yoeLong));
|
||||
updateResolveMap(fieldValues, YEAR, year > 0 ? yoeLong : Math.subtractExact(1, yoeLong));
|
||||
} else {
|
||||
// reinstate the field removed earlier, no cross-check issues
|
||||
fieldValues.put(YEAR_OF_ERA, yoeLong);
|
||||
|
@ -409,12 +408,12 @@ public final class HijrahChronology extends Chronology implements Serializable {
|
|||
} else {
|
||||
// invent era
|
||||
updateResolveMap(fieldValues, YEAR,
|
||||
year == null || year > 0 ? yoeLong : Jdk8Methods.safeSubtract(1, yoeLong));
|
||||
year == null || year > 0 ? yoeLong : Math.subtractExact(1, yoeLong));
|
||||
}
|
||||
} else if (era == 1L) {
|
||||
updateResolveMap(fieldValues, YEAR, yoeLong);
|
||||
} else if (era == 0L) {
|
||||
updateResolveMap(fieldValues, YEAR, Jdk8Methods.safeSubtract(1, yoeLong));
|
||||
updateResolveMap(fieldValues, YEAR, Math.subtractExact(1, yoeLong));
|
||||
} else {
|
||||
throw new DateTimeException("Invalid value for era: " + era);
|
||||
}
|
||||
|
@ -428,8 +427,8 @@ public final class HijrahChronology extends Chronology implements Serializable {
|
|||
if (fieldValues.containsKey(DAY_OF_MONTH)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long months = Jdk8Methods.safeSubtract(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_MONTH), 1);
|
||||
long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
|
||||
return date(y, 1, 1).plusMonths(months).plusDays(days);
|
||||
} else {
|
||||
int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR),
|
||||
|
@ -446,9 +445,9 @@ public final class HijrahChronology extends Chronology implements Serializable {
|
|||
if (fieldValues.containsKey(ALIGNED_DAY_OF_WEEK_IN_MONTH)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long months = Jdk8Methods.safeSubtract(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH), 1);
|
||||
long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH), 1);
|
||||
return date(y, 1, 1).plus(months, MONTHS).plus(weeks, WEEKS).plus(days, DAYS);
|
||||
}
|
||||
int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR));
|
||||
|
@ -464,9 +463,9 @@ public final class HijrahChronology extends Chronology implements Serializable {
|
|||
if (fieldValues.containsKey(DAY_OF_WEEK)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long months = Jdk8Methods.safeSubtract(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_WEEK), 1);
|
||||
long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(DAY_OF_WEEK), 1);
|
||||
return date(y, 1, 1).plus(months, MONTHS).plus(weeks, WEEKS).plus(days, DAYS);
|
||||
}
|
||||
int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR));
|
||||
|
@ -483,7 +482,7 @@ public final class HijrahChronology extends Chronology implements Serializable {
|
|||
if (fieldValues.containsKey(DAY_OF_YEAR)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_YEAR), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(DAY_OF_YEAR), 1);
|
||||
return dateYearDay(y, 1).plusDays(days);
|
||||
}
|
||||
int doy = DAY_OF_YEAR.checkValidIntValue(fieldValues.remove(DAY_OF_YEAR));
|
||||
|
@ -493,8 +492,8 @@ public final class HijrahChronology extends Chronology implements Serializable {
|
|||
if (fieldValues.containsKey(ALIGNED_DAY_OF_WEEK_IN_YEAR)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR), 1);
|
||||
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR), 1);
|
||||
return date(y, 1, 1).plus(weeks, WEEKS).plus(days, DAYS);
|
||||
}
|
||||
int aw = ALIGNED_WEEK_OF_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR));
|
||||
|
@ -509,8 +508,8 @@ public final class HijrahChronology extends Chronology implements Serializable {
|
|||
if (fieldValues.containsKey(DAY_OF_WEEK)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_WEEK), 1);
|
||||
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(DAY_OF_WEEK), 1);
|
||||
return date(y, 1, 1).plus(weeks, WEEKS).plus(days, DAYS);
|
||||
}
|
||||
int aw = ALIGNED_WEEK_OF_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR));
|
||||
|
|
|
@ -62,7 +62,6 @@ import org.threeten.bp.DayOfWeek;
|
|||
import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.LocalTime;
|
||||
import org.threeten.bp.ZoneId;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
import org.threeten.bp.temporal.ChronoField;
|
||||
import org.threeten.bp.temporal.TemporalAccessor;
|
||||
import org.threeten.bp.temporal.TemporalAdjuster;
|
||||
|
@ -746,7 +745,7 @@ public final class HijrahDate
|
|||
if (years == 0) {
|
||||
return this;
|
||||
}
|
||||
int newYear = Jdk8Methods.safeAdd(this.yearOfEra, (int) years);
|
||||
int newYear = Math.addExact(this.yearOfEra, (int) years);
|
||||
return HijrahDate.of(this.era, newYear, this.monthOfYear, this.dayOfMonth);
|
||||
}
|
||||
|
||||
|
@ -761,9 +760,9 @@ public final class HijrahDate
|
|||
newMonth = newMonth % 12;
|
||||
while (newMonth < 0) {
|
||||
newMonth += 12;
|
||||
years = Jdk8Methods.safeSubtract(years, 1);
|
||||
years = Math.subtractExact(years, 1);
|
||||
}
|
||||
int newYear = Jdk8Methods.safeAdd(this.yearOfEra, years);
|
||||
int newYear = Math.addExact(this.yearOfEra, years);
|
||||
return HijrahDate.of(this.era, newYear, newMonth + 1, this.dayOfMonth);
|
||||
}
|
||||
|
||||
|
|
|
@ -77,7 +77,6 @@ import org.threeten.bp.Year;
|
|||
import org.threeten.bp.ZoneId;
|
||||
import org.threeten.bp.ZonedDateTime;
|
||||
import org.threeten.bp.format.ResolverStyle;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
import org.threeten.bp.temporal.ChronoField;
|
||||
import org.threeten.bp.temporal.TemporalAccessor;
|
||||
import org.threeten.bp.temporal.TemporalField;
|
||||
|
@ -402,8 +401,8 @@ public final class IsoChronology extends Chronology implements Serializable {
|
|||
if (resolverStyle != ResolverStyle.LENIENT) {
|
||||
PROLEPTIC_MONTH.checkValidValue(prolepticMonth);
|
||||
}
|
||||
updateResolveMap(fieldValues, MONTH_OF_YEAR, Jdk8Methods.floorMod(prolepticMonth, 12) + 1);
|
||||
updateResolveMap(fieldValues, YEAR, Jdk8Methods.floorDiv(prolepticMonth, 12));
|
||||
updateResolveMap(fieldValues, MONTH_OF_YEAR, Math.floorMod(prolepticMonth, 12) + 1);
|
||||
updateResolveMap(fieldValues, YEAR, Math.floorDiv(prolepticMonth, 12));
|
||||
}
|
||||
|
||||
// eras
|
||||
|
@ -418,7 +417,7 @@ public final class IsoChronology extends Chronology implements Serializable {
|
|||
if (resolverStyle == ResolverStyle.STRICT) {
|
||||
// do not invent era if strict, but do cross-check with year
|
||||
if (year != null) {
|
||||
updateResolveMap(fieldValues, YEAR, year > 0 ? yoeLong : Jdk8Methods.safeSubtract(1, yoeLong));
|
||||
updateResolveMap(fieldValues, YEAR, year > 0 ? yoeLong : Math.subtractExact(1, yoeLong));
|
||||
} else {
|
||||
// reinstate the field removed earlier, no cross-check issues
|
||||
fieldValues.put(YEAR_OF_ERA, yoeLong);
|
||||
|
@ -426,12 +425,12 @@ public final class IsoChronology extends Chronology implements Serializable {
|
|||
} else {
|
||||
// invent era
|
||||
updateResolveMap(fieldValues, YEAR,
|
||||
year == null || year > 0 ? yoeLong : Jdk8Methods.safeSubtract(1, yoeLong));
|
||||
year == null || year > 0 ? yoeLong : Math.subtractExact(1, yoeLong));
|
||||
}
|
||||
} else if (era == 1L) {
|
||||
updateResolveMap(fieldValues, YEAR, yoeLong);
|
||||
} else if (era == 0L) {
|
||||
updateResolveMap(fieldValues, YEAR, Jdk8Methods.safeSubtract(1, yoeLong));
|
||||
updateResolveMap(fieldValues, YEAR, Math.subtractExact(1, yoeLong));
|
||||
} else {
|
||||
throw new DateTimeException("Invalid value for era: " + era);
|
||||
}
|
||||
|
@ -444,11 +443,11 @@ public final class IsoChronology extends Chronology implements Serializable {
|
|||
if (fieldValues.containsKey(MONTH_OF_YEAR)) {
|
||||
if (fieldValues.containsKey(DAY_OF_MONTH)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
int moy = Jdk8Methods.safeToInt(fieldValues.remove(MONTH_OF_YEAR));
|
||||
int dom = Jdk8Methods.safeToInt(fieldValues.remove(DAY_OF_MONTH));
|
||||
int moy = Math.toIntExact(fieldValues.remove(MONTH_OF_YEAR));
|
||||
int dom = Math.toIntExact(fieldValues.remove(DAY_OF_MONTH));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long months = Jdk8Methods.safeSubtract(moy, 1);
|
||||
long days = Jdk8Methods.safeSubtract(dom, 1);
|
||||
long months = Math.subtractExact(moy, 1);
|
||||
long days = Math.subtractExact(dom, 1);
|
||||
return LocalDate.of(y, 1, 1).plusMonths(months).plusDays(days);
|
||||
} else if (resolverStyle == ResolverStyle.SMART) {
|
||||
DAY_OF_MONTH.checkValidValue(dom);
|
||||
|
@ -466,9 +465,9 @@ public final class IsoChronology extends Chronology implements Serializable {
|
|||
if (fieldValues.containsKey(ALIGNED_DAY_OF_WEEK_IN_MONTH)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long months = Jdk8Methods.safeSubtract(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH), 1);
|
||||
long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH), 1);
|
||||
return LocalDate.of(y, 1, 1).plusMonths(months).plusWeeks(weeks).plusDays(days);
|
||||
}
|
||||
int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR));
|
||||
|
@ -484,9 +483,9 @@ public final class IsoChronology extends Chronology implements Serializable {
|
|||
if (fieldValues.containsKey(DAY_OF_WEEK)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long months = Jdk8Methods.safeSubtract(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_WEEK), 1);
|
||||
long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(DAY_OF_WEEK), 1);
|
||||
return LocalDate.of(y, 1, 1).plusMonths(months).plusWeeks(weeks).plusDays(days);
|
||||
}
|
||||
int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR));
|
||||
|
@ -503,7 +502,7 @@ public final class IsoChronology extends Chronology implements Serializable {
|
|||
if (fieldValues.containsKey(DAY_OF_YEAR)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_YEAR), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(DAY_OF_YEAR), 1);
|
||||
return LocalDate.ofYearDay(y, 1).plusDays(days);
|
||||
}
|
||||
int doy = DAY_OF_YEAR.checkValidIntValue(fieldValues.remove(DAY_OF_YEAR));
|
||||
|
@ -513,8 +512,8 @@ public final class IsoChronology extends Chronology implements Serializable {
|
|||
if (fieldValues.containsKey(ALIGNED_DAY_OF_WEEK_IN_YEAR)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR), 1);
|
||||
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR), 1);
|
||||
return LocalDate.of(y, 1, 1).plusWeeks(weeks).plusDays(days);
|
||||
}
|
||||
int aw = ALIGNED_WEEK_OF_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR));
|
||||
|
@ -529,8 +528,8 @@ public final class IsoChronology extends Chronology implements Serializable {
|
|||
if (fieldValues.containsKey(DAY_OF_WEEK)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_WEEK), 1);
|
||||
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(DAY_OF_WEEK), 1);
|
||||
return LocalDate.of(y, 1, 1).plusWeeks(weeks).plusDays(days);
|
||||
}
|
||||
int aw = ALIGNED_WEEK_OF_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR));
|
||||
|
|
|
@ -78,7 +78,6 @@ import org.threeten.bp.Instant;
|
|||
import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.ZoneId;
|
||||
import org.threeten.bp.format.ResolverStyle;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
import org.threeten.bp.temporal.ChronoField;
|
||||
import org.threeten.bp.temporal.TemporalAccessor;
|
||||
import org.threeten.bp.temporal.TemporalField;
|
||||
|
@ -440,8 +439,8 @@ public final class JapaneseChronology extends Chronology implements Serializable
|
|||
if (resolverStyle != ResolverStyle.LENIENT) {
|
||||
PROLEPTIC_MONTH.checkValidValue(prolepticMonth);
|
||||
}
|
||||
updateResolveMap(fieldValues, MONTH_OF_YEAR, Jdk8Methods.floorMod(prolepticMonth, 12) + 1);
|
||||
updateResolveMap(fieldValues, YEAR, Jdk8Methods.floorDiv(prolepticMonth, 12));
|
||||
updateResolveMap(fieldValues, MONTH_OF_YEAR, Math.floorMod(prolepticMonth, 12) + 1);
|
||||
updateResolveMap(fieldValues, YEAR, Math.floorDiv(prolepticMonth, 12));
|
||||
}
|
||||
|
||||
// eras
|
||||
|
@ -476,8 +475,8 @@ public final class JapaneseChronology extends Chronology implements Serializable
|
|||
if (fieldValues.containsKey(DAY_OF_MONTH)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long months = Jdk8Methods.safeSubtract(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_MONTH), 1);
|
||||
long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
|
||||
return date(y, 1, 1).plusMonths(months).plusDays(days);
|
||||
} else {
|
||||
int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR),
|
||||
|
@ -494,9 +493,9 @@ public final class JapaneseChronology extends Chronology implements Serializable
|
|||
if (fieldValues.containsKey(ALIGNED_DAY_OF_WEEK_IN_MONTH)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long months = Jdk8Methods.safeSubtract(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH), 1);
|
||||
long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH), 1);
|
||||
return date(y, 1, 1).plus(months, MONTHS).plus(weeks, WEEKS).plus(days, DAYS);
|
||||
}
|
||||
int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR));
|
||||
|
@ -512,9 +511,9 @@ public final class JapaneseChronology extends Chronology implements Serializable
|
|||
if (fieldValues.containsKey(DAY_OF_WEEK)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long months = Jdk8Methods.safeSubtract(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_WEEK), 1);
|
||||
long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(DAY_OF_WEEK), 1);
|
||||
return date(y, 1, 1).plus(months, MONTHS).plus(weeks, WEEKS).plus(days, DAYS);
|
||||
}
|
||||
int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR));
|
||||
|
@ -531,7 +530,7 @@ public final class JapaneseChronology extends Chronology implements Serializable
|
|||
if (fieldValues.containsKey(DAY_OF_YEAR)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_YEAR), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(DAY_OF_YEAR), 1);
|
||||
return dateYearDay(y, 1).plusDays(days);
|
||||
}
|
||||
int doy = DAY_OF_YEAR.checkValidIntValue(fieldValues.remove(DAY_OF_YEAR));
|
||||
|
@ -541,8 +540,8 @@ public final class JapaneseChronology extends Chronology implements Serializable
|
|||
if (fieldValues.containsKey(ALIGNED_DAY_OF_WEEK_IN_YEAR)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR), 1);
|
||||
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR), 1);
|
||||
return date(y, 1, 1).plus(weeks, WEEKS).plus(days, DAYS);
|
||||
}
|
||||
int aw = ALIGNED_WEEK_OF_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR));
|
||||
|
@ -557,8 +556,8 @@ public final class JapaneseChronology extends Chronology implements Serializable
|
|||
if (fieldValues.containsKey(DAY_OF_WEEK)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_WEEK), 1);
|
||||
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(DAY_OF_WEEK), 1);
|
||||
return date(y, 1, 1).plus(weeks, WEEKS).plus(days, DAYS);
|
||||
}
|
||||
int aw = ALIGNED_WEEK_OF_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR));
|
||||
|
@ -578,8 +577,8 @@ public final class JapaneseChronology extends Chronology implements Serializable
|
|||
JapaneseEra era, int yoe) {
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
int y = era.startDate().getYear() + yoe - 1;
|
||||
long months = Jdk8Methods.safeSubtract(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_MONTH), 1);
|
||||
long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
|
||||
return date(y, 1, 1).plus(months, MONTHS).plus(days, DAYS);
|
||||
}
|
||||
int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
|
||||
|
@ -611,7 +610,7 @@ public final class JapaneseChronology extends Chronology implements Serializable
|
|||
JapaneseEra era, int yoe) {
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
int y = era.startDate().getYear() + yoe - 1;
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_YEAR), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(DAY_OF_YEAR), 1);
|
||||
return dateYearDay(y, 1).plus(days, DAYS);
|
||||
}
|
||||
int doy = range(DAY_OF_YEAR).checkValidIntValue(fieldValues.remove(DAY_OF_YEAR), DAY_OF_YEAR);
|
||||
|
|
|
@ -76,7 +76,6 @@ import org.threeten.bp.Instant;
|
|||
import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.ZoneId;
|
||||
import org.threeten.bp.format.ResolverStyle;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
import org.threeten.bp.temporal.ChronoField;
|
||||
import org.threeten.bp.temporal.TemporalAccessor;
|
||||
import org.threeten.bp.temporal.TemporalField;
|
||||
|
@ -305,8 +304,8 @@ public final class MinguoChronology extends Chronology implements Serializable {
|
|||
if (resolverStyle != ResolverStyle.LENIENT) {
|
||||
PROLEPTIC_MONTH.checkValidValue(prolepticMonth);
|
||||
}
|
||||
updateResolveMap(fieldValues, MONTH_OF_YEAR, Jdk8Methods.floorMod(prolepticMonth, 12) + 1);
|
||||
updateResolveMap(fieldValues, YEAR, Jdk8Methods.floorDiv(prolepticMonth, 12));
|
||||
updateResolveMap(fieldValues, MONTH_OF_YEAR, Math.floorMod(prolepticMonth, 12) + 1);
|
||||
updateResolveMap(fieldValues, YEAR, Math.floorDiv(prolepticMonth, 12));
|
||||
}
|
||||
|
||||
// eras
|
||||
|
@ -321,7 +320,7 @@ public final class MinguoChronology extends Chronology implements Serializable {
|
|||
if (resolverStyle == ResolverStyle.STRICT) {
|
||||
// do not invent era if strict, but do cross-check with year
|
||||
if (year != null) {
|
||||
updateResolveMap(fieldValues, YEAR, year > 0 ? yoeLong : Jdk8Methods.safeSubtract(1, yoeLong));
|
||||
updateResolveMap(fieldValues, YEAR, year > 0 ? yoeLong : Math.subtractExact(1, yoeLong));
|
||||
} else {
|
||||
// reinstate the field removed earlier, no cross-check issues
|
||||
fieldValues.put(YEAR_OF_ERA, yoeLong);
|
||||
|
@ -330,12 +329,12 @@ public final class MinguoChronology extends Chronology implements Serializable {
|
|||
// invent era
|
||||
updateResolveMap(fieldValues, YEAR, year == null || year > 0
|
||||
? yoeLong
|
||||
: Jdk8Methods.safeSubtract(1, yoeLong));
|
||||
: Math.subtractExact(1, yoeLong));
|
||||
}
|
||||
} else if (era == 1L) {
|
||||
updateResolveMap(fieldValues, YEAR, yoeLong);
|
||||
} else if (era == 0L) {
|
||||
updateResolveMap(fieldValues, YEAR, Jdk8Methods.safeSubtract(1, yoeLong));
|
||||
updateResolveMap(fieldValues, YEAR, Math.subtractExact(1, yoeLong));
|
||||
} else {
|
||||
throw new DateTimeException("Invalid value for era: " + era);
|
||||
}
|
||||
|
@ -349,8 +348,8 @@ public final class MinguoChronology extends Chronology implements Serializable {
|
|||
if (fieldValues.containsKey(DAY_OF_MONTH)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long months = Jdk8Methods.safeSubtract(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_MONTH), 1);
|
||||
long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
|
||||
return date(y, 1, 1).plusMonths(months).plusDays(days);
|
||||
} else {
|
||||
int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR),
|
||||
|
@ -367,9 +366,9 @@ public final class MinguoChronology extends Chronology implements Serializable {
|
|||
if (fieldValues.containsKey(ALIGNED_DAY_OF_WEEK_IN_MONTH)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long months = Jdk8Methods.safeSubtract(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH), 1);
|
||||
long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH), 1);
|
||||
return date(y, 1, 1).plus(months, MONTHS).plus(weeks, WEEKS).plus(days, DAYS);
|
||||
}
|
||||
int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR));
|
||||
|
@ -385,9 +384,9 @@ public final class MinguoChronology extends Chronology implements Serializable {
|
|||
if (fieldValues.containsKey(DAY_OF_WEEK)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long months = Jdk8Methods.safeSubtract(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_WEEK), 1);
|
||||
long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(DAY_OF_WEEK), 1);
|
||||
return date(y, 1, 1).plus(months, MONTHS).plus(weeks, WEEKS).plus(days, DAYS);
|
||||
}
|
||||
int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR));
|
||||
|
@ -404,7 +403,7 @@ public final class MinguoChronology extends Chronology implements Serializable {
|
|||
if (fieldValues.containsKey(DAY_OF_YEAR)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_YEAR), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(DAY_OF_YEAR), 1);
|
||||
return dateYearDay(y, 1).plusDays(days);
|
||||
}
|
||||
int doy = DAY_OF_YEAR.checkValidIntValue(fieldValues.remove(DAY_OF_YEAR));
|
||||
|
@ -414,8 +413,8 @@ public final class MinguoChronology extends Chronology implements Serializable {
|
|||
if (fieldValues.containsKey(ALIGNED_DAY_OF_WEEK_IN_YEAR)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR), 1);
|
||||
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR), 1);
|
||||
return date(y, 1, 1).plus(weeks, WEEKS).plus(days, DAYS);
|
||||
}
|
||||
int aw = ALIGNED_WEEK_OF_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR));
|
||||
|
@ -430,8 +429,8 @@ public final class MinguoChronology extends Chronology implements Serializable {
|
|||
if (fieldValues.containsKey(DAY_OF_WEEK)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_WEEK), 1);
|
||||
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(DAY_OF_WEEK), 1);
|
||||
return date(y, 1, 1).plus(weeks, WEEKS).plus(days, DAYS);
|
||||
}
|
||||
int aw = ALIGNED_WEEK_OF_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR));
|
||||
|
|
|
@ -77,7 +77,6 @@ import org.threeten.bp.Instant;
|
|||
import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.ZoneId;
|
||||
import org.threeten.bp.format.ResolverStyle;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
import org.threeten.bp.temporal.ChronoField;
|
||||
import org.threeten.bp.temporal.TemporalAccessor;
|
||||
import org.threeten.bp.temporal.TemporalField;
|
||||
|
@ -343,8 +342,8 @@ public final class ThaiBuddhistChronology extends Chronology implements Serializ
|
|||
if (resolverStyle != ResolverStyle.LENIENT) {
|
||||
PROLEPTIC_MONTH.checkValidValue(prolepticMonth);
|
||||
}
|
||||
updateResolveMap(fieldValues, MONTH_OF_YEAR, Jdk8Methods.floorMod(prolepticMonth, 12) + 1);
|
||||
updateResolveMap(fieldValues, YEAR, Jdk8Methods.floorDiv(prolepticMonth, 12));
|
||||
updateResolveMap(fieldValues, MONTH_OF_YEAR, Math.floorMod(prolepticMonth, 12) + 1);
|
||||
updateResolveMap(fieldValues, YEAR, Math.floorDiv(prolepticMonth, 12));
|
||||
}
|
||||
|
||||
// eras
|
||||
|
@ -361,7 +360,7 @@ public final class ThaiBuddhistChronology extends Chronology implements Serializ
|
|||
if (year != null) {
|
||||
updateResolveMap(fieldValues, YEAR, year > 0
|
||||
? yoeLong
|
||||
: Jdk8Methods.safeSubtract(1, yoeLong));
|
||||
: Math.subtractExact(1, yoeLong));
|
||||
} else {
|
||||
// reinstate the field removed earlier, no cross-check issues
|
||||
fieldValues.put(YEAR_OF_ERA, yoeLong);
|
||||
|
@ -370,12 +369,12 @@ public final class ThaiBuddhistChronology extends Chronology implements Serializ
|
|||
// invent era
|
||||
updateResolveMap(fieldValues, YEAR, year == null || year > 0
|
||||
? yoeLong
|
||||
: Jdk8Methods.safeSubtract(1, yoeLong));
|
||||
: Math.subtractExact(1, yoeLong));
|
||||
}
|
||||
} else if (era == 1L) {
|
||||
updateResolveMap(fieldValues, YEAR, yoeLong);
|
||||
} else if (era == 0L) {
|
||||
updateResolveMap(fieldValues, YEAR, Jdk8Methods.safeSubtract(1, yoeLong));
|
||||
updateResolveMap(fieldValues, YEAR, Math.subtractExact(1, yoeLong));
|
||||
} else {
|
||||
throw new DateTimeException("Invalid value for era: " + era);
|
||||
}
|
||||
|
@ -389,8 +388,8 @@ public final class ThaiBuddhistChronology extends Chronology implements Serializ
|
|||
if (fieldValues.containsKey(DAY_OF_MONTH)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long months = Jdk8Methods.safeSubtract(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_MONTH), 1);
|
||||
long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
|
||||
return date(y, 1, 1).plusMonths(months).plusDays(days);
|
||||
} else {
|
||||
int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR),
|
||||
|
@ -407,9 +406,9 @@ public final class ThaiBuddhistChronology extends Chronology implements Serializ
|
|||
if (fieldValues.containsKey(ALIGNED_DAY_OF_WEEK_IN_MONTH)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long months = Jdk8Methods.safeSubtract(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH), 1);
|
||||
long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH), 1);
|
||||
return date(y, 1, 1).plus(months, MONTHS).plus(weeks, WEEKS).plus(days, DAYS);
|
||||
}
|
||||
int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR));
|
||||
|
@ -425,9 +424,9 @@ public final class ThaiBuddhistChronology extends Chronology implements Serializ
|
|||
if (fieldValues.containsKey(DAY_OF_WEEK)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long months = Jdk8Methods.safeSubtract(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_WEEK), 1);
|
||||
long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
|
||||
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(DAY_OF_WEEK), 1);
|
||||
return date(y, 1, 1).plus(months, MONTHS).plus(weeks, WEEKS).plus(days, DAYS);
|
||||
}
|
||||
int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR));
|
||||
|
@ -444,7 +443,7 @@ public final class ThaiBuddhistChronology extends Chronology implements Serializ
|
|||
if (fieldValues.containsKey(DAY_OF_YEAR)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_YEAR), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(DAY_OF_YEAR), 1);
|
||||
return dateYearDay(y, 1).plusDays(days);
|
||||
}
|
||||
int doy = DAY_OF_YEAR.checkValidIntValue(fieldValues.remove(DAY_OF_YEAR));
|
||||
|
@ -454,8 +453,8 @@ public final class ThaiBuddhistChronology extends Chronology implements Serializ
|
|||
if (fieldValues.containsKey(ALIGNED_DAY_OF_WEEK_IN_YEAR)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR), 1);
|
||||
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR), 1);
|
||||
return date(y, 1, 1).plus(weeks, WEEKS).plus(days, DAYS);
|
||||
}
|
||||
int aw = ALIGNED_WEEK_OF_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR));
|
||||
|
@ -470,8 +469,8 @@ public final class ThaiBuddhistChronology extends Chronology implements Serializ
|
|||
if (fieldValues.containsKey(DAY_OF_WEEK)) {
|
||||
int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR));
|
||||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long weeks = Jdk8Methods.safeSubtract(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
|
||||
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_WEEK), 1);
|
||||
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
|
||||
long days = Math.subtractExact(fieldValues.remove(DAY_OF_WEEK), 1);
|
||||
return date(y, 1, 1).plus(weeks, WEEKS).plus(days, DAYS);
|
||||
}
|
||||
int aw = ALIGNED_WEEK_OF_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR));
|
||||
|
|
|
@ -82,7 +82,6 @@ import org.threeten.bp.chrono.ChronoLocalDateTime;
|
|||
import org.threeten.bp.chrono.ChronoZonedDateTime;
|
||||
import org.threeten.bp.chrono.Chronology;
|
||||
import org.threeten.bp.chrono.IsoChronology;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
import org.threeten.bp.temporal.ChronoField;
|
||||
import org.threeten.bp.temporal.TemporalAccessor;
|
||||
import org.threeten.bp.temporal.TemporalField;
|
||||
|
@ -518,25 +517,25 @@ public final class DateTimeBuilder
|
|||
if (nos == null) {
|
||||
nos = 0L;
|
||||
}
|
||||
long totalNanos = Jdk8Methods.safeMultiply(hodVal, 3600000000000L);
|
||||
totalNanos = Jdk8Methods.safeAdd(totalNanos, Jdk8Methods.safeMultiply(moh, 60000000000L));
|
||||
totalNanos = Jdk8Methods.safeAdd(totalNanos, Jdk8Methods.safeMultiply(som, 1000000000L));
|
||||
totalNanos = Jdk8Methods.safeAdd(totalNanos, nos);
|
||||
int excessDays = (int) Jdk8Methods.floorDiv(totalNanos, 86400000000000L); // safe int cast
|
||||
long nod = Jdk8Methods.floorMod(totalNanos, 86400000000000L);
|
||||
long totalNanos = Math.multiplyExact(hodVal, 3600000000000L);
|
||||
totalNanos = Math.addExact(totalNanos, Math.multiplyExact(moh, 60000000000L));
|
||||
totalNanos = Math.addExact(totalNanos, Math.multiplyExact(som, 1000000000L));
|
||||
totalNanos = Math.addExact(totalNanos, nos);
|
||||
int excessDays = (int) Math.floorDiv(totalNanos, 86400000000000L); // safe int cast
|
||||
long nod = Math.floorMod(totalNanos, 86400000000000L);
|
||||
addObject(LocalTime.ofNanoOfDay(nod));
|
||||
this.excessDays = Period.ofDays(excessDays);
|
||||
} else {
|
||||
long totalSecs = Jdk8Methods.safeMultiply(hodVal, 3600L);
|
||||
totalSecs = Jdk8Methods.safeAdd(totalSecs, Jdk8Methods.safeMultiply(moh, 60L));
|
||||
int excessDays = (int) Jdk8Methods.floorDiv(totalSecs, 86400L); // safe int cast
|
||||
long sod = Jdk8Methods.floorMod(totalSecs, 86400L);
|
||||
long totalSecs = Math.multiplyExact(hodVal, 3600L);
|
||||
totalSecs = Math.addExact(totalSecs, Math.multiplyExact(moh, 60L));
|
||||
int excessDays = (int) Math.floorDiv(totalSecs, 86400L); // safe int cast
|
||||
long sod = Math.floorMod(totalSecs, 86400L);
|
||||
addObject(LocalTime.ofSecondOfDay(sod));
|
||||
this.excessDays = Period.ofDays(excessDays);
|
||||
}
|
||||
} else {
|
||||
int excessDays = Jdk8Methods.safeToInt(Jdk8Methods.floorDiv(hodVal, 24L));
|
||||
hodVal = Jdk8Methods.floorMod(hodVal, 24);
|
||||
int excessDays = Math.toIntExact(Math.floorDiv(hodVal, 24L));
|
||||
hodVal = Math.floorMod(hodVal, 24);
|
||||
addObject(LocalTime.of((int) hodVal, 0));
|
||||
this.excessDays = Period.ofDays(excessDays);
|
||||
}
|
||||
|
|
|
@ -86,7 +86,6 @@ import org.threeten.bp.ZoneOffset;
|
|||
import org.threeten.bp.chrono.ChronoLocalDate;
|
||||
import org.threeten.bp.chrono.Chronology;
|
||||
import org.threeten.bp.format.SimpleDateTimeTextProvider.LocaleStore;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
import org.threeten.bp.temporal.ChronoField;
|
||||
import org.threeten.bp.temporal.IsoFields;
|
||||
import org.threeten.bp.temporal.TemporalAccessor;
|
||||
|
@ -2967,8 +2966,8 @@ public final class DateTimeFormatterBuilder {
|
|||
if (inSec >= -SECONDS_0000_TO_1970) {
|
||||
// current era
|
||||
long zeroSecs = inSec - SECONDS_PER_10000_YEARS + SECONDS_0000_TO_1970;
|
||||
long hi = Jdk8Methods.floorDiv(zeroSecs, SECONDS_PER_10000_YEARS) + 1;
|
||||
long lo = Jdk8Methods.floorMod(zeroSecs, SECONDS_PER_10000_YEARS);
|
||||
long hi = Math.floorDiv(zeroSecs, SECONDS_PER_10000_YEARS) + 1;
|
||||
long lo = Math.floorMod(zeroSecs, SECONDS_PER_10000_YEARS);
|
||||
LocalDateTime ldt = LocalDateTime.ofEpochSecond(lo - SECONDS_0000_TO_1970, 0, ZoneOffset.UTC);
|
||||
if (hi > 0) {
|
||||
buf.append('+').append(hi);
|
||||
|
@ -3064,7 +3063,7 @@ public final class DateTimeFormatterBuilder {
|
|||
try {
|
||||
LocalDateTime ldt = LocalDateTime.of(year, month, day, hour, min, sec, 0).plusDays(days);
|
||||
instantSecs = ldt.toEpochSecond(ZoneOffset.UTC);
|
||||
instantSecs += Jdk8Methods.safeMultiply(yearParsed / 10000L, SECONDS_PER_10000_YEARS);
|
||||
instantSecs += Math.multiplyExact(yearParsed / 10000L, SECONDS_PER_10000_YEARS);
|
||||
} catch (RuntimeException ex) {
|
||||
return ~position;
|
||||
}
|
||||
|
@ -3120,7 +3119,7 @@ public final class DateTimeFormatterBuilder {
|
|||
if (offsetSecs == null) {
|
||||
return false;
|
||||
}
|
||||
int totalSecs = Jdk8Methods.safeToInt(offsetSecs);
|
||||
int totalSecs = Math.toIntExact(offsetSecs);
|
||||
if (totalSecs == 0) {
|
||||
buf.append(noOffsetText);
|
||||
} else {
|
||||
|
@ -3253,7 +3252,7 @@ public final class DateTimeFormatterBuilder {
|
|||
if (style == TextStyle.FULL) {
|
||||
return new OffsetIdPrinterParser("", "+HH:MM:ss").print(context, buf);
|
||||
}
|
||||
int totalSecs = Jdk8Methods.safeToInt(offsetSecs);
|
||||
int totalSecs = Math.toIntExact(offsetSecs);
|
||||
if (totalSecs != 0) {
|
||||
int absHours = Math.abs((totalSecs / 3600) % 100); // anything larger than 99 silently dropped
|
||||
int absMinutes = Math.abs((totalSecs / 60) % 60);
|
||||
|
|
|
@ -57,7 +57,6 @@ import org.threeten.bp.ZoneId;
|
|||
import org.threeten.bp.chrono.Chronology;
|
||||
import org.threeten.bp.chrono.IsoChronology;
|
||||
import org.threeten.bp.format.DateTimeFormatterBuilder.ReducedPrinterParser;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
import org.threeten.bp.temporal.TemporalAccessor;
|
||||
import org.threeten.bp.temporal.TemporalField;
|
||||
import org.threeten.bp.temporal.TemporalQueries;
|
||||
|
@ -470,7 +469,7 @@ public final class DateTimeParseContext {
|
|||
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
|
||||
}
|
||||
long value = fieldValues.get(field);
|
||||
return Jdk8Methods.safeToInt(value);
|
||||
return Math.toIntExact(value);
|
||||
}
|
||||
@Override
|
||||
public long getLong(TemporalField field) {
|
||||
|
|
|
@ -1,315 +0,0 @@
|
|||
/*
|
||||
* Copyright 2020 Alexey Andreev.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of JSR-310 nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.threeten.bp.jdk8;
|
||||
|
||||
/**
|
||||
* A set of utility methods that provide additional functionality for working
|
||||
* with dates and times.
|
||||
* <p>
|
||||
* The contents of this class replace functionality available in JDK 8.
|
||||
*
|
||||
* <h3>Specification for implementors</h3>
|
||||
* This is a thread-safe utility class.
|
||||
* All returned classes are immutable and thread-safe.
|
||||
*/
|
||||
public final class Jdk8Methods {
|
||||
|
||||
/**
|
||||
* Private constructor since this is a utility class.
|
||||
*/
|
||||
private Jdk8Methods() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Safely adds two int values.
|
||||
*
|
||||
* @param a the first value
|
||||
* @param b the second value
|
||||
* @return the result
|
||||
* @throws ArithmeticException if the result overflows an int
|
||||
*/
|
||||
public static int safeAdd(int a, int b) {
|
||||
int sum = a + b;
|
||||
// check for a change of sign in the result when the inputs have the same sign
|
||||
if ((a ^ sum) < 0 && (a ^ b) >= 0) {
|
||||
throw new ArithmeticException("Addition overflows an int: " + a + " + " + b);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely adds two long values.
|
||||
*
|
||||
* @param a the first value
|
||||
* @param b the second value
|
||||
* @return the result
|
||||
* @throws ArithmeticException if the result overflows a long
|
||||
*/
|
||||
public static long safeAdd(long a, long b) {
|
||||
long sum = a + b;
|
||||
// check for a change of sign in the result when the inputs have the same sign
|
||||
if ((a ^ sum) < 0 && (a ^ b) >= 0) {
|
||||
throw new ArithmeticException("Addition overflows a long: " + a + " + " + b);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Safely subtracts one int from another.
|
||||
*
|
||||
* @param a the first value
|
||||
* @param b the second value to subtract from the first
|
||||
* @return the result
|
||||
* @throws ArithmeticException if the result overflows an int
|
||||
*/
|
||||
public static int safeSubtract(int a, int b) {
|
||||
int result = a - b;
|
||||
// check for a change of sign in the result when the inputs have the different signs
|
||||
if ((a ^ result) < 0 && (a ^ b) < 0) {
|
||||
throw new ArithmeticException("Subtraction overflows an int: " + a + " - " + b);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely subtracts one long from another.
|
||||
*
|
||||
* @param a the first value
|
||||
* @param b the second value to subtract from the first
|
||||
* @return the result
|
||||
* @throws ArithmeticException if the result overflows a long
|
||||
*/
|
||||
public static long safeSubtract(long a, long b) {
|
||||
long result = a - b;
|
||||
// check for a change of sign in the result when the inputs have the different signs
|
||||
if ((a ^ result) < 0 && (a ^ b) < 0) {
|
||||
throw new ArithmeticException("Subtraction overflows a long: " + a + " - " + b);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Safely multiply one int by another.
|
||||
*
|
||||
* @param a the first value
|
||||
* @param b the second value
|
||||
* @return the result
|
||||
* @throws ArithmeticException if the result overflows an int
|
||||
*/
|
||||
public static int safeMultiply(int a, int b) {
|
||||
long total = (long) a * (long) b;
|
||||
if (total < Integer.MIN_VALUE || total > Integer.MAX_VALUE) {
|
||||
throw new ArithmeticException("Multiplication overflows an int: " + a + " * " + b);
|
||||
}
|
||||
return (int) total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely multiply a long by an int.
|
||||
*
|
||||
* @param a the first value
|
||||
* @param b the second value
|
||||
* @return the new total
|
||||
* @throws ArithmeticException if the result overflows a long
|
||||
*/
|
||||
public static long safeMultiply(long a, int b) {
|
||||
switch (b) {
|
||||
case -1:
|
||||
if (a == Long.MIN_VALUE) {
|
||||
throw new ArithmeticException("Multiplication overflows a long: " + a + " * " + b);
|
||||
}
|
||||
return -a;
|
||||
case 0:
|
||||
return 0L;
|
||||
case 1:
|
||||
return a;
|
||||
}
|
||||
long total = a * b;
|
||||
if (total / b != a) {
|
||||
throw new ArithmeticException("Multiplication overflows a long: " + a + " * " + b);
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply two values throwing an exception if overflow occurs.
|
||||
*
|
||||
* @param a the first value
|
||||
* @param b the second value
|
||||
* @return the new total
|
||||
* @throws ArithmeticException if the result overflows a long
|
||||
*/
|
||||
public static long safeMultiply(long a, long b) {
|
||||
if (b == 1) {
|
||||
return a;
|
||||
}
|
||||
if (a == 1) {
|
||||
return b;
|
||||
}
|
||||
if (a == 0 || b == 0) {
|
||||
return 0;
|
||||
}
|
||||
long total = a * b;
|
||||
if (total / b != a || (a == Long.MIN_VALUE && b == -1) || (b == Long.MIN_VALUE && a == -1)) {
|
||||
throw new ArithmeticException("Multiplication overflows a long: " + a + " * " + b);
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Safely convert a long to an int.
|
||||
*
|
||||
* @param value the value to convert
|
||||
* @return the int value
|
||||
* @throws ArithmeticException if the result overflows an int
|
||||
*/
|
||||
public static int safeToInt(long value) {
|
||||
if (value > Integer.MAX_VALUE || value < Integer.MIN_VALUE) {
|
||||
throw new ArithmeticException("Calculation overflows an int: " + value);
|
||||
}
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
/**
|
||||
* Returns the floor division.
|
||||
* <p>
|
||||
* This returns {@code 0} for {@code floorDiv(0, 4)}.<br />
|
||||
* This returns {@code -1} for {@code floorDiv(-1, 4)}.<br />
|
||||
* This returns {@code -1} for {@code floorDiv(-2, 4)}.<br />
|
||||
* This returns {@code -1} for {@code floorDiv(-3, 4)}.<br />
|
||||
* This returns {@code -1} for {@code floorDiv(-4, 4)}.<br />
|
||||
* This returns {@code -2} for {@code floorDiv(-5, 4)}.<br />
|
||||
*
|
||||
* @param a the dividend
|
||||
* @param b the divisor
|
||||
* @return the floor division
|
||||
*/
|
||||
public static long floorDiv(long a, long b) {
|
||||
return a >= 0 ? a / b : ((a + 1) / b) - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the floor modulus.
|
||||
* <p>
|
||||
* This returns {@code 0} for {@code floorMod(0, 4)}.<br />
|
||||
* This returns {@code 1} for {@code floorMod(-1, 4)}.<br />
|
||||
* This returns {@code 2} for {@code floorMod(-2, 4)}.<br />
|
||||
* This returns {@code 3} for {@code floorMod(-3, 4)}.<br />
|
||||
* This returns {@code 0} for {@code floorMod(-4, 4)}.<br />
|
||||
*
|
||||
* @param a the dividend
|
||||
* @param b the divisor
|
||||
* @return the floor modulus (positive)
|
||||
*/
|
||||
public static long floorMod(long a, long b) {
|
||||
return ((a % b) + b) % b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the floor modulus.
|
||||
* <p>
|
||||
* This returns {@code 0} for {@code floorMod(0, 4)}.<br />
|
||||
* This returns {@code 3} for {@code floorMod(-1, 4)}.<br />
|
||||
* This returns {@code 2} for {@code floorMod(-2, 4)}.<br />
|
||||
* This returns {@code 1} for {@code floorMod(-3, 4)}.<br />
|
||||
* This returns {@code 0} for {@code floorMod(-4, 4)}.<br />
|
||||
* This returns {@code 3} for {@code floorMod(-5, 4)}.<br />
|
||||
*
|
||||
* @param a the dividend
|
||||
* @param b the divisor
|
||||
* @return the floor modulus (positive)
|
||||
*/
|
||||
public static int floorMod(long a, int b) {
|
||||
return (int) (((a % b) + b) % b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the floor division.
|
||||
* <p>
|
||||
* This returns {@code 1} for {@code floorDiv(3, 3)}.<br />
|
||||
* This returns {@code 0} for {@code floorDiv(2, 3)}.<br />
|
||||
* This returns {@code 0} for {@code floorDiv(1, 3)}.<br />
|
||||
* This returns {@code 0} for {@code floorDiv(0, 3)}.<br />
|
||||
* This returns {@code -1} for {@code floorDiv(-1, 3)}.<br />
|
||||
* This returns {@code -1} for {@code floorDiv(-2, 3)}.<br />
|
||||
* This returns {@code -1} for {@code floorDiv(-3, 3)}.<br />
|
||||
* This returns {@code -2} for {@code floorDiv(-4, 3)}.<br />
|
||||
*
|
||||
* @param a the dividend
|
||||
* @param b the divisor
|
||||
* @return the floor division
|
||||
*/
|
||||
public static int floorDiv(int a, int b) {
|
||||
return a >= 0 ? a / b : ((a + 1) / b) - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the floor modulus.
|
||||
* <p>
|
||||
* This returns {@code 0} for {@code floorMod(3, 3)}.<br />
|
||||
* This returns {@code 2} for {@code floorMod(2, 3)}.<br />
|
||||
* This returns {@code 1} for {@code floorMod(1, 3)}.<br />
|
||||
* This returns {@code 0} for {@code floorMod(0, 3)}.<br />
|
||||
* This returns {@code 2} for {@code floorMod(-1, 3)}.<br />
|
||||
* This returns {@code 1} for {@code floorMod(-2, 3)}.<br />
|
||||
* This returns {@code 0} for {@code floorMod(-3, 3)}.<br />
|
||||
* This returns {@code 2} for {@code floorMod(-4, 3)}.<br />
|
||||
*
|
||||
* @param a the dividend
|
||||
* @param b the divisor
|
||||
* @return the floor modulus (positive)
|
||||
*/
|
||||
public static int floorMod(int a, int b) {
|
||||
return ((a % b) + b) % b;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
<!--
|
||||
/*
|
||||
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of JSR-310 nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
-->
|
||||
<body>
|
||||
<p>
|
||||
Simulates JDK 8 features on JDK 7.
|
||||
Do NOT use these classes directly.
|
||||
</p>
|
||||
</body>
|
||||
|
|
@ -66,7 +66,6 @@ import org.threeten.bp.LocalDate;
|
|||
import org.threeten.bp.chrono.Chronology;
|
||||
import org.threeten.bp.chrono.IsoChronology;
|
||||
import org.threeten.bp.format.ResolverStyle;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
|
||||
/**
|
||||
* Fields and units specific to the ISO-8601 calendar system,
|
||||
|
@ -286,8 +285,8 @@ public final class IsoFields {
|
|||
if (resolverStyle == ResolverStyle.LENIENT) {
|
||||
long qoy = qoyLong;
|
||||
date = LocalDate.of(y, 1, 1);
|
||||
date = date.plusMonths(Jdk8Methods.safeMultiply(Jdk8Methods.safeSubtract(qoy, 1), 3));
|
||||
date = date.plusDays(Jdk8Methods.safeSubtract(doq, 1));
|
||||
date = date.plusMonths(Math.multiplyExact(Math.subtractExact(qoy, 1), 3));
|
||||
date = date.plusDays(Math.subtractExact(doq, 1));
|
||||
} else {
|
||||
int qoy = QUARTER_OF_YEAR.range().checkValidIntValue(qoyLong, QUARTER_OF_YEAR);
|
||||
if (resolverStyle == ResolverStyle.STRICT) {
|
||||
|
@ -395,7 +394,7 @@ public final class IsoFields {
|
|||
@Override
|
||||
public <R extends Temporal> R adjustInto(R temporal, long newValue) {
|
||||
range().checkValidValue(newValue, this);
|
||||
return (R) temporal.plus(Jdk8Methods.safeSubtract(newValue, getFrom(temporal)), WEEKS);
|
||||
return (R) temporal.plus(Math.subtractExact(newValue, getFrom(temporal)), WEEKS);
|
||||
}
|
||||
@Override
|
||||
public TemporalAccessor resolve(Map<TemporalField, Long> fieldValues,
|
||||
|
@ -617,7 +616,7 @@ public final class IsoFields {
|
|||
public <R extends Temporal> R addTo(R temporal, long periodToAdd) {
|
||||
switch (this) {
|
||||
case WEEK_BASED_YEARS:
|
||||
long added = Jdk8Methods.safeAdd(temporal.get(WEEK_BASED_YEAR), periodToAdd);
|
||||
long added = Math.addExact(temporal.get(WEEK_BASED_YEAR), periodToAdd);
|
||||
return (R) temporal.with(WEEK_BASED_YEAR, added);
|
||||
case QUARTER_YEARS:
|
||||
// no overflow (256 is multiple of 4)
|
||||
|
@ -631,7 +630,7 @@ public final class IsoFields {
|
|||
public long between(Temporal temporal1, Temporal temporal2) {
|
||||
switch (this) {
|
||||
case WEEK_BASED_YEARS:
|
||||
return Jdk8Methods.safeSubtract(temporal2.getLong(WEEK_BASED_YEAR),
|
||||
return Math.subtractExact(temporal2.getLong(WEEK_BASED_YEAR),
|
||||
temporal1.getLong(WEEK_BASED_YEAR));
|
||||
case QUARTER_YEARS:
|
||||
return temporal1.until(temporal2, MONTHS) / 3;
|
||||
|
|
|
@ -55,7 +55,6 @@ import java.util.Objects;
|
|||
import org.threeten.bp.DateTimeException;
|
||||
import org.threeten.bp.chrono.Chronology;
|
||||
import org.threeten.bp.format.ResolverStyle;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
|
||||
/**
|
||||
* A set of date fields that provide access to Julian Days.
|
||||
|
@ -245,7 +244,7 @@ public final class JulianFields {
|
|||
if (!range().isValidValue(newValue)) {
|
||||
throw new DateTimeException("Invalid value: " + name + " " + newValue);
|
||||
}
|
||||
return (R) dateTime.with(EPOCH_DAY, Jdk8Methods.safeSubtract(newValue, offset));
|
||||
return (R) dateTime.with(EPOCH_DAY, Math.subtractExact(newValue, offset));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -260,7 +259,7 @@ public final class JulianFields {
|
|||
TemporalAccessor partialTemporal, ResolverStyle resolverStyle) {
|
||||
long value = fieldValues.remove(this);
|
||||
Chronology chrono = Chronology.from(partialTemporal);
|
||||
return chrono.dateEpochDay(Jdk8Methods.safeSubtract(value, offset));
|
||||
return chrono.dateEpochDay(Math.subtractExact(value, offset));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
|
@ -68,7 +68,6 @@ import org.threeten.bp.Year;
|
|||
import org.threeten.bp.chrono.ChronoLocalDate;
|
||||
import org.threeten.bp.chrono.Chronology;
|
||||
import org.threeten.bp.format.ResolverStyle;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
|
||||
/**
|
||||
* Localized definitions of the day-of-week, week-of-month and week-of-year fields.
|
||||
|
@ -642,7 +641,7 @@ public final class WeekFields implements Serializable {
|
|||
// Offset the ISO DOW by the start of this week
|
||||
int sow = weekDef.getFirstDayOfWeek().getValue();
|
||||
int isoDow = temporal.get(ChronoField.DAY_OF_WEEK);
|
||||
int dow = Jdk8Methods.floorMod(isoDow - sow, 7) + 1;
|
||||
int dow = Math.floorMod(isoDow - sow, 7) + 1;
|
||||
|
||||
if (rangeUnit == ChronoUnit.WEEKS) {
|
||||
return dow;
|
||||
|
@ -665,7 +664,7 @@ public final class WeekFields implements Serializable {
|
|||
|
||||
private int localizedDayOfWeek(TemporalAccessor temporal, int sow) {
|
||||
int isoDow = temporal.get(DAY_OF_WEEK);
|
||||
return Jdk8Methods.floorMod(isoDow - sow, 7) + 1;
|
||||
return Math.floorMod(isoDow - sow, 7) + 1;
|
||||
}
|
||||
|
||||
private long localizedWeekOfMonth(TemporalAccessor temporal, int dow) {
|
||||
|
@ -683,7 +682,7 @@ public final class WeekFields implements Serializable {
|
|||
private int localizedWOWBY(TemporalAccessor temporal) {
|
||||
int sow = weekDef.getFirstDayOfWeek().getValue();
|
||||
int isoDow = temporal.get(DAY_OF_WEEK);
|
||||
int dow = Jdk8Methods.floorMod(isoDow - sow, 7) + 1;
|
||||
int dow = Math.floorMod(isoDow - sow, 7) + 1;
|
||||
long woy = localizedWeekOfYear(temporal, dow);
|
||||
if (woy == 0) {
|
||||
ChronoLocalDate previous = Chronology.from(temporal).date(temporal).minus(1, ChronoUnit.WEEKS);
|
||||
|
@ -703,7 +702,7 @@ public final class WeekFields implements Serializable {
|
|||
private int localizedWBY(TemporalAccessor temporal) {
|
||||
int sow = weekDef.getFirstDayOfWeek().getValue();
|
||||
int isoDow = temporal.get(DAY_OF_WEEK);
|
||||
int dow = Jdk8Methods.floorMod(isoDow - sow, 7) + 1;
|
||||
int dow = Math.floorMod(isoDow - sow, 7) + 1;
|
||||
int year = temporal.get(YEAR);
|
||||
long woy = localizedWeekOfYear(temporal, dow);
|
||||
if (woy == 0) {
|
||||
|
@ -729,7 +728,7 @@ public final class WeekFields implements Serializable {
|
|||
*/
|
||||
private int startOfWeekOffset(int day, int dow) {
|
||||
// offset of first day corresponding to the day of week in first 7 days (zero origin)
|
||||
int weekStart = Jdk8Methods.floorMod(day - dow, 7);
|
||||
int weekStart = Math.floorMod(day - dow, 7);
|
||||
int offset = -weekStart;
|
||||
if (weekStart + 1 > weekDef.getMinimalDaysInFirstWeek()) {
|
||||
// The previous week has the minimum days in the current month to be a 'week'
|
||||
|
@ -795,7 +794,7 @@ public final class WeekFields implements Serializable {
|
|||
if (rangeUnit == WEEKS) { // day-of-week
|
||||
final long value = fieldValues.remove(this);
|
||||
int localDow = range.checkValidIntValue(value, this);
|
||||
int isoDow = Jdk8Methods.floorMod((sow - 1) + (localDow - 1), 7) + 1;
|
||||
int isoDow = Math.floorMod((sow - 1) + (localDow - 1), 7) + 1;
|
||||
fieldValues.put(DAY_OF_WEEK, (long) isoDow);
|
||||
return null;
|
||||
}
|
||||
|
@ -810,7 +809,7 @@ public final class WeekFields implements Serializable {
|
|||
}
|
||||
Chronology chrono = Chronology.from(partialTemporal); // defaults to ISO
|
||||
int isoDow = DAY_OF_WEEK.checkValidIntValue(fieldValues.get(DAY_OF_WEEK));
|
||||
int dow = Jdk8Methods.floorMod(isoDow - sow, 7) + 1;
|
||||
int dow = Math.floorMod(isoDow - sow, 7) + 1;
|
||||
final int wby = range().checkValidIntValue(fieldValues.get(this), this);
|
||||
ChronoLocalDate date;
|
||||
long days;
|
||||
|
@ -844,7 +843,7 @@ public final class WeekFields implements Serializable {
|
|||
return null;
|
||||
}
|
||||
int isoDow = DAY_OF_WEEK.checkValidIntValue(fieldValues.get(DAY_OF_WEEK));
|
||||
int dow = Jdk8Methods.floorMod(isoDow - sow, 7) + 1;
|
||||
int dow = Math.floorMod(isoDow - sow, 7) + 1;
|
||||
int year = YEAR.checkValidIntValue(fieldValues.get(YEAR));
|
||||
Chronology chrono = Chronology.from(partialTemporal); // defaults to ISO
|
||||
if (rangeUnit == MONTHS) { // week-of-month
|
||||
|
@ -976,7 +975,7 @@ public final class WeekFields implements Serializable {
|
|||
// Offset the ISO DOW by the start of this week
|
||||
int sow = weekDef.getFirstDayOfWeek().getValue();
|
||||
int isoDow = temporal.get(ChronoField.DAY_OF_WEEK);
|
||||
int dow = Jdk8Methods.floorMod(isoDow - sow, 7) + 1;
|
||||
int dow = Math.floorMod(isoDow - sow, 7) + 1;
|
||||
|
||||
int offset = startOfWeekOffset(temporal.get(field), dow);
|
||||
ValueRange fieldRange = temporal.range(field);
|
||||
|
@ -987,7 +986,7 @@ public final class WeekFields implements Serializable {
|
|||
private ValueRange rangeWOWBY(TemporalAccessor temporal) {
|
||||
int sow = weekDef.getFirstDayOfWeek().getValue();
|
||||
int isoDow = temporal.get(DAY_OF_WEEK);
|
||||
int dow = Jdk8Methods.floorMod(isoDow - sow, 7) + 1;
|
||||
int dow = Math.floorMod(isoDow - sow, 7) + 1;
|
||||
long woy = localizedWeekOfYear(temporal, dow);
|
||||
if (woy == 0) {
|
||||
return rangeWOWBY(Chronology.from(temporal).date(temporal).minus(2, ChronoUnit.WEEKS));
|
||||
|
|
|
@ -59,7 +59,6 @@ import org.threeten.bp.LocalDate;
|
|||
import org.threeten.bp.LocalDateTime;
|
||||
import org.threeten.bp.Year;
|
||||
import org.threeten.bp.ZoneOffset;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
|
||||
/**
|
||||
* The rules describing how the zone offset varies through the year and historically.
|
||||
|
@ -479,7 +478,7 @@ final class StandardZoneRules extends ZoneRules implements Serializable {
|
|||
private int findYear(long epochSecond, ZoneOffset offset) {
|
||||
// inline for performance
|
||||
long localSecond = epochSecond + offset.getTotalSeconds();
|
||||
long localEpochDay = Jdk8Methods.floorDiv(localSecond, 86400);
|
||||
long localEpochDay = Math.floorDiv(localSecond, 86400);
|
||||
return LocalDate.ofEpochDay(localEpochDay).getYear();
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,6 @@ import org.threeten.bp.LocalTime;
|
|||
import org.threeten.bp.Month;
|
||||
import org.threeten.bp.ZoneOffset;
|
||||
import org.threeten.bp.chrono.IsoChronology;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
|
||||
/**
|
||||
* A rule expressing how to create a transition.
|
||||
|
@ -422,9 +421,9 @@ public final class ZoneOffsetTransitionRule implements Serializable {
|
|||
buf.append(time);
|
||||
} else {
|
||||
long timeOfDaysMins = time.toSecondOfDay() / 60 + adjustDays * 24 * 60;
|
||||
appendZeroPad(buf, Jdk8Methods.floorDiv(timeOfDaysMins, 60));
|
||||
appendZeroPad(buf, Math.floorDiv(timeOfDaysMins, 60));
|
||||
buf.append(':');
|
||||
appendZeroPad(buf, Jdk8Methods.floorMod(timeOfDaysMins, 60));
|
||||
appendZeroPad(buf, Math.floorMod(timeOfDaysMins, 60));
|
||||
}
|
||||
buf.append(" ").append(timeDefinition)
|
||||
.append(", standard offset ").append(standardOffset)
|
||||
|
|
|
@ -53,7 +53,6 @@ import org.teavm.junit.TeaVMTestRunner;
|
|||
import org.teavm.junit.TestPlatform;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.threeten.bp.jdk8.Jdk8Methods;
|
||||
|
||||
/**
|
||||
* Test.
|
||||
|
@ -78,7 +77,7 @@ public class TestDateTimesImplementation {
|
|||
|
||||
@Test(dataProvider = "safeAddIntProvider")
|
||||
public void test_safeAddInt(int a, int b, int expected) {
|
||||
assertEquals(Jdk8Methods.safeAdd(a, b), expected);
|
||||
assertEquals(Math.addExact(a, b), expected);
|
||||
}
|
||||
|
||||
@DataProvider(name = "safeAddIntProviderOverflow")
|
||||
|
@ -93,7 +92,7 @@ public class TestDateTimesImplementation {
|
|||
|
||||
@Test(dataProvider = "safeAddIntProviderOverflow", expectedExceptions = ArithmeticException.class)
|
||||
public void test_safeAddInt_overflow(int a, int b) {
|
||||
Jdk8Methods.safeAdd(a, b);
|
||||
Math.addExact(a, b);
|
||||
}
|
||||
|
||||
@DataProvider(name = "safeAddLongProvider")
|
||||
|
@ -109,7 +108,7 @@ public class TestDateTimesImplementation {
|
|||
|
||||
@Test(dataProvider = "safeAddLongProvider")
|
||||
public void test_safeAddLong(long a, long b, long expected) {
|
||||
assertEquals(Jdk8Methods.safeAdd(a, b), expected);
|
||||
assertEquals(Math.addExact(a, b), expected);
|
||||
}
|
||||
|
||||
@DataProvider(name = "safeAddLongProviderOverflow")
|
||||
|
@ -124,7 +123,7 @@ public class TestDateTimesImplementation {
|
|||
|
||||
@Test(dataProvider = "safeAddLongProviderOverflow", expectedExceptions = ArithmeticException.class)
|
||||
public void test_safeAddLong_overflow(long a, long b) {
|
||||
Jdk8Methods.safeAdd(a, b);
|
||||
Math.addExact(a, b);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -143,7 +142,7 @@ public class TestDateTimesImplementation {
|
|||
|
||||
@Test(dataProvider = "safeSubtractIntProvider")
|
||||
public void test_safeSubtractInt(int a, int b, int expected) {
|
||||
assertEquals(Jdk8Methods.safeSubtract(a, b), expected);
|
||||
assertEquals(Math.subtractExact(a, b), expected);
|
||||
}
|
||||
|
||||
@DataProvider(name = "safeSubtractIntProviderOverflow")
|
||||
|
@ -158,7 +157,7 @@ public class TestDateTimesImplementation {
|
|||
|
||||
@Test(dataProvider = "safeSubtractIntProviderOverflow", expectedExceptions = ArithmeticException.class)
|
||||
public void test_safeSubtractInt_overflow(int a, int b) {
|
||||
Jdk8Methods.safeSubtract(a, b);
|
||||
Math.subtractExact(a, b);
|
||||
}
|
||||
|
||||
@DataProvider(name = "safeSubtractLongProvider")
|
||||
|
@ -174,7 +173,7 @@ public class TestDateTimesImplementation {
|
|||
|
||||
@Test(dataProvider = "safeSubtractLongProvider")
|
||||
public void test_safeSubtractLong(long a, long b, long expected) {
|
||||
assertEquals(Jdk8Methods.safeSubtract(a, b), expected);
|
||||
assertEquals(Math.subtractExact(a, b), expected);
|
||||
}
|
||||
|
||||
@DataProvider(name = "safeSubtractLongProviderOverflow")
|
||||
|
@ -189,7 +188,7 @@ public class TestDateTimesImplementation {
|
|||
|
||||
@Test(dataProvider = "safeSubtractLongProviderOverflow", expectedExceptions = ArithmeticException.class)
|
||||
public void test_safeSubtractLong_overflow(long a, long b) {
|
||||
Jdk8Methods.safeSubtract(a, b);
|
||||
Math.subtractExact(a, b);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -214,7 +213,7 @@ public class TestDateTimesImplementation {
|
|||
|
||||
@Test(dataProvider = "safeMultiplyIntProvider")
|
||||
public void test_safeMultiplyInt(int a, int b, int expected) {
|
||||
assertEquals(Jdk8Methods.safeMultiply(a, b), expected);
|
||||
assertEquals(Math.multiplyExact(a, b), expected);
|
||||
}
|
||||
|
||||
@DataProvider(name = "safeMultiplyIntProviderOverflow")
|
||||
|
@ -231,7 +230,7 @@ public class TestDateTimesImplementation {
|
|||
|
||||
@Test(dataProvider = "safeMultiplyIntProviderOverflow", expectedExceptions = ArithmeticException.class)
|
||||
public void test_safeMultiplyInt_overflow(int a, int b) {
|
||||
Jdk8Methods.safeMultiply(a, b);
|
||||
Math.multiplyExact(a, b);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -255,7 +254,7 @@ public class TestDateTimesImplementation {
|
|||
|
||||
@Test(dataProvider = "safeMultiplyLongProvider")
|
||||
public void test_safeMultiplyLong(long a, int b, long expected) {
|
||||
assertEquals(Jdk8Methods.safeMultiply(a, b), expected);
|
||||
assertEquals(Math.multiplyExact(a, b), expected);
|
||||
}
|
||||
|
||||
@DataProvider(name = "safeMultiplyLongProviderOverflow")
|
||||
|
@ -271,7 +270,7 @@ public class TestDateTimesImplementation {
|
|||
|
||||
@Test(dataProvider = "safeMultiplyLongProviderOverflow", expectedExceptions = ArithmeticException.class)
|
||||
public void test_safeMultiplyLong_overflow(long a, int b) {
|
||||
Jdk8Methods.safeMultiply(a, b);
|
||||
Math.multiplyExact(a, b);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -294,7 +293,7 @@ public class TestDateTimesImplementation {
|
|||
|
||||
@Test(dataProvider = "safeMultiplyLongLongProvider")
|
||||
public void test_safeMultiplyLongLong(long a, long b, long expected) {
|
||||
assertEquals(Jdk8Methods.safeMultiply(a, b), expected);
|
||||
assertEquals(Math.multiplyExact(a, b), expected);
|
||||
}
|
||||
|
||||
@DataProvider(name = "safeMultiplyLongLongProviderOverflow")
|
||||
|
@ -312,7 +311,7 @@ public class TestDateTimesImplementation {
|
|||
@Test(dataProvider = "safeMultiplyLongLongProviderOverflow", expectedExceptions = ArithmeticException.class)
|
||||
@SkipPlatform({TestPlatform.C, TestPlatform.WEBASSEMBLY, TestPlatform.WASI})
|
||||
public void test_safeMultiplyLongLong_overflow(long a, long b) {
|
||||
Jdk8Methods.safeMultiply(a, b);
|
||||
Math.multiplyExact(a, b);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -333,7 +332,7 @@ public class TestDateTimesImplementation {
|
|||
|
||||
@Test(dataProvider = "safeToIntProvider")
|
||||
public void test_safeToInt(long l) {
|
||||
assertEquals(Jdk8Methods.safeToInt(l), l);
|
||||
assertEquals(Math.toIntExact(l), l);
|
||||
}
|
||||
|
||||
@DataProvider(name = "safeToIntProviderOverflow")
|
||||
|
@ -348,7 +347,7 @@ public class TestDateTimesImplementation {
|
|||
|
||||
@Test(dataProvider = "safeToIntProviderOverflow", expectedExceptions = ArithmeticException.class)
|
||||
public void test_safeToInt_overflow(long l) {
|
||||
Jdk8Methods.safeToInt(l);
|
||||
Math.toIntExact(l);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -432,13 +431,13 @@ public class TestDateTimesImplementation {
|
|||
|
||||
@Test(dataProvider = "FloorDiv")
|
||||
public void test_floorDiv_long(long a, int b, long expected) {
|
||||
assertEquals(Jdk8Methods.floorDiv(a, b), expected);
|
||||
assertEquals(Math.floorDiv(a, b), expected);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "FloorDiv")
|
||||
public void test_floorDiv_int(long a, int b, long expected) {
|
||||
if (a <= Integer.MAX_VALUE && a >= Integer.MIN_VALUE) {
|
||||
assertEquals(Jdk8Methods.floorDiv((int) a, b), (int) expected);
|
||||
assertEquals(Math.floorDiv((int) a, b), (int) expected);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -462,18 +461,18 @@ public class TestDateTimesImplementation {
|
|||
|
||||
@Test(dataProvider = "FloorMod")
|
||||
public void test_floorMod_long(long a, long b, int expected) {
|
||||
assertEquals(Jdk8Methods.floorMod(a, b), expected);
|
||||
assertEquals(Math.floorMod(a, b), expected);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "FloorMod")
|
||||
public void test_floorMod_long(long a, int b, int expected) {
|
||||
assertEquals(Jdk8Methods.floorMod(a, b), expected);
|
||||
assertEquals(Math.floorMod(a, b), expected);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "FloorMod")
|
||||
public void test_floorMod_int(long a, int b, int expected) {
|
||||
if (a <= Integer.MAX_VALUE && a >= Integer.MIN_VALUE) {
|
||||
assertEquals(Jdk8Methods.floorMod((int) a, b), expected);
|
||||
assertEquals(Math.floorMod((int) a, b), expected);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user