java.time: remove jdk7 hacks

This commit is contained in:
Alexey Andreev 2021-03-17 11:54:46 +03:00
parent 3513bacc2e
commit 051c3bb227
59 changed files with 508 additions and 1099 deletions

View File

@ -35,6 +35,7 @@ import static org.threeten.bp.LocalTime.NANOS_PER_MINUTE;
import static org.threeten.bp.LocalTime.NANOS_PER_SECOND; import static org.threeten.bp.LocalTime.NANOS_PER_SECOND;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects;
import java.util.TimeZone; import java.util.TimeZone;
import org.threeten.bp.jdk8.Jdk8Methods; import org.threeten.bp.jdk8.Jdk8Methods;
@ -153,7 +154,7 @@ public abstract class Clock {
* @return a clock that uses the best available system clock in the specified zone, not null * @return a clock that uses the best available system clock in the specified zone, not null
*/ */
public static Clock system(ZoneId zone) { public static Clock system(ZoneId zone) {
Jdk8Methods.requireNonNull(zone, "zone"); Objects.requireNonNull(zone, "zone");
return new SystemClock(zone); return new SystemClock(zone);
} }
@ -236,8 +237,8 @@ public abstract class Clock {
* @throws ArithmeticException if the duration is too large to be represented as nanos * @throws ArithmeticException if the duration is too large to be represented as nanos
*/ */
public static Clock tick(Clock baseClock, Duration tickDuration) { public static Clock tick(Clock baseClock, Duration tickDuration) {
Jdk8Methods.requireNonNull(baseClock, "baseClock"); Objects.requireNonNull(baseClock, "baseClock");
Jdk8Methods.requireNonNull(tickDuration, "tickDuration"); Objects.requireNonNull(tickDuration, "tickDuration");
if (tickDuration.isNegative()) { if (tickDuration.isNegative()) {
throw new IllegalArgumentException("Tick duration must not be negative"); throw new IllegalArgumentException("Tick duration must not be negative");
} }
@ -271,8 +272,8 @@ public abstract class Clock {
* @return a clock that always returns the same instant, not null * @return a clock that always returns the same instant, not null
*/ */
public static Clock fixed(Instant fixedInstant, ZoneId zone) { public static Clock fixed(Instant fixedInstant, ZoneId zone) {
Jdk8Methods.requireNonNull(fixedInstant, "fixedInstant"); Objects.requireNonNull(fixedInstant, "fixedInstant");
Jdk8Methods.requireNonNull(zone, "zone"); Objects.requireNonNull(zone, "zone");
return new FixedClock(fixedInstant, zone); return new FixedClock(fixedInstant, zone);
} }
@ -297,8 +298,8 @@ public abstract class Clock {
* @return a clock based on the base clock with the duration added, not null * @return a clock based on the base clock with the duration added, not null
*/ */
public static Clock offset(Clock baseClock, Duration offsetDuration) { public static Clock offset(Clock baseClock, Duration offsetDuration) {
Jdk8Methods.requireNonNull(baseClock, "baseClock"); Objects.requireNonNull(baseClock, "baseClock");
Jdk8Methods.requireNonNull(offsetDuration, "offsetDuration"); Objects.requireNonNull(offsetDuration, "offsetDuration");
if (offsetDuration.equals(Duration.ZERO)) { if (offsetDuration.equals(Duration.ZERO)) {
return baseClock; return baseClock;
} }

View File

@ -1,269 +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.
*/
package org.threeten.bp;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
/**
* A set of utilities to assist in bridging the gap to Java 8.
* <p>
* This class is not found in Java SE 8 but provides methods that are.
*/
public final class DateTimeUtils {
/**
* Restricted constructor.
*/
private DateTimeUtils() {
}
//-----------------------------------------------------------------------
/**
* Converts a {@code java.util.Date} to an {@code Instant}.
*
* @param utilDate the util date, not null
* @return the instant, not null
*/
public static Instant toInstant(Date utilDate) {
return Instant.ofEpochMilli(utilDate.getTime());
}
/**
* Converts an {@code Instant} to a {@code java.util.Date}.
* <p>
* Fractions of the instant smaller than milliseconds will be dropped.
*
* @param instant the instant, not null
* @return the util date, not null
* @throws IllegalArgumentException if the conversion fails
*/
public static Date toDate(Instant instant) {
try {
return new Date(instant.toEpochMilli());
} catch (ArithmeticException ex) {
throw new IllegalArgumentException(ex);
}
}
//-----------------------------------------------------------------------
/**
* Converts a {@code Calendar} to an {@code Instant}.
*
* @param calendar the calendar, not null
* @return the instant, not null
*/
public static Instant toInstant(Calendar calendar) {
return Instant.ofEpochMilli(calendar.getTimeInMillis());
}
/**
* Converts a {@code Calendar} to a {@code ZonedDateTime}.
* <p>
* Note that {@code GregorianCalendar} supports a Julian-Gregorian cutover
* date and {@code ZonedDateTime} does not so some differences will occur.
*
* @param calendar the calendar, not null
* @return the instant, not null
*/
public static ZonedDateTime toZonedDateTime(Calendar calendar) {
Instant instant = Instant.ofEpochMilli(calendar.getTimeInMillis());
ZoneId zone = toZoneId(calendar.getTimeZone());
return ZonedDateTime.ofInstant(instant, zone);
}
/**
* Converts a {@code ZonedDateTime} to a {@code Calendar}.
* <p>
* The resulting {@code GregorianCalendar} is pure Gregorian and uses
* ISO week definitions, starting on Monday and with 4 days in a minimal week.
* <p>
* Fractions of the instant smaller than milliseconds will be dropped.
*
* @param zdt the zoned date-time, not null
* @return the calendar, not null
* @throws IllegalArgumentException if the conversion fails
*/
public static GregorianCalendar toGregorianCalendar(ZonedDateTime zdt) {
TimeZone zone = toTimeZone(zdt.getZone());
GregorianCalendar cal = new GregorianCalendar(zone);
cal.setGregorianChange(new Date(Long.MIN_VALUE));
cal.setFirstDayOfWeek(Calendar.MONDAY);
cal.setMinimalDaysInFirstWeek(4);
try {
cal.setTimeInMillis(zdt.toInstant().toEpochMilli());
} catch (ArithmeticException ex) {
throw new IllegalArgumentException(ex);
}
return cal;
}
//-----------------------------------------------------------------------
/**
* Converts a {@code TimeZone} to a {@code ZoneId}.
*
* @param timeZone the time-zone, not null
* @return the zone, not null
*/
public static ZoneId toZoneId(TimeZone timeZone) {
return ZoneId.of(timeZone.getID(), ZoneId.SHORT_IDS);
}
/**
* Converts a {@code ZoneId} to a {@code TimeZone}.
*
* @param zoneId the zone, not null
* @return the time-zone, not null
*/
public static TimeZone toTimeZone(ZoneId zoneId) {
String tzid = zoneId.getId();
if (tzid.startsWith("+") || tzid.startsWith("-")) {
tzid = "GMT" + tzid;
} else if (tzid.equals("Z")) {
tzid = "UTC";
}
return TimeZone.getTimeZone(tzid);
}
//-----------------------------------------------------------------------
/**
* Converts a {@code java.sql.Date} to a {@code LocalDate}.
*
* @param sqlDate the SQL date, not null
* @return the local date, not null
*/
@SuppressWarnings("deprecation")
public static LocalDate toLocalDate(java.sql.Date sqlDate) {
return LocalDate.of(sqlDate.getYear() + 1900, sqlDate.getMonth() + 1, sqlDate.getDate());
}
/**
* Converts a {@code LocalDate} to a {@code java.sql.Date}.
*
* @param date the local date, not null
* @return the SQL date, not null
*/
@SuppressWarnings("deprecation")
public static java.sql.Date toSqlDate(LocalDate date) {
return new java.sql.Date(date.getYear() - 1900, date.getMonthValue() -1, date.getDayOfMonth());
}
//-----------------------------------------------------------------------
/**
* Converts a {@code java.sql.Time} to a {@code LocalTime}.
*
* @param sqlTime the SQL time, not null
* @return the local time, not null
*/
@SuppressWarnings("deprecation")
public static LocalTime toLocalTime(java.sql.Time sqlTime) {
return LocalTime.of(sqlTime.getHours(), sqlTime.getMinutes(), sqlTime.getSeconds());
}
/**
* Converts a {@code LocalTime} to a {@code java.sql.Time}.
*
* @param time the local time, not null
* @return the SQL time, not null
*/
@SuppressWarnings("deprecation")
public static java.sql.Time toSqlTime(LocalTime time) {
return new java.sql.Time(time.getHour(), time.getMinute(), time.getSecond());
}
//-----------------------------------------------------------------------
/**
* Converts a {@code LocalDateTime} to a {@code java.sql.Timestamp}.
*
* @param dateTime the local date-time, not null
* @return the SQL timestamp, not null
*/
@SuppressWarnings("deprecation")
public static Timestamp toSqlTimestamp(LocalDateTime dateTime) {
return new Timestamp(
dateTime.getYear() - 1900,
dateTime.getMonthValue() - 1,
dateTime.getDayOfMonth(),
dateTime.getHour(),
dateTime.getMinute(),
dateTime.getSecond(),
dateTime.getNano());
}
/**
* Converts a {@code java.sql.Timestamp} to a {@code LocalDateTime}.
*
* @param sqlTimestamp the SQL timestamp, not null
* @return the local date-time, not null
*/
@SuppressWarnings("deprecation")
public static LocalDateTime toLocalDateTime(Timestamp sqlTimestamp) {
return LocalDateTime.of(
sqlTimestamp.getYear() + 1900,
sqlTimestamp.getMonth() + 1,
sqlTimestamp.getDate(),
sqlTimestamp.getHours(),
sqlTimestamp.getMinutes(),
sqlTimestamp.getSeconds(),
sqlTimestamp.getNanos());
}
/**
* Converts an {@code Instant} to a {@code java.sql.Timestamp}.
*
* @param instant the instant, not null
* @return the SQL timestamp, not null
*/
public static Timestamp toSqlTimestamp(Instant instant) {
try {
Timestamp ts = new Timestamp(instant.getEpochSecond() * 1000);
ts.setNanos(instant.getNano());
return ts;
} catch (ArithmeticException ex) {
throw new IllegalArgumentException(ex);
}
}
/**
* Converts a {@code java.sql.Timestamp} to an {@code Instant}.
*
* @param sqlTimestamp the SQL timestamp, not null
* @return the instant, not null
*/
public static Instant toInstant(Timestamp sqlTimestamp) {
return Instant.ofEpochSecond(sqlTimestamp.getTime() / 1000, sqlTimestamp.getNanos());
}
}

View File

@ -51,6 +51,7 @@ import java.math.RoundingMode;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -295,7 +296,7 @@ public final class Duration
* @throws ArithmeticException if a numeric overflow occurs * @throws ArithmeticException if a numeric overflow occurs
*/ */
public static Duration from(TemporalAmount amount) { public static Duration from(TemporalAmount amount) {
Jdk8Methods.requireNonNull(amount, "amount"); Objects.requireNonNull(amount, "amount");
Duration duration = ZERO; Duration duration = ZERO;
for (TemporalUnit unit : amount.getUnits()) { for (TemporalUnit unit : amount.getUnits()) {
duration = duration.plus(amount.get(unit), unit); duration = duration.plus(amount.get(unit), unit);
@ -338,9 +339,7 @@ public final class Duration
Temporal adjustedEnd = endExclusive.with(NANO_OF_SECOND, startNos); Temporal adjustedEnd = endExclusive.with(NANO_OF_SECOND, startNos);
secs = startInclusive.until(adjustedEnd, SECONDS);; secs = startInclusive.until(adjustedEnd, SECONDS);;
} }
} catch (DateTimeException ex2) { } catch (DateTimeException | ArithmeticException ex2) {
// ignore and only use seconds
} catch (ArithmeticException ex2) {
// ignore and only use seconds // ignore and only use seconds
} }
} }
@ -393,7 +392,7 @@ public final class Duration
* @throws DateTimeParseException if the text cannot be parsed to a duration * @throws DateTimeParseException if the text cannot be parsed to a duration
*/ */
public static Duration parse(CharSequence text) { public static Duration parse(CharSequence text) {
Jdk8Methods.requireNonNull(text, "text"); Objects.requireNonNull(text, "text");
Matcher matcher = PATTERN.matcher(text); Matcher matcher = PATTERN.matcher(text);
if (matcher.matches()) { if (matcher.matches()) {
// check for letter T but no time sections // check for letter T but no time sections
@ -433,10 +432,8 @@ public final class Duration
} }
long val = Long.parseLong(parsed); long val = Long.parseLong(parsed);
return Jdk8Methods.safeMultiply(val, multiplier); return Jdk8Methods.safeMultiply(val, multiplier);
} catch (NumberFormatException ex) { } catch (NumberFormatException | ArithmeticException ex) {
throw (DateTimeParseException) new DateTimeParseException("Text cannot be parsed to a Duration: " + errorText, text, 0).initCause(ex); throw new DateTimeParseException("Text cannot be parsed to a Duration: " + errorText, text, 0, ex);
} catch (ArithmeticException ex) {
throw (DateTimeParseException) new DateTimeParseException("Text cannot be parsed to a Duration: " + errorText, text, 0).initCause(ex);
} }
} }
@ -448,10 +445,8 @@ public final class Duration
try { try {
parsed = (parsed + "000000000").substring(0, 9); parsed = (parsed + "000000000").substring(0, 9);
return Integer.parseInt(parsed) * negate; return Integer.parseInt(parsed) * negate;
} catch (NumberFormatException ex) { } catch (NumberFormatException | ArithmeticException ex) {
throw (DateTimeParseException) new DateTimeParseException("Text cannot be parsed to a Duration: fraction", text, 0).initCause(ex); throw new DateTimeParseException("Text cannot be parsed to a Duration: fraction", text, 0, ex);
} catch (ArithmeticException ex) {
throw (DateTimeParseException) new DateTimeParseException("Text cannot be parsed to a Duration: fraction", text, 0).initCause(ex);
} }
} }
@ -633,7 +628,7 @@ public final class Duration
* @throws ArithmeticException if numeric overflow occurs * @throws ArithmeticException if numeric overflow occurs
*/ */
public Duration plus(long amountToAdd, TemporalUnit unit) { public Duration plus(long amountToAdd, TemporalUnit unit) {
Jdk8Methods.requireNonNull(unit, "unit"); Objects.requireNonNull(unit, "unit");
if (unit == DAYS) { if (unit == DAYS) {
return plus(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_DAY), 0); return plus(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_DAY), 0);
} }
@ -1131,7 +1126,7 @@ public final class Duration
*/ */
@Override @Override
public int compareTo(Duration otherDuration) { public int compareTo(Duration otherDuration) {
int cmp = Jdk8Methods.compareLongs(seconds, otherDuration.seconds); int cmp = Long.compare(seconds, otherDuration.seconds);
if (cmp != 0) { if (cmp != 0) {
return cmp; return cmp;
} }

View File

@ -47,10 +47,10 @@ import java.io.IOException;
import java.io.InvalidObjectException; import java.io.InvalidObjectException;
import java.io.ObjectStreamException; import java.io.ObjectStreamException;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects;
import org.threeten.bp.format.DateTimeFormatter; import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.format.DateTimeParseException; import org.threeten.bp.format.DateTimeParseException;
import org.threeten.bp.jdk8.DefaultInterfaceTemporalAccessor;
import org.threeten.bp.jdk8.Jdk8Methods; import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField; import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.ChronoUnit; import org.threeten.bp.temporal.ChronoUnit;
@ -155,8 +155,7 @@ import org.threeten.bp.temporal.ValueRange;
* This class is immutable and thread-safe. * This class is immutable and thread-safe.
*/ */
public final class Instant public final class Instant
extends DefaultInterfaceTemporalAccessor implements Temporal, TemporalAdjuster, Comparable<Instant>, Serializable, TemporalAccessor {
implements Temporal, TemporalAdjuster, Comparable<Instant>, Serializable {
/** /**
* Constant for the 1970-01-01T00:00:00Z epoch instant. * Constant for the 1970-01-01T00:00:00Z epoch instant.
@ -257,7 +256,7 @@ public final class Instant
* @return the current instant, not null * @return the current instant, not null
*/ */
public static Instant now(Clock clock) { public static Instant now(Clock clock) {
Jdk8Methods.requireNonNull(clock, "clock"); Objects.requireNonNull(clock, "clock");
return clock.instant(); return clock.instant();
} }
@ -459,7 +458,7 @@ public final class Instant
*/ */
@Override // override for Javadoc @Override // override for Javadoc
public ValueRange range(TemporalField field) { public ValueRange range(TemporalField field) {
return super.range(field); return Temporal.super.range(field);
} }
/** /**
@ -1084,7 +1083,7 @@ public final class Instant
*/ */
@Override @Override
public int compareTo(Instant otherInstant) { public int compareTo(Instant otherInstant) {
int cmp = Jdk8Methods.compareLongs(seconds, otherInstant.seconds); int cmp = Long.compare(seconds, otherInstant.seconds);
if (cmp != 0) { if (cmp != 0) {
return cmp; return cmp;
} }

View File

@ -50,6 +50,7 @@ import java.io.IOException;
import java.io.InvalidObjectException; import java.io.InvalidObjectException;
import java.io.ObjectStreamException; import java.io.ObjectStreamException;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects;
import org.threeten.bp.chrono.ChronoLocalDate; import org.threeten.bp.chrono.ChronoLocalDate;
import org.threeten.bp.chrono.Era; import org.threeten.bp.chrono.Era;
@ -111,15 +112,6 @@ public final class LocalDate
* This could be used by an application as a "far future" date. * This could be used by an application as a "far future" date.
*/ */
public static final LocalDate MAX = LocalDate.of(Year.MAX_VALUE, 12, 31); public static final LocalDate MAX = LocalDate.of(Year.MAX_VALUE, 12, 31);
/**
* Simulate JDK 8 method reference LocalDate::from.
*/
public static final TemporalQuery<LocalDate> FROM = new TemporalQuery<LocalDate>() {
@Override
public LocalDate queryFrom(TemporalAccessor temporal) {
return LocalDate.from(temporal);
}
};
/** /**
* Serialization version. * Serialization version.
@ -192,7 +184,7 @@ public final class LocalDate
* @return the current date, not null * @return the current date, not null
*/ */
public static LocalDate now(Clock clock) { public static LocalDate now(Clock clock) {
Jdk8Methods.requireNonNull(clock, "clock"); Objects.requireNonNull(clock, "clock");
final Instant now = clock.instant(); // called once final Instant now = clock.instant(); // called once
ZoneOffset offset = clock.getZone().getRules().getOffset(now); ZoneOffset offset = clock.getZone().getRules().getOffset(now);
long epochSec = now.getEpochSecond() + offset.getTotalSeconds(); // overflow caught later long epochSec = now.getEpochSecond() + offset.getTotalSeconds(); // overflow caught later
@ -215,7 +207,7 @@ public final class LocalDate
*/ */
public static LocalDate of(int year, Month month, int dayOfMonth) { public static LocalDate of(int year, Month month, int dayOfMonth) {
YEAR.checkValidValue(year); YEAR.checkValidValue(year);
Jdk8Methods.requireNonNull(month, "month"); Objects.requireNonNull(month, "month");
DAY_OF_MONTH.checkValidValue(dayOfMonth); DAY_OF_MONTH.checkValidValue(dayOfMonth);
return create(year, month, dayOfMonth); return create(year, month, dayOfMonth);
} }
@ -363,8 +355,8 @@ public final class LocalDate
* @throws DateTimeParseException if the text cannot be parsed * @throws DateTimeParseException if the text cannot be parsed
*/ */
public static LocalDate parse(CharSequence text, DateTimeFormatter formatter) { public static LocalDate parse(CharSequence text, DateTimeFormatter formatter) {
Jdk8Methods.requireNonNull(formatter, "formatter"); Objects.requireNonNull(formatter, "formatter");
return formatter.parse(text, LocalDate.FROM); return formatter.parse(text, LocalDate::from);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@ -1615,7 +1607,7 @@ public final class LocalDate
* @return the zoned date-time formed from this date and the earliest valid time for the zone, not null * @return the zoned date-time formed from this date and the earliest valid time for the zone, not null
*/ */
public ZonedDateTime atStartOfDay(ZoneId zone) { public ZonedDateTime atStartOfDay(ZoneId zone) {
Jdk8Methods.requireNonNull(zone, "zone"); Objects.requireNonNull(zone, "zone");
// need to handle case where there is a gap from 11:30 to 00:30 // need to handle case where there is a gap from 11:30 to 00:30
// standard ZDT factory would result in 01:00 rather than 00:30 // standard ZDT factory would result in 01:00 rather than 00:30
LocalDateTime ldt = atTime(LocalTime.MIDNIGHT); LocalDateTime ldt = atTime(LocalTime.MIDNIGHT);

View File

@ -47,6 +47,7 @@ import java.io.IOException;
import java.io.InvalidObjectException; import java.io.InvalidObjectException;
import java.io.ObjectStreamException; import java.io.ObjectStreamException;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects;
import org.threeten.bp.chrono.ChronoLocalDateTime; import org.threeten.bp.chrono.ChronoLocalDateTime;
import org.threeten.bp.format.DateTimeFormatter; import org.threeten.bp.format.DateTimeFormatter;
@ -112,20 +113,6 @@ public final class LocalDateTime
* This could be used by an application as a "far future" date-time. * This could be used by an application as a "far future" date-time.
*/ */
public static final LocalDateTime MAX = LocalDateTime.of(LocalDate.MAX, LocalTime.MAX); public static final LocalDateTime MAX = LocalDateTime.of(LocalDate.MAX, LocalTime.MAX);
/**
* Simulate JDK 8 method reference LocalDateTime::from.
*/
public static final TemporalQuery<LocalDateTime> FROM = new TemporalQuery<LocalDateTime>() {
@Override
public LocalDateTime queryFrom(TemporalAccessor temporal) {
return LocalDateTime.from(temporal);
}
};
/**
* Serialization version.
*/
private static final long serialVersionUID = 6207766400415563566L;
/** /**
* The date part. * The date part.
@ -179,7 +166,7 @@ public final class LocalDateTime
* @return the current date-time, not null * @return the current date-time, not null
*/ */
public static LocalDateTime now(Clock clock) { public static LocalDateTime now(Clock clock) {
Jdk8Methods.requireNonNull(clock, "clock"); Objects.requireNonNull(clock, "clock");
final Instant now = clock.instant(); // called once final Instant now = clock.instant(); // called once
ZoneOffset offset = clock.getZone().getRules().getOffset(now); ZoneOffset offset = clock.getZone().getRules().getOffset(now);
return ofEpochSecond(now.getEpochSecond(), now.getNano(), offset); return ofEpochSecond(now.getEpochSecond(), now.getNano(), offset);
@ -331,8 +318,8 @@ public final class LocalDateTime
* @return the local date-time, not null * @return the local date-time, not null
*/ */
public static LocalDateTime of(LocalDate date, LocalTime time) { public static LocalDateTime of(LocalDate date, LocalTime time) {
Jdk8Methods.requireNonNull(date, "date"); Objects.requireNonNull(date, "date");
Jdk8Methods.requireNonNull(time, "time"); Objects.requireNonNull(time, "time");
return new LocalDateTime(date, time); return new LocalDateTime(date, time);
} }
@ -351,8 +338,8 @@ public final class LocalDateTime
* @throws DateTimeException if the result exceeds the supported range * @throws DateTimeException if the result exceeds the supported range
*/ */
public static LocalDateTime ofInstant(Instant instant, ZoneId zone) { public static LocalDateTime ofInstant(Instant instant, ZoneId zone) {
Jdk8Methods.requireNonNull(instant, "instant"); Objects.requireNonNull(instant, "instant");
Jdk8Methods.requireNonNull(zone, "zone"); Objects.requireNonNull(zone, "zone");
ZoneRules rules = zone.getRules(); ZoneRules rules = zone.getRules();
ZoneOffset offset = rules.getOffset(instant); ZoneOffset offset = rules.getOffset(instant);
return ofEpochSecond(instant.getEpochSecond(), instant.getNano(), offset); return ofEpochSecond(instant.getEpochSecond(), instant.getNano(), offset);
@ -373,7 +360,7 @@ public final class LocalDateTime
* @throws DateTimeException if the result exceeds the supported range * @throws DateTimeException if the result exceeds the supported range
*/ */
public static LocalDateTime ofEpochSecond(long epochSecond, int nanoOfSecond, ZoneOffset offset) { public static LocalDateTime ofEpochSecond(long epochSecond, int nanoOfSecond, ZoneOffset offset) {
Jdk8Methods.requireNonNull(offset, "offset"); Objects.requireNonNull(offset, "offset");
long localSecond = epochSecond + offset.getTotalSeconds(); // overflow caught later long localSecond = epochSecond + offset.getTotalSeconds(); // overflow caught later
long localEpochDay = Jdk8Methods.floorDiv(localSecond, SECONDS_PER_DAY); long localEpochDay = Jdk8Methods.floorDiv(localSecond, SECONDS_PER_DAY);
int secsOfDay = Jdk8Methods.floorMod(localSecond, SECONDS_PER_DAY); int secsOfDay = Jdk8Methods.floorMod(localSecond, SECONDS_PER_DAY);
@ -440,8 +427,8 @@ public final class LocalDateTime
* @throws DateTimeParseException if the text cannot be parsed * @throws DateTimeParseException if the text cannot be parsed
*/ */
public static LocalDateTime parse(CharSequence text, DateTimeFormatter formatter) { public static LocalDateTime parse(CharSequence text, DateTimeFormatter formatter) {
Jdk8Methods.requireNonNull(formatter, "formatter"); Objects.requireNonNull(formatter, "formatter");
return formatter.parse(text, LocalDateTime.FROM); return formatter.parse(text, LocalDateTime::from);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------

View File

@ -46,11 +46,10 @@ import java.io.IOException;
import java.io.InvalidObjectException; import java.io.InvalidObjectException;
import java.io.ObjectStreamException; import java.io.ObjectStreamException;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects;
import org.threeten.bp.format.DateTimeFormatter; import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.format.DateTimeParseException; import org.threeten.bp.format.DateTimeParseException;
import org.threeten.bp.jdk8.DefaultInterfaceTemporalAccessor;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField; import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.ChronoUnit; import org.threeten.bp.temporal.ChronoUnit;
import org.threeten.bp.temporal.Temporal; import org.threeten.bp.temporal.Temporal;
@ -86,8 +85,7 @@ import org.threeten.bp.temporal.ValueRange;
* This class is immutable and thread-safe. * This class is immutable and thread-safe.
*/ */
public final class LocalTime public final class LocalTime
extends DefaultInterfaceTemporalAccessor implements Temporal, TemporalAdjuster, Comparable<LocalTime>, Serializable, TemporalAccessor {
implements Temporal, TemporalAdjuster, Comparable<LocalTime>, Serializable {
/** /**
* The minimum supported {@code LocalTime}, '00:00'. * The minimum supported {@code LocalTime}, '00:00'.
@ -244,7 +242,7 @@ public final class LocalTime
* @return the current time, not null * @return the current time, not null
*/ */
public static LocalTime now(Clock clock) { public static LocalTime now(Clock clock) {
Jdk8Methods.requireNonNull(clock, "clock"); Objects.requireNonNull(clock, "clock");
// inline OffsetTime factory to avoid creating object and InstantProvider checks // inline OffsetTime factory to avoid creating object and InstantProvider checks
final Instant now = clock.instant(); // called once final Instant now = clock.instant(); // called once
ZoneOffset offset = clock.getZone().getRules().getOffset(now); ZoneOffset offset = clock.getZone().getRules().getOffset(now);
@ -433,7 +431,7 @@ public final class LocalTime
* @throws DateTimeParseException if the text cannot be parsed * @throws DateTimeParseException if the text cannot be parsed
*/ */
public static LocalTime parse(CharSequence text, DateTimeFormatter formatter) { public static LocalTime parse(CharSequence text, DateTimeFormatter formatter) {
Jdk8Methods.requireNonNull(formatter, "formatter"); Objects.requireNonNull(formatter, "formatter");
return formatter.parse(text, LocalTime.FROM); return formatter.parse(text, LocalTime.FROM);
} }
@ -548,7 +546,7 @@ public final class LocalTime
*/ */
@Override // override for Javadoc @Override // override for Javadoc
public ValueRange range(TemporalField field) { public ValueRange range(TemporalField field) {
return super.range(field); return Temporal.super.range(field);
} }
/** /**
@ -580,7 +578,7 @@ public final class LocalTime
if (field instanceof ChronoField) { if (field instanceof ChronoField) {
return get0(field); return get0(field);
} }
return super.get(field); return Temporal.super.get(field);
} }
/** /**
@ -1373,13 +1371,13 @@ public final class LocalTime
*/ */
@Override @Override
public int compareTo(LocalTime other) { public int compareTo(LocalTime other) {
int cmp = Jdk8Methods.compareInts(hour, other.hour); int cmp = Integer.compare(hour, other.hour);
if (cmp == 0) { if (cmp == 0) {
cmp = Jdk8Methods.compareInts(minute, other.minute); cmp = Integer.compare(minute, other.minute);
if (cmp == 0) { if (cmp == 0) {
cmp = Jdk8Methods.compareInts(second, other.second); cmp = Integer.compare(second, other.second);
if (cmp == 0) { if (cmp == 0) {
cmp = Jdk8Methods.compareInts(nano, other.nano); cmp = Integer.compare(nano, other.nano);
} }
} }
} }
@ -1484,7 +1482,7 @@ public final class LocalTime
} else if (nanoValue % 1000 == 0) { } else if (nanoValue % 1000 == 0) {
buf.append(Integer.toString((nanoValue / 1000) + 1000000).substring(1)); buf.append(Integer.toString((nanoValue / 1000) + 1000000).substring(1));
} else { } else {
buf.append(Integer.toString((nanoValue) + 1000000000).substring(1)); buf.append(Integer.toString(nanoValue + 1000000000).substring(1));
} }
} }
} }
@ -1502,7 +1500,7 @@ public final class LocalTime
* @throws DateTimeException if an error occurs during printing * @throws DateTimeException if an error occurs during printing
*/ */
public String format(DateTimeFormatter formatter) { public String format(DateTimeFormatter formatter) {
Jdk8Methods.requireNonNull(formatter, "formatter"); Objects.requireNonNull(formatter, "formatter");
return formatter.format(this); return formatter.format(this);
} }

View File

@ -40,14 +40,13 @@ import java.io.IOException;
import java.io.InvalidObjectException; import java.io.InvalidObjectException;
import java.io.ObjectStreamException; import java.io.ObjectStreamException;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects;
import org.threeten.bp.chrono.Chronology; import org.threeten.bp.chrono.Chronology;
import org.threeten.bp.chrono.IsoChronology; import org.threeten.bp.chrono.IsoChronology;
import org.threeten.bp.format.DateTimeFormatter; import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.format.DateTimeFormatterBuilder; import org.threeten.bp.format.DateTimeFormatterBuilder;
import org.threeten.bp.format.DateTimeParseException; import org.threeten.bp.format.DateTimeParseException;
import org.threeten.bp.jdk8.DefaultInterfaceTemporalAccessor;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField; import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.Temporal; import org.threeten.bp.temporal.Temporal;
import org.threeten.bp.temporal.TemporalAccessor; import org.threeten.bp.temporal.TemporalAccessor;
@ -88,23 +87,7 @@ import org.threeten.bp.temporal.ValueRange;
* This class is immutable and thread-safe. * This class is immutable and thread-safe.
*/ */
public final class MonthDay public final class MonthDay
extends DefaultInterfaceTemporalAccessor
implements TemporalAccessor, TemporalAdjuster, Comparable<MonthDay>, Serializable { implements TemporalAccessor, TemporalAdjuster, Comparable<MonthDay>, Serializable {
/**
* Simulate JDK 8 method reference MonthDay::from.
*/
public static final TemporalQuery<MonthDay> FROM = new TemporalQuery<MonthDay>() {
@Override
public MonthDay queryFrom(TemporalAccessor temporal) {
return MonthDay.from(temporal);
}
};
/**
* Serialization version.
*/
private static final long serialVersionUID = -939150713474957432L;
/** /**
* Parser. * Parser.
*/ */
@ -189,7 +172,7 @@ public final class MonthDay
* @throws DateTimeException if the day-of-month is invalid for the month * @throws DateTimeException if the day-of-month is invalid for the month
*/ */
public static MonthDay of(Month month, int dayOfMonth) { public static MonthDay of(Month month, int dayOfMonth) {
Jdk8Methods.requireNonNull(month, "month"); Objects.requireNonNull(month, "month");
DAY_OF_MONTH.checkValidValue(dayOfMonth); DAY_OF_MONTH.checkValidValue(dayOfMonth);
if (dayOfMonth > month.maxLength()) { if (dayOfMonth > month.maxLength()) {
throw new DateTimeException("Illegal value for DayOfMonth field, value " + dayOfMonth + throw new DateTimeException("Illegal value for DayOfMonth field, value " + dayOfMonth +
@ -277,8 +260,8 @@ public final class MonthDay
* @throws DateTimeParseException if the text cannot be parsed * @throws DateTimeParseException if the text cannot be parsed
*/ */
public static MonthDay parse(CharSequence text, DateTimeFormatter formatter) { public static MonthDay parse(CharSequence text, DateTimeFormatter formatter) {
Jdk8Methods.requireNonNull(formatter, "formatter"); Objects.requireNonNull(formatter, "formatter");
return formatter.parse(text, MonthDay.FROM); return formatter.parse(text, MonthDay::from);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@ -356,7 +339,7 @@ public final class MonthDay
} else if (field == DAY_OF_MONTH) { } else if (field == DAY_OF_MONTH) {
return ValueRange.of(1, getMonth().minLength(), getMonth().maxLength()); return ValueRange.of(1, getMonth().minLength(), getMonth().maxLength());
} }
return super.range(field); return TemporalAccessor.super.range(field);
} }
/** /**
@ -509,7 +492,7 @@ public final class MonthDay
* @return a {@code MonthDay} based on this month-day with the requested month, not null * @return a {@code MonthDay} based on this month-day with the requested month, not null
*/ */
public MonthDay with(Month month) { public MonthDay with(Month month) {
Jdk8Methods.requireNonNull(month, "month"); Objects.requireNonNull(month, "month");
if (month.getValue() == this.month) { if (month.getValue() == this.month) {
return this; return this;
} }
@ -562,7 +545,7 @@ public final class MonthDay
if (query == TemporalQueries.chronology()) { if (query == TemporalQueries.chronology()) {
return (R) IsoChronology.INSTANCE; return (R) IsoChronology.INSTANCE;
} }
return super.query(query); return TemporalAccessor.super.query(query);
} }
/** /**
@ -716,7 +699,7 @@ public final class MonthDay
* @throws DateTimeException if an error occurs during printing * @throws DateTimeException if an error occurs during printing
*/ */
public String format(DateTimeFormatter formatter) { public String format(DateTimeFormatter formatter) {
Jdk8Methods.requireNonNull(formatter, "formatter"); Objects.requireNonNull(formatter, "formatter");
return formatter.format(this); return formatter.format(this);
} }

View File

@ -44,12 +44,11 @@ import java.io.InvalidObjectException;
import java.io.ObjectStreamException; import java.io.ObjectStreamException;
import java.io.Serializable; import java.io.Serializable;
import java.util.Comparator; import java.util.Comparator;
import java.util.Objects;
import org.threeten.bp.chrono.IsoChronology; import org.threeten.bp.chrono.IsoChronology;
import org.threeten.bp.format.DateTimeFormatter; import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.format.DateTimeParseException; import org.threeten.bp.format.DateTimeParseException;
import org.threeten.bp.jdk8.DefaultInterfaceTemporal;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField; import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.ChronoUnit; import org.threeten.bp.temporal.ChronoUnit;
import org.threeten.bp.temporal.Temporal; import org.threeten.bp.temporal.Temporal;
@ -88,7 +87,6 @@ import org.threeten.bp.zone.ZoneRules;
* This class is immutable and thread-safe. * This class is immutable and thread-safe.
*/ */
public final class OffsetDateTime public final class OffsetDateTime
extends DefaultInterfaceTemporal
implements Temporal, TemporalAdjuster, Comparable<OffsetDateTime>, Serializable { implements Temporal, TemporalAdjuster, Comparable<OffsetDateTime>, Serializable {
/** /**
@ -133,16 +131,8 @@ public final class OffsetDateTime
public static Comparator<OffsetDateTime> timeLineOrder() { public static Comparator<OffsetDateTime> timeLineOrder() {
return INSTANT_COMPARATOR; return INSTANT_COMPARATOR;
} }
private static final Comparator<OffsetDateTime> INSTANT_COMPARATOR = new Comparator<OffsetDateTime>() { private static final Comparator<OffsetDateTime> INSTANT_COMPARATOR =
@Override Comparator.comparingLong(OffsetDateTime::toEpochSecond).thenComparingInt(OffsetDateTime::getNano);
public int compare(OffsetDateTime datetime1, OffsetDateTime datetime2) {
int cmp = Jdk8Methods.compareLongs(datetime1.toEpochSecond(), datetime2.toEpochSecond());
if (cmp == 0) {
cmp = Jdk8Methods.compareLongs(datetime1.getNano(), datetime2.getNano());
}
return cmp;
}
};
/** /**
* Serialization version. * Serialization version.
@ -205,7 +195,7 @@ public final class OffsetDateTime
* @return the current date-time, not null * @return the current date-time, not null
*/ */
public static OffsetDateTime now(Clock clock) { public static OffsetDateTime now(Clock clock) {
Jdk8Methods.requireNonNull(clock, "clock"); Objects.requireNonNull(clock, "clock");
final Instant now = clock.instant(); // called once final Instant now = clock.instant(); // called once
return ofInstant(now, clock.getZone().getRules().getOffset(now)); return ofInstant(now, clock.getZone().getRules().getOffset(now));
} }
@ -284,8 +274,8 @@ public final class OffsetDateTime
* @throws DateTimeException if the result exceeds the supported range * @throws DateTimeException if the result exceeds the supported range
*/ */
public static OffsetDateTime ofInstant(Instant instant, ZoneId zone) { public static OffsetDateTime ofInstant(Instant instant, ZoneId zone) {
Jdk8Methods.requireNonNull(instant, "instant"); Objects.requireNonNull(instant, "instant");
Jdk8Methods.requireNonNull(zone, "zone"); Objects.requireNonNull(zone, "zone");
ZoneRules rules = zone.getRules(); ZoneRules rules = zone.getRules();
ZoneOffset offset = rules.getOffset(instant); ZoneOffset offset = rules.getOffset(instant);
LocalDateTime ldt = LocalDateTime.ofEpochSecond(instant.getEpochSecond(), instant.getNano(), offset); LocalDateTime ldt = LocalDateTime.ofEpochSecond(instant.getEpochSecond(), instant.getNano(), offset);
@ -355,7 +345,7 @@ public final class OffsetDateTime
* @throws DateTimeParseException if the text cannot be parsed * @throws DateTimeParseException if the text cannot be parsed
*/ */
public static OffsetDateTime parse(CharSequence text, DateTimeFormatter formatter) { public static OffsetDateTime parse(CharSequence text, DateTimeFormatter formatter) {
Jdk8Methods.requireNonNull(formatter, "formatter"); Objects.requireNonNull(formatter, "formatter");
return formatter.parse(text, OffsetDateTime.FROM); return formatter.parse(text, OffsetDateTime.FROM);
} }
@ -367,8 +357,8 @@ public final class OffsetDateTime
* @param offset the zone offset, not null * @param offset the zone offset, not null
*/ */
private OffsetDateTime(LocalDateTime dateTime, ZoneOffset offset) { private OffsetDateTime(LocalDateTime dateTime, ZoneOffset offset) {
this.dateTime = Jdk8Methods.requireNonNull(dateTime, "dateTime"); this.dateTime = Objects.requireNonNull(dateTime, "dateTime");
this.offset = Jdk8Methods.requireNonNull(offset, "offset"); this.offset = Objects.requireNonNull(offset, "offset");
} }
/** /**
@ -516,7 +506,7 @@ public final class OffsetDateTime
} }
return dateTime.get(field); return dateTime.get(field);
} }
return super.get(field); return Temporal.super.get(field);
} }
/** /**
@ -1403,7 +1393,7 @@ public final class OffsetDateTime
} else if (query == TemporalQueries.zoneId()) { } else if (query == TemporalQueries.zoneId()) {
return null; return null;
} }
return super.query(query); return Temporal.super.query(query);
} }
/** /**
@ -1661,7 +1651,7 @@ public final class OffsetDateTime
if (getOffset().equals(other.getOffset())) { if (getOffset().equals(other.getOffset())) {
return toLocalDateTime().compareTo(other.toLocalDateTime()); return toLocalDateTime().compareTo(other.toLocalDateTime());
} }
int cmp = Jdk8Methods.compareLongs(toEpochSecond(), other.toEpochSecond()); int cmp = Long.compare(toEpochSecond(), other.toEpochSecond());
if (cmp == 0) { if (cmp == 0) {
cmp = toLocalTime().getNano() - other.toLocalTime().getNano(); cmp = toLocalTime().getNano() - other.toLocalTime().getNano();
if (cmp == 0) { if (cmp == 0) {
@ -1787,7 +1777,7 @@ public final class OffsetDateTime
* @throws DateTimeException if an error occurs during printing * @throws DateTimeException if an error occurs during printing
*/ */
public String format(DateTimeFormatter formatter) { public String format(DateTimeFormatter formatter) {
Jdk8Methods.requireNonNull(formatter, "formatter"); Objects.requireNonNull(formatter, "formatter");
return formatter.format(this); return formatter.format(this);
} }

View File

@ -45,11 +45,10 @@ import java.io.IOException;
import java.io.InvalidObjectException; import java.io.InvalidObjectException;
import java.io.ObjectStreamException; import java.io.ObjectStreamException;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects;
import org.threeten.bp.format.DateTimeFormatter; import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.format.DateTimeParseException; import org.threeten.bp.format.DateTimeParseException;
import org.threeten.bp.jdk8.DefaultInterfaceTemporalAccessor;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField; import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.ChronoUnit; import org.threeten.bp.temporal.ChronoUnit;
import org.threeten.bp.temporal.Temporal; import org.threeten.bp.temporal.Temporal;
@ -79,8 +78,7 @@ import org.threeten.bp.zone.ZoneRules;
* This class is immutable and thread-safe. * This class is immutable and thread-safe.
*/ */
public final class OffsetTime public final class OffsetTime
extends DefaultInterfaceTemporalAccessor implements Temporal, TemporalAdjuster, Comparable<OffsetTime>, Serializable, TemporalAccessor {
implements Temporal, TemporalAdjuster, Comparable<OffsetTime>, Serializable {
/** /**
* The minimum supported {@code OffsetTime}, '00:00:00+18:00'. * The minimum supported {@code OffsetTime}, '00:00:00+18:00'.
@ -169,7 +167,7 @@ public final class OffsetTime
* @return the current time, not null * @return the current time, not null
*/ */
public static OffsetTime now(Clock clock) { public static OffsetTime now(Clock clock) {
Jdk8Methods.requireNonNull(clock, "clock"); Objects.requireNonNull(clock, "clock");
final Instant now = clock.instant(); // called once final Instant now = clock.instant(); // called once
return ofInstant(now, clock.getZone().getRules().getOffset(now)); return ofInstant(now, clock.getZone().getRules().getOffset(now));
} }
@ -226,8 +224,8 @@ public final class OffsetTime
* @return the offset time, not null * @return the offset time, not null
*/ */
public static OffsetTime ofInstant(Instant instant, ZoneId zone) { public static OffsetTime ofInstant(Instant instant, ZoneId zone) {
Jdk8Methods.requireNonNull(instant, "instant"); Objects.requireNonNull(instant, "instant");
Jdk8Methods.requireNonNull(zone, "zone"); Objects.requireNonNull(zone, "zone");
ZoneRules rules = zone.getRules(); ZoneRules rules = zone.getRules();
ZoneOffset offset = rules.getOffset(instant); ZoneOffset offset = rules.getOffset(instant);
long secsOfDay = instant.getEpochSecond() % SECONDS_PER_DAY; long secsOfDay = instant.getEpochSecond() % SECONDS_PER_DAY;
@ -295,7 +293,7 @@ public final class OffsetTime
* @throws DateTimeParseException if the text cannot be parsed * @throws DateTimeParseException if the text cannot be parsed
*/ */
public static OffsetTime parse(CharSequence text, DateTimeFormatter formatter) { public static OffsetTime parse(CharSequence text, DateTimeFormatter formatter) {
Jdk8Methods.requireNonNull(formatter, "formatter"); Objects.requireNonNull(formatter, "formatter");
return formatter.parse(text, OffsetTime.FROM); return formatter.parse(text, OffsetTime.FROM);
} }
@ -307,8 +305,8 @@ public final class OffsetTime
* @param offset the zone offset, not null * @param offset the zone offset, not null
*/ */
private OffsetTime(LocalTime time, ZoneOffset offset) { private OffsetTime(LocalTime time, ZoneOffset offset) {
this.time = Jdk8Methods.requireNonNull(time, "time"); this.time = Objects.requireNonNull(time, "time");
this.offset = Jdk8Methods.requireNonNull(offset, "offset"); this.offset = Objects.requireNonNull(offset, "offset");
} }
/** /**
@ -437,7 +435,7 @@ public final class OffsetTime
*/ */
@Override // override for Javadoc @Override // override for Javadoc
public int get(TemporalField field) { public int get(TemporalField field) {
return super.get(field); return Temporal.super.get(field);
} }
/** /**
@ -989,7 +987,7 @@ public final class OffsetTime
} else if (query == TemporalQueries.chronology() || query == TemporalQueries.localDate() || query == TemporalQueries.zoneId()) { } else if (query == TemporalQueries.chronology() || query == TemporalQueries.localDate() || query == TemporalQueries.zoneId()) {
return null; return null;
} }
return super.query(query); return Temporal.super.query(query);
} }
/** /**
@ -1162,7 +1160,7 @@ public final class OffsetTime
if (offset.equals(other.offset)) { if (offset.equals(other.offset)) {
return time.compareTo(other.time); return time.compareTo(other.time);
} }
int compare = Jdk8Methods.compareLongs(toEpochNano(), other.toEpochNano()); int compare = Long.compare(toEpochNano(), other.toEpochNano());
if (compare == 0) { if (compare == 0) {
compare = time.compareTo(other.time); compare = time.compareTo(other.time);
} }
@ -1284,7 +1282,7 @@ public final class OffsetTime
* @throws DateTimeException if an error occurs during printing * @throws DateTimeException if an error occurs during printing
*/ */
public String format(DateTimeFormatter formatter) { public String format(DateTimeFormatter formatter) {
Jdk8Methods.requireNonNull(formatter, "formatter"); Objects.requireNonNull(formatter, "formatter");
return formatter.format(this); return formatter.format(this);
} }

View File

@ -39,6 +39,7 @@ import java.io.Serializable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -216,7 +217,7 @@ public final class Period
throw new DateTimeException("Period requires ISO chronology: " + amount); throw new DateTimeException("Period requires ISO chronology: " + amount);
} }
} }
Jdk8Methods.requireNonNull(amount, "amount"); Objects.requireNonNull(amount, "amount");
int years = 0; int years = 0;
int months = 0; int months = 0;
int days = 0; int days = 0;
@ -300,7 +301,7 @@ public final class Period
* @throws DateTimeParseException if the text cannot be parsed to a period * @throws DateTimeParseException if the text cannot be parsed to a period
*/ */
public static Period parse(CharSequence text) { public static Period parse(CharSequence text) {
Jdk8Methods.requireNonNull(text, "text"); Objects.requireNonNull(text, "text");
Matcher matcher = PATTERN.matcher(text); Matcher matcher = PATTERN.matcher(text);
if (matcher.matches()) { if (matcher.matches()) {
int negate = ("-".equals(matcher.group(1)) ? -1 : 1); int negate = ("-".equals(matcher.group(1)) ? -1 : 1);
@ -379,7 +380,7 @@ public final class Period
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@Override @Override
public List<TemporalUnit> getUnits() { public List<TemporalUnit> getUnits() {
return Collections.<TemporalUnit>unmodifiableList(Arrays.asList(YEARS, MONTHS, DAYS)); return Collections.unmodifiableList(Arrays.asList(YEARS, MONTHS, DAYS));
} }
@Override @Override
@ -796,7 +797,7 @@ public final class Period
*/ */
@Override @Override
public Temporal addTo(Temporal temporal) { public Temporal addTo(Temporal temporal) {
Jdk8Methods.requireNonNull(temporal, "temporal"); Objects.requireNonNull(temporal, "temporal");
if (years != 0) { if (years != 0) {
if (months != 0) { if (months != 0) {
temporal = temporal.plus(toTotalMonths(), MONTHS); temporal = temporal.plus(toTotalMonths(), MONTHS);
@ -846,7 +847,7 @@ public final class Period
*/ */
@Override @Override
public Temporal subtractFrom(Temporal temporal) { public Temporal subtractFrom(Temporal temporal) {
Jdk8Methods.requireNonNull(temporal, "temporal"); Objects.requireNonNull(temporal, "temporal");
if (years != 0) { if (years != 0) {
if (months != 0) { if (months != 0) {
temporal = temporal.minus(toTotalMonths(), MONTHS); temporal = temporal.minus(toTotalMonths(), MONTHS);

View File

@ -46,6 +46,7 @@ import java.io.IOException;
import java.io.InvalidObjectException; import java.io.InvalidObjectException;
import java.io.ObjectStreamException; import java.io.ObjectStreamException;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects;
import org.threeten.bp.chrono.Chronology; import org.threeten.bp.chrono.Chronology;
import org.threeten.bp.chrono.IsoChronology; import org.threeten.bp.chrono.IsoChronology;
@ -53,7 +54,6 @@ import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.format.DateTimeFormatterBuilder; import org.threeten.bp.format.DateTimeFormatterBuilder;
import org.threeten.bp.format.DateTimeParseException; import org.threeten.bp.format.DateTimeParseException;
import org.threeten.bp.format.SignStyle; import org.threeten.bp.format.SignStyle;
import org.threeten.bp.jdk8.DefaultInterfaceTemporalAccessor;
import org.threeten.bp.jdk8.Jdk8Methods; import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField; import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.ChronoUnit; import org.threeten.bp.temporal.ChronoUnit;
@ -96,8 +96,7 @@ import org.threeten.bp.temporal.ValueRange;
* This class is immutable and thread-safe. * This class is immutable and thread-safe.
*/ */
public final class Year public final class Year
extends DefaultInterfaceTemporalAccessor implements Temporal, TemporalAdjuster, Comparable<Year>, Serializable, TemporalAccessor {
implements Temporal, TemporalAdjuster, Comparable<Year>, Serializable {
/** /**
* The minimum supported year, '-999,999,999'. * The minimum supported year, '-999,999,999'.
@ -107,15 +106,6 @@ public final class Year
* The maximum supported year, '+999,999,999'. * The maximum supported year, '+999,999,999'.
*/ */
public static final int MAX_VALUE = 999999999; public static final int MAX_VALUE = 999999999;
/**
* Simulate JDK 8 method reference Year::from.
*/
public static final TemporalQuery<Year> FROM = new TemporalQuery<Year>() {
@Override
public Year queryFrom(TemporalAccessor temporal) {
return Year.from(temporal);
}
};
/** /**
* Serialization version. * Serialization version.
@ -223,13 +213,13 @@ public final class Year
return (Year) temporal; return (Year) temporal;
} }
try { try {
if (IsoChronology.INSTANCE.equals(Chronology.from(temporal)) == false) { if (!IsoChronology.INSTANCE.equals(Chronology.from(temporal))) {
temporal = LocalDate.from(temporal); temporal = LocalDate.from(temporal);
} }
return of(temporal.get(YEAR)); return of(temporal.get(YEAR));
} catch (DateTimeException ex) { } catch (DateTimeException ex) {
throw new DateTimeException("Unable to obtain Year from TemporalAccessor: " + throw new DateTimeException("Unable to obtain Year from TemporalAccessor: "
temporal + ", type " + temporal.getClass().getName()); + temporal + ", type " + temporal.getClass().getName());
} }
} }
@ -259,8 +249,8 @@ public final class Year
* @throws DateTimeParseException if the text cannot be parsed * @throws DateTimeParseException if the text cannot be parsed
*/ */
public static Year parse(CharSequence text, DateTimeFormatter formatter) { public static Year parse(CharSequence text, DateTimeFormatter formatter) {
Jdk8Methods.requireNonNull(formatter, "formatter"); Objects.requireNonNull(formatter, "formatter");
return formatter.parse(text, Year.FROM); return formatter.parse(text, Year::from);
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@ -379,7 +369,7 @@ public final class Year
if (field == YEAR_OF_ERA) { if (field == YEAR_OF_ERA) {
return (year <= 0 ? ValueRange.of(1, MAX_VALUE + 1) : ValueRange.of(1, MAX_VALUE)); return (year <= 0 ? ValueRange.of(1, MAX_VALUE + 1) : ValueRange.of(1, MAX_VALUE));
} }
return super.range(field); return Temporal.super.range(field);
} }
/** /**
@ -702,7 +692,7 @@ public final class Year
query == TemporalQueries.zone() || query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) { query == TemporalQueries.zone() || query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) {
return null; return null;
} }
return super.query(query); return Temporal.super.query(query);
} }
/** /**
@ -954,7 +944,7 @@ public final class Year
* @throws DateTimeException if an error occurs during printing * @throws DateTimeException if an error occurs during printing
*/ */
public String format(DateTimeFormatter formatter) { public String format(DateTimeFormatter formatter) {
Jdk8Methods.requireNonNull(formatter, "formatter"); Objects.requireNonNull(formatter, "formatter");
return formatter.format(this); return formatter.format(this);
} }

View File

@ -49,6 +49,7 @@ import java.io.IOException;
import java.io.InvalidObjectException; import java.io.InvalidObjectException;
import java.io.ObjectStreamException; import java.io.ObjectStreamException;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects;
import org.threeten.bp.chrono.Chronology; import org.threeten.bp.chrono.Chronology;
import org.threeten.bp.chrono.IsoChronology; import org.threeten.bp.chrono.IsoChronology;
@ -56,7 +57,6 @@ import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.format.DateTimeFormatterBuilder; import org.threeten.bp.format.DateTimeFormatterBuilder;
import org.threeten.bp.format.DateTimeParseException; import org.threeten.bp.format.DateTimeParseException;
import org.threeten.bp.format.SignStyle; import org.threeten.bp.format.SignStyle;
import org.threeten.bp.jdk8.DefaultInterfaceTemporalAccessor;
import org.threeten.bp.jdk8.Jdk8Methods; import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField; import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.ChronoUnit; import org.threeten.bp.temporal.ChronoUnit;
@ -92,18 +92,7 @@ import org.threeten.bp.temporal.ValueRange;
* This class is immutable and thread-safe. * This class is immutable and thread-safe.
*/ */
public final class YearMonth public final class YearMonth
extends DefaultInterfaceTemporalAccessor implements Temporal, TemporalAdjuster, Comparable<YearMonth>, Serializable, TemporalAccessor {
implements Temporal, TemporalAdjuster, Comparable<YearMonth>, Serializable {
/**
* Simulate JDK 8 method reference YearMonth::from.
*/
public static final TemporalQuery<YearMonth> FROM = new TemporalQuery<YearMonth>() {
@Override
public YearMonth queryFrom(TemporalAccessor temporal) {
return YearMonth.from(temporal);
}
};
/** /**
* Serialization version. * Serialization version.
@ -185,7 +174,7 @@ public final class YearMonth
* @throws DateTimeException if the year value is invalid * @throws DateTimeException if the year value is invalid
*/ */
public static YearMonth of(int year, Month month) { public static YearMonth of(int year, Month month) {
Jdk8Methods.requireNonNull(month, "month"); Objects.requireNonNull(month, "month");
return of(year, month.getValue()); return of(year, month.getValue());
} }
@ -264,8 +253,8 @@ public final class YearMonth
* @throws DateTimeParseException if the text cannot be parsed * @throws DateTimeParseException if the text cannot be parsed
*/ */
public static YearMonth parse(CharSequence text, DateTimeFormatter formatter) { public static YearMonth parse(CharSequence text, DateTimeFormatter formatter) {
Jdk8Methods.requireNonNull(formatter, "formatter"); Objects.requireNonNull(formatter, "formatter");
return formatter.parse(text, YearMonth.FROM); return formatter.parse(text, YearMonth::from);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@ -368,7 +357,7 @@ public final class YearMonth
if (field == YEAR_OF_ERA) { if (field == YEAR_OF_ERA) {
return (getYear() <= 0 ? ValueRange.of(1, Year.MAX_VALUE + 1) : ValueRange.of(1, Year.MAX_VALUE)); return (getYear() <= 0 ? ValueRange.of(1, Year.MAX_VALUE + 1) : ValueRange.of(1, Year.MAX_VALUE));
} }
return super.range(field); return Temporal.super.range(field);
} }
/** /**
@ -831,7 +820,7 @@ public final class YearMonth
query == TemporalQueries.zone() || query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) { query == TemporalQueries.zone() || query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) {
return null; return null;
} }
return super.query(query); return Temporal.super.query(query);
} }
/** /**
@ -1076,7 +1065,7 @@ public final class YearMonth
* @throws DateTimeException if an error occurs during printing * @throws DateTimeException if an error occurs during printing
*/ */
public String format(DateTimeFormatter formatter) { public String format(DateTimeFormatter formatter) {
Jdk8Methods.requireNonNull(formatter, "formatter"); Objects.requireNonNull(formatter, "formatter");
return formatter.format(this); return formatter.format(this);
} }

View File

@ -39,13 +39,12 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.TimeZone; import java.util.TimeZone;
import org.threeten.bp.format.DateTimeFormatterBuilder; import org.threeten.bp.format.DateTimeFormatterBuilder;
import org.threeten.bp.format.TextStyle; import org.threeten.bp.format.TextStyle;
import org.threeten.bp.jdk8.DefaultInterfaceTemporalAccessor;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.TemporalAccessor; import org.threeten.bp.temporal.TemporalAccessor;
import org.threeten.bp.temporal.TemporalField; import org.threeten.bp.temporal.TemporalField;
import org.threeten.bp.temporal.TemporalQueries; import org.threeten.bp.temporal.TemporalQueries;
@ -279,8 +278,8 @@ public abstract class ZoneId implements Serializable {
* @throws ZoneRulesException if the zone ID is a region ID that cannot be found * @throws ZoneRulesException if the zone ID is a region ID that cannot be found
*/ */
public static ZoneId of(String zoneId, Map<String, String> aliasMap) { public static ZoneId of(String zoneId, Map<String, String> aliasMap) {
Jdk8Methods.requireNonNull(zoneId, "zoneId"); Objects.requireNonNull(zoneId, "zoneId");
Jdk8Methods.requireNonNull(aliasMap, "aliasMap"); Objects.requireNonNull(aliasMap, "aliasMap");
String id = aliasMap.get(zoneId); String id = aliasMap.get(zoneId);
id = (id != null ? id : zoneId); id = (id != null ? id : zoneId);
return of(id); return of(id);
@ -327,7 +326,7 @@ public abstract class ZoneId implements Serializable {
* @throws ZoneRulesException if the zone ID is a region ID that cannot be found * @throws ZoneRulesException if the zone ID is a region ID that cannot be found
*/ */
public static ZoneId of(String zoneId) { public static ZoneId of(String zoneId) {
Jdk8Methods.requireNonNull(zoneId, "zoneId"); Objects.requireNonNull(zoneId, "zoneId");
if (zoneId.equals("Z")) { if (zoneId.equals("Z")) {
return ZoneOffset.UTC; return ZoneOffset.UTC;
} }
@ -372,8 +371,8 @@ public abstract class ZoneId implements Serializable {
* "GMT", "UTC", or "UT", or "" * "GMT", "UTC", or "UT", or ""
*/ */
public static ZoneId ofOffset(String prefix, ZoneOffset offset) { public static ZoneId ofOffset(String prefix, ZoneOffset offset) {
Jdk8Methods.requireNonNull(prefix, "prefix"); Objects.requireNonNull(prefix, "prefix");
Jdk8Methods.requireNonNull(offset, "offset"); Objects.requireNonNull(offset, "offset");
if (prefix.length() == 0) { if (prefix.length() == 0) {
return offset; return offset;
} }
@ -472,7 +471,7 @@ public abstract class ZoneId implements Serializable {
* @return the text value of the zone, not null * @return the text value of the zone, not null
*/ */
public String getDisplayName(TextStyle style, Locale locale) { public String getDisplayName(TextStyle style, Locale locale) {
return new DateTimeFormatterBuilder().appendZoneText(style).toFormatter(locale).format(new DefaultInterfaceTemporalAccessor() { return new DateTimeFormatterBuilder().appendZoneText(style).toFormatter(locale).format(new TemporalAccessor() {
@Override @Override
public boolean isSupported(TemporalField field) { public boolean isSupported(TemporalField field) {
return false; return false;
@ -487,7 +486,7 @@ public abstract class ZoneId implements Serializable {
if (query == TemporalQueries.zoneId()) { if (query == TemporalQueries.zoneId()) {
return (R) ZoneId.this; return (R) ZoneId.this;
} }
return super.query(query); return TemporalAccessor.super.query(query);
} }
}); });
} }

View File

@ -41,8 +41,8 @@ import java.io.ObjectStreamException;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField; import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.Temporal; import org.threeten.bp.temporal.Temporal;
import org.threeten.bp.temporal.TemporalAccessor; import org.threeten.bp.temporal.TemporalAccessor;
@ -90,16 +90,6 @@ public final class ZoneOffset
extends ZoneId extends ZoneId
implements TemporalAccessor, TemporalAdjuster, Comparable<ZoneOffset>, Serializable { implements TemporalAccessor, TemporalAdjuster, Comparable<ZoneOffset>, Serializable {
/**
* Simulate JDK 8 method reference ZoneOffset::from.
*/
public static final TemporalQuery<ZoneOffset> FROM = new TemporalQuery<ZoneOffset>() {
@Override
public ZoneOffset queryFrom(TemporalAccessor temporal) {
return ZoneOffset.from(temporal);
}
};
/** Cache of time-zone offset by offset in seconds. */ /** Cache of time-zone offset by offset in seconds. */
private static final Map<Integer, ZoneOffset> SECONDS_CACHE = new HashMap<>(); private static final Map<Integer, ZoneOffset> SECONDS_CACHE = new HashMap<>();
/** Cache of time-zone offset by ID. */ /** Cache of time-zone offset by ID. */
@ -180,7 +170,7 @@ public final class ZoneOffset
* @throws DateTimeException if the offset ID is invalid * @throws DateTimeException if the offset ID is invalid
*/ */
public static ZoneOffset of(String offsetId) { public static ZoneOffset of(String offsetId) {
Jdk8Methods.requireNonNull(offsetId, "offsetId"); Objects.requireNonNull(offsetId, "offsetId");
// "Z" is always in the cache // "Z" is always in the cache
ZoneOffset offset = ID_CACHE.get(offsetId); ZoneOffset offset = ID_CACHE.get(offsetId);
if (offset != null) { if (offset != null) {

View File

@ -37,9 +37,9 @@ import java.io.IOException;
import java.io.InvalidObjectException; import java.io.InvalidObjectException;
import java.io.ObjectStreamException; import java.io.ObjectStreamException;
import java.io.Serializable; import java.io.Serializable;
import java.util.regex.Pattern; import java.util.Objects;
import org.threeten.bp.jdk8.Jdk8Methods; import java.util.regex.Pattern;
import org.threeten.bp.zone.ZoneRules; import org.threeten.bp.zone.ZoneRules;
import org.threeten.bp.zone.ZoneRulesException; import org.threeten.bp.zone.ZoneRulesException;
import org.threeten.bp.zone.ZoneRulesProvider; import org.threeten.bp.zone.ZoneRulesProvider;
@ -133,8 +133,8 @@ final class ZoneRegion extends ZoneId implements Serializable {
* @throws DateTimeException if checking availability and the ID cannot be found * @throws DateTimeException if checking availability and the ID cannot be found
*/ */
static ZoneRegion ofId(String zoneId, boolean checkAvailable) { static ZoneRegion ofId(String zoneId, boolean checkAvailable) {
Jdk8Methods.requireNonNull(zoneId, "zoneId"); Objects.requireNonNull(zoneId, "zoneId");
if (zoneId.length() < 2 || PATTERN.matcher(zoneId).matches() == false) { if (zoneId.length() < 2 || !PATTERN.matcher(zoneId).matches()) {
throw new DateTimeException("Invalid ID for region-based ZoneId, invalid format: " + zoneId); throw new DateTimeException("Invalid ID for region-based ZoneId, invalid format: " + zoneId);
} }
ZoneRules rules = null; ZoneRules rules = null;

View File

@ -42,11 +42,11 @@ import java.io.InvalidObjectException;
import java.io.ObjectStreamException; import java.io.ObjectStreamException;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
import java.util.Objects;
import org.threeten.bp.chrono.ChronoZonedDateTime; import org.threeten.bp.chrono.ChronoZonedDateTime;
import org.threeten.bp.format.DateTimeFormatter; import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.format.DateTimeParseException; import org.threeten.bp.format.DateTimeParseException;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField; import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.ChronoUnit; import org.threeten.bp.temporal.ChronoUnit;
import org.threeten.bp.temporal.Temporal; import org.threeten.bp.temporal.Temporal;
@ -123,21 +123,6 @@ public final class ZonedDateTime
extends ChronoZonedDateTime<LocalDate> extends ChronoZonedDateTime<LocalDate>
implements Temporal, Serializable { implements Temporal, Serializable {
/**
* Simulate JDK 8 method reference ZonedDateTime::from.
*/
public static final TemporalQuery<ZonedDateTime> FROM = new TemporalQuery<ZonedDateTime>() {
@Override
public ZonedDateTime queryFrom(TemporalAccessor temporal) {
return ZonedDateTime.from(temporal);
}
};
/**
* Serialization version.
*/
private static final long serialVersionUID = -6260982410461394882L;
/** /**
* The local date-time. * The local date-time.
*/ */
@ -198,7 +183,7 @@ public final class ZonedDateTime
* @return the current date-time, not null * @return the current date-time, not null
*/ */
public static ZonedDateTime now(Clock clock) { public static ZonedDateTime now(Clock clock) {
Jdk8Methods.requireNonNull(clock, "clock"); Objects.requireNonNull(clock, "clock");
final Instant now = clock.instant(); // called once final Instant now = clock.instant(); // called once
return ofInstant(now, clock.getZone()); return ofInstant(now, clock.getZone());
} }
@ -333,8 +318,8 @@ public final class ZonedDateTime
* @return the zoned date-time, not null * @return the zoned date-time, not null
*/ */
public static ZonedDateTime ofLocal(LocalDateTime localDateTime, ZoneId zone, ZoneOffset preferredOffset) { public static ZonedDateTime ofLocal(LocalDateTime localDateTime, ZoneId zone, ZoneOffset preferredOffset) {
Jdk8Methods.requireNonNull(localDateTime, "localDateTime"); Objects.requireNonNull(localDateTime, "localDateTime");
Jdk8Methods.requireNonNull(zone, "zone"); Objects.requireNonNull(zone, "zone");
if (zone instanceof ZoneOffset) { if (zone instanceof ZoneOffset) {
return new ZonedDateTime(localDateTime, (ZoneOffset) zone, zone); return new ZonedDateTime(localDateTime, (ZoneOffset) zone, zone);
} }
@ -351,7 +336,7 @@ public final class ZonedDateTime
if (preferredOffset != null && validOffsets.contains(preferredOffset)) { if (preferredOffset != null && validOffsets.contains(preferredOffset)) {
offset = preferredOffset; offset = preferredOffset;
} else { } else {
offset = Jdk8Methods.requireNonNull(validOffsets.get(0), "offset"); // protect against bad ZoneRules offset = Objects.requireNonNull(validOffsets.get(0), "offset"); // protect against bad ZoneRules
} }
} }
return new ZonedDateTime(localDateTime, offset, zone); return new ZonedDateTime(localDateTime, offset, zone);
@ -373,8 +358,8 @@ public final class ZonedDateTime
* @throws DateTimeException if the result exceeds the supported range * @throws DateTimeException if the result exceeds the supported range
*/ */
public static ZonedDateTime ofInstant(Instant instant, ZoneId zone) { public static ZonedDateTime ofInstant(Instant instant, ZoneId zone) {
Jdk8Methods.requireNonNull(instant, "instant"); Objects.requireNonNull(instant, "instant");
Jdk8Methods.requireNonNull(zone, "zone"); Objects.requireNonNull(zone, "zone");
return create(instant.getEpochSecond(), instant.getNano(), zone); return create(instant.getEpochSecond(), instant.getNano(), zone);
} }
@ -399,9 +384,9 @@ public final class ZonedDateTime
* @return the zoned date-time, not null * @return the zoned date-time, not null
*/ */
public static ZonedDateTime ofInstant(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) { public static ZonedDateTime ofInstant(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
Jdk8Methods.requireNonNull(localDateTime, "localDateTime"); Objects.requireNonNull(localDateTime, "localDateTime");
Jdk8Methods.requireNonNull(offset, "offset"); Objects.requireNonNull(offset, "offset");
Jdk8Methods.requireNonNull(zone, "zone"); Objects.requireNonNull(zone, "zone");
return create(localDateTime.toEpochSecond(offset), localDateTime.getNano(), zone); return create(localDateTime.toEpochSecond(offset), localDateTime.getNano(), zone);
} }
@ -438,9 +423,9 @@ public final class ZonedDateTime
* @return the zoned date-time, not null * @return the zoned date-time, not null
*/ */
public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) { public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
Jdk8Methods.requireNonNull(localDateTime, "localDateTime"); Objects.requireNonNull(localDateTime, "localDateTime");
Jdk8Methods.requireNonNull(offset, "offset"); Objects.requireNonNull(offset, "offset");
Jdk8Methods.requireNonNull(zone, "zone"); Objects.requireNonNull(zone, "zone");
ZoneRules rules = zone.getRules(); ZoneRules rules = zone.getRules();
if (rules.isValidOffset(localDateTime, offset) == false) { if (rules.isValidOffset(localDateTime, offset) == false) {
ZoneOffsetTransition trans = rules.getTransition(localDateTime); ZoneOffsetTransition trans = rules.getTransition(localDateTime);
@ -479,9 +464,9 @@ public final class ZonedDateTime
* @return the zoned date-time, not null * @return the zoned date-time, not null
*/ */
private static ZonedDateTime ofLenient(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) { private static ZonedDateTime ofLenient(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
Jdk8Methods.requireNonNull(localDateTime, "localDateTime"); Objects.requireNonNull(localDateTime, "localDateTime");
Jdk8Methods.requireNonNull(offset, "offset"); Objects.requireNonNull(offset, "offset");
Jdk8Methods.requireNonNull(zone, "zone"); Objects.requireNonNull(zone, "zone");
if (zone instanceof ZoneOffset && offset.equals(zone) == false) { if (zone instanceof ZoneOffset && offset.equals(zone) == false) {
throw new IllegalArgumentException("ZoneId must match ZoneOffset"); throw new IllegalArgumentException("ZoneId must match ZoneOffset");
} }
@ -558,8 +543,8 @@ public final class ZonedDateTime
* @throws DateTimeParseException if the text cannot be parsed * @throws DateTimeParseException if the text cannot be parsed
*/ */
public static ZonedDateTime parse(CharSequence text, DateTimeFormatter formatter) { public static ZonedDateTime parse(CharSequence text, DateTimeFormatter formatter) {
Jdk8Methods.requireNonNull(formatter, "formatter"); Objects.requireNonNull(formatter, "formatter");
return formatter.parse(text, ZonedDateTime.FROM); return formatter.parse(text, ZonedDateTime::from);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@ -887,7 +872,7 @@ public final class ZonedDateTime
*/ */
@Override @Override
public ZonedDateTime withZoneSameLocal(ZoneId zone) { public ZonedDateTime withZoneSameLocal(ZoneId zone) {
Jdk8Methods.requireNonNull(zone, "zone"); Objects.requireNonNull(zone, "zone");
return this.zone.equals(zone) ? this : ofLocal(dateTime, zone, offset); return this.zone.equals(zone) ? this : ofLocal(dateTime, zone, offset);
} }
@ -910,7 +895,7 @@ public final class ZonedDateTime
*/ */
@Override @Override
public ZonedDateTime withZoneSameInstant(ZoneId zone) { public ZonedDateTime withZoneSameInstant(ZoneId zone) {
Jdk8Methods.requireNonNull(zone, "zone"); Objects.requireNonNull(zone, "zone");
return this.zone.equals(zone) ? this : return this.zone.equals(zone) ? this :
create(dateTime.toEpochSecond(offset), dateTime.getNano(), zone); create(dateTime.toEpochSecond(offset), dateTime.getNano(), zone);
} }

View File

@ -39,13 +39,11 @@ import static org.threeten.bp.temporal.ChronoField.YEAR;
import static org.threeten.bp.temporal.ChronoField.YEAR_OF_ERA; import static org.threeten.bp.temporal.ChronoField.YEAR_OF_ERA;
import java.util.Comparator; import java.util.Comparator;
import java.util.Objects;
import org.threeten.bp.DateTimeException; import org.threeten.bp.DateTimeException;
import org.threeten.bp.LocalDate; import org.threeten.bp.LocalDate;
import org.threeten.bp.LocalTime; import org.threeten.bp.LocalTime;
import org.threeten.bp.format.DateTimeFormatter; import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.jdk8.DefaultInterfaceTemporal;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField; import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.ChronoUnit; import org.threeten.bp.temporal.ChronoUnit;
import org.threeten.bp.temporal.Temporal; import org.threeten.bp.temporal.Temporal;
@ -219,7 +217,6 @@ import org.threeten.bp.temporal.TemporalUnit;
* Since there are no default methods in JDK 7, an abstract class is used. * Since there are no default methods in JDK 7, an abstract class is used.
*/ */
public abstract class ChronoLocalDate public abstract class ChronoLocalDate
extends DefaultInterfaceTemporal
implements Temporal, TemporalAdjuster, Comparable<ChronoLocalDate> { implements Temporal, TemporalAdjuster, Comparable<ChronoLocalDate> {
/** /**
@ -240,13 +237,9 @@ public abstract class ChronoLocalDate
public static Comparator<ChronoLocalDate> timeLineOrder() { public static Comparator<ChronoLocalDate> timeLineOrder() {
return DATE_COMPARATOR; return DATE_COMPARATOR;
} }
private static final Comparator<ChronoLocalDate> DATE_COMPARATOR = private static final Comparator<ChronoLocalDate> DATE_COMPARATOR =
new Comparator<ChronoLocalDate>() { Comparator.comparingLong(ChronoLocalDate::toEpochDay);
@Override
public int compare(ChronoLocalDate date1, ChronoLocalDate date2) {
return Jdk8Methods.compareLongs(date1.toEpochDay(), date2.toEpochDay());
}
};
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
@ -271,7 +264,7 @@ public abstract class ChronoLocalDate
* @see Chronology#date(TemporalAccessor) * @see Chronology#date(TemporalAccessor)
*/ */
public static ChronoLocalDate from(TemporalAccessor temporal) { public static ChronoLocalDate from(TemporalAccessor temporal) {
Jdk8Methods.requireNonNull(temporal, "temporal"); Objects.requireNonNull(temporal, "temporal");
if (temporal instanceof ChronoLocalDate) { if (temporal instanceof ChronoLocalDate) {
return (ChronoLocalDate) temporal; return (ChronoLocalDate) temporal;
} }
@ -368,7 +361,7 @@ public abstract class ChronoLocalDate
// override for covariant return type // override for covariant return type
@Override @Override
public ChronoLocalDate with(TemporalAdjuster adjuster) { public ChronoLocalDate with(TemporalAdjuster adjuster) {
return getChronology().ensureChronoLocalDate(super.with(adjuster)); return getChronology().ensureChronoLocalDate(Temporal.super.with(adjuster));
} }
@Override @Override
@ -376,7 +369,7 @@ public abstract class ChronoLocalDate
@Override @Override
public ChronoLocalDate plus(TemporalAmount amount) { public ChronoLocalDate plus(TemporalAmount amount) {
return getChronology().ensureChronoLocalDate(super.plus(amount)); return getChronology().ensureChronoLocalDate(Temporal.super.plus(amount));
} }
@Override @Override
@ -384,12 +377,12 @@ public abstract class ChronoLocalDate
@Override @Override
public ChronoLocalDate minus(TemporalAmount amount) { public ChronoLocalDate minus(TemporalAmount amount) {
return getChronology().ensureChronoLocalDate(super.minus(amount)); return getChronology().ensureChronoLocalDate(Temporal.super.minus(amount));
} }
@Override @Override
public ChronoLocalDate minus(long amountToSubtract, TemporalUnit unit) { public ChronoLocalDate minus(long amountToSubtract, TemporalUnit unit) {
return getChronology().ensureChronoLocalDate(super.minus(amountToSubtract, unit)); return getChronology().ensureChronoLocalDate(Temporal.super.minus(amountToSubtract, unit));
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@ -406,7 +399,7 @@ public abstract class ChronoLocalDate
query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) { query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) {
return null; return null;
} }
return super.query(query); return Temporal.super.query(query);
} }
@Override @Override
@ -453,7 +446,7 @@ public abstract class ChronoLocalDate
* @throws DateTimeException if an error occurs during printing * @throws DateTimeException if an error occurs during printing
*/ */
public String format(DateTimeFormatter formatter) { public String format(DateTimeFormatter formatter) {
Jdk8Methods.requireNonNull(formatter, "formatter"); Objects.requireNonNull(formatter, "formatter");
return formatter.format(this); return formatter.format(this);
} }
@ -514,7 +507,7 @@ public abstract class ChronoLocalDate
*/ */
@Override @Override
public int compareTo(ChronoLocalDate other) { public int compareTo(ChronoLocalDate other) {
int cmp = Jdk8Methods.compareLongs(toEpochDay(), other.toEpochDay()); int cmp = Long.compare(toEpochDay(), other.toEpochDay());
if (cmp == 0) { if (cmp == 0) {
cmp = getChronology().compareTo(other.getChronology()); cmp = getChronology().compareTo(other.getChronology());
} }

View File

@ -36,6 +36,7 @@ import static org.threeten.bp.temporal.ChronoField.NANO_OF_DAY;
import static org.threeten.bp.temporal.ChronoUnit.NANOS; import static org.threeten.bp.temporal.ChronoUnit.NANOS;
import java.util.Comparator; import java.util.Comparator;
import java.util.Objects;
import org.threeten.bp.DateTimeException; import org.threeten.bp.DateTimeException;
import org.threeten.bp.Instant; import org.threeten.bp.Instant;
@ -45,8 +46,6 @@ import org.threeten.bp.LocalTime;
import org.threeten.bp.ZoneId; import org.threeten.bp.ZoneId;
import org.threeten.bp.ZoneOffset; import org.threeten.bp.ZoneOffset;
import org.threeten.bp.format.DateTimeFormatter; import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.jdk8.DefaultInterfaceTemporal;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField; import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.Temporal; import org.threeten.bp.temporal.Temporal;
import org.threeten.bp.temporal.TemporalAccessor; import org.threeten.bp.temporal.TemporalAccessor;
@ -91,7 +90,6 @@ import org.threeten.bp.zone.ZoneRules;
* @param <D> the date type * @param <D> the date type
*/ */
public abstract class ChronoLocalDateTime<D extends ChronoLocalDate> public abstract class ChronoLocalDateTime<D extends ChronoLocalDate>
extends DefaultInterfaceTemporal
implements Temporal, TemporalAdjuster, Comparable<ChronoLocalDateTime<?>> { implements Temporal, TemporalAdjuster, Comparable<ChronoLocalDateTime<?>> {
/** /**
@ -113,16 +111,8 @@ public abstract class ChronoLocalDateTime<D extends ChronoLocalDate>
return DATE_TIME_COMPARATOR; return DATE_TIME_COMPARATOR;
} }
private static final Comparator<ChronoLocalDateTime<?>> DATE_TIME_COMPARATOR = private static final Comparator<ChronoLocalDateTime<?>> DATE_TIME_COMPARATOR =
new Comparator<ChronoLocalDateTime<?>>() { Comparator.comparingLong((ChronoLocalDateTime<?> datetime) -> datetime.toLocalDate().toEpochDay())
@Override .thenComparingLong(datetime -> datetime.toLocalTime().toNanoOfDay());
public int compare(ChronoLocalDateTime<?> datetime1, ChronoLocalDateTime<?> datetime2) {
int cmp = Jdk8Methods.compareLongs(datetime1.toLocalDate().toEpochDay(), datetime2.toLocalDate().toEpochDay());
if (cmp == 0) {
cmp = Jdk8Methods.compareLongs(datetime1.toLocalTime().toNanoOfDay(), datetime2.toLocalTime().toNanoOfDay());
}
return cmp;
}
};
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
@ -147,7 +137,7 @@ public abstract class ChronoLocalDateTime<D extends ChronoLocalDate>
* @see Chronology#localDateTime(TemporalAccessor) * @see Chronology#localDateTime(TemporalAccessor)
*/ */
public static ChronoLocalDateTime<?> from(TemporalAccessor temporal) { public static ChronoLocalDateTime<?> from(TemporalAccessor temporal) {
Jdk8Methods.requireNonNull(temporal, "temporal"); Objects.requireNonNull(temporal, "temporal");
if (temporal instanceof ChronoLocalDateTime) { if (temporal instanceof ChronoLocalDateTime) {
return (ChronoLocalDateTime<?>) temporal; return (ChronoLocalDateTime<?>) temporal;
} }
@ -195,7 +185,7 @@ public abstract class ChronoLocalDateTime<D extends ChronoLocalDate>
// override for covariant return type // override for covariant return type
@Override @Override
public ChronoLocalDateTime<D> with(TemporalAdjuster adjuster) { public ChronoLocalDateTime<D> with(TemporalAdjuster adjuster) {
return toLocalDate().getChronology().ensureChronoLocalDateTime(super.with(adjuster)); return toLocalDate().getChronology().ensureChronoLocalDateTime(Temporal.super.with(adjuster));
} }
@Override @Override
@ -203,7 +193,7 @@ public abstract class ChronoLocalDateTime<D extends ChronoLocalDate>
@Override @Override
public ChronoLocalDateTime<D> plus(TemporalAmount amount) { public ChronoLocalDateTime<D> plus(TemporalAmount amount) {
return toLocalDate().getChronology().ensureChronoLocalDateTime(super.plus(amount)); return toLocalDate().getChronology().ensureChronoLocalDateTime(Temporal.super.plus(amount));
} }
@Override @Override
@ -211,12 +201,12 @@ public abstract class ChronoLocalDateTime<D extends ChronoLocalDate>
@Override @Override
public ChronoLocalDateTime<D> minus(TemporalAmount amount) { public ChronoLocalDateTime<D> minus(TemporalAmount amount) {
return toLocalDate().getChronology().ensureChronoLocalDateTime(super.minus(amount)); return toLocalDate().getChronology().ensureChronoLocalDateTime(Temporal.super.minus(amount));
} }
@Override @Override
public ChronoLocalDateTime<D> minus(long amountToSubtract, TemporalUnit unit) { public ChronoLocalDateTime<D> minus(long amountToSubtract, TemporalUnit unit) {
return toLocalDate().getChronology().ensureChronoLocalDateTime(super.minus(amountToSubtract, unit)); return toLocalDate().getChronology().ensureChronoLocalDateTime(Temporal.super.minus(amountToSubtract, unit));
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@ -234,7 +224,7 @@ public abstract class ChronoLocalDateTime<D extends ChronoLocalDate>
} else if (query == TemporalQueries.zone() || query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) { } else if (query == TemporalQueries.zone() || query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) {
return null; return null;
} }
return super.query(query); return Temporal.super.query(query);
} }
@Override @Override
@ -259,7 +249,7 @@ public abstract class ChronoLocalDateTime<D extends ChronoLocalDate>
* @throws DateTimeException if an error occurs during printing * @throws DateTimeException if an error occurs during printing
*/ */
public String format(DateTimeFormatter formatter) { public String format(DateTimeFormatter formatter) {
Jdk8Methods.requireNonNull(formatter, "formatter"); Objects.requireNonNull(formatter, "formatter");
return formatter.format(this); return formatter.format(this);
} }
@ -319,7 +309,7 @@ public abstract class ChronoLocalDateTime<D extends ChronoLocalDate>
* @return the number of seconds from the epoch of 1970-01-01T00:00:00Z * @return the number of seconds from the epoch of 1970-01-01T00:00:00Z
*/ */
public long toEpochSecond(ZoneOffset offset) { public long toEpochSecond(ZoneOffset offset) {
Jdk8Methods.requireNonNull(offset, "offset"); Objects.requireNonNull(offset, "offset");
long epochDay = toLocalDate().toEpochDay(); long epochDay = toLocalDate().toEpochDay();
long secs = epochDay * 86400 + toLocalTime().toSecondOfDay(); long secs = epochDay * 86400 + toLocalTime().toSecondOfDay();
secs -= offset.getTotalSeconds(); secs -= offset.getTotalSeconds();

View File

@ -37,6 +37,7 @@ import java.io.IOException;
import java.io.ObjectInput; import java.io.ObjectInput;
import java.io.ObjectOutput; import java.io.ObjectOutput;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects;
import org.threeten.bp.LocalTime; import org.threeten.bp.LocalTime;
import org.threeten.bp.ZoneId; import org.threeten.bp.ZoneId;
@ -150,8 +151,8 @@ final class ChronoLocalDateTimeImpl<D extends ChronoLocalDate>
* @param time the time part of the date-time, not null * @param time the time part of the date-time, not null
*/ */
private ChronoLocalDateTimeImpl(D date, LocalTime time) { private ChronoLocalDateTimeImpl(D date, LocalTime time) {
Jdk8Methods.requireNonNull(date, "date"); Objects.requireNonNull(date, "date");
Jdk8Methods.requireNonNull(time, "time"); Objects.requireNonNull(time, "time");
this.date = date; this.date = date;
this.time = time; this.time = time;
} }

View File

@ -32,9 +32,9 @@
package org.threeten.bp.chrono; package org.threeten.bp.chrono;
import java.util.List; import java.util.List;
import java.util.Objects;
import org.threeten.bp.DateTimeException; import org.threeten.bp.DateTimeException;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoUnit; import org.threeten.bp.temporal.ChronoUnit;
import org.threeten.bp.temporal.Temporal; import org.threeten.bp.temporal.Temporal;
import org.threeten.bp.temporal.TemporalAmount; import org.threeten.bp.temporal.TemporalAmount;
@ -86,8 +86,8 @@ public abstract class ChronoPeriod
* @see ChronoLocalDate#until(ChronoLocalDate) * @see ChronoLocalDate#until(ChronoLocalDate)
*/ */
public static ChronoPeriod between(ChronoLocalDate startDateInclusive, ChronoLocalDate endDateExclusive) { public static ChronoPeriod between(ChronoLocalDate startDateInclusive, ChronoLocalDate endDateExclusive) {
Jdk8Methods.requireNonNull(startDateInclusive, "startDateInclusive"); Objects.requireNonNull(startDateInclusive, "startDateInclusive");
Jdk8Methods.requireNonNull(endDateExclusive, "endDateExclusive"); Objects.requireNonNull(endDateExclusive, "endDateExclusive");
return startDateInclusive.until(endDateExclusive); return startDateInclusive.until(endDateExclusive);
} }

View File

@ -39,6 +39,7 @@ import java.io.Serializable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects;
import org.threeten.bp.DateTimeException; import org.threeten.bp.DateTimeException;
import org.threeten.bp.jdk8.Jdk8Methods; import org.threeten.bp.jdk8.Jdk8Methods;
@ -152,7 +153,7 @@ final class ChronoPeriodImpl
@Override @Override
public Temporal addTo(Temporal temporal) { public Temporal addTo(Temporal temporal) {
Jdk8Methods.requireNonNull(temporal, "temporal"); Objects.requireNonNull(temporal, "temporal");
Chronology temporalChrono = temporal.query(TemporalQueries.chronology()); Chronology temporalChrono = temporal.query(TemporalQueries.chronology());
if (temporalChrono != null && chronology.equals(temporalChrono) == false) { if (temporalChrono != null && chronology.equals(temporalChrono) == false) {
throw new DateTimeException("Invalid chronology, required: " + chronology.getId() + ", but was: " + temporalChrono.getId()); throw new DateTimeException("Invalid chronology, required: " + chronology.getId() + ", but was: " + temporalChrono.getId());
@ -171,7 +172,7 @@ final class ChronoPeriodImpl
@Override @Override
public Temporal subtractFrom(Temporal temporal) { public Temporal subtractFrom(Temporal temporal) {
Jdk8Methods.requireNonNull(temporal, "temporal"); Objects.requireNonNull(temporal, "temporal");
Chronology temporalChrono = temporal.query(TemporalQueries.chronology()); Chronology temporalChrono = temporal.query(TemporalQueries.chronology());
if (temporalChrono != null && chronology.equals(temporalChrono) == false) { if (temporalChrono != null && chronology.equals(temporalChrono) == false) {
throw new DateTimeException("Invalid chronology, required: " + chronology.getId() + ", but was: " + temporalChrono.getId()); throw new DateTimeException("Invalid chronology, required: " + chronology.getId() + ", but was: " + temporalChrono.getId());

View File

@ -36,6 +36,8 @@ import static org.threeten.bp.temporal.ChronoField.OFFSET_SECONDS;
import static org.threeten.bp.temporal.ChronoUnit.NANOS; import static org.threeten.bp.temporal.ChronoUnit.NANOS;
import java.util.Comparator; import java.util.Comparator;
import java.util.Objects;
import java.util.function.ToLongFunction;
import org.threeten.bp.DateTimeException; import org.threeten.bp.DateTimeException;
import org.threeten.bp.Instant; import org.threeten.bp.Instant;
@ -45,8 +47,6 @@ import org.threeten.bp.ZoneId;
import org.threeten.bp.ZoneOffset; import org.threeten.bp.ZoneOffset;
import org.threeten.bp.ZonedDateTime; import org.threeten.bp.ZonedDateTime;
import org.threeten.bp.format.DateTimeFormatter; import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.jdk8.DefaultInterfaceTemporal;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField; import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.Temporal; import org.threeten.bp.temporal.Temporal;
import org.threeten.bp.temporal.TemporalAccessor; import org.threeten.bp.temporal.TemporalAccessor;
@ -92,7 +92,6 @@ import org.threeten.bp.temporal.ValueRange;
* @param <D> the date type * @param <D> the date type
*/ */
public abstract class ChronoZonedDateTime<D extends ChronoLocalDate> public abstract class ChronoZonedDateTime<D extends ChronoLocalDate>
extends DefaultInterfaceTemporal
implements Temporal, Comparable<ChronoZonedDateTime<?>> { implements Temporal, Comparable<ChronoZonedDateTime<?>> {
/** /**
@ -113,16 +112,9 @@ public abstract class ChronoZonedDateTime<D extends ChronoLocalDate>
public static Comparator<ChronoZonedDateTime<?>> timeLineOrder() { public static Comparator<ChronoZonedDateTime<?>> timeLineOrder() {
return INSTANT_COMPARATOR; return INSTANT_COMPARATOR;
} }
private static Comparator<ChronoZonedDateTime<?>> INSTANT_COMPARATOR = new Comparator<ChronoZonedDateTime<?>>() { private static final Comparator<ChronoZonedDateTime<?>> INSTANT_COMPARATOR =
@Override Comparator.comparingLong((ToLongFunction<ChronoZonedDateTime<?>>) ChronoZonedDateTime::toEpochSecond)
public int compare(ChronoZonedDateTime<?> datetime1, ChronoZonedDateTime<?> datetime2) { .thenComparingLong(datetime -> datetime.toLocalTime().toNanoOfDay());
int cmp = Jdk8Methods.compareLongs(datetime1.toEpochSecond(), datetime2.toEpochSecond());
if (cmp == 0) {
cmp = Jdk8Methods.compareLongs(datetime1.toLocalTime().toNanoOfDay(), datetime2.toLocalTime().toNanoOfDay());
}
return cmp;
}
};
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
@ -147,7 +139,7 @@ public abstract class ChronoZonedDateTime<D extends ChronoLocalDate>
* @see Chronology#zonedDateTime(TemporalAccessor) * @see Chronology#zonedDateTime(TemporalAccessor)
*/ */
public static ChronoZonedDateTime<?> from(TemporalAccessor temporal) { public static ChronoZonedDateTime<?> from(TemporalAccessor temporal) {
Jdk8Methods.requireNonNull(temporal, "temporal"); Objects.requireNonNull(temporal, "temporal");
if (temporal instanceof ChronoZonedDateTime) { if (temporal instanceof ChronoZonedDateTime) {
return (ChronoZonedDateTime<?>) temporal; return (ChronoZonedDateTime<?>) temporal;
} }
@ -179,7 +171,7 @@ public abstract class ChronoZonedDateTime<D extends ChronoLocalDate>
} }
return toLocalDateTime().get(field); return toLocalDateTime().get(field);
} }
return super.get(field); return Temporal.super.get(field);
} }
@Override @Override
@ -341,7 +333,7 @@ public abstract class ChronoZonedDateTime<D extends ChronoLocalDate>
// override for covariant return type // override for covariant return type
@Override @Override
public ChronoZonedDateTime<D> with(TemporalAdjuster adjuster) { public ChronoZonedDateTime<D> with(TemporalAdjuster adjuster) {
return toLocalDate().getChronology().ensureChronoZonedDateTime(super.with(adjuster)); return toLocalDate().getChronology().ensureChronoZonedDateTime(Temporal.super.with(adjuster));
} }
@Override @Override
@ -349,7 +341,7 @@ public abstract class ChronoZonedDateTime<D extends ChronoLocalDate>
@Override @Override
public ChronoZonedDateTime<D> plus(TemporalAmount amount) { public ChronoZonedDateTime<D> plus(TemporalAmount amount) {
return toLocalDate().getChronology().ensureChronoZonedDateTime(super.plus(amount)); return toLocalDate().getChronology().ensureChronoZonedDateTime(Temporal.super.plus(amount));
} }
@Override @Override
@ -357,12 +349,12 @@ public abstract class ChronoZonedDateTime<D extends ChronoLocalDate>
@Override @Override
public ChronoZonedDateTime<D> minus(TemporalAmount amount) { public ChronoZonedDateTime<D> minus(TemporalAmount amount) {
return toLocalDate().getChronology().ensureChronoZonedDateTime(super.minus(amount)); return toLocalDate().getChronology().ensureChronoZonedDateTime(Temporal.super.minus(amount));
} }
@Override @Override
public ChronoZonedDateTime<D> minus(long amountToSubtract, TemporalUnit unit) { public ChronoZonedDateTime<D> minus(long amountToSubtract, TemporalUnit unit) {
return toLocalDate().getChronology().ensureChronoZonedDateTime(super.minus(amountToSubtract, unit)); return toLocalDate().getChronology().ensureChronoZonedDateTime(Temporal.super.minus(amountToSubtract, unit));
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@ -382,7 +374,7 @@ public abstract class ChronoZonedDateTime<D extends ChronoLocalDate>
} else if (query == TemporalQueries.localTime()) { } else if (query == TemporalQueries.localTime()) {
return (R) toLocalTime(); return (R) toLocalTime();
} }
return super.query(query); return Temporal.super.query(query);
} }
/** /**
@ -393,7 +385,7 @@ public abstract class ChronoZonedDateTime<D extends ChronoLocalDate>
* @throws DateTimeException if an error occurs during printing * @throws DateTimeException if an error occurs during printing
*/ */
public String format(DateTimeFormatter formatter) { public String format(DateTimeFormatter formatter) {
Jdk8Methods.requireNonNull(formatter, "formatter"); Objects.requireNonNull(formatter, "formatter");
return formatter.format(this); return formatter.format(this);
} }
@ -446,7 +438,7 @@ public abstract class ChronoZonedDateTime<D extends ChronoLocalDate>
*/ */
@Override @Override
public int compareTo(ChronoZonedDateTime<?> other) { public int compareTo(ChronoZonedDateTime<?> other) {
int cmp = Jdk8Methods.compareLongs(toEpochSecond(), other.toEpochSecond()); int cmp = Long.compare(toEpochSecond(), other.toEpochSecond());
if (cmp == 0) { if (cmp == 0) {
cmp = toLocalTime().getNano() - other.toLocalTime().getNano(); cmp = toLocalTime().getNano() - other.toLocalTime().getNano();
if (cmp == 0) { if (cmp == 0) {

View File

@ -40,12 +40,12 @@ import java.io.ObjectOutput;
import java.io.ObjectStreamException; import java.io.ObjectStreamException;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
import java.util.Objects;
import org.threeten.bp.Instant; import org.threeten.bp.Instant;
import org.threeten.bp.LocalDateTime; import org.threeten.bp.LocalDateTime;
import org.threeten.bp.ZoneId; import org.threeten.bp.ZoneId;
import org.threeten.bp.ZoneOffset; import org.threeten.bp.ZoneOffset;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField; import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.ChronoUnit; import org.threeten.bp.temporal.ChronoUnit;
import org.threeten.bp.temporal.Temporal; import org.threeten.bp.temporal.Temporal;
@ -103,10 +103,10 @@ final class ChronoZonedDateTimeImpl<D extends ChronoLocalDate>
*/ */
static <R extends ChronoLocalDate> ChronoZonedDateTime<R> ofBest( static <R extends ChronoLocalDate> ChronoZonedDateTime<R> ofBest(
ChronoLocalDateTimeImpl<R> localDateTime, ZoneId zone, ZoneOffset preferredOffset) { ChronoLocalDateTimeImpl<R> localDateTime, ZoneId zone, ZoneOffset preferredOffset) {
Jdk8Methods.requireNonNull(localDateTime, "localDateTime"); Objects.requireNonNull(localDateTime, "localDateTime");
Jdk8Methods.requireNonNull(zone, "zone"); Objects.requireNonNull(zone, "zone");
if (zone instanceof ZoneOffset) { if (zone instanceof ZoneOffset) {
return new ChronoZonedDateTimeImpl<R>(localDateTime, (ZoneOffset) zone, zone); return new ChronoZonedDateTimeImpl<>(localDateTime, (ZoneOffset) zone, zone);
} }
ZoneRules rules = zone.getRules(); ZoneRules rules = zone.getRules();
LocalDateTime isoLDT = LocalDateTime.from(localDateTime); LocalDateTime isoLDT = LocalDateTime.from(localDateTime);
@ -125,8 +125,8 @@ final class ChronoZonedDateTimeImpl<D extends ChronoLocalDate>
offset = validOffsets.get(0); offset = validOffsets.get(0);
} }
} }
Jdk8Methods.requireNonNull(offset, "offset"); // protect against bad ZoneRules Objects.requireNonNull(offset, "offset"); // protect against bad ZoneRules
return new ChronoZonedDateTimeImpl<R>(localDateTime, offset, zone); return new ChronoZonedDateTimeImpl<>(localDateTime, offset, zone);
} }
/** /**
@ -140,11 +140,11 @@ final class ChronoZonedDateTimeImpl<D extends ChronoLocalDate>
static <R extends ChronoLocalDate> ChronoZonedDateTimeImpl<R> ofInstant(Chronology chrono, Instant instant, ZoneId zone) { static <R extends ChronoLocalDate> ChronoZonedDateTimeImpl<R> ofInstant(Chronology chrono, Instant instant, ZoneId zone) {
ZoneRules rules = zone.getRules(); ZoneRules rules = zone.getRules();
ZoneOffset offset = rules.getOffset(instant); ZoneOffset offset = rules.getOffset(instant);
Jdk8Methods.requireNonNull(offset, "offset"); // protect against bad ZoneRules Objects.requireNonNull(offset, "offset"); // protect against bad ZoneRules
LocalDateTime ldt = LocalDateTime.ofEpochSecond(instant.getEpochSecond(), instant.getNano(), offset); LocalDateTime ldt = LocalDateTime.ofEpochSecond(instant.getEpochSecond(), instant.getNano(), offset);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ChronoLocalDateTimeImpl<R> cldt = (ChronoLocalDateTimeImpl<R>) chrono.localDateTime(ldt); ChronoLocalDateTimeImpl<R> cldt = (ChronoLocalDateTimeImpl<R>) chrono.localDateTime(ldt);
return new ChronoZonedDateTimeImpl<R>(cldt, offset, zone); return new ChronoZonedDateTimeImpl<>(cldt, offset, zone);
} }
/** /**
@ -167,9 +167,9 @@ final class ChronoZonedDateTimeImpl<D extends ChronoLocalDate>
* @param zone the zone ID, not null * @param zone the zone ID, not null
*/ */
private ChronoZonedDateTimeImpl(ChronoLocalDateTimeImpl<D> dateTime, ZoneOffset offset, ZoneId zone) { private ChronoZonedDateTimeImpl(ChronoLocalDateTimeImpl<D> dateTime, ZoneOffset offset, ZoneId zone) {
this.dateTime = Jdk8Methods.requireNonNull(dateTime, "dateTime"); this.dateTime = Objects.requireNonNull(dateTime, "dateTime");
this.offset = Jdk8Methods.requireNonNull(offset, "offset"); this.offset = Objects.requireNonNull(offset, "offset");
this.zone = Jdk8Methods.requireNonNull(zone, "zone"); this.zone = Objects.requireNonNull(zone, "zone");
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@ -203,7 +203,7 @@ final class ChronoZonedDateTimeImpl<D extends ChronoLocalDate>
if (trans != null) { if (trans != null) {
ZoneOffset offset = trans.getOffsetAfter(); ZoneOffset offset = trans.getOffsetAfter();
if (offset.equals(getOffset()) == false) { if (offset.equals(getOffset()) == false) {
return new ChronoZonedDateTimeImpl<D>(dateTime, offset, zone); return new ChronoZonedDateTimeImpl<>(dateTime, offset, zone);
} }
} }
return this; return this;
@ -225,7 +225,7 @@ final class ChronoZonedDateTimeImpl<D extends ChronoLocalDate>
@Override @Override
public ChronoZonedDateTime<D> withZoneSameInstant(ZoneId zone) { public ChronoZonedDateTime<D> withZoneSameInstant(ZoneId zone) {
Jdk8Methods.requireNonNull(zone, "zone"); Objects.requireNonNull(zone, "zone");
return this.zone.equals(zone) ? this : create(dateTime.toInstant(offset), zone); return this.zone.equals(zone) ? this : create(dateTime.toInstant(offset), zone);
} }

View File

@ -41,6 +41,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.ServiceLoader; import java.util.ServiceLoader;
import java.util.Set; import java.util.Set;
@ -53,8 +54,6 @@ import org.threeten.bp.ZoneId;
import org.threeten.bp.format.DateTimeFormatterBuilder; import org.threeten.bp.format.DateTimeFormatterBuilder;
import org.threeten.bp.format.ResolverStyle; import org.threeten.bp.format.ResolverStyle;
import org.threeten.bp.format.TextStyle; import org.threeten.bp.format.TextStyle;
import org.threeten.bp.jdk8.DefaultInterfaceTemporalAccessor;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField; import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.Temporal; import org.threeten.bp.temporal.Temporal;
import org.threeten.bp.temporal.TemporalAccessor; import org.threeten.bp.temporal.TemporalAccessor;
@ -138,16 +137,6 @@ import org.threeten.bp.temporal.ValueRange;
*/ */
public abstract class Chronology implements Comparable<Chronology> { public abstract class Chronology implements Comparable<Chronology> {
/**
* Simulate JDK 8 method reference Chronology::from.
*/
public static final TemporalQuery<Chronology> FROM = new TemporalQuery<Chronology>() {
@Override
public Chronology queryFrom(TemporalAccessor temporal) {
return Chronology.from(temporal);
}
};
/** /**
* Map of available calendars by ID. * Map of available calendars by ID.
*/ */
@ -175,7 +164,7 @@ public abstract class Chronology implements Comparable<Chronology> {
* @throws DateTimeException if unable to convert to an {@code Chronology} * @throws DateTimeException if unable to convert to an {@code Chronology}
*/ */
public static Chronology from(TemporalAccessor temporal) { public static Chronology from(TemporalAccessor temporal) {
Jdk8Methods.requireNonNull(temporal, "temporal"); Objects.requireNonNull(temporal, "temporal");
Chronology obj = temporal.query(TemporalQueries.chronology()); Chronology obj = temporal.query(TemporalQueries.chronology());
return (obj != null ? obj : IsoChronology.INSTANCE); return (obj != null ? obj : IsoChronology.INSTANCE);
} }
@ -223,7 +212,7 @@ public abstract class Chronology implements Comparable<Chronology> {
*/ */
public static Chronology ofLocale(Locale locale) { public static Chronology ofLocale(Locale locale) {
init(); init();
Jdk8Methods.requireNonNull(locale, "locale"); Objects.requireNonNull(locale, "locale");
String type = "iso"; String type = "iso";
if (locale.equals(JapaneseChronology.LOCALE)) { if (locale.equals(JapaneseChronology.LOCALE)) {
type = "japanese"; type = "japanese";
@ -281,7 +270,7 @@ public abstract class Chronology implements Comparable<Chronology> {
*/ */
public static Set<Chronology> getAvailableChronologies() { public static Set<Chronology> getAvailableChronologies() {
init(); init();
return new HashSet<Chronology>(CHRONOS_BY_ID.values()); return new HashSet<>(CHRONOS_BY_ID.values());
} }
private static void init() { private static void init() {
@ -528,7 +517,7 @@ public abstract class Chronology implements Comparable<Chronology> {
* @throws DateTimeException if unable to create the date * @throws DateTimeException if unable to create the date
*/ */
public ChronoLocalDate dateNow(Clock clock) { public ChronoLocalDate dateNow(Clock clock) {
Jdk8Methods.requireNonNull(clock, "clock"); Objects.requireNonNull(clock, "clock");
return date(LocalDate.now(clock)); return date(LocalDate.now(clock));
} }
@ -725,7 +714,8 @@ public abstract class Chronology implements Comparable<Chronology> {
* @return the text value of the chronology, not null * @return the text value of the chronology, not null
*/ */
public String getDisplayName(TextStyle style, Locale locale) { public String getDisplayName(TextStyle style, Locale locale) {
return new DateTimeFormatterBuilder().appendChronologyText(style).toFormatter(locale).format(new DefaultInterfaceTemporalAccessor() { return new DateTimeFormatterBuilder().appendChronologyText(style).toFormatter(locale).format(
new TemporalAccessor() {
@Override @Override
public boolean isSupported(TemporalField field) { public boolean isSupported(TemporalField field) {
return false; return false;
@ -740,7 +730,7 @@ public abstract class Chronology implements Comparable<Chronology> {
if (query == TemporalQueries.chronology()) { if (query == TemporalQueries.chronology()) {
return (R) Chronology.this; return (R) Chronology.this;
} }
return super.query(query); return TemporalAccessor.super.query(query);
} }
}); });
} }

View File

@ -31,11 +31,20 @@
*/ */
package org.threeten.bp.chrono; package org.threeten.bp.chrono;
import static org.threeten.bp.temporal.ChronoField.ERA;
import java.util.Locale; import java.util.Locale;
import org.threeten.bp.format.DateTimeFormatterBuilder;
import org.threeten.bp.format.TextStyle; import org.threeten.bp.format.TextStyle;
import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.ChronoUnit;
import org.threeten.bp.temporal.Temporal;
import org.threeten.bp.temporal.TemporalAccessor; import org.threeten.bp.temporal.TemporalAccessor;
import org.threeten.bp.temporal.TemporalAdjuster; import org.threeten.bp.temporal.TemporalAdjuster;
import org.threeten.bp.temporal.TemporalField;
import org.threeten.bp.temporal.TemporalQueries;
import org.threeten.bp.temporal.TemporalQuery;
import org.threeten.bp.temporal.UnsupportedTemporalTypeException;
/** /**
* An era of the time-line. * An era of the time-line.
@ -59,6 +68,52 @@ import org.threeten.bp.temporal.TemporalAdjuster;
* It is recommended to use an enum whenever possible. * It is recommended to use an enum whenever possible.
*/ */
public interface Era extends TemporalAccessor, TemporalAdjuster { public interface Era extends TemporalAccessor, TemporalAdjuster {
@Override
default boolean isSupported(TemporalField field) {
if (field instanceof ChronoField) {
return field == ERA;
}
return field != null && field.isSupportedBy(this);
}
@Override
default int get(TemporalField field) {
if (field == ERA) {
return getValue();
}
return range(field).checkValidIntValue(getLong(field), field);
}
@Override
default long getLong(TemporalField field) {
if (field == ERA) {
return getValue();
} else if (field instanceof ChronoField) {
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.getFrom(this);
}
@SuppressWarnings("unchecked")
@Override
default <R> R query(TemporalQuery<R> query) {
if (query == TemporalQueries.precision()) {
return (R) ChronoUnit.ERAS;
}
if (query == TemporalQueries.chronology() || query == TemporalQueries.zone()
|| query == TemporalQueries.zoneId() || query == TemporalQueries.offset()
|| query == TemporalQueries.localDate() || query == TemporalQueries.localTime()) {
return null;
}
return query.queryFrom(this);
}
//-------------------------------------------------------------------------
@Override
default Temporal adjustInto(Temporal temporal) {
return temporal.with(ERA, getValue());
}
/** /**
* Gets the numeric value associated with the era as defined by the chronology. * Gets the numeric value associated with the era as defined by the chronology.
@ -90,6 +145,8 @@ public interface Era extends TemporalAccessor, TemporalAdjuster {
* @param locale the locale to use, not null * @param locale the locale to use, not null
* @return the text value of the era, not null * @return the text value of the era, not null
*/ */
String getDisplayName(TextStyle style, Locale locale); default String getDisplayName(TextStyle style, Locale locale) {
return new DateTimeFormatterBuilder().appendText(ERA, style).toFormatter(locale).format(this);
}
} }

View File

@ -56,6 +56,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import org.threeten.bp.Clock; import org.threeten.bp.Clock;
import org.threeten.bp.DateTimeException; import org.threeten.bp.DateTimeException;
@ -322,7 +323,7 @@ public final class HijrahChronology extends Chronology implements Serializable {
@Override // override with covariant return type @Override // override with covariant return type
public HijrahDate dateNow(Clock clock) { public HijrahDate dateNow(Clock clock) {
Jdk8Methods.requireNonNull(clock, "clock"); Objects.requireNonNull(clock, "clock");
return (HijrahDate) super.dateNow(clock); return (HijrahDate) super.dateNow(clock);
} }
@ -354,7 +355,7 @@ public final class HijrahChronology extends Chronology implements Serializable {
@Override @Override
public List<Era> eras() { public List<Era> eras() {
return Arrays.<Era>asList(HijrahEra.values()); return Arrays.asList(HijrahEra.values());
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------

View File

@ -50,6 +50,7 @@ import java.io.InputStreamReader;
import java.io.Serializable; import java.io.Serializable;
import java.text.ParseException; import java.text.ParseException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Objects;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
@ -502,7 +503,7 @@ public final class HijrahDate
* @throws InvalidCalendarFieldException if the day-of-month is invalid for the month-year * @throws InvalidCalendarFieldException if the day-of-month is invalid for the month-year
*/ */
static HijrahDate of(HijrahEra era, int yearOfEra, int monthOfYear, int dayOfMonth) { static HijrahDate of(HijrahEra era, int yearOfEra, int monthOfYear, int dayOfMonth) {
Jdk8Methods.requireNonNull(era, "era"); Objects.requireNonNull(era, "era");
checkValidYearOfEra(yearOfEra); checkValidYearOfEra(yearOfEra);
checkValidMonth(monthOfYear); checkValidMonth(monthOfYear);
checkValidDayOfMonth(dayOfMonth); checkValidDayOfMonth(dayOfMonth);
@ -725,7 +726,7 @@ public final class HijrahDate
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public final ChronoLocalDateTime<HijrahDate> atTime(LocalTime localTime) { public ChronoLocalDateTime<HijrahDate> atTime(LocalTime localTime) {
return (ChronoLocalDateTime<HijrahDate>) super.atTime(localTime); return (ChronoLocalDateTime<HijrahDate>) super.atTime(localTime);
} }
@ -921,6 +922,7 @@ public final class HijrahDate
try { try {
day = ADJUSTED_CYCLES[cycleNumber]; day = ADJUSTED_CYCLES[cycleNumber];
// TODO remove catching AIOOBE (and other usages)
} catch (ArrayIndexOutOfBoundsException e) { } catch (ArrayIndexOutOfBoundsException e) {
day = null; day = null;
} }
@ -1673,7 +1675,7 @@ public final class HijrahDate
* @throws IOException for zip/jar file handling exception. * @throws IOException for zip/jar file handling exception.
*/ */
private static InputStream getConfigFileInputStream() throws IOException { private static InputStream getConfigFileInputStream() throws IOException {
// TODO: eliminate this
String fileName = System String fileName = System
.getProperty("org.threeten.bp.i18n.HijrahDate.deviationConfigFile"); .getProperty("org.threeten.bp.i18n.HijrahDate.deviationConfigFile");

View File

@ -51,6 +51,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import org.threeten.bp.Clock; import org.threeten.bp.Clock;
import org.threeten.bp.DateTimeException; import org.threeten.bp.DateTimeException;
@ -328,7 +329,7 @@ public final class IsoChronology extends Chronology implements Serializable {
*/ */
@Override // override with covariant return type @Override // override with covariant return type
public LocalDate dateNow(Clock clock) { public LocalDate dateNow(Clock clock) {
Jdk8Methods.requireNonNull(clock, "clock"); Objects.requireNonNull(clock, "clock");
return date(LocalDate.now(clock)); return date(LocalDate.now(clock));
} }
@ -440,7 +441,7 @@ public final class IsoChronology extends Chronology implements Serializable {
long months = Jdk8Methods.safeSubtract(moy, 1); long months = Jdk8Methods.safeSubtract(moy, 1);
long days = Jdk8Methods.safeSubtract(dom, 1); long days = Jdk8Methods.safeSubtract(dom, 1);
return LocalDate.of(y, 1, 1).plusMonths(months).plusDays(days); return LocalDate.of(y, 1, 1).plusMonths(months).plusDays(days);
} else if (resolverStyle == ResolverStyle.SMART){ } else if (resolverStyle == ResolverStyle.SMART) {
DAY_OF_MONTH.checkValidValue(dom); DAY_OF_MONTH.checkValidValue(dom);
if (moy == 4 || moy == 6 || moy == 9 || moy == 11) { if (moy == 4 || moy == 6 || moy == 9 || moy == 11) {
dom = Math.min(dom, 30); dom = Math.min(dom, 30);

View File

@ -56,6 +56,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import org.threeten.bp.Clock; import org.threeten.bp.Clock;
import org.threeten.bp.DateTimeException; import org.threeten.bp.DateTimeException;
@ -304,7 +305,7 @@ public final class JapaneseChronology extends Chronology implements Serializable
@Override // override with covariant return type @Override // override with covariant return type
public JapaneseDate dateNow(Clock clock) { public JapaneseDate dateNow(Clock clock) {
Jdk8Methods.requireNonNull(clock, "clock"); Objects.requireNonNull(clock, "clock");
return (JapaneseDate) super.dateNow(clock); return (JapaneseDate) super.dateNow(clock);
} }
@ -354,7 +355,7 @@ public final class JapaneseChronology extends Chronology implements Serializable
@Override @Override
public List<Era> eras() { public List<Era> eras() {
return Arrays.<Era>asList(JapaneseEra.values()); return Arrays.asList(JapaneseEra.values());
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------

View File

@ -41,6 +41,7 @@ import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.Serializable; import java.io.Serializable;
import java.util.Calendar; import java.util.Calendar;
import java.util.Objects;
import org.threeten.bp.Clock; import org.threeten.bp.Clock;
import org.threeten.bp.DateTimeException; import org.threeten.bp.DateTimeException;
@ -48,7 +49,6 @@ import org.threeten.bp.LocalDate;
import org.threeten.bp.LocalTime; import org.threeten.bp.LocalTime;
import org.threeten.bp.Period; import org.threeten.bp.Period;
import org.threeten.bp.ZoneId; import org.threeten.bp.ZoneId;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField; import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.TemporalAccessor; import org.threeten.bp.temporal.TemporalAccessor;
import org.threeten.bp.temporal.TemporalAdjuster; import org.threeten.bp.temporal.TemporalAdjuster;
@ -181,7 +181,7 @@ public final class JapaneseDate
* or if the day-of-month is invalid for the month-year * or if the day-of-month is invalid for the month-year
*/ */
public static JapaneseDate of(JapaneseEra era, int yearOfEra, int month, int dayOfMonth) { public static JapaneseDate of(JapaneseEra era, int yearOfEra, int month, int dayOfMonth) {
Jdk8Methods.requireNonNull(era, "era"); Objects.requireNonNull(era, "era");
if (yearOfEra < 1) { if (yearOfEra < 1) {
throw new DateTimeException("Invalid YearOfEra: " + yearOfEra); throw new DateTimeException("Invalid YearOfEra: " + yearOfEra);
} }
@ -211,7 +211,7 @@ public final class JapaneseDate
* or if the day-of-year is invalid for the year * or if the day-of-year is invalid for the year
*/ */
static JapaneseDate ofYearDay(JapaneseEra era, int yearOfEra, int dayOfYear) { static JapaneseDate ofYearDay(JapaneseEra era, int yearOfEra, int dayOfYear) {
Jdk8Methods.requireNonNull(era, "era"); Objects.requireNonNull(era, "era");
if (yearOfEra < 1) { if (yearOfEra < 1) {
throw new DateTimeException("Invalid YearOfEra: " + yearOfEra); throw new DateTimeException("Invalid YearOfEra: " + yearOfEra);
} }

View File

@ -38,11 +38,10 @@ import java.io.InvalidObjectException;
import java.io.ObjectStreamException; import java.io.ObjectStreamException;
import java.io.Serializable; import java.io.Serializable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects;
import org.threeten.bp.DateTimeException; import org.threeten.bp.DateTimeException;
import org.threeten.bp.LocalDate; import org.threeten.bp.LocalDate;
import org.threeten.bp.jdk8.DefaultInterfaceEra;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField; import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.TemporalField; import org.threeten.bp.temporal.TemporalField;
import org.threeten.bp.temporal.ValueRange; import org.threeten.bp.temporal.ValueRange;
@ -62,8 +61,7 @@ import org.threeten.bp.temporal.ValueRange;
* This class is immutable and thread-safe. * This class is immutable and thread-safe.
*/ */
public final class JapaneseEra public final class JapaneseEra
extends DefaultInterfaceEra implements Era, Serializable {
implements Serializable {
// The offset value to 0-based index from the era value. // The offset value to 0-based index from the era value.
// i.e., getValue() + ERA_OFFSET == 0-based index; except that -999 is mapped to zero // i.e., getValue() + ERA_OFFSET == 0-based index; except that -999 is mapped to zero
@ -180,8 +178,8 @@ public final class JapaneseEra
if (known.length > 5) { if (known.length > 5) {
throw new DateTimeException("Only one additional Japanese era can be added"); throw new DateTimeException("Only one additional Japanese era can be added");
} }
Jdk8Methods.requireNonNull(since, "since"); Objects.requireNonNull(since, "since");
Jdk8Methods.requireNonNull(name, "name"); Objects.requireNonNull(name, "name");
if (!since.isAfter(REIWA.since)) { if (!since.isAfter(REIWA.since)) {
throw new DateTimeException("Invalid since date for additional Japanese era, must be after Reiwa"); throw new DateTimeException("Invalid since date for additional Japanese era, must be after Reiwa");
} }
@ -222,7 +220,7 @@ public final class JapaneseEra
* @throws IllegalArgumentException if there is not JapaneseEra with the specified name * @throws IllegalArgumentException if there is not JapaneseEra with the specified name
*/ */
public static JapaneseEra valueOf(String japaneseEra) { public static JapaneseEra valueOf(String japaneseEra) {
Jdk8Methods.requireNonNull(japaneseEra, "japaneseEra"); Objects.requireNonNull(japaneseEra, "japaneseEra");
JapaneseEra[] known = KNOWN_ERAS; JapaneseEra[] known = KNOWN_ERAS;
for (JapaneseEra era : known) { for (JapaneseEra era : known) {
if (japaneseEra.equals(era.name)) { if (japaneseEra.equals(era.name)) {
@ -320,7 +318,7 @@ public final class JapaneseEra
if (field == ChronoField.ERA) { if (field == ChronoField.ERA) {
return JapaneseChronology.INSTANCE.range(ChronoField.ERA); return JapaneseChronology.INSTANCE.range(ChronoField.ERA);
} }
return super.range(field); return Era.super.range(field);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------

View File

@ -54,6 +54,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import org.threeten.bp.Clock; import org.threeten.bp.Clock;
import org.threeten.bp.DateTimeException; import org.threeten.bp.DateTimeException;
@ -223,7 +224,7 @@ public final class MinguoChronology extends Chronology implements Serializable {
@Override // override with covariant return type @Override // override with covariant return type
public MinguoDate dateNow(Clock clock) { public MinguoDate dateNow(Clock clock) {
Jdk8Methods.requireNonNull(clock, "clock"); Objects.requireNonNull(clock, "clock");
return (MinguoDate) super.dateNow(clock); return (MinguoDate) super.dateNow(clock);
} }

View File

@ -40,6 +40,7 @@ import java.io.DataInput;
import java.io.DataOutput; import java.io.DataOutput;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects;
import org.threeten.bp.Clock; import org.threeten.bp.Clock;
import org.threeten.bp.DateTimeException; import org.threeten.bp.DateTimeException;
@ -47,7 +48,6 @@ import org.threeten.bp.LocalDate;
import org.threeten.bp.LocalTime; import org.threeten.bp.LocalTime;
import org.threeten.bp.Period; import org.threeten.bp.Period;
import org.threeten.bp.ZoneId; import org.threeten.bp.ZoneId;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField; import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.TemporalAccessor; import org.threeten.bp.temporal.TemporalAccessor;
import org.threeten.bp.temporal.TemporalAdjuster; import org.threeten.bp.temporal.TemporalAdjuster;
@ -175,7 +175,7 @@ public final class MinguoDate
* @param isoDate the standard local date, validated not null * @param isoDate the standard local date, validated not null
*/ */
MinguoDate(LocalDate date) { MinguoDate(LocalDate date) {
Jdk8Methods.requireNonNull(date, "date"); Objects.requireNonNull(date, "date");
this.isoDate = date; this.isoDate = date;
} }

View File

@ -55,6 +55,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import org.threeten.bp.Clock; import org.threeten.bp.Clock;
import org.threeten.bp.DateTimeException; import org.threeten.bp.DateTimeException;
@ -259,7 +260,7 @@ public final class ThaiBuddhistChronology extends Chronology implements Serializ
@Override // override with covariant return type @Override // override with covariant return type
public ThaiBuddhistDate dateNow(Clock clock) { public ThaiBuddhistDate dateNow(Clock clock) {
Jdk8Methods.requireNonNull(clock, "clock"); Objects.requireNonNull(clock, "clock");
return (ThaiBuddhistDate) super.dateNow(clock); return (ThaiBuddhistDate) super.dateNow(clock);
} }
@ -294,7 +295,7 @@ public final class ThaiBuddhistChronology extends Chronology implements Serializ
@Override @Override
public List<Era> eras() { public List<Era> eras() {
return Arrays.<Era>asList(ThaiBuddhistEra.values()); return Arrays.asList(ThaiBuddhistEra.values());
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------

View File

@ -40,6 +40,7 @@ import java.io.DataInput;
import java.io.DataOutput; import java.io.DataOutput;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects;
import org.threeten.bp.Clock; import org.threeten.bp.Clock;
import org.threeten.bp.DateTimeException; import org.threeten.bp.DateTimeException;
@ -47,7 +48,6 @@ import org.threeten.bp.LocalDate;
import org.threeten.bp.LocalTime; import org.threeten.bp.LocalTime;
import org.threeten.bp.Period; import org.threeten.bp.Period;
import org.threeten.bp.ZoneId; import org.threeten.bp.ZoneId;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField; import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.TemporalAccessor; import org.threeten.bp.temporal.TemporalAccessor;
import org.threeten.bp.temporal.TemporalAdjuster; import org.threeten.bp.temporal.TemporalAdjuster;
@ -175,7 +175,7 @@ public final class ThaiBuddhistDate
* @param isoDate the standard local date, validated not null * @param isoDate the standard local date, validated not null
*/ */
ThaiBuddhistDate(LocalDate date) { ThaiBuddhistDate(LocalDate date) {
Jdk8Methods.requireNonNull(date, "date"); Objects.requireNonNull(date, "date");
this.isoDate = date; this.isoDate = date;
} }

View File

@ -54,6 +54,7 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import org.threeten.bp.DateTimeException; import org.threeten.bp.DateTimeException;
@ -68,7 +69,6 @@ import org.threeten.bp.chrono.ChronoLocalDateTime;
import org.threeten.bp.chrono.ChronoZonedDateTime; import org.threeten.bp.chrono.ChronoZonedDateTime;
import org.threeten.bp.chrono.Chronology; import org.threeten.bp.chrono.Chronology;
import org.threeten.bp.chrono.IsoChronology; import org.threeten.bp.chrono.IsoChronology;
import org.threeten.bp.jdk8.DefaultInterfaceTemporalAccessor;
import org.threeten.bp.jdk8.Jdk8Methods; import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField; import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.TemporalAccessor; import org.threeten.bp.temporal.TemporalAccessor;
@ -92,14 +92,13 @@ import org.threeten.bp.temporal.TemporalQuery;
* This class is mutable and not thread-safe. * This class is mutable and not thread-safe.
* It should only be used from a single thread. * It should only be used from a single thread.
*/ */
final class DateTimeBuilder public final class DateTimeBuilder
extends DefaultInterfaceTemporalAccessor
implements TemporalAccessor, Cloneable { implements TemporalAccessor, Cloneable {
/** /**
* The map of other fields. * The map of other fields.
*/ */
final Map<TemporalField, Long> fieldValues = new HashMap<TemporalField, Long>(); final Map<TemporalField, Long> fieldValues = new HashMap<>();
/** /**
* The chronology. * The chronology.
*/ */
@ -164,7 +163,7 @@ final class DateTimeBuilder
* @throws DateTimeException if the field is already present with a different value * @throws DateTimeException if the field is already present with a different value
*/ */
DateTimeBuilder addFieldValue(TemporalField field, long value) { DateTimeBuilder addFieldValue(TemporalField field, long value) {
Jdk8Methods.requireNonNull(field, "field"); Objects.requireNonNull(field, "field");
Long old = getFieldValue0(field); // check first for better error message Long old = getFieldValue0(field); // check first for better error message
if (old != null && old.longValue() != value) { if (old != null && old.longValue() != value) {
throw new DateTimeException("Conflict found: " + field + " " + old + " differs from " + field + " " + value + ": " + this); throw new DateTimeException("Conflict found: " + field + " " + old + " differs from " + field + " " + value + ": " + this);
@ -655,7 +654,7 @@ final class DateTimeBuilder
@Override @Override
public long getLong(TemporalField field) { public long getLong(TemporalField field) {
Jdk8Methods.requireNonNull(field, "field"); Objects.requireNonNull(field, "field");
Long value = getFieldValue0(field); Long value = getFieldValue0(field);
if (value == null) { if (value == null) {
if (date != null && date.isSupported(field)) { if (date != null && date.isSupported(field)) {

View File

@ -52,6 +52,7 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import org.threeten.bp.DateTimeException; import org.threeten.bp.DateTimeException;
@ -62,7 +63,6 @@ import org.threeten.bp.chrono.Chronology;
import org.threeten.bp.chrono.IsoChronology; import org.threeten.bp.chrono.IsoChronology;
import org.threeten.bp.format.DateTimeFormatterBuilder.CompositePrinterParser; import org.threeten.bp.format.DateTimeFormatterBuilder.CompositePrinterParser;
import org.threeten.bp.format.DateTimeParseContext.Parsed; import org.threeten.bp.format.DateTimeParseContext.Parsed;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField; import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.IsoFields; import org.threeten.bp.temporal.IsoFields;
import org.threeten.bp.temporal.TemporalAccessor; import org.threeten.bp.temporal.TemporalAccessor;
@ -584,7 +584,7 @@ public final class DateTimeFormatter {
static { static {
// manually code maps to ensure correct data always used // manually code maps to ensure correct data always used
// (locale data can be changed by application code) // (locale data can be changed by application code)
Map<Long, String> dow = new HashMap<Long, String>(); Map<Long, String> dow = new HashMap<>();
dow.put(1L, "Mon"); dow.put(1L, "Mon");
dow.put(2L, "Tue"); dow.put(2L, "Tue");
dow.put(3L, "Wed"); dow.put(3L, "Wed");
@ -592,7 +592,7 @@ public final class DateTimeFormatter {
dow.put(5L, "Fri"); dow.put(5L, "Fri");
dow.put(6L, "Sat"); dow.put(6L, "Sat");
dow.put(7L, "Sun"); dow.put(7L, "Sun");
Map<Long, String> moy = new HashMap<Long, String>(); Map<Long, String> moy = new HashMap<>();
moy.put(1L, "Jan"); moy.put(1L, "Jan");
moy.put(2L, "Feb"); moy.put(2L, "Feb");
moy.put(3L, "Mar"); moy.put(3L, "Mar");
@ -808,7 +808,7 @@ public final class DateTimeFormatter {
* @return the date formatter, not null * @return the date formatter, not null
*/ */
public static DateTimeFormatter ofLocalizedDate(FormatStyle dateStyle) { public static DateTimeFormatter ofLocalizedDate(FormatStyle dateStyle) {
Jdk8Methods.requireNonNull(dateStyle, "dateStyle"); Objects.requireNonNull(dateStyle, "dateStyle");
return new DateTimeFormatterBuilder().appendLocalized(dateStyle, null) return new DateTimeFormatterBuilder().appendLocalized(dateStyle, null)
.toFormatter().withChronology(IsoChronology.INSTANCE); .toFormatter().withChronology(IsoChronology.INSTANCE);
} }
@ -832,7 +832,7 @@ public final class DateTimeFormatter {
* @return the time formatter, not null * @return the time formatter, not null
*/ */
public static DateTimeFormatter ofLocalizedTime(FormatStyle timeStyle) { public static DateTimeFormatter ofLocalizedTime(FormatStyle timeStyle) {
Jdk8Methods.requireNonNull(timeStyle, "timeStyle"); Objects.requireNonNull(timeStyle, "timeStyle");
return new DateTimeFormatterBuilder().appendLocalized(null, timeStyle) return new DateTimeFormatterBuilder().appendLocalized(null, timeStyle)
.toFormatter().withChronology(IsoChronology.INSTANCE); .toFormatter().withChronology(IsoChronology.INSTANCE);
} }
@ -856,7 +856,7 @@ public final class DateTimeFormatter {
* @return the date-time formatter, not null * @return the date-time formatter, not null
*/ */
public static DateTimeFormatter ofLocalizedDateTime(FormatStyle dateTimeStyle) { public static DateTimeFormatter ofLocalizedDateTime(FormatStyle dateTimeStyle) {
Jdk8Methods.requireNonNull(dateTimeStyle, "dateTimeStyle"); Objects.requireNonNull(dateTimeStyle, "dateTimeStyle");
return new DateTimeFormatterBuilder().appendLocalized(dateTimeStyle, dateTimeStyle) return new DateTimeFormatterBuilder().appendLocalized(dateTimeStyle, dateTimeStyle)
.toFormatter().withChronology(IsoChronology.INSTANCE); .toFormatter().withChronology(IsoChronology.INSTANCE);
} }
@ -881,8 +881,8 @@ public final class DateTimeFormatter {
* @return the date, time or date-time formatter, not null * @return the date, time or date-time formatter, not null
*/ */
public static DateTimeFormatter ofLocalizedDateTime(FormatStyle dateStyle, FormatStyle timeStyle) { public static DateTimeFormatter ofLocalizedDateTime(FormatStyle dateStyle, FormatStyle timeStyle) {
Jdk8Methods.requireNonNull(dateStyle, "dateStyle"); Objects.requireNonNull(dateStyle, "dateStyle");
Jdk8Methods.requireNonNull(timeStyle, "timeStyle"); Objects.requireNonNull(timeStyle, "timeStyle");
return new DateTimeFormatterBuilder().appendLocalized(dateStyle, timeStyle) return new DateTimeFormatterBuilder().appendLocalized(dateStyle, timeStyle)
.toFormatter().withChronology(IsoChronology.INSTANCE); .toFormatter().withChronology(IsoChronology.INSTANCE);
} }
@ -928,18 +928,15 @@ public final class DateTimeFormatter {
* </pre> * </pre>
* @return a query that provides access to the excess days that were parsed * @return a query that provides access to the excess days that were parsed
*/ */
public static final TemporalQuery<Period> parsedExcessDays() { public static TemporalQuery<Period> parsedExcessDays() {
return PARSED_EXCESS_DAYS; return temporal -> {
}
private static final TemporalQuery<Period> PARSED_EXCESS_DAYS = new TemporalQuery<Period>() {
public Period queryFrom(TemporalAccessor temporal) {
if (temporal instanceof DateTimeBuilder) { if (temporal instanceof DateTimeBuilder) {
return ((DateTimeBuilder) temporal).excessDays; return ((DateTimeBuilder) temporal).excessDays;
} else { } else {
return Period.ZERO; return Period.ZERO;
} }
}
}; };
}
/** /**
* A query that provides access to whether a leap-second was parsed. * A query that provides access to whether a leap-second was parsed.
@ -971,18 +968,15 @@ public final class DateTimeFormatter {
* </pre> * </pre>
* @return a query that provides access to whether a leap-second was parsed * @return a query that provides access to whether a leap-second was parsed
*/ */
public static final TemporalQuery<Boolean> parsedLeapSecond() { public static TemporalQuery<Boolean> parsedLeapSecond() {
return PARSED_LEAP_SECOND; return temporal -> {
}
private static final TemporalQuery<Boolean> PARSED_LEAP_SECOND = new TemporalQuery<Boolean>() {
public Boolean queryFrom(TemporalAccessor temporal) {
if (temporal instanceof DateTimeBuilder) { if (temporal instanceof DateTimeBuilder) {
return ((DateTimeBuilder) temporal).leapSecond; return ((DateTimeBuilder) temporal).leapSecond;
} else { } else {
return Boolean.FALSE; return Boolean.FALSE;
} }
}
}; };
}
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
@ -1029,10 +1023,10 @@ public final class DateTimeFormatter {
DateTimeFormatter(CompositePrinterParser printerParser, Locale locale, DateTimeFormatter(CompositePrinterParser printerParser, Locale locale,
DecimalStyle decimalStyle, ResolverStyle resolverStyle, DecimalStyle decimalStyle, ResolverStyle resolverStyle,
Set<TemporalField> resolverFields, Chronology chrono, ZoneId zone) { Set<TemporalField> resolverFields, Chronology chrono, ZoneId zone) {
this.printerParser = Jdk8Methods.requireNonNull(printerParser, "printerParser"); this.printerParser = Objects.requireNonNull(printerParser, "printerParser");
this.locale = Jdk8Methods.requireNonNull(locale, "locale"); this.locale = Objects.requireNonNull(locale, "locale");
this.decimalStyle = Jdk8Methods.requireNonNull(decimalStyle, "decimalStyle"); this.decimalStyle = Objects.requireNonNull(decimalStyle, "decimalStyle");
this.resolverStyle = Jdk8Methods.requireNonNull(resolverStyle, "resolverStyle"); this.resolverStyle = Objects.requireNonNull(resolverStyle, "resolverStyle");
this.resolverFields = resolverFields; this.resolverFields = resolverFields;
this.chrono = chrono; this.chrono = chrono;
this.zone = zone; this.zone = zone;
@ -1133,7 +1127,7 @@ public final class DateTimeFormatter {
* @return a formatter based on this formatter with the requested override chronology, not null * @return a formatter based on this formatter with the requested override chronology, not null
*/ */
public DateTimeFormatter withChronology(Chronology chrono) { public DateTimeFormatter withChronology(Chronology chrono) {
if (Jdk8Methods.equals(this.chrono, chrono)) { if (Objects.equals(this.chrono, chrono)) {
return this; return this;
} }
return new DateTimeFormatter(printerParser, locale, decimalStyle, resolverStyle, resolverFields, chrono, zone); return new DateTimeFormatter(printerParser, locale, decimalStyle, resolverStyle, resolverFields, chrono, zone);
@ -1180,7 +1174,7 @@ public final class DateTimeFormatter {
* @return a formatter based on this formatter with the requested override zone, not null * @return a formatter based on this formatter with the requested override zone, not null
*/ */
public DateTimeFormatter withZone(ZoneId zone) { public DateTimeFormatter withZone(ZoneId zone) {
if (Jdk8Methods.equals(this.zone, zone)) { if (Objects.equals(this.zone, zone)) {
return this; return this;
} }
return new DateTimeFormatter(printerParser, locale, decimalStyle, resolverStyle, resolverFields, chrono, zone); return new DateTimeFormatter(printerParser, locale, decimalStyle, resolverStyle, resolverFields, chrono, zone);
@ -1221,8 +1215,8 @@ public final class DateTimeFormatter {
* @return a formatter based on this formatter with the requested resolver style, not null * @return a formatter based on this formatter with the requested resolver style, not null
*/ */
public DateTimeFormatter withResolverStyle(ResolverStyle resolverStyle) { public DateTimeFormatter withResolverStyle(ResolverStyle resolverStyle) {
Jdk8Methods.requireNonNull(resolverStyle, "resolverStyle"); Objects.requireNonNull(resolverStyle, "resolverStyle");
if (Jdk8Methods.equals(this.resolverStyle, resolverStyle)) { if (Objects.equals(this.resolverStyle, resolverStyle)) {
return this; return this;
} }
return new DateTimeFormatter(printerParser, locale, decimalStyle, resolverStyle, resolverFields, chrono, zone); return new DateTimeFormatter(printerParser, locale, decimalStyle, resolverStyle, resolverFields, chrono, zone);
@ -1286,8 +1280,8 @@ public final class DateTimeFormatter {
if (resolverFields == null) { if (resolverFields == null) {
return new DateTimeFormatter(printerParser, locale, decimalStyle, resolverStyle, null, chrono, zone); return new DateTimeFormatter(printerParser, locale, decimalStyle, resolverStyle, null, chrono, zone);
} }
Set<TemporalField> fields = new HashSet<TemporalField>(Arrays.asList(resolverFields)); Set<TemporalField> fields = new HashSet<>(Arrays.asList(resolverFields));
if (Jdk8Methods.equals(this.resolverFields, fields)) { if (Objects.equals(this.resolverFields, fields)) {
return this; return this;
} }
fields = Collections.unmodifiableSet(fields); fields = Collections.unmodifiableSet(fields);
@ -1337,10 +1331,10 @@ public final class DateTimeFormatter {
if (resolverFields == null) { if (resolverFields == null) {
return new DateTimeFormatter(printerParser, locale, decimalStyle, resolverStyle, null, chrono, zone); return new DateTimeFormatter(printerParser, locale, decimalStyle, resolverStyle, null, chrono, zone);
} }
if (Jdk8Methods.equals(this.resolverFields, resolverFields)) { if (Objects.equals(this.resolverFields, resolverFields)) {
return this; return this;
} }
resolverFields = Collections.unmodifiableSet(new HashSet<TemporalField>(resolverFields)); resolverFields = Collections.unmodifiableSet(new HashSet<>(resolverFields));
return new DateTimeFormatter(printerParser, locale, decimalStyle, resolverStyle, resolverFields, chrono, zone); return new DateTimeFormatter(printerParser, locale, decimalStyle, resolverStyle, resolverFields, chrono, zone);
} }
@ -1377,8 +1371,8 @@ public final class DateTimeFormatter {
* @throws DateTimeException if an error occurs during formatting * @throws DateTimeException if an error occurs during formatting
*/ */
public void formatTo(TemporalAccessor temporal, Appendable appendable) { public void formatTo(TemporalAccessor temporal, Appendable appendable) {
Jdk8Methods.requireNonNull(temporal, "temporal"); Objects.requireNonNull(temporal, "temporal");
Jdk8Methods.requireNonNull(appendable, "appendable"); Objects.requireNonNull(appendable, "appendable");
try { try {
DateTimePrintContext context = new DateTimePrintContext(temporal, this); DateTimePrintContext context = new DateTimePrintContext(temporal, this);
if (appendable instanceof StringBuilder) { if (appendable instanceof StringBuilder) {
@ -1411,7 +1405,7 @@ public final class DateTimeFormatter {
* @throws DateTimeParseException if unable to parse the requested result * @throws DateTimeParseException if unable to parse the requested result
*/ */
public TemporalAccessor parse(CharSequence text) { public TemporalAccessor parse(CharSequence text) {
Jdk8Methods.requireNonNull(text, "text"); Objects.requireNonNull(text, "text");
try { try {
return parseToBuilder(text, null).resolve(resolverStyle, resolverFields); return parseToBuilder(text, null).resolve(resolverStyle, resolverFields);
} catch (DateTimeParseException ex) { } catch (DateTimeParseException ex) {
@ -1452,13 +1446,11 @@ public final class DateTimeFormatter {
* @throws IndexOutOfBoundsException if the position is invalid * @throws IndexOutOfBoundsException if the position is invalid
*/ */
public TemporalAccessor parse(CharSequence text, ParsePosition position) { public TemporalAccessor parse(CharSequence text, ParsePosition position) {
Jdk8Methods.requireNonNull(text, "text"); Objects.requireNonNull(text, "text");
Jdk8Methods.requireNonNull(position, "position"); Objects.requireNonNull(position, "position");
try { try {
return parseToBuilder(text, position).resolve(resolverStyle, resolverFields); return parseToBuilder(text, position).resolve(resolverStyle, resolverFields);
} catch (DateTimeParseException ex) { } catch (DateTimeParseException | IndexOutOfBoundsException ex) {
throw ex;
} catch (IndexOutOfBoundsException ex) {
throw ex; throw ex;
} catch (RuntimeException ex) { } catch (RuntimeException ex) {
throw createError(text, ex); throw createError(text, ex);
@ -1485,8 +1477,8 @@ public final class DateTimeFormatter {
* @throws DateTimeParseException if unable to parse the requested result * @throws DateTimeParseException if unable to parse the requested result
*/ */
public <T> T parse(CharSequence text, TemporalQuery<T> type) { public <T> T parse(CharSequence text, TemporalQuery<T> type) {
Jdk8Methods.requireNonNull(text, "text"); Objects.requireNonNull(text, "text");
Jdk8Methods.requireNonNull(type, "type"); Objects.requireNonNull(type, "type");
try { try {
DateTimeBuilder builder = parseToBuilder(text, null).resolve(resolverStyle, resolverFields); DateTimeBuilder builder = parseToBuilder(text, null).resolve(resolverStyle, resolverFields);
return builder.build(type); return builder.build(type);
@ -1527,8 +1519,8 @@ public final class DateTimeFormatter {
* @throws DateTimeParseException if unable to parse the requested result * @throws DateTimeParseException if unable to parse the requested result
*/ */
public TemporalAccessor parseBest(CharSequence text, TemporalQuery<?>... types) { public TemporalAccessor parseBest(CharSequence text, TemporalQuery<?>... types) {
Jdk8Methods.requireNonNull(text, "text"); Objects.requireNonNull(text, "text");
Jdk8Methods.requireNonNull(types, "types"); Objects.requireNonNull(types, "types");
if (types.length < 2) { if (types.length < 2) {
throw new IllegalArgumentException("At least two types must be specified"); throw new IllegalArgumentException("At least two types must be specified");
} }
@ -1638,8 +1630,8 @@ public final class DateTimeFormatter {
} }
private Parsed parseUnresolved0(CharSequence text, ParsePosition position) { private Parsed parseUnresolved0(CharSequence text, ParsePosition position) {
Jdk8Methods.requireNonNull(text, "text"); Objects.requireNonNull(text, "text");
Jdk8Methods.requireNonNull(position, "position"); Objects.requireNonNull(position, "position");
DateTimeParseContext context = new DateTimeParseContext(this); DateTimeParseContext context = new DateTimeParseContext(this);
int pos = position.getIndex(); int pos = position.getIndex();
pos = printerParser.parse(context, text, pos); pos = printerParser.parse(context, text, pos);
@ -1696,7 +1688,7 @@ public final class DateTimeFormatter {
* @return this formatter as a classic format instance, not null * @return this formatter as a classic format instance, not null
*/ */
public Format toFormat(TemporalQuery<?> query) { public Format toFormat(TemporalQuery<?> query) {
Jdk8Methods.requireNonNull(query, "query"); Objects.requireNonNull(query, "query");
return new ClassicFormat(this, query); return new ClassicFormat(this, query);
} }
@ -1731,10 +1723,10 @@ public final class DateTimeFormatter {
@Override @Override
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) { public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
Jdk8Methods.requireNonNull(obj, "obj"); Objects.requireNonNull(obj, "obj");
Jdk8Methods.requireNonNull(toAppendTo, "toAppendTo"); Objects.requireNonNull(toAppendTo, "toAppendTo");
Jdk8Methods.requireNonNull(pos, "pos"); Objects.requireNonNull(pos, "pos");
if (obj instanceof TemporalAccessor == false) { if (!(obj instanceof TemporalAccessor)) {
throw new IllegalArgumentException("Format target must implement TemporalAccessor"); throw new IllegalArgumentException("Format target must implement TemporalAccessor");
} }
pos.setBeginIndex(0); pos.setBeginIndex(0);
@ -1748,7 +1740,7 @@ public final class DateTimeFormatter {
} }
@Override @Override
public Object parseObject(String text) throws ParseException { public Object parseObject(String text) throws ParseException {
Jdk8Methods.requireNonNull(text, "text"); Objects.requireNonNull(text, "text");
try { try {
if (query == null) { if (query == null) {
return formatter.parseToBuilder(text, null) return formatter.parseToBuilder(text, null)
@ -1763,7 +1755,7 @@ public final class DateTimeFormatter {
} }
@Override @Override
public Object parseObject(String text, ParsePosition pos) { public Object parseObject(String text, ParsePosition pos) {
Jdk8Methods.requireNonNull(text, "text"); Objects.requireNonNull(text, "text");
Parsed unresolved; Parsed unresolved;
try { try {
unresolved = formatter.parseUnresolved0(text, pos); unresolved = formatter.parseUnresolved0(text, pos);

View File

@ -58,6 +58,7 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.MissingResourceException; import java.util.MissingResourceException;
import java.util.Objects;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.Set; import java.util.Set;
import java.util.TimeZone; import java.util.TimeZone;
@ -166,8 +167,8 @@ public final class DateTimeFormatterBuilder {
*/ */
public static String getLocalizedDateTimePattern( public static String getLocalizedDateTimePattern(
FormatStyle dateStyle, FormatStyle timeStyle, Chronology chrono, Locale locale) { FormatStyle dateStyle, FormatStyle timeStyle, Chronology chrono, Locale locale) {
Jdk8Methods.requireNonNull(locale, "locale"); Objects.requireNonNull(locale, "locale");
Jdk8Methods.requireNonNull(chrono, "chrono"); Objects.requireNonNull(chrono, "chrono");
if (dateStyle == null && timeStyle == null) { if (dateStyle == null && timeStyle == null) {
throw new IllegalArgumentException("Either dateStyle or timeStyle must be non-null"); throw new IllegalArgumentException("Either dateStyle or timeStyle must be non-null");
} }
@ -320,7 +321,7 @@ public final class DateTimeFormatterBuilder {
* @return this, for chaining, not null * @return this, for chaining, not null
*/ */
public DateTimeFormatterBuilder parseDefaulting(TemporalField field, long value) { public DateTimeFormatterBuilder parseDefaulting(TemporalField field, long value) {
Jdk8Methods.requireNonNull(field, "field"); Objects.requireNonNull(field, "field");
appendInternal(new DefaultingParser(field, value)); appendInternal(new DefaultingParser(field, value));
return this; return this;
} }
@ -345,7 +346,7 @@ public final class DateTimeFormatterBuilder {
* @return this, for chaining, not null * @return this, for chaining, not null
*/ */
public DateTimeFormatterBuilder appendValue(TemporalField field) { public DateTimeFormatterBuilder appendValue(TemporalField field) {
Jdk8Methods.requireNonNull(field, "field"); Objects.requireNonNull(field, "field");
appendValue(new NumberPrinterParser(field, 1, 19, SignStyle.NORMAL)); appendValue(new NumberPrinterParser(field, 1, 19, SignStyle.NORMAL));
return this; return this;
} }
@ -399,7 +400,7 @@ public final class DateTimeFormatterBuilder {
* @throws IllegalArgumentException if the width is invalid * @throws IllegalArgumentException if the width is invalid
*/ */
public DateTimeFormatterBuilder appendValue(TemporalField field, int width) { public DateTimeFormatterBuilder appendValue(TemporalField field, int width) {
Jdk8Methods.requireNonNull(field, "field"); Objects.requireNonNull(field, "field");
if (width < 1 || width > 19) { if (width < 1 || width > 19) {
throw new IllegalArgumentException("The width must be from 1 to 19 inclusive but was " + width); throw new IllegalArgumentException("The width must be from 1 to 19 inclusive but was " + width);
} }
@ -442,8 +443,8 @@ public final class DateTimeFormatterBuilder {
if (minWidth == maxWidth && signStyle == SignStyle.NOT_NEGATIVE) { if (minWidth == maxWidth && signStyle == SignStyle.NOT_NEGATIVE) {
return appendValue(field, maxWidth); return appendValue(field, maxWidth);
} }
Jdk8Methods.requireNonNull(field, "field"); Objects.requireNonNull(field, "field");
Jdk8Methods.requireNonNull(signStyle, "signStyle"); Objects.requireNonNull(signStyle, "signStyle");
if (minWidth < 1 || minWidth > 19) { if (minWidth < 1 || minWidth > 19) {
throw new IllegalArgumentException("The minimum width must be from 1 to 19 inclusive but was " + minWidth); throw new IllegalArgumentException("The minimum width must be from 1 to 19 inclusive but was " + minWidth);
} }
@ -500,7 +501,7 @@ public final class DateTimeFormatterBuilder {
*/ */
public DateTimeFormatterBuilder appendValueReduced(TemporalField field, public DateTimeFormatterBuilder appendValueReduced(TemporalField field,
int width, int maxWidth, int baseValue) { int width, int maxWidth, int baseValue) {
Jdk8Methods.requireNonNull(field, "field"); Objects.requireNonNull(field, "field");
ReducedPrinterParser pp = new ReducedPrinterParser(field, width, maxWidth, baseValue, null); ReducedPrinterParser pp = new ReducedPrinterParser(field, width, maxWidth, baseValue, null);
appendValue(pp); appendValue(pp);
return this; return this;
@ -560,8 +561,8 @@ public final class DateTimeFormatterBuilder {
*/ */
public DateTimeFormatterBuilder appendValueReduced( public DateTimeFormatterBuilder appendValueReduced(
TemporalField field, int width, int maxWidth, ChronoLocalDate baseDate) { TemporalField field, int width, int maxWidth, ChronoLocalDate baseDate) {
Jdk8Methods.requireNonNull(field, "field"); Objects.requireNonNull(field, "field");
Jdk8Methods.requireNonNull(baseDate, "baseDate"); Objects.requireNonNull(baseDate, "baseDate");
ReducedPrinterParser pp = new ReducedPrinterParser(field, width, maxWidth, 0, baseDate); ReducedPrinterParser pp = new ReducedPrinterParser(field, width, maxWidth, 0, baseDate);
appendValue(pp); appendValue(pp);
return this; return this;
@ -678,8 +679,8 @@ public final class DateTimeFormatterBuilder {
* @return this, for chaining, not null * @return this, for chaining, not null
*/ */
public DateTimeFormatterBuilder appendText(TemporalField field, TextStyle textStyle) { public DateTimeFormatterBuilder appendText(TemporalField field, TextStyle textStyle) {
Jdk8Methods.requireNonNull(field, "field"); Objects.requireNonNull(field, "field");
Jdk8Methods.requireNonNull(textStyle, "textStyle"); Objects.requireNonNull(textStyle, "textStyle");
appendInternal(new TextPrinterParser(field, textStyle, DateTimeTextProvider.getInstance())); appendInternal(new TextPrinterParser(field, textStyle, DateTimeTextProvider.getInstance()));
return this; return this;
} }
@ -719,9 +720,9 @@ public final class DateTimeFormatterBuilder {
* @return this, for chaining, not null * @return this, for chaining, not null
*/ */
public DateTimeFormatterBuilder appendText(TemporalField field, Map<Long, String> textLookup) { public DateTimeFormatterBuilder appendText(TemporalField field, Map<Long, String> textLookup) {
Jdk8Methods.requireNonNull(field, "field"); Objects.requireNonNull(field, "field");
Jdk8Methods.requireNonNull(textLookup, "textLookup"); Objects.requireNonNull(textLookup, "textLookup");
Map<Long, String> copy = new LinkedHashMap<Long, String>(textLookup); Map<Long, String> copy = new LinkedHashMap<>(textLookup);
Map<TextStyle, Map<Long, String>> map = Collections.singletonMap(TextStyle.FULL, copy); Map<TextStyle, Map<Long, String>> map = Collections.singletonMap(TextStyle.FULL, copy);
final LocaleStore store = new LocaleStore(map); final LocaleStore store = new LocaleStore(map);
DateTimeTextProvider provider = new DateTimeTextProvider() { DateTimeTextProvider provider = new DateTimeTextProvider() {
@ -898,7 +899,7 @@ public final class DateTimeFormatterBuilder {
* full} nor {@link TextStyle#SHORT short} * full} nor {@link TextStyle#SHORT short}
*/ */
public DateTimeFormatterBuilder appendLocalizedOffset(TextStyle style) { public DateTimeFormatterBuilder appendLocalizedOffset(TextStyle style) {
Jdk8Methods.requireNonNull(style, "style"); Objects.requireNonNull(style, "style");
if (style != TextStyle.FULL && style != TextStyle.SHORT) { if (style != TextStyle.FULL && style != TextStyle.SHORT) {
throw new IllegalArgumentException("Style must be either full or short"); throw new IllegalArgumentException("Style must be either full or short");
} }
@ -1059,7 +1060,7 @@ public final class DateTimeFormatterBuilder {
public DateTimeFormatterBuilder appendZoneText(TextStyle textStyle, public DateTimeFormatterBuilder appendZoneText(TextStyle textStyle,
Set<ZoneId> preferredZones) { Set<ZoneId> preferredZones) {
// TODO: preferred zones currently ignored // TODO: preferred zones currently ignored
Jdk8Methods.requireNonNull(preferredZones, "preferredZones"); Objects.requireNonNull(preferredZones, "preferredZones");
appendInternal(new ZoneTextPrinterParser(textStyle)); appendInternal(new ZoneTextPrinterParser(textStyle));
return this; return this;
} }
@ -1098,7 +1099,7 @@ public final class DateTimeFormatterBuilder {
* @return this, for chaining, not null * @return this, for chaining, not null
*/ */
public DateTimeFormatterBuilder appendChronologyText(TextStyle textStyle) { public DateTimeFormatterBuilder appendChronologyText(TextStyle textStyle) {
Jdk8Methods.requireNonNull(textStyle, "textStyle"); Objects.requireNonNull(textStyle, "textStyle");
appendInternal(new ChronoPrinterParser(textStyle)); appendInternal(new ChronoPrinterParser(textStyle));
return this; return this;
} }
@ -1165,7 +1166,7 @@ public final class DateTimeFormatterBuilder {
* @return this, for chaining, not null * @return this, for chaining, not null
*/ */
public DateTimeFormatterBuilder appendLiteral(String literal) { public DateTimeFormatterBuilder appendLiteral(String literal) {
Jdk8Methods.requireNonNull(literal, "literal"); Objects.requireNonNull(literal, "literal");
if (literal.length() > 0) { if (literal.length() > 0) {
if (literal.length() == 1) { if (literal.length() == 1) {
appendInternal(new CharLiteralPrinterParser(literal.charAt(0))); appendInternal(new CharLiteralPrinterParser(literal.charAt(0)));
@ -1187,7 +1188,7 @@ public final class DateTimeFormatterBuilder {
* @return this, for chaining, not null * @return this, for chaining, not null
*/ */
public DateTimeFormatterBuilder append(DateTimeFormatter formatter) { public DateTimeFormatterBuilder append(DateTimeFormatter formatter) {
Jdk8Methods.requireNonNull(formatter, "formatter"); Objects.requireNonNull(formatter, "formatter");
appendInternal(formatter.toPrinterParser(false)); appendInternal(formatter.toPrinterParser(false));
return this; return this;
} }
@ -1206,7 +1207,7 @@ public final class DateTimeFormatterBuilder {
* @return this, for chaining, not null * @return this, for chaining, not null
*/ */
public DateTimeFormatterBuilder appendOptional(DateTimeFormatter formatter) { public DateTimeFormatterBuilder appendOptional(DateTimeFormatter formatter) {
Jdk8Methods.requireNonNull(formatter, "formatter"); Objects.requireNonNull(formatter, "formatter");
appendInternal(formatter.toPrinterParser(true)); appendInternal(formatter.toPrinterParser(true));
return this; return this;
} }
@ -1378,7 +1379,7 @@ public final class DateTimeFormatterBuilder {
* @throws IllegalArgumentException if the pattern is invalid * @throws IllegalArgumentException if the pattern is invalid
*/ */
public DateTimeFormatterBuilder appendPattern(String pattern) { public DateTimeFormatterBuilder appendPattern(String pattern) {
Jdk8Methods.requireNonNull(pattern, "pattern"); Objects.requireNonNull(pattern, "pattern");
parsePattern(pattern); parsePattern(pattern);
return this; return this;
} }
@ -1832,7 +1833,7 @@ public final class DateTimeFormatterBuilder {
* @return the index into the active parsers list * @return the index into the active parsers list
*/ */
private int appendInternal(DateTimePrinterParser pp) { private int appendInternal(DateTimePrinterParser pp) {
Jdk8Methods.requireNonNull(pp, "pp"); Objects.requireNonNull(pp, "pp");
if (active.padNextWidth > 0) { if (active.padNextWidth > 0) {
if (pp != null) { if (pp != null) {
pp = new PadPrinterParserDecorator(pp, active.padNextWidth, active.padNextChar); pp = new PadPrinterParserDecorator(pp, active.padNextWidth, active.padNextChar);
@ -1880,7 +1881,7 @@ public final class DateTimeFormatterBuilder {
* @return the created formatter, not null * @return the created formatter, not null
*/ */
public DateTimeFormatter toFormatter(Locale locale) { public DateTimeFormatter toFormatter(Locale locale) {
Jdk8Methods.requireNonNull(locale, "locale"); Objects.requireNonNull(locale, "locale");
while (active.parent != null) { while (active.parent != null) {
optionalEnd(); optionalEnd();
} }
@ -2672,7 +2673,7 @@ public final class DateTimeFormatterBuilder {
* @param decimalPoint whether to output the localized decimal point symbol * @param decimalPoint whether to output the localized decimal point symbol
*/ */
FractionPrinterParser(TemporalField field, int minWidth, int maxWidth, boolean decimalPoint) { FractionPrinterParser(TemporalField field, int minWidth, int maxWidth, boolean decimalPoint) {
Jdk8Methods.requireNonNull(field, "field"); Objects.requireNonNull(field, "field");
if (field.range().isFixed() == false) { if (field.range().isFixed() == false) {
throw new IllegalArgumentException("Field must have a fixed set of values: " + field); throw new IllegalArgumentException("Field must have a fixed set of values: " + field);
} }
@ -3069,8 +3070,8 @@ public final class DateTimeFormatterBuilder {
* @param pattern the pattern * @param pattern the pattern
*/ */
OffsetIdPrinterParser(String noOffsetText, String pattern) { OffsetIdPrinterParser(String noOffsetText, String pattern) {
Jdk8Methods.requireNonNull(noOffsetText, "noOffsetText"); Objects.requireNonNull(noOffsetText, "noOffsetText");
Jdk8Methods.requireNonNull(pattern, "pattern"); Objects.requireNonNull(pattern, "pattern");
this.noOffsetText = noOffsetText; this.noOffsetText = noOffsetText;
this.type = checkPattern(pattern); this.type = checkPattern(pattern);
} }
@ -3353,7 +3354,7 @@ public final class DateTimeFormatterBuilder {
private final TextStyle textStyle; private final TextStyle textStyle;
ZoneTextPrinterParser(TextStyle textStyle) { ZoneTextPrinterParser(TextStyle textStyle) {
this.textStyle = Jdk8Methods.requireNonNull(textStyle, "textStyle"); this.textStyle = Objects.requireNonNull(textStyle, "textStyle");
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
@ -3384,7 +3385,7 @@ public final class DateTimeFormatterBuilder {
public int parse(DateTimeParseContext context, CharSequence text, int position) { public int parse(DateTimeParseContext context, CharSequence text, int position) {
// this is a poor implementation that handles some but not all of the spec // this is a poor implementation that handles some but not all of the spec
// JDK8 has a lot of extra information here // JDK8 has a lot of extra information here
Map<String, String> ids = new TreeMap<String, String>(LENGTH_COMPARATOR); Map<String, String> ids = new TreeMap<>(LENGTH_COMPARATOR);
for (String id : ZoneId.getAvailableZoneIds()) { for (String id : ZoneId.getAvailableZoneIds()) {
ids.put(id, id); ids.put(id, id);
TimeZone tz = TimeZone.getTimeZone(id); TimeZone tz = TimeZone.getTimeZone(id);

View File

@ -36,14 +36,15 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import org.threeten.bp.Period; import org.threeten.bp.Period;
import org.threeten.bp.ZoneId; import org.threeten.bp.ZoneId;
import org.threeten.bp.chrono.Chronology; import org.threeten.bp.chrono.Chronology;
import org.threeten.bp.chrono.IsoChronology; import org.threeten.bp.chrono.IsoChronology;
import org.threeten.bp.format.DateTimeFormatterBuilder.ReducedPrinterParser; import org.threeten.bp.format.DateTimeFormatterBuilder.ReducedPrinterParser;
import org.threeten.bp.jdk8.DefaultInterfaceTemporalAccessor;
import org.threeten.bp.jdk8.Jdk8Methods; import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.TemporalAccessor;
import org.threeten.bp.temporal.TemporalField; import org.threeten.bp.temporal.TemporalField;
import org.threeten.bp.temporal.TemporalQueries; import org.threeten.bp.temporal.TemporalQueries;
import org.threeten.bp.temporal.TemporalQuery; import org.threeten.bp.temporal.TemporalQuery;
@ -64,7 +65,7 @@ import org.threeten.bp.temporal.UnsupportedTemporalTypeException;
* Usage of the class is thread-safe within standard parsing as a new instance of this class * Usage of the class is thread-safe within standard parsing as a new instance of this class
* is automatically created for each parse and parsing is single-threaded * is automatically created for each parse and parsing is single-threaded
*/ */
final class DateTimeParseContext { public final class DateTimeParseContext {
/** /**
* The locale, not null. * The locale, not null.
@ -110,7 +111,7 @@ final class DateTimeParseContext {
} }
// for testing // for testing
DateTimeParseContext(Locale locale, DecimalStyle symbols, Chronology chronology) { public DateTimeParseContext(Locale locale, DecimalStyle symbols, Chronology chronology) {
super(); super();
this.locale = locale; this.locale = locale;
this.symbols = symbols; this.symbols = symbols;
@ -341,7 +342,7 @@ final class DateTimeParseContext {
* @return the new position * @return the new position
*/ */
int setParsedField(TemporalField field, long value, int errorPos, int successPos) { int setParsedField(TemporalField field, long value, int errorPos, int successPos) {
Jdk8Methods.requireNonNull(field, "field"); Objects.requireNonNull(field, "field");
Long old = currentParsed().fieldValues.put(field, value); Long old = currentParsed().fieldValues.put(field, value);
return (old != null && old.longValue() != value) ? ~errorPos : successPos; return (old != null && old.longValue() != value) ? ~errorPos : successPos;
} }
@ -355,7 +356,7 @@ final class DateTimeParseContext {
* @param chrono the parsed chronology, not null * @param chrono the parsed chronology, not null
*/ */
void setParsed(Chronology chrono) { void setParsed(Chronology chrono) {
Jdk8Methods.requireNonNull(chrono, "chrono"); Objects.requireNonNull(chrono, "chrono");
Parsed currentParsed = currentParsed(); Parsed currentParsed = currentParsed();
currentParsed.chrono = chrono; currentParsed.chrono = chrono;
if (currentParsed.callbacks != null) { if (currentParsed.callbacks != null) {
@ -385,7 +386,7 @@ final class DateTimeParseContext {
* @param zone the parsed zone, not null * @param zone the parsed zone, not null
*/ */
void setParsed(ZoneId zone) { void setParsed(ZoneId zone) {
Jdk8Methods.requireNonNull(zone, "zone"); Objects.requireNonNull(zone, "zone");
currentParsed().zone = zone; currentParsed().zone = zone;
} }
@ -422,10 +423,10 @@ final class DateTimeParseContext {
/** /**
* Temporary store of parsed data. * Temporary store of parsed data.
*/ */
final class Parsed extends DefaultInterfaceTemporalAccessor { final class Parsed implements TemporalAccessor {
Chronology chrono = null; Chronology chrono = null;
ZoneId zone = null; ZoneId zone = null;
final Map<TemporalField, Long> fieldValues = new HashMap<TemporalField, Long>(); final Map<TemporalField, Long> fieldValues = new HashMap<>();
boolean leapSecond; boolean leapSecond;
Period excessDays = Period.ZERO; Period excessDays = Period.ZERO;
List<Object[]> callbacks; List<Object[]> callbacks;
@ -472,7 +473,7 @@ final class DateTimeParseContext {
if (query == TemporalQueries.zoneId() || query == TemporalQueries.zone()) { if (query == TemporalQueries.zoneId() || query == TemporalQueries.zone()) {
return (R) zone; return (R) zone;
} }
return super.query(query); return TemporalAccessor.super.query(query);
} }
/** /**
@ -513,7 +514,7 @@ final class DateTimeParseContext {
* @param locale the locale, not null * @param locale the locale, not null
*/ */
void setLocale(Locale locale) { void setLocale(Locale locale) {
Jdk8Methods.requireNonNull(locale, "locale"); Objects.requireNonNull(locale, "locale");
this.locale = locale; this.locale = locale;
} }

View File

@ -35,6 +35,7 @@ import static org.threeten.bp.temporal.ChronoField.EPOCH_DAY;
import static org.threeten.bp.temporal.ChronoField.INSTANT_SECONDS; import static org.threeten.bp.temporal.ChronoField.INSTANT_SECONDS;
import java.util.Locale; import java.util.Locale;
import java.util.Objects;
import org.threeten.bp.DateTimeException; import org.threeten.bp.DateTimeException;
import org.threeten.bp.Instant; import org.threeten.bp.Instant;
@ -43,8 +44,6 @@ import org.threeten.bp.ZoneOffset;
import org.threeten.bp.chrono.ChronoLocalDate; import org.threeten.bp.chrono.ChronoLocalDate;
import org.threeten.bp.chrono.Chronology; import org.threeten.bp.chrono.Chronology;
import org.threeten.bp.chrono.IsoChronology; import org.threeten.bp.chrono.IsoChronology;
import org.threeten.bp.jdk8.DefaultInterfaceTemporalAccessor;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField; import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.TemporalAccessor; import org.threeten.bp.temporal.TemporalAccessor;
import org.threeten.bp.temporal.TemporalField; import org.threeten.bp.temporal.TemporalField;
@ -62,7 +61,7 @@ import org.threeten.bp.temporal.ValueRange;
* Usage of the class is thread-safe within standard printing as the framework creates * Usage of the class is thread-safe within standard printing as the framework creates
* a new instance of the class for each print and printing is single-threaded. * a new instance of the class for each print and printing is single-threaded.
*/ */
final class DateTimePrintContext { public final class DateTimePrintContext {
/** /**
* The temporal being output. * The temporal being output.
@ -95,7 +94,7 @@ final class DateTimePrintContext {
} }
// for testing // for testing
DateTimePrintContext(TemporalAccessor temporal, Locale locale, DecimalStyle symbols) { public DateTimePrintContext(TemporalAccessor temporal, Locale locale, DecimalStyle symbols) {
this.temporal = temporal; this.temporal = temporal;
this.locale = locale; this.locale = locale;
this.symbols = symbols; this.symbols = symbols;
@ -112,10 +111,10 @@ final class DateTimePrintContext {
// ensure minimal change // ensure minimal change
Chronology temporalChrono = temporal.query(TemporalQueries.chronology()); Chronology temporalChrono = temporal.query(TemporalQueries.chronology());
ZoneId temporalZone = temporal.query(TemporalQueries.zoneId()); ZoneId temporalZone = temporal.query(TemporalQueries.zoneId());
if (Jdk8Methods.equals(temporalChrono, overrideChrono)) { if (Objects.equals(temporalChrono, overrideChrono)) {
overrideChrono = null; overrideChrono = null;
} }
if (Jdk8Methods.equals(temporalZone, overrideZone)) { if (Objects.equals(temporalZone, overrideZone)) {
overrideZone = null; overrideZone = null;
} }
if (overrideChrono == null && overrideZone == null) { if (overrideChrono == null && overrideZone == null) {
@ -158,7 +157,7 @@ final class DateTimePrintContext {
} }
// need class here to handle non-standard cases // need class here to handle non-standard cases
return new DefaultInterfaceTemporalAccessor() { return new TemporalAccessor() {
@Override @Override
public boolean isSupported(TemporalField field) { public boolean isSupported(TemporalField field) {
if (effectiveDate != null && field.isDateBased()) { if (effectiveDate != null && field.isDateBased()) {
@ -299,7 +298,7 @@ final class DateTimePrintContext {
* @param temporal the date-time object, not null * @param temporal the date-time object, not null
*/ */
void setDateTime(TemporalAccessor temporal) { void setDateTime(TemporalAccessor temporal) {
Jdk8Methods.requireNonNull(temporal, "temporal"); Objects.requireNonNull(temporal, "temporal");
this.temporal = temporal; this.temporal = temporal;
} }
@ -312,7 +311,7 @@ final class DateTimePrintContext {
* @param locale the locale, not null * @param locale the locale, not null
*/ */
void setLocale(Locale locale) { void setLocale(Locale locale) {
Jdk8Methods.requireNonNull(locale, "locale"); Objects.requireNonNull(locale, "locale");
this.locale = locale; this.locale = locale;
} }

View File

@ -37,10 +37,9 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import org.threeten.bp.jdk8.Jdk8Methods;
/** /**
* Localized symbols used in date and time formatting. * Localized symbols used in date and time formatting.
* <p> * <p>
@ -113,7 +112,7 @@ public final class DecimalStyle {
* @return the info, not null * @return the info, not null
*/ */
public static DecimalStyle of(Locale locale) { public static DecimalStyle of(Locale locale) {
Jdk8Methods.requireNonNull(locale, "locale"); Objects.requireNonNull(locale, "locale");
DecimalStyle info = CACHE.get(locale); DecimalStyle info = CACHE.get(locale);
if (info == null) { if (info == null) {
info = create(locale); info = create(locale);

View File

@ -65,11 +65,8 @@ final class SimpleDateTimeTextProvider extends DateTimeTextProvider {
// TODO: Better implementation based on CLDR // TODO: Better implementation based on CLDR
/** Comparator. */ /** Comparator. */
private static final Comparator<Entry<String, Long>> COMPARATOR = new Comparator<Entry<String, Long>>() { private static final Comparator<Entry<String, Long>> COMPARATOR = (obj1, obj2) -> {
@Override
public int compare(Entry<String, Long> obj1, Entry<String, Long> obj2) {
return obj2.getKey().length() - obj1.getKey().length(); // longest to shortest return obj2.getKey().length() - obj1.getKey().length(); // longest to shortest
}
}; };
/** Cache. */ /** Cache. */

View File

@ -1,112 +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.
*/
package org.threeten.bp.jdk8;
import static org.threeten.bp.temporal.ChronoField.ERA;
import java.util.Locale;
import org.threeten.bp.chrono.Era;
import org.threeten.bp.format.DateTimeFormatterBuilder;
import org.threeten.bp.format.TextStyle;
import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.ChronoUnit;
import org.threeten.bp.temporal.Temporal;
import org.threeten.bp.temporal.TemporalField;
import org.threeten.bp.temporal.TemporalQueries;
import org.threeten.bp.temporal.TemporalQuery;
import org.threeten.bp.temporal.UnsupportedTemporalTypeException;
/**
* A temporary class providing implementations that will become default interface
* methods once integrated into JDK 8.
*
* @param the chronology of this era
*/
public abstract class DefaultInterfaceEra
extends DefaultInterfaceTemporalAccessor
implements Era {
//-----------------------------------------------------------------------
@Override
public boolean isSupported(TemporalField field) {
if (field instanceof ChronoField) {
return field == ERA;
}
return field != null && field.isSupportedBy(this);
}
@Override
public int get(TemporalField field) {
if (field == ERA) {
return getValue();
}
return range(field).checkValidIntValue(getLong(field), field);
}
@Override
public long getLong(TemporalField field) {
if (field == ERA) {
return getValue();
} else if (field instanceof ChronoField) {
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.getFrom(this);
}
//-------------------------------------------------------------------------
@Override
public Temporal adjustInto(Temporal temporal) {
return temporal.with(ERA, getValue());
}
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQueries.precision()) {
return (R) ChronoUnit.ERAS;
}
if (query == TemporalQueries.chronology() || query == TemporalQueries.zone() ||
query == TemporalQueries.zoneId() || query == TemporalQueries.offset() ||
query == TemporalQueries.localDate() || query == TemporalQueries.localTime()) {
return null;
}
return query.queryFrom(this);
}
//-----------------------------------------------------------------------
@Override
public String getDisplayName(TextStyle style, Locale locale) {
return new DateTimeFormatterBuilder().appendText(ERA, style).toFormatter(locale).format(this);
}
}

View File

@ -1,67 +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.
*/
package org.threeten.bp.jdk8;
import org.threeten.bp.temporal.Temporal;
import org.threeten.bp.temporal.TemporalAdjuster;
import org.threeten.bp.temporal.TemporalAmount;
import org.threeten.bp.temporal.TemporalUnit;
/**
* A temporary class providing implementations that will become default interface
* methods once integrated into JDK 8.
*/
public abstract class DefaultInterfaceTemporal
extends DefaultInterfaceTemporalAccessor
implements Temporal {
@Override
public Temporal with(TemporalAdjuster adjuster) {
return adjuster.adjustInto(this);
}
@Override
public Temporal plus(TemporalAmount amount) {
return amount.addTo(this);
}
@Override
public Temporal minus(TemporalAmount amount) {
return amount.subtractFrom(this);
}
@Override
public Temporal minus(long amountToSubtract, TemporalUnit unit) {
return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit));
}
}

View File

@ -49,90 +49,6 @@ public final class Jdk8Methods {
private Jdk8Methods() { private Jdk8Methods() {
} }
//-----------------------------------------------------------------------
/**
* Ensures that the argument is non-null.
*
* @param <T> the value type
* @param value the value to check
* @return the checked non-null value
* @throws NullPointerException if the value is null
*/
public static <T> T requireNonNull(T value) {
if (value == null) {
throw new NullPointerException("Value must not be null");
}
return value;
}
/**
* Ensures that the argument is non-null.
*
* @param <T> the value type
* @param value the value to check
* @param parameterName the name of the parameter
* @return the checked non-null value
* @throws NullPointerException if the value is null
*/
public static <T> T requireNonNull(T value, String parameterName) {
if (value == null) {
throw new NullPointerException(parameterName + " must not be null");
}
return value;
}
//-----------------------------------------------------------------------
/**
* Compares two objects.
*
* @param a the first value
* @param b the second value
* @return the result
*/
public static boolean equals(Object a, Object b) {
if (a == null) {
return b == null;
}
if (b == null) {
return false;
}
return a.equals(b);
}
/**
* Compares two ints.
*
* @param a the first value
* @param b the second value
* @return the result
*/
public static int compareInts(int a, int b) {
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
}
/**
* Compares two longs.
*
* @param a the first value
* @param b the second value
* @return the result
*/
public static int compareLongs(long a, long b) {
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
}
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**
* Safely adds two int values. * Safely adds two int values.

View File

@ -47,7 +47,7 @@ import static org.threeten.bp.temporal.ChronoUnit.YEARS;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import org.threeten.bp.DayOfWeek; import org.threeten.bp.DayOfWeek;
import org.threeten.bp.Instant; import org.threeten.bp.Instant;
import org.threeten.bp.Year; import org.threeten.bp.Year;
@ -55,7 +55,6 @@ import org.threeten.bp.ZoneOffset;
import org.threeten.bp.chrono.ChronoLocalDate; import org.threeten.bp.chrono.ChronoLocalDate;
import org.threeten.bp.chrono.Chronology; import org.threeten.bp.chrono.Chronology;
import org.threeten.bp.format.ResolverStyle; import org.threeten.bp.format.ResolverStyle;
import org.threeten.bp.jdk8.Jdk8Methods;
/** /**
* A standard set of fields. * A standard set of fields.
@ -600,7 +599,7 @@ public enum ChronoField implements TemporalField {
@Override @Override
public String getDisplayName(Locale locale) { public String getDisplayName(Locale locale) {
Jdk8Methods.requireNonNull(locale, "locale"); Objects.requireNonNull(locale, "locale");
return toString(); return toString();
} }

View File

@ -46,6 +46,7 @@ import static org.threeten.bp.temporal.ChronoUnit.YEARS;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import org.threeten.bp.Duration; import org.threeten.bp.Duration;
import org.threeten.bp.LocalDate; import org.threeten.bp.LocalDate;
@ -202,7 +203,7 @@ public final class IsoFields {
/** /**
* Implementation of the field. * Implementation of the field.
*/ */
private static enum Field implements TemporalField { private enum Field implements TemporalField {
DAY_OF_QUARTER { DAY_OF_QUARTER {
@Override @Override
public String toString() { public String toString() {
@ -351,7 +352,7 @@ public final class IsoFields {
} }
@Override @Override
public String getDisplayName(Locale locale) { public String getDisplayName(Locale locale) {
Jdk8Methods.requireNonNull(locale, "locale"); Objects.requireNonNull(locale, "locale");
return "Week"; return "Week";
} }
@ -476,7 +477,7 @@ public final class IsoFields {
@Override @Override
public String getDisplayName(Locale locale) { public String getDisplayName(Locale locale) {
Jdk8Methods.requireNonNull(locale, "locale"); Objects.requireNonNull(locale, "locale");
return toString(); return toString();
} }
@ -561,7 +562,7 @@ public final class IsoFields {
/** /**
* Implementation of the period unit. * Implementation of the period unit.
*/ */
private static enum Unit implements TemporalUnit { private enum Unit implements TemporalUnit {
WEEK_BASED_YEARS("WeekBasedYears", Duration.ofSeconds(31556952L)), WEEK_BASED_YEARS("WeekBasedYears", Duration.ofSeconds(31556952L)),
QUARTER_YEARS("QuarterYears", Duration.ofSeconds(31556952L / 4)); QUARTER_YEARS("QuarterYears", Duration.ofSeconds(31556952L / 4));

View File

@ -38,6 +38,7 @@ import static org.threeten.bp.temporal.ChronoUnit.FOREVER;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import org.threeten.bp.DateTimeException; import org.threeten.bp.DateTimeException;
import org.threeten.bp.chrono.Chronology; import org.threeten.bp.chrono.Chronology;
import org.threeten.bp.format.ResolverStyle; import org.threeten.bp.format.ResolverStyle;
@ -148,7 +149,7 @@ public final class JulianFields {
/** /**
* Hidden implementation. * Hidden implementation.
*/ */
private static enum Field implements TemporalField { private enum Field implements TemporalField {
/** /**
* Julian Day field. * Julian Day field.
*/ */
@ -236,7 +237,7 @@ public final class JulianFields {
@Override @Override
public String getDisplayName(Locale locale) { public String getDisplayName(Locale locale) {
Jdk8Methods.requireNonNull(locale, "locale"); Objects.requireNonNull(locale, "locale");
return toString(); return toString();
} }
@ -254,6 +255,8 @@ public final class JulianFields {
public String toString() { public String toString() {
return name; return name;
} }
}
private JulianFields() {
} }
} }

View File

@ -150,7 +150,9 @@ public interface Temporal extends TemporalAccessor {
* @throws DateTimeException if unable to make the adjustment * @throws DateTimeException if unable to make the adjustment
* @throws ArithmeticException if numeric overflow occurs * @throws ArithmeticException if numeric overflow occurs
*/ */
Temporal with(TemporalAdjuster adjuster); default Temporal with(TemporalAdjuster adjuster) {
return adjuster.adjustInto(this);
}
/** /**
* Returns an object of the same type as this object with the specified field altered. * Returns an object of the same type as this object with the specified field altered.
@ -213,7 +215,9 @@ public interface Temporal extends TemporalAccessor {
* @throws DateTimeException if the addition cannot be made * @throws DateTimeException if the addition cannot be made
* @throws ArithmeticException if numeric overflow occurs * @throws ArithmeticException if numeric overflow occurs
*/ */
Temporal plus(TemporalAmount amount); default Temporal plus(TemporalAmount amount) {
return amount.addTo(this);
}
/** /**
* Returns an object of the same type as this object with the specified period added. * Returns an object of the same type as this object with the specified period added.
@ -280,7 +284,9 @@ public interface Temporal extends TemporalAccessor {
* @throws DateTimeException if the subtraction cannot be made * @throws DateTimeException if the subtraction cannot be made
* @throws ArithmeticException if numeric overflow occurs * @throws ArithmeticException if numeric overflow occurs
*/ */
Temporal minus(TemporalAmount amount); default Temporal minus(TemporalAmount amount) {
return amount.subtractFrom(this);
}
/** /**
* Returns an object of the same type as this object with the specified period subtracted. * Returns an object of the same type as this object with the specified period subtracted.
@ -311,7 +317,11 @@ public interface Temporal extends TemporalAccessor {
* @throws DateTimeException if the unit cannot be subtracted * @throws DateTimeException if the unit cannot be subtracted
* @throws ArithmeticException if numeric overflow occurs * @throws ArithmeticException if numeric overflow occurs
*/ */
Temporal minus(long amountToSubtract, TemporalUnit unit); default Temporal minus(long amountToSubtract, TemporalUnit unit) {
return amountToSubtract == Long.MIN_VALUE
? plus(Long.MAX_VALUE, unit).plus(1, unit)
: plus(-amountToSubtract, unit);
}
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**

View File

@ -121,7 +121,15 @@ public interface TemporalAccessor {
* @return the range of valid values for the field, not null * @return the range of valid values for the field, not null
* @throws DateTimeException if the range for the field cannot be obtained * @throws DateTimeException if the range for the field cannot be obtained
*/ */
ValueRange range(TemporalField field); default ValueRange range(TemporalField field) {
if (field instanceof ChronoField) {
if (isSupported(field)) {
return field.range();
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.rangeRefinedBy(this);
}
/** /**
* Gets the value of the specified field as an {@code int}. * Gets the value of the specified field as an {@code int}.
@ -150,7 +158,9 @@ public interface TemporalAccessor {
* @throws DateTimeException if the value is outside the range of valid values for the field * @throws DateTimeException if the value is outside the range of valid values for the field
* @throws ArithmeticException if numeric overflow occurs * @throws ArithmeticException if numeric overflow occurs
*/ */
int get(TemporalField field); default int get(TemporalField field) {
return range(field).checkValidIntValue(getLong(field), field);
}
/** /**
* Gets the value of the specified field as a {@code long}. * Gets the value of the specified field as a {@code long}.
@ -213,6 +223,10 @@ public interface TemporalAccessor {
* @throws DateTimeException if unable to query * @throws DateTimeException if unable to query
* @throws ArithmeticException if numeric overflow occurs * @throws ArithmeticException if numeric overflow occurs
*/ */
<R> R query(TemporalQuery<R> query); default <R> R query(TemporalQuery<R> query) {
if (query == TemporalQueries.zoneId() || query == TemporalQueries.chronology() || query == TemporalQueries.precision()) {
return null;
}
return query.queryFrom(this);
}
} }

View File

@ -37,9 +37,9 @@ import static org.threeten.bp.temporal.ChronoField.DAY_OF_YEAR;
import static org.threeten.bp.temporal.ChronoUnit.DAYS; import static org.threeten.bp.temporal.ChronoUnit.DAYS;
import static org.threeten.bp.temporal.ChronoUnit.MONTHS; import static org.threeten.bp.temporal.ChronoUnit.MONTHS;
import static org.threeten.bp.temporal.ChronoUnit.YEARS; import static org.threeten.bp.temporal.ChronoUnit.YEARS;
import java.util.Objects;
import org.threeten.bp.DayOfWeek; import org.threeten.bp.DayOfWeek;
import org.threeten.bp.jdk8.Jdk8Methods;
/** /**
* Common implementations of {@code TemporalAdjuster}. * Common implementations of {@code TemporalAdjuster}.
@ -259,7 +259,7 @@ public final class TemporalAdjusters {
* @return the first in month adjuster, not null * @return the first in month adjuster, not null
*/ */
public static TemporalAdjuster firstInMonth(DayOfWeek dayOfWeek) { public static TemporalAdjuster firstInMonth(DayOfWeek dayOfWeek) {
Jdk8Methods.requireNonNull(dayOfWeek, "dayOfWeek"); Objects.requireNonNull(dayOfWeek, "dayOfWeek");
return new DayOfWeekInMonth(1, dayOfWeek); return new DayOfWeekInMonth(1, dayOfWeek);
} }
@ -280,7 +280,7 @@ public final class TemporalAdjusters {
* @return the first in month adjuster, not null * @return the first in month adjuster, not null
*/ */
public static TemporalAdjuster lastInMonth(DayOfWeek dayOfWeek) { public static TemporalAdjuster lastInMonth(DayOfWeek dayOfWeek) {
Jdk8Methods.requireNonNull(dayOfWeek, "dayOfWeek"); Objects.requireNonNull(dayOfWeek, "dayOfWeek");
return new DayOfWeekInMonth(-1, dayOfWeek); return new DayOfWeekInMonth(-1, dayOfWeek);
} }
@ -317,7 +317,7 @@ public final class TemporalAdjusters {
* @return the day-of-week in month adjuster, not null * @return the day-of-week in month adjuster, not null
*/ */
public static TemporalAdjuster dayOfWeekInMonth(int ordinal, DayOfWeek dayOfWeek) { public static TemporalAdjuster dayOfWeekInMonth(int ordinal, DayOfWeek dayOfWeek) {
Jdk8Methods.requireNonNull(dayOfWeek, "dayOfWeek"); Objects.requireNonNull(dayOfWeek, "dayOfWeek");
return new DayOfWeekInMonth(ordinal, dayOfWeek); return new DayOfWeekInMonth(ordinal, dayOfWeek);
} }
@ -447,7 +447,7 @@ public final class TemporalAdjusters {
private final int dowValue; private final int dowValue;
private RelativeDayOfWeek(int relative, DayOfWeek dayOfWeek) { private RelativeDayOfWeek(int relative, DayOfWeek dayOfWeek) {
Jdk8Methods.requireNonNull(dayOfWeek, "dayOfWeek"); Objects.requireNonNull(dayOfWeek, "dayOfWeek");
this.relative = relative; this.relative = relative;
this.dowValue = dayOfWeek.getValue(); this.dowValue = dayOfWeek.getValue();
} }

View File

@ -47,9 +47,7 @@ import java.util.GregorianCalendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.Objects;
import java.util.concurrent.ConcurrentMap;
import org.threeten.bp.DateTimeException; import org.threeten.bp.DateTimeException;
import org.threeten.bp.DayOfWeek; import org.threeten.bp.DayOfWeek;
import org.threeten.bp.Year; import org.threeten.bp.Year;
@ -197,7 +195,7 @@ public final class WeekFields implements Serializable {
* @return the week-definition, not null * @return the week-definition, not null
*/ */
public static WeekFields of(Locale locale) { public static WeekFields of(Locale locale) {
Jdk8Methods.requireNonNull(locale, "locale"); Objects.requireNonNull(locale, "locale");
locale = new Locale(locale.getLanguage(), locale.getCountry()); // elminate variants locale = new Locale(locale.getLanguage(), locale.getCountry()); // elminate variants
// obtain these from GregorianCalendar for now // obtain these from GregorianCalendar for now
@ -248,7 +246,7 @@ public final class WeekFields implements Serializable {
* @throws IllegalArgumentException if the minimal days value is invalid * @throws IllegalArgumentException if the minimal days value is invalid
*/ */
private WeekFields(DayOfWeek firstDayOfWeek, int minimalDaysInFirstWeek) { private WeekFields(DayOfWeek firstDayOfWeek, int minimalDaysInFirstWeek) {
Jdk8Methods.requireNonNull(firstDayOfWeek, "firstDayOfWeek"); Objects.requireNonNull(firstDayOfWeek, "firstDayOfWeek");
if (minimalDaysInFirstWeek < 1 || minimalDaysInFirstWeek > 7) { if (minimalDaysInFirstWeek < 1 || minimalDaysInFirstWeek > 7) {
throw new IllegalArgumentException("Minimal number of days is invalid"); throw new IllegalArgumentException("Minimal number of days is invalid");
} }
@ -996,7 +994,7 @@ public final class WeekFields implements Serializable {
@Override @Override
public String getDisplayName(Locale locale) { public String getDisplayName(Locale locale) {
Jdk8Methods.requireNonNull(locale, "locale"); Objects.requireNonNull(locale, "locale");
if (rangeUnit == YEARS) { // week-of-year if (rangeUnit == YEARS) { // week-of-year
return "Week"; return "Week";
} }

View File

@ -42,6 +42,7 @@ import java.util.Enumeration;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.NavigableMap; import java.util.NavigableMap;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.concurrent.ConcurrentNavigableMap; import java.util.concurrent.ConcurrentNavigableMap;
@ -134,7 +135,7 @@ public final class TzdbZoneRulesProvider extends ZoneRulesProvider {
@Override @Override
protected ZoneRules provideRules(String zoneId, boolean forCaching) { protected ZoneRules provideRules(String zoneId, boolean forCaching) {
Jdk8Methods.requireNonNull(zoneId, "zoneId"); Objects.requireNonNull(zoneId, "zoneId");
ZoneRules rules = versions.lastEntry().getValue().getRules(zoneId); ZoneRules rules = versions.lastEntry().getValue().getRules(zoneId);
if (rules == null) { if (rules == null) {
throw new ZoneRulesException("Unknown time-zone ID: " + zoneId); throw new ZoneRulesException("Unknown time-zone ID: " + zoneId);

View File

@ -38,12 +38,12 @@ import java.io.Serializable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects;
import org.threeten.bp.Duration; import org.threeten.bp.Duration;
import org.threeten.bp.Instant; import org.threeten.bp.Instant;
import org.threeten.bp.LocalDateTime; import org.threeten.bp.LocalDateTime;
import org.threeten.bp.ZoneOffset; import org.threeten.bp.ZoneOffset;
import org.threeten.bp.jdk8.Jdk8Methods;
/** /**
* A transition between two offsets caused by a discontinuity in the local time-line. * A transition between two offsets caused by a discontinuity in the local time-line.
@ -99,9 +99,9 @@ public final class ZoneOffsetTransition
* are equal, or {@code transition.getNano()} returns non-zero value * are equal, or {@code transition.getNano()} returns non-zero value
*/ */
public static ZoneOffsetTransition of(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter) { public static ZoneOffsetTransition of(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter) {
Jdk8Methods.requireNonNull(transition, "transition"); Objects.requireNonNull(transition, "transition");
Jdk8Methods.requireNonNull(offsetBefore, "offsetBefore"); Objects.requireNonNull(offsetBefore, "offsetBefore");
Jdk8Methods.requireNonNull(offsetAfter, "offsetAfter"); Objects.requireNonNull(offsetAfter, "offsetAfter");
if (offsetBefore.equals(offsetAfter)) { if (offsetBefore.equals(offsetAfter)) {
throw new IllegalArgumentException("Offsets must not be equal"); throw new IllegalArgumentException("Offsets must not be equal");
} }

View File

@ -39,6 +39,7 @@ import java.io.DataOutput;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects;
import org.threeten.bp.DayOfWeek; import org.threeten.bp.DayOfWeek;
import org.threeten.bp.LocalDate; import org.threeten.bp.LocalDate;
import org.threeten.bp.LocalDateTime; import org.threeten.bp.LocalDateTime;
@ -149,12 +150,12 @@ public final class ZoneOffsetTransitionRule implements Serializable {
ZoneOffset standardOffset, ZoneOffset standardOffset,
ZoneOffset offsetBefore, ZoneOffset offsetBefore,
ZoneOffset offsetAfter) { ZoneOffset offsetAfter) {
Jdk8Methods.requireNonNull(month, "month"); Objects.requireNonNull(month, "month");
Jdk8Methods.requireNonNull(time, "time"); Objects.requireNonNull(time, "time");
Jdk8Methods.requireNonNull(timeDefnition, "timeDefnition"); Objects.requireNonNull(timeDefnition, "timeDefnition");
Jdk8Methods.requireNonNull(standardOffset, "standardOffset"); Objects.requireNonNull(standardOffset, "standardOffset");
Jdk8Methods.requireNonNull(offsetBefore, "offsetBefore"); Objects.requireNonNull(offsetBefore, "offsetBefore");
Jdk8Methods.requireNonNull(offsetAfter, "offsetAfter"); Objects.requireNonNull(offsetAfter, "offsetAfter");
if (dayOfMonthIndicator < -28 || dayOfMonthIndicator > 31 || dayOfMonthIndicator == 0) { if (dayOfMonthIndicator < -28 || dayOfMonthIndicator > 31 || dayOfMonthIndicator == 0) {
throw new IllegalArgumentException("Day of month indicator must be between -28 and 31 inclusive excluding zero"); throw new IllegalArgumentException("Day of month indicator must be between -28 and 31 inclusive excluding zero");
} }

View File

@ -34,13 +34,13 @@ package org.threeten.bp.zone;
import java.io.Serializable; import java.io.Serializable;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Objects;
import org.threeten.bp.Duration; import org.threeten.bp.Duration;
import org.threeten.bp.Instant; import org.threeten.bp.Instant;
import org.threeten.bp.LocalDateTime; import org.threeten.bp.LocalDateTime;
import org.threeten.bp.ZoneId; import org.threeten.bp.ZoneId;
import org.threeten.bp.ZoneOffset; import org.threeten.bp.ZoneOffset;
import org.threeten.bp.jdk8.Jdk8Methods;
/** /**
* The rules defining how the zone offset varies for a single time-zone. * The rules defining how the zone offset varies for a single time-zone.
@ -82,11 +82,11 @@ public abstract class ZoneRules {
List<ZoneOffsetTransition> standardOffsetTransitionList, List<ZoneOffsetTransition> standardOffsetTransitionList,
List<ZoneOffsetTransition> transitionList, List<ZoneOffsetTransition> transitionList,
List<ZoneOffsetTransitionRule> lastRules) { List<ZoneOffsetTransitionRule> lastRules) {
Jdk8Methods.requireNonNull(baseStandardOffset, "baseStandardOffset"); Objects.requireNonNull(baseStandardOffset, "baseStandardOffset");
Jdk8Methods.requireNonNull(baseWallOffset, "baseWallOffset"); Objects.requireNonNull(baseWallOffset, "baseWallOffset");
Jdk8Methods.requireNonNull(standardOffsetTransitionList, "standardOffsetTransitionList"); Objects.requireNonNull(standardOffsetTransitionList, "standardOffsetTransitionList");
Jdk8Methods.requireNonNull(transitionList, "transitionList"); Objects.requireNonNull(transitionList, "transitionList");
Jdk8Methods.requireNonNull(lastRules, "lastRules"); Objects.requireNonNull(lastRules, "lastRules");
return new StandardZoneRules(baseStandardOffset, baseWallOffset, return new StandardZoneRules(baseStandardOffset, baseWallOffset,
standardOffsetTransitionList, transitionList, lastRules); standardOffsetTransitionList, transitionList, lastRules);
} }
@ -100,7 +100,7 @@ public abstract class ZoneRules {
* @return the zone rules, not null * @return the zone rules, not null
*/ */
public static ZoneRules of(ZoneOffset offset) { public static ZoneRules of(ZoneOffset offset) {
Jdk8Methods.requireNonNull(offset, "offset"); Objects.requireNonNull(offset, "offset");
return new Fixed(offset); return new Fixed(offset);
} }

View File

@ -40,6 +40,7 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import org.threeten.bp.DateTimeException; import org.threeten.bp.DateTimeException;
import org.threeten.bp.DayOfWeek; import org.threeten.bp.DayOfWeek;
@ -50,7 +51,6 @@ import org.threeten.bp.Month;
import org.threeten.bp.Year; import org.threeten.bp.Year;
import org.threeten.bp.ZoneOffset; import org.threeten.bp.ZoneOffset;
import org.threeten.bp.chrono.IsoChronology; import org.threeten.bp.chrono.IsoChronology;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.zone.ZoneOffsetTransitionRule.TimeDefinition; import org.threeten.bp.zone.ZoneOffsetTransitionRule.TimeDefinition;
/** /**
@ -117,9 +117,9 @@ class ZoneRulesBuilder {
ZoneOffset standardOffset, ZoneOffset standardOffset,
LocalDateTime until, LocalDateTime until,
TimeDefinition untilDefinition) { TimeDefinition untilDefinition) {
Jdk8Methods.requireNonNull(standardOffset, "standardOffset"); Objects.requireNonNull(standardOffset, "standardOffset");
Jdk8Methods.requireNonNull(until, "until"); Objects.requireNonNull(until, "until");
Jdk8Methods.requireNonNull(untilDefinition, "untilDefinition"); Objects.requireNonNull(untilDefinition, "untilDefinition");
TZWindow window = new TZWindow(standardOffset, until, untilDefinition); TZWindow window = new TZWindow(standardOffset, until, untilDefinition);
if (windowList.size() > 0) { if (windowList.size() > 0) {
TZWindow previous = windowList.get(windowList.size() - 1); TZWindow previous = windowList.get(windowList.size() - 1);
@ -192,7 +192,7 @@ class ZoneRulesBuilder {
LocalDateTime transitionDateTime, LocalDateTime transitionDateTime,
TimeDefinition timeDefinition, TimeDefinition timeDefinition,
int savingAmountSecs) { int savingAmountSecs) {
Jdk8Methods.requireNonNull(transitionDateTime, "transitionDateTime"); Objects.requireNonNull(transitionDateTime, "transitionDateTime");
return addRuleToWindow( return addRuleToWindow(
transitionDateTime.getYear(), transitionDateTime.getYear(), transitionDateTime.getYear(), transitionDateTime.getYear(),
transitionDateTime.getMonth(), transitionDateTime.getDayOfMonth(), transitionDateTime.getMonth(), transitionDateTime.getDayOfMonth(),
@ -264,9 +264,9 @@ class ZoneRulesBuilder {
boolean timeEndOfDay, boolean timeEndOfDay,
TimeDefinition timeDefinition, TimeDefinition timeDefinition,
int savingAmountSecs) { int savingAmountSecs) {
Jdk8Methods.requireNonNull(month, "month"); Objects.requireNonNull(month, "month");
Jdk8Methods.requireNonNull(time, "time"); Objects.requireNonNull(time, "time");
Jdk8Methods.requireNonNull(timeDefinition, "timeDefinition"); Objects.requireNonNull(timeDefinition, "timeDefinition");
YEAR.checkValidValue(startYear); YEAR.checkValidValue(startYear);
YEAR.checkValidValue(endYear); YEAR.checkValidValue(endYear);
if (dayOfMonthIndicator < -28 || dayOfMonthIndicator > 31 || dayOfMonthIndicator == 0) { if (dayOfMonthIndicator < -28 || dayOfMonthIndicator > 31 || dayOfMonthIndicator == 0) {
@ -293,8 +293,8 @@ class ZoneRulesBuilder {
int adjustDays, int adjustDays,
TimeDefinition timeDefinition, TimeDefinition timeDefinition,
int savingAmountSecs) { int savingAmountSecs) {
Jdk8Methods.requireNonNull(month, "month"); Objects.requireNonNull(month, "month");
Jdk8Methods.requireNonNull(timeDefinition, "timeDefinition"); Objects.requireNonNull(timeDefinition, "timeDefinition");
YEAR.checkValidValue(startYear); YEAR.checkValidValue(startYear);
YEAR.checkValidValue(endYear); YEAR.checkValidValue(endYear);
if (dayOfMonthIndicator < -28 || dayOfMonthIndicator > 31 || dayOfMonthIndicator == 0) { if (dayOfMonthIndicator < -28 || dayOfMonthIndicator > 31 || dayOfMonthIndicator == 0) {
@ -337,7 +337,7 @@ class ZoneRulesBuilder {
* @throws IllegalStateException if there is only one rule defined as being forever for any given window * @throws IllegalStateException if there is only one rule defined as being forever for any given window
*/ */
ZoneRules toRules(String zoneId, Map<Object, Object> deduplicateMap) { ZoneRules toRules(String zoneId, Map<Object, Object> deduplicateMap) {
Jdk8Methods.requireNonNull(zoneId, "zoneId"); Objects.requireNonNull(zoneId, "zoneId");
this.deduplicateMap = deduplicateMap; this.deduplicateMap = deduplicateMap;
if (windowList.isEmpty()) { if (windowList.isEmpty()) {
throw new IllegalStateException("No windows have been added to the builder"); throw new IllegalStateException("No windows have been added to the builder");
@ -742,7 +742,7 @@ class ZoneRulesBuilder {
} }
long timeSecs1 = time.toSecondOfDay() + adjustDays * 86400; long timeSecs1 = time.toSecondOfDay() + adjustDays * 86400;
long timeSecs2 = other.time.toSecondOfDay() + other.adjustDays * 86400; long timeSecs2 = other.time.toSecondOfDay() + other.adjustDays * 86400;
return timeSecs1 < timeSecs2 ? -1 : (timeSecs1 > timeSecs2 ? 1 : 0); return Long.compare(timeSecs1, timeSecs2);
} }
private LocalDate toLocalDate() { private LocalDate toLocalDate() {

View File

@ -37,12 +37,12 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.NavigableMap; import java.util.NavigableMap;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import org.threeten.bp.DateTimeException; import org.threeten.bp.DateTimeException;
import org.threeten.bp.ZoneId; import org.threeten.bp.ZoneId;
import org.threeten.bp.ZonedDateTime; import org.threeten.bp.ZonedDateTime;
import org.threeten.bp.jdk8.Jdk8Methods;
/** /**
* Provider of time-zone rules to the system. * Provider of time-zone rules to the system.
@ -119,7 +119,7 @@ public abstract class ZoneRulesProvider {
* @throws ZoneRulesException if rules cannot be obtained for the zone ID * @throws ZoneRulesException if rules cannot be obtained for the zone ID
*/ */
public static ZoneRules getRules(String zoneId, boolean forCaching) { public static ZoneRules getRules(String zoneId, boolean forCaching) {
Jdk8Methods.requireNonNull(zoneId, "zoneId"); Objects.requireNonNull(zoneId, "zoneId");
return getProvider(zoneId).provideRules(zoneId, forCaching); return getProvider(zoneId).provideRules(zoneId, forCaching);
} }
@ -148,7 +148,7 @@ public abstract class ZoneRulesProvider {
* @throws ZoneRulesException if history cannot be obtained for the zone ID * @throws ZoneRulesException if history cannot be obtained for the zone ID
*/ */
public static NavigableMap<String, ZoneRules> getVersions(String zoneId) { public static NavigableMap<String, ZoneRules> getVersions(String zoneId) {
Jdk8Methods.requireNonNull(zoneId, "zoneId"); Objects.requireNonNull(zoneId, "zoneId");
return getProvider(zoneId).provideVersions(zoneId); return getProvider(zoneId).provideVersions(zoneId);
} }
@ -187,7 +187,7 @@ public abstract class ZoneRulesProvider {
* @throws ZoneRulesException if a region is already registered * @throws ZoneRulesException if a region is already registered
*/ */
public static void registerProvider(ZoneRulesProvider provider) { public static void registerProvider(ZoneRulesProvider provider) {
Jdk8Methods.requireNonNull(provider, "provider"); Objects.requireNonNull(provider, "provider");
registerProvider0(provider); registerProvider0(provider);
PROVIDERS.add(provider); PROVIDERS.add(provider);
} }
@ -200,7 +200,7 @@ public abstract class ZoneRulesProvider {
*/ */
private static void registerProvider0(ZoneRulesProvider provider) { private static void registerProvider0(ZoneRulesProvider provider) {
for (String zoneId : provider.provideZoneIds()) { for (String zoneId : provider.provideZoneIds()) {
Jdk8Methods.requireNonNull(zoneId, "zoneId"); Objects.requireNonNull(zoneId, "zoneId");
ZoneRulesProvider old = ZONES.putIfAbsent(zoneId, provider); ZoneRulesProvider old = ZONES.putIfAbsent(zoneId, provider);
if (old != null) { if (old != null) {
throw new ZoneRulesException( throw new ZoneRulesException(