diff --git a/classlib/src/main/java/org/threeten/bp/Clock.java b/classlib/src/main/java/org/threeten/bp/Clock.java
index 7fc368188..4e11ecfd0 100644
--- a/classlib/src/main/java/org/threeten/bp/Clock.java
+++ b/classlib/src/main/java/org/threeten/bp/Clock.java
@@ -35,6 +35,7 @@ import static org.threeten.bp.LocalTime.NANOS_PER_MINUTE;
import static org.threeten.bp.LocalTime.NANOS_PER_SECOND;
import java.io.Serializable;
+import java.util.Objects;
import java.util.TimeZone;
import org.threeten.bp.jdk8.Jdk8Methods;
@@ -153,7 +154,7 @@ public abstract class Clock {
* @return a clock that uses the best available system clock in the specified zone, not null
*/
public static Clock system(ZoneId zone) {
- Jdk8Methods.requireNonNull(zone, "zone");
+ Objects.requireNonNull(zone, "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
*/
public static Clock tick(Clock baseClock, Duration tickDuration) {
- Jdk8Methods.requireNonNull(baseClock, "baseClock");
- Jdk8Methods.requireNonNull(tickDuration, "tickDuration");
+ Objects.requireNonNull(baseClock, "baseClock");
+ Objects.requireNonNull(tickDuration, "tickDuration");
if (tickDuration.isNegative()) {
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
*/
public static Clock fixed(Instant fixedInstant, ZoneId zone) {
- Jdk8Methods.requireNonNull(fixedInstant, "fixedInstant");
- Jdk8Methods.requireNonNull(zone, "zone");
+ Objects.requireNonNull(fixedInstant, "fixedInstant");
+ Objects.requireNonNull(zone, "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
*/
public static Clock offset(Clock baseClock, Duration offsetDuration) {
- Jdk8Methods.requireNonNull(baseClock, "baseClock");
- Jdk8Methods.requireNonNull(offsetDuration, "offsetDuration");
+ Objects.requireNonNull(baseClock, "baseClock");
+ Objects.requireNonNull(offsetDuration, "offsetDuration");
if (offsetDuration.equals(Duration.ZERO)) {
return baseClock;
}
diff --git a/classlib/src/main/java/org/threeten/bp/DateTimeUtils.java b/classlib/src/main/java/org/threeten/bp/DateTimeUtils.java
deleted file mode 100644
index f54b2fa3e..000000000
--- a/classlib/src/main/java/org/threeten/bp/DateTimeUtils.java
+++ /dev/null
@@ -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.
- *
- * 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}.
- *
- * 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}.
- *
- * 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}.
- *
- * The resulting {@code GregorianCalendar} is pure Gregorian and uses
- * ISO week definitions, starting on Monday and with 4 days in a minimal week.
- *
- * 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());
- }
-
-}
diff --git a/classlib/src/main/java/org/threeten/bp/Duration.java b/classlib/src/main/java/org/threeten/bp/Duration.java
index 837e9b474..49808f261 100644
--- a/classlib/src/main/java/org/threeten/bp/Duration.java
+++ b/classlib/src/main/java/org/threeten/bp/Duration.java
@@ -51,6 +51,7 @@ import java.math.RoundingMode;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -295,7 +296,7 @@ public final class Duration
* @throws ArithmeticException if a numeric overflow occurs
*/
public static Duration from(TemporalAmount amount) {
- Jdk8Methods.requireNonNull(amount, "amount");
+ Objects.requireNonNull(amount, "amount");
Duration duration = ZERO;
for (TemporalUnit unit : amount.getUnits()) {
duration = duration.plus(amount.get(unit), unit);
@@ -338,9 +339,7 @@ public final class Duration
Temporal adjustedEnd = endExclusive.with(NANO_OF_SECOND, startNos);
secs = startInclusive.until(adjustedEnd, SECONDS);;
}
- } catch (DateTimeException ex2) {
- // ignore and only use seconds
- } catch (ArithmeticException ex2) {
+ } catch (DateTimeException | ArithmeticException ex2) {
// ignore and only use seconds
}
}
@@ -393,7 +392,7 @@ public final class Duration
* @throws DateTimeParseException if the text cannot be parsed to a duration
*/
public static Duration parse(CharSequence text) {
- Jdk8Methods.requireNonNull(text, "text");
+ Objects.requireNonNull(text, "text");
Matcher matcher = PATTERN.matcher(text);
if (matcher.matches()) {
// check for letter T but no time sections
@@ -433,10 +432,8 @@ public final class Duration
}
long val = Long.parseLong(parsed);
return Jdk8Methods.safeMultiply(val, multiplier);
- } catch (NumberFormatException ex) {
- throw (DateTimeParseException) new DateTimeParseException("Text cannot be parsed to a Duration: " + errorText, text, 0).initCause(ex);
- } catch (ArithmeticException ex) {
- throw (DateTimeParseException) new DateTimeParseException("Text cannot be parsed to a Duration: " + errorText, text, 0).initCause(ex);
+ } catch (NumberFormatException | ArithmeticException ex) {
+ throw new DateTimeParseException("Text cannot be parsed to a Duration: " + errorText, text, 0, ex);
}
}
@@ -448,10 +445,8 @@ public final class Duration
try {
parsed = (parsed + "000000000").substring(0, 9);
return Integer.parseInt(parsed) * negate;
- } catch (NumberFormatException ex) {
- throw (DateTimeParseException) new DateTimeParseException("Text cannot be parsed to a Duration: fraction", text, 0).initCause(ex);
- } catch (ArithmeticException ex) {
- throw (DateTimeParseException) new DateTimeParseException("Text cannot be parsed to a Duration: fraction", text, 0).initCause(ex);
+ } catch (NumberFormatException | ArithmeticException ex) {
+ throw new DateTimeParseException("Text cannot be parsed to a Duration: fraction", text, 0, ex);
}
}
@@ -633,7 +628,7 @@ public final class Duration
* @throws ArithmeticException if numeric overflow occurs
*/
public Duration plus(long amountToAdd, TemporalUnit unit) {
- Jdk8Methods.requireNonNull(unit, "unit");
+ Objects.requireNonNull(unit, "unit");
if (unit == DAYS) {
return plus(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_DAY), 0);
}
@@ -1131,7 +1126,7 @@ public final class Duration
*/
@Override
public int compareTo(Duration otherDuration) {
- int cmp = Jdk8Methods.compareLongs(seconds, otherDuration.seconds);
+ int cmp = Long.compare(seconds, otherDuration.seconds);
if (cmp != 0) {
return cmp;
}
diff --git a/classlib/src/main/java/org/threeten/bp/Instant.java b/classlib/src/main/java/org/threeten/bp/Instant.java
index 2c77d949f..99e3da90c 100644
--- a/classlib/src/main/java/org/threeten/bp/Instant.java
+++ b/classlib/src/main/java/org/threeten/bp/Instant.java
@@ -47,10 +47,10 @@ import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectStreamException;
import java.io.Serializable;
+import java.util.Objects;
import org.threeten.bp.format.DateTimeFormatter;
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.ChronoUnit;
@@ -155,8 +155,7 @@ import org.threeten.bp.temporal.ValueRange;
* This class is immutable and thread-safe.
*/
public final class Instant
- extends DefaultInterfaceTemporalAccessor
- implements Temporal, TemporalAdjuster, Comparable, Serializable {
+ implements Temporal, TemporalAdjuster, Comparable, Serializable, TemporalAccessor {
/**
* Constant for the 1970-01-01T00:00:00Z epoch instant.
@@ -257,7 +256,7 @@ public final class Instant
* @return the current instant, not null
*/
public static Instant now(Clock clock) {
- Jdk8Methods.requireNonNull(clock, "clock");
+ Objects.requireNonNull(clock, "clock");
return clock.instant();
}
@@ -459,7 +458,7 @@ public final class Instant
*/
@Override // override for Javadoc
public ValueRange range(TemporalField field) {
- return super.range(field);
+ return Temporal.super.range(field);
}
/**
@@ -1084,7 +1083,7 @@ public final class Instant
*/
@Override
public int compareTo(Instant otherInstant) {
- int cmp = Jdk8Methods.compareLongs(seconds, otherInstant.seconds);
+ int cmp = Long.compare(seconds, otherInstant.seconds);
if (cmp != 0) {
return cmp;
}
diff --git a/classlib/src/main/java/org/threeten/bp/LocalDate.java b/classlib/src/main/java/org/threeten/bp/LocalDate.java
index f808028ba..27d36886b 100644
--- a/classlib/src/main/java/org/threeten/bp/LocalDate.java
+++ b/classlib/src/main/java/org/threeten/bp/LocalDate.java
@@ -50,6 +50,7 @@ import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectStreamException;
import java.io.Serializable;
+import java.util.Objects;
import org.threeten.bp.chrono.ChronoLocalDate;
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.
*/
public static final LocalDate MAX = LocalDate.of(Year.MAX_VALUE, 12, 31);
- /**
- * Simulate JDK 8 method reference LocalDate::from.
- */
- public static final TemporalQuery FROM = new TemporalQuery() {
- @Override
- public LocalDate queryFrom(TemporalAccessor temporal) {
- return LocalDate.from(temporal);
- }
- };
/**
* Serialization version.
@@ -192,7 +184,7 @@ public final class LocalDate
* @return the current date, not null
*/
public static LocalDate now(Clock clock) {
- Jdk8Methods.requireNonNull(clock, "clock");
+ Objects.requireNonNull(clock, "clock");
final Instant now = clock.instant(); // called once
ZoneOffset offset = clock.getZone().getRules().getOffset(now);
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) {
YEAR.checkValidValue(year);
- Jdk8Methods.requireNonNull(month, "month");
+ Objects.requireNonNull(month, "month");
DAY_OF_MONTH.checkValidValue(dayOfMonth);
return create(year, month, dayOfMonth);
}
@@ -363,8 +355,8 @@ public final class LocalDate
* @throws DateTimeParseException if the text cannot be parsed
*/
public static LocalDate parse(CharSequence text, DateTimeFormatter formatter) {
- Jdk8Methods.requireNonNull(formatter, "formatter");
- return formatter.parse(text, LocalDate.FROM);
+ Objects.requireNonNull(formatter, "formatter");
+ 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
*/
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
// standard ZDT factory would result in 01:00 rather than 00:30
LocalDateTime ldt = atTime(LocalTime.MIDNIGHT);
diff --git a/classlib/src/main/java/org/threeten/bp/LocalDateTime.java b/classlib/src/main/java/org/threeten/bp/LocalDateTime.java
index 0396b0b30..e3dcb8bdc 100644
--- a/classlib/src/main/java/org/threeten/bp/LocalDateTime.java
+++ b/classlib/src/main/java/org/threeten/bp/LocalDateTime.java
@@ -47,6 +47,7 @@ import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectStreamException;
import java.io.Serializable;
+import java.util.Objects;
import org.threeten.bp.chrono.ChronoLocalDateTime;
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.
*/
public static final LocalDateTime MAX = LocalDateTime.of(LocalDate.MAX, LocalTime.MAX);
- /**
- * Simulate JDK 8 method reference LocalDateTime::from.
- */
- public static final TemporalQuery FROM = new TemporalQuery() {
- @Override
- public LocalDateTime queryFrom(TemporalAccessor temporal) {
- return LocalDateTime.from(temporal);
- }
- };
-
- /**
- * Serialization version.
- */
- private static final long serialVersionUID = 6207766400415563566L;
/**
* The date part.
@@ -179,7 +166,7 @@ public final class LocalDateTime
* @return the current date-time, not null
*/
public static LocalDateTime now(Clock clock) {
- Jdk8Methods.requireNonNull(clock, "clock");
+ Objects.requireNonNull(clock, "clock");
final Instant now = clock.instant(); // called once
ZoneOffset offset = clock.getZone().getRules().getOffset(now);
return ofEpochSecond(now.getEpochSecond(), now.getNano(), offset);
@@ -331,8 +318,8 @@ public final class LocalDateTime
* @return the local date-time, not null
*/
public static LocalDateTime of(LocalDate date, LocalTime time) {
- Jdk8Methods.requireNonNull(date, "date");
- Jdk8Methods.requireNonNull(time, "time");
+ Objects.requireNonNull(date, "date");
+ Objects.requireNonNull(time, "time");
return new LocalDateTime(date, time);
}
@@ -351,8 +338,8 @@ public final class LocalDateTime
* @throws DateTimeException if the result exceeds the supported range
*/
public static LocalDateTime ofInstant(Instant instant, ZoneId zone) {
- Jdk8Methods.requireNonNull(instant, "instant");
- Jdk8Methods.requireNonNull(zone, "zone");
+ Objects.requireNonNull(instant, "instant");
+ Objects.requireNonNull(zone, "zone");
ZoneRules rules = zone.getRules();
ZoneOffset offset = rules.getOffset(instant);
return ofEpochSecond(instant.getEpochSecond(), instant.getNano(), offset);
@@ -373,7 +360,7 @@ public final class LocalDateTime
* @throws DateTimeException if the result exceeds the supported range
*/
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 localEpochDay = Jdk8Methods.floorDiv(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
*/
public static LocalDateTime parse(CharSequence text, DateTimeFormatter formatter) {
- Jdk8Methods.requireNonNull(formatter, "formatter");
- return formatter.parse(text, LocalDateTime.FROM);
+ Objects.requireNonNull(formatter, "formatter");
+ return formatter.parse(text, LocalDateTime::from);
}
//-----------------------------------------------------------------------
diff --git a/classlib/src/main/java/org/threeten/bp/LocalTime.java b/classlib/src/main/java/org/threeten/bp/LocalTime.java
index 778ef514d..ff4adb76d 100644
--- a/classlib/src/main/java/org/threeten/bp/LocalTime.java
+++ b/classlib/src/main/java/org/threeten/bp/LocalTime.java
@@ -46,11 +46,10 @@ import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectStreamException;
import java.io.Serializable;
+import java.util.Objects;
import org.threeten.bp.format.DateTimeFormatter;
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.ChronoUnit;
import org.threeten.bp.temporal.Temporal;
@@ -86,8 +85,7 @@ import org.threeten.bp.temporal.ValueRange;
* This class is immutable and thread-safe.
*/
public final class LocalTime
- extends DefaultInterfaceTemporalAccessor
- implements Temporal, TemporalAdjuster, Comparable, Serializable {
+ implements Temporal, TemporalAdjuster, Comparable, Serializable, TemporalAccessor {
/**
* The minimum supported {@code LocalTime}, '00:00'.
@@ -244,7 +242,7 @@ public final class LocalTime
* @return the current time, not null
*/
public static LocalTime now(Clock clock) {
- Jdk8Methods.requireNonNull(clock, "clock");
+ Objects.requireNonNull(clock, "clock");
// inline OffsetTime factory to avoid creating object and InstantProvider checks
final Instant now = clock.instant(); // called once
ZoneOffset offset = clock.getZone().getRules().getOffset(now);
@@ -433,7 +431,7 @@ public final class LocalTime
* @throws DateTimeParseException if the text cannot be parsed
*/
public static LocalTime parse(CharSequence text, DateTimeFormatter formatter) {
- Jdk8Methods.requireNonNull(formatter, "formatter");
+ Objects.requireNonNull(formatter, "formatter");
return formatter.parse(text, LocalTime.FROM);
}
@@ -548,7 +546,7 @@ public final class LocalTime
*/
@Override // override for Javadoc
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) {
return get0(field);
}
- return super.get(field);
+ return Temporal.super.get(field);
}
/**
@@ -1373,13 +1371,13 @@ public final class LocalTime
*/
@Override
public int compareTo(LocalTime other) {
- int cmp = Jdk8Methods.compareInts(hour, other.hour);
+ int cmp = Integer.compare(hour, other.hour);
if (cmp == 0) {
- cmp = Jdk8Methods.compareInts(minute, other.minute);
+ cmp = Integer.compare(minute, other.minute);
if (cmp == 0) {
- cmp = Jdk8Methods.compareInts(second, other.second);
+ cmp = Integer.compare(second, other.second);
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) {
buf.append(Integer.toString((nanoValue / 1000) + 1000000).substring(1));
} 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
*/
public String format(DateTimeFormatter formatter) {
- Jdk8Methods.requireNonNull(formatter, "formatter");
+ Objects.requireNonNull(formatter, "formatter");
return formatter.format(this);
}
diff --git a/classlib/src/main/java/org/threeten/bp/MonthDay.java b/classlib/src/main/java/org/threeten/bp/MonthDay.java
index 2ed437eab..28ee83192 100644
--- a/classlib/src/main/java/org/threeten/bp/MonthDay.java
+++ b/classlib/src/main/java/org/threeten/bp/MonthDay.java
@@ -40,14 +40,13 @@ import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectStreamException;
import java.io.Serializable;
+import java.util.Objects;
import org.threeten.bp.chrono.Chronology;
import org.threeten.bp.chrono.IsoChronology;
import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.format.DateTimeFormatterBuilder;
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.Temporal;
import org.threeten.bp.temporal.TemporalAccessor;
@@ -88,23 +87,7 @@ import org.threeten.bp.temporal.ValueRange;
* This class is immutable and thread-safe.
*/
public final class MonthDay
- extends DefaultInterfaceTemporalAccessor
implements TemporalAccessor, TemporalAdjuster, Comparable, Serializable {
-
- /**
- * Simulate JDK 8 method reference MonthDay::from.
- */
- public static final TemporalQuery FROM = new TemporalQuery() {
- @Override
- public MonthDay queryFrom(TemporalAccessor temporal) {
- return MonthDay.from(temporal);
- }
- };
-
- /**
- * Serialization version.
- */
- private static final long serialVersionUID = -939150713474957432L;
/**
* Parser.
*/
@@ -189,7 +172,7 @@ public final class MonthDay
* @throws DateTimeException if the day-of-month is invalid for the month
*/
public static MonthDay of(Month month, int dayOfMonth) {
- Jdk8Methods.requireNonNull(month, "month");
+ Objects.requireNonNull(month, "month");
DAY_OF_MONTH.checkValidValue(dayOfMonth);
if (dayOfMonth > month.maxLength()) {
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
*/
public static MonthDay parse(CharSequence text, DateTimeFormatter formatter) {
- Jdk8Methods.requireNonNull(formatter, "formatter");
- return formatter.parse(text, MonthDay.FROM);
+ Objects.requireNonNull(formatter, "formatter");
+ return formatter.parse(text, MonthDay::from);
}
//-----------------------------------------------------------------------
@@ -356,7 +339,7 @@ public final class MonthDay
} else if (field == DAY_OF_MONTH) {
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
*/
public MonthDay with(Month month) {
- Jdk8Methods.requireNonNull(month, "month");
+ Objects.requireNonNull(month, "month");
if (month.getValue() == this.month) {
return this;
}
@@ -562,7 +545,7 @@ public final class MonthDay
if (query == TemporalQueries.chronology()) {
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
*/
public String format(DateTimeFormatter formatter) {
- Jdk8Methods.requireNonNull(formatter, "formatter");
+ Objects.requireNonNull(formatter, "formatter");
return formatter.format(this);
}
diff --git a/classlib/src/main/java/org/threeten/bp/OffsetDateTime.java b/classlib/src/main/java/org/threeten/bp/OffsetDateTime.java
index a8a44bb44..f6f6cdfc9 100644
--- a/classlib/src/main/java/org/threeten/bp/OffsetDateTime.java
+++ b/classlib/src/main/java/org/threeten/bp/OffsetDateTime.java
@@ -44,12 +44,11 @@ import java.io.InvalidObjectException;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.util.Comparator;
+import java.util.Objects;
import org.threeten.bp.chrono.IsoChronology;
import org.threeten.bp.format.DateTimeFormatter;
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.ChronoUnit;
import org.threeten.bp.temporal.Temporal;
@@ -88,7 +87,6 @@ import org.threeten.bp.zone.ZoneRules;
* This class is immutable and thread-safe.
*/
public final class OffsetDateTime
- extends DefaultInterfaceTemporal
implements Temporal, TemporalAdjuster, Comparable, Serializable {
/**
@@ -133,16 +131,8 @@ public final class OffsetDateTime
public static Comparator timeLineOrder() {
return INSTANT_COMPARATOR;
}
- private static final Comparator INSTANT_COMPARATOR = new Comparator() {
- @Override
- 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;
- }
- };
+ private static final Comparator INSTANT_COMPARATOR =
+ Comparator.comparingLong(OffsetDateTime::toEpochSecond).thenComparingInt(OffsetDateTime::getNano);
/**
* Serialization version.
@@ -205,7 +195,7 @@ public final class OffsetDateTime
* @return the current date-time, not null
*/
public static OffsetDateTime now(Clock clock) {
- Jdk8Methods.requireNonNull(clock, "clock");
+ Objects.requireNonNull(clock, "clock");
final Instant now = clock.instant(); // called once
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
*/
public static OffsetDateTime ofInstant(Instant instant, ZoneId zone) {
- Jdk8Methods.requireNonNull(instant, "instant");
- Jdk8Methods.requireNonNull(zone, "zone");
+ Objects.requireNonNull(instant, "instant");
+ Objects.requireNonNull(zone, "zone");
ZoneRules rules = zone.getRules();
ZoneOffset offset = rules.getOffset(instant);
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
*/
public static OffsetDateTime parse(CharSequence text, DateTimeFormatter formatter) {
- Jdk8Methods.requireNonNull(formatter, "formatter");
+ Objects.requireNonNull(formatter, "formatter");
return formatter.parse(text, OffsetDateTime.FROM);
}
@@ -367,8 +357,8 @@ public final class OffsetDateTime
* @param offset the zone offset, not null
*/
private OffsetDateTime(LocalDateTime dateTime, ZoneOffset offset) {
- this.dateTime = Jdk8Methods.requireNonNull(dateTime, "dateTime");
- this.offset = Jdk8Methods.requireNonNull(offset, "offset");
+ this.dateTime = Objects.requireNonNull(dateTime, "dateTime");
+ this.offset = Objects.requireNonNull(offset, "offset");
}
/**
@@ -516,7 +506,7 @@ public final class OffsetDateTime
}
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()) {
return null;
}
- return super.query(query);
+ return Temporal.super.query(query);
}
/**
@@ -1661,7 +1651,7 @@ public final class OffsetDateTime
if (getOffset().equals(other.getOffset())) {
return toLocalDateTime().compareTo(other.toLocalDateTime());
}
- int cmp = Jdk8Methods.compareLongs(toEpochSecond(), other.toEpochSecond());
+ int cmp = Long.compare(toEpochSecond(), other.toEpochSecond());
if (cmp == 0) {
cmp = toLocalTime().getNano() - other.toLocalTime().getNano();
if (cmp == 0) {
@@ -1787,7 +1777,7 @@ public final class OffsetDateTime
* @throws DateTimeException if an error occurs during printing
*/
public String format(DateTimeFormatter formatter) {
- Jdk8Methods.requireNonNull(formatter, "formatter");
+ Objects.requireNonNull(formatter, "formatter");
return formatter.format(this);
}
diff --git a/classlib/src/main/java/org/threeten/bp/OffsetTime.java b/classlib/src/main/java/org/threeten/bp/OffsetTime.java
index ebd653fd7..a953759a1 100644
--- a/classlib/src/main/java/org/threeten/bp/OffsetTime.java
+++ b/classlib/src/main/java/org/threeten/bp/OffsetTime.java
@@ -45,11 +45,10 @@ import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectStreamException;
import java.io.Serializable;
+import java.util.Objects;
import org.threeten.bp.format.DateTimeFormatter;
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.ChronoUnit;
import org.threeten.bp.temporal.Temporal;
@@ -79,8 +78,7 @@ import org.threeten.bp.zone.ZoneRules;
* This class is immutable and thread-safe.
*/
public final class OffsetTime
- extends DefaultInterfaceTemporalAccessor
- implements Temporal, TemporalAdjuster, Comparable, Serializable {
+ implements Temporal, TemporalAdjuster, Comparable, Serializable, TemporalAccessor {
/**
* The minimum supported {@code OffsetTime}, '00:00:00+18:00'.
@@ -169,7 +167,7 @@ public final class OffsetTime
* @return the current time, not null
*/
public static OffsetTime now(Clock clock) {
- Jdk8Methods.requireNonNull(clock, "clock");
+ Objects.requireNonNull(clock, "clock");
final Instant now = clock.instant(); // called once
return ofInstant(now, clock.getZone().getRules().getOffset(now));
}
@@ -226,8 +224,8 @@ public final class OffsetTime
* @return the offset time, not null
*/
public static OffsetTime ofInstant(Instant instant, ZoneId zone) {
- Jdk8Methods.requireNonNull(instant, "instant");
- Jdk8Methods.requireNonNull(zone, "zone");
+ Objects.requireNonNull(instant, "instant");
+ Objects.requireNonNull(zone, "zone");
ZoneRules rules = zone.getRules();
ZoneOffset offset = rules.getOffset(instant);
long secsOfDay = instant.getEpochSecond() % SECONDS_PER_DAY;
@@ -295,7 +293,7 @@ public final class OffsetTime
* @throws DateTimeParseException if the text cannot be parsed
*/
public static OffsetTime parse(CharSequence text, DateTimeFormatter formatter) {
- Jdk8Methods.requireNonNull(formatter, "formatter");
+ Objects.requireNonNull(formatter, "formatter");
return formatter.parse(text, OffsetTime.FROM);
}
@@ -307,8 +305,8 @@ public final class OffsetTime
* @param offset the zone offset, not null
*/
private OffsetTime(LocalTime time, ZoneOffset offset) {
- this.time = Jdk8Methods.requireNonNull(time, "time");
- this.offset = Jdk8Methods.requireNonNull(offset, "offset");
+ this.time = Objects.requireNonNull(time, "time");
+ this.offset = Objects.requireNonNull(offset, "offset");
}
/**
@@ -437,7 +435,7 @@ public final class OffsetTime
*/
@Override // override for Javadoc
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()) {
return null;
}
- return super.query(query);
+ return Temporal.super.query(query);
}
/**
@@ -1162,7 +1160,7 @@ public final class OffsetTime
if (offset.equals(other.offset)) {
return time.compareTo(other.time);
}
- int compare = Jdk8Methods.compareLongs(toEpochNano(), other.toEpochNano());
+ int compare = Long.compare(toEpochNano(), other.toEpochNano());
if (compare == 0) {
compare = time.compareTo(other.time);
}
@@ -1284,7 +1282,7 @@ public final class OffsetTime
* @throws DateTimeException if an error occurs during printing
*/
public String format(DateTimeFormatter formatter) {
- Jdk8Methods.requireNonNull(formatter, "formatter");
+ Objects.requireNonNull(formatter, "formatter");
return formatter.format(this);
}
diff --git a/classlib/src/main/java/org/threeten/bp/Period.java b/classlib/src/main/java/org/threeten/bp/Period.java
index 8c8b6db0c..cb40f1b6c 100644
--- a/classlib/src/main/java/org/threeten/bp/Period.java
+++ b/classlib/src/main/java/org/threeten/bp/Period.java
@@ -39,6 +39,7 @@ import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -216,7 +217,7 @@ public final class Period
throw new DateTimeException("Period requires ISO chronology: " + amount);
}
}
- Jdk8Methods.requireNonNull(amount, "amount");
+ Objects.requireNonNull(amount, "amount");
int years = 0;
int months = 0;
int days = 0;
@@ -300,7 +301,7 @@ public final class Period
* @throws DateTimeParseException if the text cannot be parsed to a period
*/
public static Period parse(CharSequence text) {
- Jdk8Methods.requireNonNull(text, "text");
+ Objects.requireNonNull(text, "text");
Matcher matcher = PATTERN.matcher(text);
if (matcher.matches()) {
int negate = ("-".equals(matcher.group(1)) ? -1 : 1);
@@ -379,7 +380,7 @@ public final class Period
//-----------------------------------------------------------------------
@Override
public List getUnits() {
- return Collections.unmodifiableList(Arrays.asList(YEARS, MONTHS, DAYS));
+ return Collections.unmodifiableList(Arrays.asList(YEARS, MONTHS, DAYS));
}
@Override
@@ -796,7 +797,7 @@ public final class Period
*/
@Override
public Temporal addTo(Temporal temporal) {
- Jdk8Methods.requireNonNull(temporal, "temporal");
+ Objects.requireNonNull(temporal, "temporal");
if (years != 0) {
if (months != 0) {
temporal = temporal.plus(toTotalMonths(), MONTHS);
@@ -846,7 +847,7 @@ public final class Period
*/
@Override
public Temporal subtractFrom(Temporal temporal) {
- Jdk8Methods.requireNonNull(temporal, "temporal");
+ Objects.requireNonNull(temporal, "temporal");
if (years != 0) {
if (months != 0) {
temporal = temporal.minus(toTotalMonths(), MONTHS);
diff --git a/classlib/src/main/java/org/threeten/bp/Year.java b/classlib/src/main/java/org/threeten/bp/Year.java
index b89567282..8e7efe52e 100644
--- a/classlib/src/main/java/org/threeten/bp/Year.java
+++ b/classlib/src/main/java/org/threeten/bp/Year.java
@@ -46,6 +46,7 @@ import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectStreamException;
import java.io.Serializable;
+import java.util.Objects;
import org.threeten.bp.chrono.Chronology;
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.DateTimeParseException;
import org.threeten.bp.format.SignStyle;
-import org.threeten.bp.jdk8.DefaultInterfaceTemporalAccessor;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.ChronoUnit;
@@ -96,8 +96,7 @@ import org.threeten.bp.temporal.ValueRange;
* This class is immutable and thread-safe.
*/
public final class Year
- extends DefaultInterfaceTemporalAccessor
- implements Temporal, TemporalAdjuster, Comparable, Serializable {
+ implements Temporal, TemporalAdjuster, Comparable, Serializable, TemporalAccessor {
/**
* The minimum supported year, '-999,999,999'.
@@ -107,15 +106,6 @@ public final class Year
* The maximum supported year, '+999,999,999'.
*/
public static final int MAX_VALUE = 999999999;
- /**
- * Simulate JDK 8 method reference Year::from.
- */
- public static final TemporalQuery FROM = new TemporalQuery() {
- @Override
- public Year queryFrom(TemporalAccessor temporal) {
- return Year.from(temporal);
- }
- };
/**
* Serialization version.
@@ -223,13 +213,13 @@ public final class Year
return (Year) temporal;
}
try {
- if (IsoChronology.INSTANCE.equals(Chronology.from(temporal)) == false) {
+ if (!IsoChronology.INSTANCE.equals(Chronology.from(temporal))) {
temporal = LocalDate.from(temporal);
}
return of(temporal.get(YEAR));
} catch (DateTimeException ex) {
- throw new DateTimeException("Unable to obtain Year from TemporalAccessor: " +
- temporal + ", type " + temporal.getClass().getName());
+ throw new DateTimeException("Unable to obtain Year from TemporalAccessor: "
+ + temporal + ", type " + temporal.getClass().getName());
}
}
@@ -259,8 +249,8 @@ public final class Year
* @throws DateTimeParseException if the text cannot be parsed
*/
public static Year parse(CharSequence text, DateTimeFormatter formatter) {
- Jdk8Methods.requireNonNull(formatter, "formatter");
- return formatter.parse(text, Year.FROM);
+ Objects.requireNonNull(formatter, "formatter");
+ return formatter.parse(text, Year::from);
}
//-------------------------------------------------------------------------
@@ -379,7 +369,7 @@ public final class Year
if (field == YEAR_OF_ERA) {
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()) {
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
*/
public String format(DateTimeFormatter formatter) {
- Jdk8Methods.requireNonNull(formatter, "formatter");
+ Objects.requireNonNull(formatter, "formatter");
return formatter.format(this);
}
diff --git a/classlib/src/main/java/org/threeten/bp/YearMonth.java b/classlib/src/main/java/org/threeten/bp/YearMonth.java
index 782ca3827..f8375330a 100644
--- a/classlib/src/main/java/org/threeten/bp/YearMonth.java
+++ b/classlib/src/main/java/org/threeten/bp/YearMonth.java
@@ -49,6 +49,7 @@ import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectStreamException;
import java.io.Serializable;
+import java.util.Objects;
import org.threeten.bp.chrono.Chronology;
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.DateTimeParseException;
import org.threeten.bp.format.SignStyle;
-import org.threeten.bp.jdk8.DefaultInterfaceTemporalAccessor;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.ChronoUnit;
@@ -92,18 +92,7 @@ import org.threeten.bp.temporal.ValueRange;
* This class is immutable and thread-safe.
*/
public final class YearMonth
- extends DefaultInterfaceTemporalAccessor
- implements Temporal, TemporalAdjuster, Comparable, Serializable {
-
- /**
- * Simulate JDK 8 method reference YearMonth::from.
- */
- public static final TemporalQuery FROM = new TemporalQuery() {
- @Override
- public YearMonth queryFrom(TemporalAccessor temporal) {
- return YearMonth.from(temporal);
- }
- };
+ implements Temporal, TemporalAdjuster, Comparable, Serializable, TemporalAccessor {
/**
* Serialization version.
@@ -185,7 +174,7 @@ public final class YearMonth
* @throws DateTimeException if the year value is invalid
*/
public static YearMonth of(int year, Month month) {
- Jdk8Methods.requireNonNull(month, "month");
+ Objects.requireNonNull(month, "month");
return of(year, month.getValue());
}
@@ -264,8 +253,8 @@ public final class YearMonth
* @throws DateTimeParseException if the text cannot be parsed
*/
public static YearMonth parse(CharSequence text, DateTimeFormatter formatter) {
- Jdk8Methods.requireNonNull(formatter, "formatter");
- return formatter.parse(text, YearMonth.FROM);
+ Objects.requireNonNull(formatter, "formatter");
+ return formatter.parse(text, YearMonth::from);
}
//-----------------------------------------------------------------------
@@ -368,7 +357,7 @@ public final class YearMonth
if (field == YEAR_OF_ERA) {
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()) {
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
*/
public String format(DateTimeFormatter formatter) {
- Jdk8Methods.requireNonNull(formatter, "formatter");
+ Objects.requireNonNull(formatter, "formatter");
return formatter.format(this);
}
diff --git a/classlib/src/main/java/org/threeten/bp/ZoneId.java b/classlib/src/main/java/org/threeten/bp/ZoneId.java
index ed8a768f2..ec4f1ab13 100644
--- a/classlib/src/main/java/org/threeten/bp/ZoneId.java
+++ b/classlib/src/main/java/org/threeten/bp/ZoneId.java
@@ -39,13 +39,12 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.TimeZone;
import org.threeten.bp.format.DateTimeFormatterBuilder;
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.TemporalField;
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
*/
public static ZoneId of(String zoneId, Map aliasMap) {
- Jdk8Methods.requireNonNull(zoneId, "zoneId");
- Jdk8Methods.requireNonNull(aliasMap, "aliasMap");
+ Objects.requireNonNull(zoneId, "zoneId");
+ Objects.requireNonNull(aliasMap, "aliasMap");
String id = aliasMap.get(zoneId);
id = (id != null ? id : zoneId);
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
*/
public static ZoneId of(String zoneId) {
- Jdk8Methods.requireNonNull(zoneId, "zoneId");
+ Objects.requireNonNull(zoneId, "zoneId");
if (zoneId.equals("Z")) {
return ZoneOffset.UTC;
}
@@ -372,8 +371,8 @@ public abstract class ZoneId implements Serializable {
* "GMT", "UTC", or "UT", or ""
*/
public static ZoneId ofOffset(String prefix, ZoneOffset offset) {
- Jdk8Methods.requireNonNull(prefix, "prefix");
- Jdk8Methods.requireNonNull(offset, "offset");
+ Objects.requireNonNull(prefix, "prefix");
+ Objects.requireNonNull(offset, "offset");
if (prefix.length() == 0) {
return offset;
}
@@ -472,7 +471,7 @@ public abstract class ZoneId implements Serializable {
* @return the text value of the zone, not null
*/
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
public boolean isSupported(TemporalField field) {
return false;
@@ -487,7 +486,7 @@ public abstract class ZoneId implements Serializable {
if (query == TemporalQueries.zoneId()) {
return (R) ZoneId.this;
}
- return super.query(query);
+ return TemporalAccessor.super.query(query);
}
});
}
diff --git a/classlib/src/main/java/org/threeten/bp/ZoneOffset.java b/classlib/src/main/java/org/threeten/bp/ZoneOffset.java
index a3e2c6b9e..3dce38b7e 100644
--- a/classlib/src/main/java/org/threeten/bp/ZoneOffset.java
+++ b/classlib/src/main/java/org/threeten/bp/ZoneOffset.java
@@ -41,8 +41,8 @@ import java.io.ObjectStreamException;
import java.io.Serializable;
import java.util.HashMap;
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.Temporal;
import org.threeten.bp.temporal.TemporalAccessor;
@@ -90,16 +90,6 @@ public final class ZoneOffset
extends ZoneId
implements TemporalAccessor, TemporalAdjuster, Comparable, Serializable {
- /**
- * Simulate JDK 8 method reference ZoneOffset::from.
- */
- public static final TemporalQuery FROM = new TemporalQuery() {
- @Override
- public ZoneOffset queryFrom(TemporalAccessor temporal) {
- return ZoneOffset.from(temporal);
- }
- };
-
/** Cache of time-zone offset by offset in seconds. */
private static final Map SECONDS_CACHE = new HashMap<>();
/** Cache of time-zone offset by ID. */
@@ -180,7 +170,7 @@ public final class ZoneOffset
* @throws DateTimeException if the offset ID is invalid
*/
public static ZoneOffset of(String offsetId) {
- Jdk8Methods.requireNonNull(offsetId, "offsetId");
+ Objects.requireNonNull(offsetId, "offsetId");
// "Z" is always in the cache
ZoneOffset offset = ID_CACHE.get(offsetId);
if (offset != null) {
diff --git a/classlib/src/main/java/org/threeten/bp/ZoneRegion.java b/classlib/src/main/java/org/threeten/bp/ZoneRegion.java
index 03f906c42..bcd72987d 100644
--- a/classlib/src/main/java/org/threeten/bp/ZoneRegion.java
+++ b/classlib/src/main/java/org/threeten/bp/ZoneRegion.java
@@ -37,9 +37,9 @@ import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectStreamException;
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.ZoneRulesException;
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
*/
static ZoneRegion ofId(String zoneId, boolean checkAvailable) {
- Jdk8Methods.requireNonNull(zoneId, "zoneId");
- if (zoneId.length() < 2 || PATTERN.matcher(zoneId).matches() == false) {
+ Objects.requireNonNull(zoneId, "zoneId");
+ if (zoneId.length() < 2 || !PATTERN.matcher(zoneId).matches()) {
throw new DateTimeException("Invalid ID for region-based ZoneId, invalid format: " + zoneId);
}
ZoneRules rules = null;
diff --git a/classlib/src/main/java/org/threeten/bp/ZonedDateTime.java b/classlib/src/main/java/org/threeten/bp/ZonedDateTime.java
index d7dc39f84..63932084a 100644
--- a/classlib/src/main/java/org/threeten/bp/ZonedDateTime.java
+++ b/classlib/src/main/java/org/threeten/bp/ZonedDateTime.java
@@ -42,11 +42,11 @@ import java.io.InvalidObjectException;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.util.List;
+import java.util.Objects;
import org.threeten.bp.chrono.ChronoZonedDateTime;
import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.format.DateTimeParseException;
-import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.ChronoUnit;
import org.threeten.bp.temporal.Temporal;
@@ -123,21 +123,6 @@ public final class ZonedDateTime
extends ChronoZonedDateTime
implements Temporal, Serializable {
- /**
- * Simulate JDK 8 method reference ZonedDateTime::from.
- */
- public static final TemporalQuery FROM = new TemporalQuery() {
- @Override
- public ZonedDateTime queryFrom(TemporalAccessor temporal) {
- return ZonedDateTime.from(temporal);
- }
- };
-
- /**
- * Serialization version.
- */
- private static final long serialVersionUID = -6260982410461394882L;
-
/**
* The local date-time.
*/
@@ -198,7 +183,7 @@ public final class ZonedDateTime
* @return the current date-time, not null
*/
public static ZonedDateTime now(Clock clock) {
- Jdk8Methods.requireNonNull(clock, "clock");
+ Objects.requireNonNull(clock, "clock");
final Instant now = clock.instant(); // called once
return ofInstant(now, clock.getZone());
}
@@ -333,8 +318,8 @@ public final class ZonedDateTime
* @return the zoned date-time, not null
*/
public static ZonedDateTime ofLocal(LocalDateTime localDateTime, ZoneId zone, ZoneOffset preferredOffset) {
- Jdk8Methods.requireNonNull(localDateTime, "localDateTime");
- Jdk8Methods.requireNonNull(zone, "zone");
+ Objects.requireNonNull(localDateTime, "localDateTime");
+ Objects.requireNonNull(zone, "zone");
if (zone instanceof ZoneOffset) {
return new ZonedDateTime(localDateTime, (ZoneOffset) zone, zone);
}
@@ -351,7 +336,7 @@ public final class ZonedDateTime
if (preferredOffset != null && validOffsets.contains(preferredOffset)) {
offset = preferredOffset;
} 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);
@@ -373,8 +358,8 @@ public final class ZonedDateTime
* @throws DateTimeException if the result exceeds the supported range
*/
public static ZonedDateTime ofInstant(Instant instant, ZoneId zone) {
- Jdk8Methods.requireNonNull(instant, "instant");
- Jdk8Methods.requireNonNull(zone, "zone");
+ Objects.requireNonNull(instant, "instant");
+ Objects.requireNonNull(zone, "zone");
return create(instant.getEpochSecond(), instant.getNano(), zone);
}
@@ -399,9 +384,9 @@ public final class ZonedDateTime
* @return the zoned date-time, not null
*/
public static ZonedDateTime ofInstant(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
- Jdk8Methods.requireNonNull(localDateTime, "localDateTime");
- Jdk8Methods.requireNonNull(offset, "offset");
- Jdk8Methods.requireNonNull(zone, "zone");
+ Objects.requireNonNull(localDateTime, "localDateTime");
+ Objects.requireNonNull(offset, "offset");
+ Objects.requireNonNull(zone, "zone");
return create(localDateTime.toEpochSecond(offset), localDateTime.getNano(), zone);
}
@@ -438,9 +423,9 @@ public final class ZonedDateTime
* @return the zoned date-time, not null
*/
public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
- Jdk8Methods.requireNonNull(localDateTime, "localDateTime");
- Jdk8Methods.requireNonNull(offset, "offset");
- Jdk8Methods.requireNonNull(zone, "zone");
+ Objects.requireNonNull(localDateTime, "localDateTime");
+ Objects.requireNonNull(offset, "offset");
+ Objects.requireNonNull(zone, "zone");
ZoneRules rules = zone.getRules();
if (rules.isValidOffset(localDateTime, offset) == false) {
ZoneOffsetTransition trans = rules.getTransition(localDateTime);
@@ -479,9 +464,9 @@ public final class ZonedDateTime
* @return the zoned date-time, not null
*/
private static ZonedDateTime ofLenient(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
- Jdk8Methods.requireNonNull(localDateTime, "localDateTime");
- Jdk8Methods.requireNonNull(offset, "offset");
- Jdk8Methods.requireNonNull(zone, "zone");
+ Objects.requireNonNull(localDateTime, "localDateTime");
+ Objects.requireNonNull(offset, "offset");
+ Objects.requireNonNull(zone, "zone");
if (zone instanceof ZoneOffset && offset.equals(zone) == false) {
throw new IllegalArgumentException("ZoneId must match ZoneOffset");
}
@@ -558,8 +543,8 @@ public final class ZonedDateTime
* @throws DateTimeParseException if the text cannot be parsed
*/
public static ZonedDateTime parse(CharSequence text, DateTimeFormatter formatter) {
- Jdk8Methods.requireNonNull(formatter, "formatter");
- return formatter.parse(text, ZonedDateTime.FROM);
+ Objects.requireNonNull(formatter, "formatter");
+ return formatter.parse(text, ZonedDateTime::from);
}
//-----------------------------------------------------------------------
@@ -887,7 +872,7 @@ public final class ZonedDateTime
*/
@Override
public ZonedDateTime withZoneSameLocal(ZoneId zone) {
- Jdk8Methods.requireNonNull(zone, "zone");
+ Objects.requireNonNull(zone, "zone");
return this.zone.equals(zone) ? this : ofLocal(dateTime, zone, offset);
}
@@ -910,7 +895,7 @@ public final class ZonedDateTime
*/
@Override
public ZonedDateTime withZoneSameInstant(ZoneId zone) {
- Jdk8Methods.requireNonNull(zone, "zone");
+ Objects.requireNonNull(zone, "zone");
return this.zone.equals(zone) ? this :
create(dateTime.toEpochSecond(offset), dateTime.getNano(), zone);
}
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/ChronoLocalDate.java b/classlib/src/main/java/org/threeten/bp/chrono/ChronoLocalDate.java
index 0f1b015ce..96652bd4e 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/ChronoLocalDate.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/ChronoLocalDate.java
@@ -39,13 +39,11 @@ import static org.threeten.bp.temporal.ChronoField.YEAR;
import static org.threeten.bp.temporal.ChronoField.YEAR_OF_ERA;
import java.util.Comparator;
-
+import java.util.Objects;
import org.threeten.bp.DateTimeException;
import org.threeten.bp.LocalDate;
import org.threeten.bp.LocalTime;
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.ChronoUnit;
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.
*/
public abstract class ChronoLocalDate
- extends DefaultInterfaceTemporal
implements Temporal, TemporalAdjuster, Comparable {
/**
@@ -240,13 +237,9 @@ public abstract class ChronoLocalDate
public static Comparator timeLineOrder() {
return DATE_COMPARATOR;
}
+
private static final Comparator DATE_COMPARATOR =
- new Comparator() {
- @Override
- public int compare(ChronoLocalDate date1, ChronoLocalDate date2) {
- return Jdk8Methods.compareLongs(date1.toEpochDay(), date2.toEpochDay());
- }
- };
+ Comparator.comparingLong(ChronoLocalDate::toEpochDay);
//-----------------------------------------------------------------------
/**
@@ -271,7 +264,7 @@ public abstract class ChronoLocalDate
* @see Chronology#date(TemporalAccessor)
*/
public static ChronoLocalDate from(TemporalAccessor temporal) {
- Jdk8Methods.requireNonNull(temporal, "temporal");
+ Objects.requireNonNull(temporal, "temporal");
if (temporal instanceof ChronoLocalDate) {
return (ChronoLocalDate) temporal;
}
@@ -368,7 +361,7 @@ public abstract class ChronoLocalDate
// override for covariant return type
@Override
public ChronoLocalDate with(TemporalAdjuster adjuster) {
- return getChronology().ensureChronoLocalDate(super.with(adjuster));
+ return getChronology().ensureChronoLocalDate(Temporal.super.with(adjuster));
}
@Override
@@ -376,7 +369,7 @@ public abstract class ChronoLocalDate
@Override
public ChronoLocalDate plus(TemporalAmount amount) {
- return getChronology().ensureChronoLocalDate(super.plus(amount));
+ return getChronology().ensureChronoLocalDate(Temporal.super.plus(amount));
}
@Override
@@ -384,12 +377,12 @@ public abstract class ChronoLocalDate
@Override
public ChronoLocalDate minus(TemporalAmount amount) {
- return getChronology().ensureChronoLocalDate(super.minus(amount));
+ return getChronology().ensureChronoLocalDate(Temporal.super.minus(amount));
}
@Override
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()) {
return null;
}
- return super.query(query);
+ return Temporal.super.query(query);
}
@Override
@@ -453,7 +446,7 @@ public abstract class ChronoLocalDate
* @throws DateTimeException if an error occurs during printing
*/
public String format(DateTimeFormatter formatter) {
- Jdk8Methods.requireNonNull(formatter, "formatter");
+ Objects.requireNonNull(formatter, "formatter");
return formatter.format(this);
}
@@ -514,7 +507,7 @@ public abstract class ChronoLocalDate
*/
@Override
public int compareTo(ChronoLocalDate other) {
- int cmp = Jdk8Methods.compareLongs(toEpochDay(), other.toEpochDay());
+ int cmp = Long.compare(toEpochDay(), other.toEpochDay());
if (cmp == 0) {
cmp = getChronology().compareTo(other.getChronology());
}
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/ChronoLocalDateTime.java b/classlib/src/main/java/org/threeten/bp/chrono/ChronoLocalDateTime.java
index 10e8b3596..592e16066 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/ChronoLocalDateTime.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/ChronoLocalDateTime.java
@@ -36,6 +36,7 @@ import static org.threeten.bp.temporal.ChronoField.NANO_OF_DAY;
import static org.threeten.bp.temporal.ChronoUnit.NANOS;
import java.util.Comparator;
+import java.util.Objects;
import org.threeten.bp.DateTimeException;
import org.threeten.bp.Instant;
@@ -45,8 +46,6 @@ import org.threeten.bp.LocalTime;
import org.threeten.bp.ZoneId;
import org.threeten.bp.ZoneOffset;
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.Temporal;
import org.threeten.bp.temporal.TemporalAccessor;
@@ -91,7 +90,6 @@ import org.threeten.bp.zone.ZoneRules;
* @param the date type
*/
public abstract class ChronoLocalDateTime
- extends DefaultInterfaceTemporal
implements Temporal, TemporalAdjuster, Comparable> {
/**
@@ -113,16 +111,8 @@ public abstract class ChronoLocalDateTime
return DATE_TIME_COMPARATOR;
}
private static final Comparator> DATE_TIME_COMPARATOR =
- new Comparator>() {
- @Override
- 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;
- }
- };
+ Comparator.comparingLong((ChronoLocalDateTime> datetime) -> datetime.toLocalDate().toEpochDay())
+ .thenComparingLong(datetime -> datetime.toLocalTime().toNanoOfDay());
//-----------------------------------------------------------------------
/**
@@ -147,7 +137,7 @@ public abstract class ChronoLocalDateTime
* @see Chronology#localDateTime(TemporalAccessor)
*/
public static ChronoLocalDateTime> from(TemporalAccessor temporal) {
- Jdk8Methods.requireNonNull(temporal, "temporal");
+ Objects.requireNonNull(temporal, "temporal");
if (temporal instanceof ChronoLocalDateTime) {
return (ChronoLocalDateTime>) temporal;
}
@@ -195,7 +185,7 @@ public abstract class ChronoLocalDateTime
// override for covariant return type
@Override
public ChronoLocalDateTime with(TemporalAdjuster adjuster) {
- return toLocalDate().getChronology().ensureChronoLocalDateTime(super.with(adjuster));
+ return toLocalDate().getChronology().ensureChronoLocalDateTime(Temporal.super.with(adjuster));
}
@Override
@@ -203,7 +193,7 @@ public abstract class ChronoLocalDateTime
@Override
public ChronoLocalDateTime plus(TemporalAmount amount) {
- return toLocalDate().getChronology().ensureChronoLocalDateTime(super.plus(amount));
+ return toLocalDate().getChronology().ensureChronoLocalDateTime(Temporal.super.plus(amount));
}
@Override
@@ -211,12 +201,12 @@ public abstract class ChronoLocalDateTime
@Override
public ChronoLocalDateTime minus(TemporalAmount amount) {
- return toLocalDate().getChronology().ensureChronoLocalDateTime(super.minus(amount));
+ return toLocalDate().getChronology().ensureChronoLocalDateTime(Temporal.super.minus(amount));
}
@Override
public ChronoLocalDateTime 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
} else if (query == TemporalQueries.zone() || query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) {
return null;
}
- return super.query(query);
+ return Temporal.super.query(query);
}
@Override
@@ -259,7 +249,7 @@ public abstract class ChronoLocalDateTime
* @throws DateTimeException if an error occurs during printing
*/
public String format(DateTimeFormatter formatter) {
- Jdk8Methods.requireNonNull(formatter, "formatter");
+ Objects.requireNonNull(formatter, "formatter");
return formatter.format(this);
}
@@ -319,7 +309,7 @@ public abstract class ChronoLocalDateTime
* @return the number of seconds from the epoch of 1970-01-01T00:00:00Z
*/
public long toEpochSecond(ZoneOffset offset) {
- Jdk8Methods.requireNonNull(offset, "offset");
+ Objects.requireNonNull(offset, "offset");
long epochDay = toLocalDate().toEpochDay();
long secs = epochDay * 86400 + toLocalTime().toSecondOfDay();
secs -= offset.getTotalSeconds();
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/ChronoLocalDateTimeImpl.java b/classlib/src/main/java/org/threeten/bp/chrono/ChronoLocalDateTimeImpl.java
index e20735eba..40f741663 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/ChronoLocalDateTimeImpl.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/ChronoLocalDateTimeImpl.java
@@ -37,6 +37,7 @@ import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;
+import java.util.Objects;
import org.threeten.bp.LocalTime;
import org.threeten.bp.ZoneId;
@@ -150,8 +151,8 @@ final class ChronoLocalDateTimeImpl
* @param time the time part of the date-time, not null
*/
private ChronoLocalDateTimeImpl(D date, LocalTime time) {
- Jdk8Methods.requireNonNull(date, "date");
- Jdk8Methods.requireNonNull(time, "time");
+ Objects.requireNonNull(date, "date");
+ Objects.requireNonNull(time, "time");
this.date = date;
this.time = time;
}
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/ChronoPeriod.java b/classlib/src/main/java/org/threeten/bp/chrono/ChronoPeriod.java
index 30bea0725..1361c6ff2 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/ChronoPeriod.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/ChronoPeriod.java
@@ -32,9 +32,9 @@
package org.threeten.bp.chrono;
import java.util.List;
+import java.util.Objects;
import org.threeten.bp.DateTimeException;
-import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoUnit;
import org.threeten.bp.temporal.Temporal;
import org.threeten.bp.temporal.TemporalAmount;
@@ -86,8 +86,8 @@ public abstract class ChronoPeriod
* @see ChronoLocalDate#until(ChronoLocalDate)
*/
public static ChronoPeriod between(ChronoLocalDate startDateInclusive, ChronoLocalDate endDateExclusive) {
- Jdk8Methods.requireNonNull(startDateInclusive, "startDateInclusive");
- Jdk8Methods.requireNonNull(endDateExclusive, "endDateExclusive");
+ Objects.requireNonNull(startDateInclusive, "startDateInclusive");
+ Objects.requireNonNull(endDateExclusive, "endDateExclusive");
return startDateInclusive.until(endDateExclusive);
}
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/ChronoPeriodImpl.java b/classlib/src/main/java/org/threeten/bp/chrono/ChronoPeriodImpl.java
index 0c77f47ee..95817e87d 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/ChronoPeriodImpl.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/ChronoPeriodImpl.java
@@ -39,6 +39,7 @@ import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
import org.threeten.bp.DateTimeException;
import org.threeten.bp.jdk8.Jdk8Methods;
@@ -152,7 +153,7 @@ final class ChronoPeriodImpl
@Override
public Temporal addTo(Temporal temporal) {
- Jdk8Methods.requireNonNull(temporal, "temporal");
+ Objects.requireNonNull(temporal, "temporal");
Chronology temporalChrono = temporal.query(TemporalQueries.chronology());
if (temporalChrono != null && chronology.equals(temporalChrono) == false) {
throw new DateTimeException("Invalid chronology, required: " + chronology.getId() + ", but was: " + temporalChrono.getId());
@@ -171,7 +172,7 @@ final class ChronoPeriodImpl
@Override
public Temporal subtractFrom(Temporal temporal) {
- Jdk8Methods.requireNonNull(temporal, "temporal");
+ Objects.requireNonNull(temporal, "temporal");
Chronology temporalChrono = temporal.query(TemporalQueries.chronology());
if (temporalChrono != null && chronology.equals(temporalChrono) == false) {
throw new DateTimeException("Invalid chronology, required: " + chronology.getId() + ", but was: " + temporalChrono.getId());
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/ChronoZonedDateTime.java b/classlib/src/main/java/org/threeten/bp/chrono/ChronoZonedDateTime.java
index 195e6d18d..9f7ed9523 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/ChronoZonedDateTime.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/ChronoZonedDateTime.java
@@ -36,6 +36,8 @@ import static org.threeten.bp.temporal.ChronoField.OFFSET_SECONDS;
import static org.threeten.bp.temporal.ChronoUnit.NANOS;
import java.util.Comparator;
+import java.util.Objects;
+import java.util.function.ToLongFunction;
import org.threeten.bp.DateTimeException;
import org.threeten.bp.Instant;
@@ -45,8 +47,6 @@ import org.threeten.bp.ZoneId;
import org.threeten.bp.ZoneOffset;
import org.threeten.bp.ZonedDateTime;
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.Temporal;
import org.threeten.bp.temporal.TemporalAccessor;
@@ -92,7 +92,6 @@ import org.threeten.bp.temporal.ValueRange;
* @param the date type
*/
public abstract class ChronoZonedDateTime
- extends DefaultInterfaceTemporal
implements Temporal, Comparable> {
/**
@@ -113,16 +112,9 @@ public abstract class ChronoZonedDateTime
public static Comparator> timeLineOrder() {
return INSTANT_COMPARATOR;
}
- private static Comparator> INSTANT_COMPARATOR = new Comparator>() {
- @Override
- public int compare(ChronoZonedDateTime> datetime1, ChronoZonedDateTime> datetime2) {
- int cmp = Jdk8Methods.compareLongs(datetime1.toEpochSecond(), datetime2.toEpochSecond());
- if (cmp == 0) {
- cmp = Jdk8Methods.compareLongs(datetime1.toLocalTime().toNanoOfDay(), datetime2.toLocalTime().toNanoOfDay());
- }
- return cmp;
- }
- };
+ private static final Comparator> INSTANT_COMPARATOR =
+ Comparator.comparingLong((ToLongFunction>) ChronoZonedDateTime::toEpochSecond)
+ .thenComparingLong(datetime -> datetime.toLocalTime().toNanoOfDay());
//-----------------------------------------------------------------------
/**
@@ -147,7 +139,7 @@ public abstract class ChronoZonedDateTime
* @see Chronology#zonedDateTime(TemporalAccessor)
*/
public static ChronoZonedDateTime> from(TemporalAccessor temporal) {
- Jdk8Methods.requireNonNull(temporal, "temporal");
+ Objects.requireNonNull(temporal, "temporal");
if (temporal instanceof ChronoZonedDateTime) {
return (ChronoZonedDateTime>) temporal;
}
@@ -179,7 +171,7 @@ public abstract class ChronoZonedDateTime
}
return toLocalDateTime().get(field);
}
- return super.get(field);
+ return Temporal.super.get(field);
}
@Override
@@ -341,7 +333,7 @@ public abstract class ChronoZonedDateTime
// override for covariant return type
@Override
public ChronoZonedDateTime with(TemporalAdjuster adjuster) {
- return toLocalDate().getChronology().ensureChronoZonedDateTime(super.with(adjuster));
+ return toLocalDate().getChronology().ensureChronoZonedDateTime(Temporal.super.with(adjuster));
}
@Override
@@ -349,7 +341,7 @@ public abstract class ChronoZonedDateTime
@Override
public ChronoZonedDateTime plus(TemporalAmount amount) {
- return toLocalDate().getChronology().ensureChronoZonedDateTime(super.plus(amount));
+ return toLocalDate().getChronology().ensureChronoZonedDateTime(Temporal.super.plus(amount));
}
@Override
@@ -357,12 +349,12 @@ public abstract class ChronoZonedDateTime
@Override
public ChronoZonedDateTime minus(TemporalAmount amount) {
- return toLocalDate().getChronology().ensureChronoZonedDateTime(super.minus(amount));
+ return toLocalDate().getChronology().ensureChronoZonedDateTime(Temporal.super.minus(amount));
}
@Override
public ChronoZonedDateTime 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
} else if (query == TemporalQueries.localTime()) {
return (R) toLocalTime();
}
- return super.query(query);
+ return Temporal.super.query(query);
}
/**
@@ -393,7 +385,7 @@ public abstract class ChronoZonedDateTime
* @throws DateTimeException if an error occurs during printing
*/
public String format(DateTimeFormatter formatter) {
- Jdk8Methods.requireNonNull(formatter, "formatter");
+ Objects.requireNonNull(formatter, "formatter");
return formatter.format(this);
}
@@ -446,7 +438,7 @@ public abstract class ChronoZonedDateTime
*/
@Override
public int compareTo(ChronoZonedDateTime> other) {
- int cmp = Jdk8Methods.compareLongs(toEpochSecond(), other.toEpochSecond());
+ int cmp = Long.compare(toEpochSecond(), other.toEpochSecond());
if (cmp == 0) {
cmp = toLocalTime().getNano() - other.toLocalTime().getNano();
if (cmp == 0) {
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/ChronoZonedDateTimeImpl.java b/classlib/src/main/java/org/threeten/bp/chrono/ChronoZonedDateTimeImpl.java
index e950d05a9..a2ec98c1f 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/ChronoZonedDateTimeImpl.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/ChronoZonedDateTimeImpl.java
@@ -40,12 +40,12 @@ import java.io.ObjectOutput;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.util.List;
+import java.util.Objects;
import org.threeten.bp.Instant;
import org.threeten.bp.LocalDateTime;
import org.threeten.bp.ZoneId;
import org.threeten.bp.ZoneOffset;
-import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.ChronoUnit;
import org.threeten.bp.temporal.Temporal;
@@ -103,10 +103,10 @@ final class ChronoZonedDateTimeImpl
*/
static ChronoZonedDateTime ofBest(
ChronoLocalDateTimeImpl localDateTime, ZoneId zone, ZoneOffset preferredOffset) {
- Jdk8Methods.requireNonNull(localDateTime, "localDateTime");
- Jdk8Methods.requireNonNull(zone, "zone");
+ Objects.requireNonNull(localDateTime, "localDateTime");
+ Objects.requireNonNull(zone, "zone");
if (zone instanceof ZoneOffset) {
- return new ChronoZonedDateTimeImpl(localDateTime, (ZoneOffset) zone, zone);
+ return new ChronoZonedDateTimeImpl<>(localDateTime, (ZoneOffset) zone, zone);
}
ZoneRules rules = zone.getRules();
LocalDateTime isoLDT = LocalDateTime.from(localDateTime);
@@ -125,8 +125,8 @@ final class ChronoZonedDateTimeImpl
offset = validOffsets.get(0);
}
}
- Jdk8Methods.requireNonNull(offset, "offset"); // protect against bad ZoneRules
- return new ChronoZonedDateTimeImpl(localDateTime, offset, zone);
+ Objects.requireNonNull(offset, "offset"); // protect against bad ZoneRules
+ return new ChronoZonedDateTimeImpl<>(localDateTime, offset, zone);
}
/**
@@ -140,11 +140,11 @@ final class ChronoZonedDateTimeImpl
static ChronoZonedDateTimeImpl ofInstant(Chronology chrono, Instant instant, ZoneId zone) {
ZoneRules rules = zone.getRules();
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);
@SuppressWarnings("unchecked")
ChronoLocalDateTimeImpl cldt = (ChronoLocalDateTimeImpl) chrono.localDateTime(ldt);
- return new ChronoZonedDateTimeImpl(cldt, offset, zone);
+ return new ChronoZonedDateTimeImpl<>(cldt, offset, zone);
}
/**
@@ -167,9 +167,9 @@ final class ChronoZonedDateTimeImpl
* @param zone the zone ID, not null
*/
private ChronoZonedDateTimeImpl(ChronoLocalDateTimeImpl dateTime, ZoneOffset offset, ZoneId zone) {
- this.dateTime = Jdk8Methods.requireNonNull(dateTime, "dateTime");
- this.offset = Jdk8Methods.requireNonNull(offset, "offset");
- this.zone = Jdk8Methods.requireNonNull(zone, "zone");
+ this.dateTime = Objects.requireNonNull(dateTime, "dateTime");
+ this.offset = Objects.requireNonNull(offset, "offset");
+ this.zone = Objects.requireNonNull(zone, "zone");
}
//-----------------------------------------------------------------------
@@ -203,7 +203,7 @@ final class ChronoZonedDateTimeImpl
if (trans != null) {
ZoneOffset offset = trans.getOffsetAfter();
if (offset.equals(getOffset()) == false) {
- return new ChronoZonedDateTimeImpl(dateTime, offset, zone);
+ return new ChronoZonedDateTimeImpl<>(dateTime, offset, zone);
}
}
return this;
@@ -225,7 +225,7 @@ final class ChronoZonedDateTimeImpl
@Override
public ChronoZonedDateTime withZoneSameInstant(ZoneId zone) {
- Jdk8Methods.requireNonNull(zone, "zone");
+ Objects.requireNonNull(zone, "zone");
return this.zone.equals(zone) ? this : create(dateTime.toInstant(offset), zone);
}
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/Chronology.java b/classlib/src/main/java/org/threeten/bp/chrono/Chronology.java
index af6c57573..5b8b4e8b9 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/Chronology.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/Chronology.java
@@ -41,6 +41,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Objects;
import java.util.ServiceLoader;
import java.util.Set;
@@ -53,8 +54,6 @@ import org.threeten.bp.ZoneId;
import org.threeten.bp.format.DateTimeFormatterBuilder;
import org.threeten.bp.format.ResolverStyle;
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.Temporal;
import org.threeten.bp.temporal.TemporalAccessor;
@@ -138,16 +137,6 @@ import org.threeten.bp.temporal.ValueRange;
*/
public abstract class Chronology implements Comparable {
- /**
- * Simulate JDK 8 method reference Chronology::from.
- */
- public static final TemporalQuery FROM = new TemporalQuery() {
- @Override
- public Chronology queryFrom(TemporalAccessor temporal) {
- return Chronology.from(temporal);
- }
- };
-
/**
* Map of available calendars by ID.
*/
@@ -175,7 +164,7 @@ public abstract class Chronology implements Comparable {
* @throws DateTimeException if unable to convert to an {@code Chronology}
*/
public static Chronology from(TemporalAccessor temporal) {
- Jdk8Methods.requireNonNull(temporal, "temporal");
+ Objects.requireNonNull(temporal, "temporal");
Chronology obj = temporal.query(TemporalQueries.chronology());
return (obj != null ? obj : IsoChronology.INSTANCE);
}
@@ -223,7 +212,7 @@ public abstract class Chronology implements Comparable {
*/
public static Chronology ofLocale(Locale locale) {
init();
- Jdk8Methods.requireNonNull(locale, "locale");
+ Objects.requireNonNull(locale, "locale");
String type = "iso";
if (locale.equals(JapaneseChronology.LOCALE)) {
type = "japanese";
@@ -281,7 +270,7 @@ public abstract class Chronology implements Comparable {
*/
public static Set getAvailableChronologies() {
init();
- return new HashSet(CHRONOS_BY_ID.values());
+ return new HashSet<>(CHRONOS_BY_ID.values());
}
private static void init() {
@@ -528,7 +517,7 @@ public abstract class Chronology implements Comparable {
* @throws DateTimeException if unable to create the date
*/
public ChronoLocalDate dateNow(Clock clock) {
- Jdk8Methods.requireNonNull(clock, "clock");
+ Objects.requireNonNull(clock, "clock");
return date(LocalDate.now(clock));
}
@@ -725,24 +714,25 @@ public abstract class Chronology implements Comparable {
* @return the text value of the chronology, not null
*/
public String getDisplayName(TextStyle style, Locale locale) {
- return new DateTimeFormatterBuilder().appendChronologyText(style).toFormatter(locale).format(new DefaultInterfaceTemporalAccessor() {
- @Override
- public boolean isSupported(TemporalField field) {
- return false;
- }
- @Override
- public long getLong(TemporalField field) {
- throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
- }
- @SuppressWarnings("unchecked")
- @Override
- public R query(TemporalQuery query) {
- if (query == TemporalQueries.chronology()) {
- return (R) Chronology.this;
- }
- return super.query(query);
- }
- });
+ return new DateTimeFormatterBuilder().appendChronologyText(style).toFormatter(locale).format(
+ new TemporalAccessor() {
+ @Override
+ public boolean isSupported(TemporalField field) {
+ return false;
+ }
+ @Override
+ public long getLong(TemporalField field) {
+ throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
+ }
+ @SuppressWarnings("unchecked")
+ @Override
+ public R query(TemporalQuery query) {
+ if (query == TemporalQueries.chronology()) {
+ return (R) Chronology.this;
+ }
+ return TemporalAccessor.super.query(query);
+ }
+ });
}
//-----------------------------------------------------------------------
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/Era.java b/classlib/src/main/java/org/threeten/bp/chrono/Era.java
index 529ccb88d..17c0f7b4d 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/Era.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/Era.java
@@ -31,11 +31,20 @@
*/
package org.threeten.bp.chrono;
+import static org.threeten.bp.temporal.ChronoField.ERA;
import java.util.Locale;
+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.TemporalAccessor;
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.
@@ -59,6 +68,52 @@ import org.threeten.bp.temporal.TemporalAdjuster;
* It is recommended to use an enum whenever possible.
*/
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 query(TemporalQuery 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.
@@ -90,6 +145,8 @@ public interface Era extends TemporalAccessor, TemporalAdjuster {
* @param locale the locale to use, 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);
+ }
}
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/HijrahChronology.java b/classlib/src/main/java/org/threeten/bp/chrono/HijrahChronology.java
index 03b00ada8..9e40351b3 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/HijrahChronology.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/HijrahChronology.java
@@ -56,6 +56,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Objects;
import org.threeten.bp.Clock;
import org.threeten.bp.DateTimeException;
@@ -322,7 +323,7 @@ public final class HijrahChronology extends Chronology implements Serializable {
@Override // override with covariant return type
public HijrahDate dateNow(Clock clock) {
- Jdk8Methods.requireNonNull(clock, "clock");
+ Objects.requireNonNull(clock, "clock");
return (HijrahDate) super.dateNow(clock);
}
@@ -354,7 +355,7 @@ public final class HijrahChronology extends Chronology implements Serializable {
@Override
public List eras() {
- return Arrays.asList(HijrahEra.values());
+ return Arrays.asList(HijrahEra.values());
}
//-----------------------------------------------------------------------
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/HijrahDate.java b/classlib/src/main/java/org/threeten/bp/chrono/HijrahDate.java
index 57bc0396f..9f8a09f4a 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/HijrahDate.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/HijrahDate.java
@@ -50,6 +50,7 @@ import java.io.InputStreamReader;
import java.io.Serializable;
import java.text.ParseException;
import java.util.HashMap;
+import java.util.Objects;
import java.util.StringTokenizer;
import java.util.zip.ZipEntry;
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
*/
static HijrahDate of(HijrahEra era, int yearOfEra, int monthOfYear, int dayOfMonth) {
- Jdk8Methods.requireNonNull(era, "era");
+ Objects.requireNonNull(era, "era");
checkValidYearOfEra(yearOfEra);
checkValidMonth(monthOfYear);
checkValidDayOfMonth(dayOfMonth);
@@ -725,7 +726,7 @@ public final class HijrahDate
//-------------------------------------------------------------------------
@Override
@SuppressWarnings("unchecked")
- public final ChronoLocalDateTime atTime(LocalTime localTime) {
+ public ChronoLocalDateTime atTime(LocalTime localTime) {
return (ChronoLocalDateTime) super.atTime(localTime);
}
@@ -921,6 +922,7 @@ public final class HijrahDate
try {
day = ADJUSTED_CYCLES[cycleNumber];
+ // TODO remove catching AIOOBE (and other usages)
} catch (ArrayIndexOutOfBoundsException e) {
day = null;
}
@@ -1673,7 +1675,7 @@ public final class HijrahDate
* @throws IOException for zip/jar file handling exception.
*/
private static InputStream getConfigFileInputStream() throws IOException {
-
+ // TODO: eliminate this
String fileName = System
.getProperty("org.threeten.bp.i18n.HijrahDate.deviationConfigFile");
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/IsoChronology.java b/classlib/src/main/java/org/threeten/bp/chrono/IsoChronology.java
index f5b7ac7ad..84bdfcec8 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/IsoChronology.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/IsoChronology.java
@@ -51,6 +51,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Objects;
import org.threeten.bp.Clock;
import org.threeten.bp.DateTimeException;
@@ -328,7 +329,7 @@ public final class IsoChronology extends Chronology implements Serializable {
*/
@Override // override with covariant return type
public LocalDate dateNow(Clock clock) {
- Jdk8Methods.requireNonNull(clock, "clock");
+ Objects.requireNonNull(clock, "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 days = Jdk8Methods.safeSubtract(dom, 1);
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);
if (moy == 4 || moy == 6 || moy == 9 || moy == 11) {
dom = Math.min(dom, 30);
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/JapaneseChronology.java b/classlib/src/main/java/org/threeten/bp/chrono/JapaneseChronology.java
index 89aa9a1ca..cba9d3c49 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/JapaneseChronology.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/JapaneseChronology.java
@@ -56,6 +56,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Objects;
import org.threeten.bp.Clock;
import org.threeten.bp.DateTimeException;
@@ -304,7 +305,7 @@ public final class JapaneseChronology extends Chronology implements Serializable
@Override // override with covariant return type
public JapaneseDate dateNow(Clock clock) {
- Jdk8Methods.requireNonNull(clock, "clock");
+ Objects.requireNonNull(clock, "clock");
return (JapaneseDate) super.dateNow(clock);
}
@@ -354,7 +355,7 @@ public final class JapaneseChronology extends Chronology implements Serializable
@Override
public List eras() {
- return Arrays.asList(JapaneseEra.values());
+ return Arrays.asList(JapaneseEra.values());
}
//-----------------------------------------------------------------------
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/JapaneseDate.java b/classlib/src/main/java/org/threeten/bp/chrono/JapaneseDate.java
index 59cc8a3f2..11085fff4 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/JapaneseDate.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/JapaneseDate.java
@@ -41,6 +41,7 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.Calendar;
+import java.util.Objects;
import org.threeten.bp.Clock;
import org.threeten.bp.DateTimeException;
@@ -48,7 +49,6 @@ import org.threeten.bp.LocalDate;
import org.threeten.bp.LocalTime;
import org.threeten.bp.Period;
import org.threeten.bp.ZoneId;
-import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.TemporalAccessor;
import org.threeten.bp.temporal.TemporalAdjuster;
@@ -181,7 +181,7 @@ public final class JapaneseDate
* or if the day-of-month is invalid for the month-year
*/
public static JapaneseDate of(JapaneseEra era, int yearOfEra, int month, int dayOfMonth) {
- Jdk8Methods.requireNonNull(era, "era");
+ Objects.requireNonNull(era, "era");
if (yearOfEra < 1) {
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
*/
static JapaneseDate ofYearDay(JapaneseEra era, int yearOfEra, int dayOfYear) {
- Jdk8Methods.requireNonNull(era, "era");
+ Objects.requireNonNull(era, "era");
if (yearOfEra < 1) {
throw new DateTimeException("Invalid YearOfEra: " + yearOfEra);
}
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/JapaneseEra.java b/classlib/src/main/java/org/threeten/bp/chrono/JapaneseEra.java
index 76c0290c7..7388ff817 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/JapaneseEra.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/JapaneseEra.java
@@ -38,11 +38,10 @@ import java.io.InvalidObjectException;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.util.Arrays;
+import java.util.Objects;
import org.threeten.bp.DateTimeException;
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.TemporalField;
import org.threeten.bp.temporal.ValueRange;
@@ -62,8 +61,7 @@ import org.threeten.bp.temporal.ValueRange;
* This class is immutable and thread-safe.
*/
public final class JapaneseEra
- extends DefaultInterfaceEra
- implements Serializable {
+ implements Era, Serializable {
// 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
@@ -180,8 +178,8 @@ public final class JapaneseEra
if (known.length > 5) {
throw new DateTimeException("Only one additional Japanese era can be added");
}
- Jdk8Methods.requireNonNull(since, "since");
- Jdk8Methods.requireNonNull(name, "name");
+ Objects.requireNonNull(since, "since");
+ Objects.requireNonNull(name, "name");
if (!since.isAfter(REIWA.since)) {
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
*/
public static JapaneseEra valueOf(String japaneseEra) {
- Jdk8Methods.requireNonNull(japaneseEra, "japaneseEra");
+ Objects.requireNonNull(japaneseEra, "japaneseEra");
JapaneseEra[] known = KNOWN_ERAS;
for (JapaneseEra era : known) {
if (japaneseEra.equals(era.name)) {
@@ -320,7 +318,7 @@ public final class JapaneseEra
if (field == ChronoField.ERA) {
return JapaneseChronology.INSTANCE.range(ChronoField.ERA);
}
- return super.range(field);
+ return Era.super.range(field);
}
//-----------------------------------------------------------------------
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/MinguoChronology.java b/classlib/src/main/java/org/threeten/bp/chrono/MinguoChronology.java
index d50d1f90f..3c964d722 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/MinguoChronology.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/MinguoChronology.java
@@ -54,6 +54,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Objects;
import org.threeten.bp.Clock;
import org.threeten.bp.DateTimeException;
@@ -223,7 +224,7 @@ public final class MinguoChronology extends Chronology implements Serializable {
@Override // override with covariant return type
public MinguoDate dateNow(Clock clock) {
- Jdk8Methods.requireNonNull(clock, "clock");
+ Objects.requireNonNull(clock, "clock");
return (MinguoDate) super.dateNow(clock);
}
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/MinguoDate.java b/classlib/src/main/java/org/threeten/bp/chrono/MinguoDate.java
index 8d066c67e..67a3797a0 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/MinguoDate.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/MinguoDate.java
@@ -40,6 +40,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.Serializable;
+import java.util.Objects;
import org.threeten.bp.Clock;
import org.threeten.bp.DateTimeException;
@@ -47,7 +48,6 @@ import org.threeten.bp.LocalDate;
import org.threeten.bp.LocalTime;
import org.threeten.bp.Period;
import org.threeten.bp.ZoneId;
-import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.TemporalAccessor;
import org.threeten.bp.temporal.TemporalAdjuster;
@@ -175,7 +175,7 @@ public final class MinguoDate
* @param isoDate the standard local date, validated not null
*/
MinguoDate(LocalDate date) {
- Jdk8Methods.requireNonNull(date, "date");
+ Objects.requireNonNull(date, "date");
this.isoDate = date;
}
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/ThaiBuddhistChronology.java b/classlib/src/main/java/org/threeten/bp/chrono/ThaiBuddhistChronology.java
index 62cad8226..c8c632f3e 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/ThaiBuddhistChronology.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/ThaiBuddhistChronology.java
@@ -55,6 +55,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Objects;
import org.threeten.bp.Clock;
import org.threeten.bp.DateTimeException;
@@ -259,7 +260,7 @@ public final class ThaiBuddhistChronology extends Chronology implements Serializ
@Override // override with covariant return type
public ThaiBuddhistDate dateNow(Clock clock) {
- Jdk8Methods.requireNonNull(clock, "clock");
+ Objects.requireNonNull(clock, "clock");
return (ThaiBuddhistDate) super.dateNow(clock);
}
@@ -294,7 +295,7 @@ public final class ThaiBuddhistChronology extends Chronology implements Serializ
@Override
public List eras() {
- return Arrays.asList(ThaiBuddhistEra.values());
+ return Arrays.asList(ThaiBuddhistEra.values());
}
//-----------------------------------------------------------------------
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/ThaiBuddhistDate.java b/classlib/src/main/java/org/threeten/bp/chrono/ThaiBuddhistDate.java
index ac4dbd09c..d9dfa1a42 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/ThaiBuddhistDate.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/ThaiBuddhistDate.java
@@ -40,6 +40,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.Serializable;
+import java.util.Objects;
import org.threeten.bp.Clock;
import org.threeten.bp.DateTimeException;
@@ -47,7 +48,6 @@ import org.threeten.bp.LocalDate;
import org.threeten.bp.LocalTime;
import org.threeten.bp.Period;
import org.threeten.bp.ZoneId;
-import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.TemporalAccessor;
import org.threeten.bp.temporal.TemporalAdjuster;
@@ -175,7 +175,7 @@ public final class ThaiBuddhistDate
* @param isoDate the standard local date, validated not null
*/
ThaiBuddhistDate(LocalDate date) {
- Jdk8Methods.requireNonNull(date, "date");
+ Objects.requireNonNull(date, "date");
this.isoDate = date;
}
diff --git a/classlib/src/main/java/org/threeten/bp/format/DateTimeBuilder.java b/classlib/src/main/java/org/threeten/bp/format/DateTimeBuilder.java
index ea23f0d8b..b353dd443 100644
--- a/classlib/src/main/java/org/threeten/bp/format/DateTimeBuilder.java
+++ b/classlib/src/main/java/org/threeten/bp/format/DateTimeBuilder.java
@@ -54,6 +54,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Objects;
import java.util.Set;
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.Chronology;
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.TemporalAccessor;
@@ -92,14 +92,13 @@ import org.threeten.bp.temporal.TemporalQuery;
* This class is mutable and not thread-safe.
* It should only be used from a single thread.
*/
-final class DateTimeBuilder
- extends DefaultInterfaceTemporalAccessor
+public final class DateTimeBuilder
implements TemporalAccessor, Cloneable {
/**
* The map of other fields.
*/
- final Map fieldValues = new HashMap();
+ final Map fieldValues = new HashMap<>();
/**
* The chronology.
*/
@@ -164,7 +163,7 @@ final class DateTimeBuilder
* @throws DateTimeException if the field is already present with a different 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
if (old != null && old.longValue() != value) {
throw new DateTimeException("Conflict found: " + field + " " + old + " differs from " + field + " " + value + ": " + this);
@@ -655,7 +654,7 @@ final class DateTimeBuilder
@Override
public long getLong(TemporalField field) {
- Jdk8Methods.requireNonNull(field, "field");
+ Objects.requireNonNull(field, "field");
Long value = getFieldValue0(field);
if (value == null) {
if (date != null && date.isSupported(field)) {
diff --git a/classlib/src/main/java/org/threeten/bp/format/DateTimeFormatter.java b/classlib/src/main/java/org/threeten/bp/format/DateTimeFormatter.java
index e6bcdc2a9..bf2996284 100644
--- a/classlib/src/main/java/org/threeten/bp/format/DateTimeFormatter.java
+++ b/classlib/src/main/java/org/threeten/bp/format/DateTimeFormatter.java
@@ -52,6 +52,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
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.format.DateTimeFormatterBuilder.CompositePrinterParser;
import org.threeten.bp.format.DateTimeParseContext.Parsed;
-import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.IsoFields;
import org.threeten.bp.temporal.TemporalAccessor;
@@ -584,7 +584,7 @@ public final class DateTimeFormatter {
static {
// manually code maps to ensure correct data always used
// (locale data can be changed by application code)
- Map dow = new HashMap();
+ Map dow = new HashMap<>();
dow.put(1L, "Mon");
dow.put(2L, "Tue");
dow.put(3L, "Wed");
@@ -592,7 +592,7 @@ public final class DateTimeFormatter {
dow.put(5L, "Fri");
dow.put(6L, "Sat");
dow.put(7L, "Sun");
- Map moy = new HashMap();
+ Map moy = new HashMap<>();
moy.put(1L, "Jan");
moy.put(2L, "Feb");
moy.put(3L, "Mar");
@@ -808,7 +808,7 @@ public final class DateTimeFormatter {
* @return the date formatter, not null
*/
public static DateTimeFormatter ofLocalizedDate(FormatStyle dateStyle) {
- Jdk8Methods.requireNonNull(dateStyle, "dateStyle");
+ Objects.requireNonNull(dateStyle, "dateStyle");
return new DateTimeFormatterBuilder().appendLocalized(dateStyle, null)
.toFormatter().withChronology(IsoChronology.INSTANCE);
}
@@ -832,7 +832,7 @@ public final class DateTimeFormatter {
* @return the time formatter, not null
*/
public static DateTimeFormatter ofLocalizedTime(FormatStyle timeStyle) {
- Jdk8Methods.requireNonNull(timeStyle, "timeStyle");
+ Objects.requireNonNull(timeStyle, "timeStyle");
return new DateTimeFormatterBuilder().appendLocalized(null, timeStyle)
.toFormatter().withChronology(IsoChronology.INSTANCE);
}
@@ -856,7 +856,7 @@ public final class DateTimeFormatter {
* @return the date-time formatter, not null
*/
public static DateTimeFormatter ofLocalizedDateTime(FormatStyle dateTimeStyle) {
- Jdk8Methods.requireNonNull(dateTimeStyle, "dateTimeStyle");
+ Objects.requireNonNull(dateTimeStyle, "dateTimeStyle");
return new DateTimeFormatterBuilder().appendLocalized(dateTimeStyle, dateTimeStyle)
.toFormatter().withChronology(IsoChronology.INSTANCE);
}
@@ -881,8 +881,8 @@ public final class DateTimeFormatter {
* @return the date, time or date-time formatter, not null
*/
public static DateTimeFormatter ofLocalizedDateTime(FormatStyle dateStyle, FormatStyle timeStyle) {
- Jdk8Methods.requireNonNull(dateStyle, "dateStyle");
- Jdk8Methods.requireNonNull(timeStyle, "timeStyle");
+ Objects.requireNonNull(dateStyle, "dateStyle");
+ Objects.requireNonNull(timeStyle, "timeStyle");
return new DateTimeFormatterBuilder().appendLocalized(dateStyle, timeStyle)
.toFormatter().withChronology(IsoChronology.INSTANCE);
}
@@ -928,18 +928,15 @@ public final class DateTimeFormatter {
*
* @return a query that provides access to the excess days that were parsed
*/
- public static final TemporalQuery parsedExcessDays() {
- return PARSED_EXCESS_DAYS;
- }
- private static final TemporalQuery PARSED_EXCESS_DAYS = new TemporalQuery() {
- public Period queryFrom(TemporalAccessor temporal) {
+ public static TemporalQuery parsedExcessDays() {
+ return temporal -> {
if (temporal instanceof DateTimeBuilder) {
return ((DateTimeBuilder) temporal).excessDays;
} else {
return Period.ZERO;
}
- }
- };
+ };
+ }
/**
* A query that provides access to whether a leap-second was parsed.
@@ -971,18 +968,15 @@ public final class DateTimeFormatter {
*
* @return a query that provides access to whether a leap-second was parsed
*/
- public static final TemporalQuery parsedLeapSecond() {
- return PARSED_LEAP_SECOND;
- }
- private static final TemporalQuery PARSED_LEAP_SECOND = new TemporalQuery() {
- public Boolean queryFrom(TemporalAccessor temporal) {
+ public static TemporalQuery parsedLeapSecond() {
+ return temporal -> {
if (temporal instanceof DateTimeBuilder) {
return ((DateTimeBuilder) temporal).leapSecond;
} else {
return Boolean.FALSE;
}
- }
- };
+ };
+ }
//-----------------------------------------------------------------------
/**
@@ -1029,10 +1023,10 @@ public final class DateTimeFormatter {
DateTimeFormatter(CompositePrinterParser printerParser, Locale locale,
DecimalStyle decimalStyle, ResolverStyle resolverStyle,
Set resolverFields, Chronology chrono, ZoneId zone) {
- this.printerParser = Jdk8Methods.requireNonNull(printerParser, "printerParser");
- this.locale = Jdk8Methods.requireNonNull(locale, "locale");
- this.decimalStyle = Jdk8Methods.requireNonNull(decimalStyle, "decimalStyle");
- this.resolverStyle = Jdk8Methods.requireNonNull(resolverStyle, "resolverStyle");
+ this.printerParser = Objects.requireNonNull(printerParser, "printerParser");
+ this.locale = Objects.requireNonNull(locale, "locale");
+ this.decimalStyle = Objects.requireNonNull(decimalStyle, "decimalStyle");
+ this.resolverStyle = Objects.requireNonNull(resolverStyle, "resolverStyle");
this.resolverFields = resolverFields;
this.chrono = chrono;
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
*/
public DateTimeFormatter withChronology(Chronology chrono) {
- if (Jdk8Methods.equals(this.chrono, chrono)) {
+ if (Objects.equals(this.chrono, chrono)) {
return this;
}
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
*/
public DateTimeFormatter withZone(ZoneId zone) {
- if (Jdk8Methods.equals(this.zone, zone)) {
+ if (Objects.equals(this.zone, zone)) {
return this;
}
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
*/
public DateTimeFormatter withResolverStyle(ResolverStyle resolverStyle) {
- Jdk8Methods.requireNonNull(resolverStyle, "resolverStyle");
- if (Jdk8Methods.equals(this.resolverStyle, resolverStyle)) {
+ Objects.requireNonNull(resolverStyle, "resolverStyle");
+ if (Objects.equals(this.resolverStyle, resolverStyle)) {
return this;
}
return new DateTimeFormatter(printerParser, locale, decimalStyle, resolverStyle, resolverFields, chrono, zone);
@@ -1286,8 +1280,8 @@ public final class DateTimeFormatter {
if (resolverFields == null) {
return new DateTimeFormatter(printerParser, locale, decimalStyle, resolverStyle, null, chrono, zone);
}
- Set fields = new HashSet(Arrays.asList(resolverFields));
- if (Jdk8Methods.equals(this.resolverFields, fields)) {
+ Set fields = new HashSet<>(Arrays.asList(resolverFields));
+ if (Objects.equals(this.resolverFields, fields)) {
return this;
}
fields = Collections.unmodifiableSet(fields);
@@ -1337,10 +1331,10 @@ public final class DateTimeFormatter {
if (resolverFields == null) {
return new DateTimeFormatter(printerParser, locale, decimalStyle, resolverStyle, null, chrono, zone);
}
- if (Jdk8Methods.equals(this.resolverFields, resolverFields)) {
+ if (Objects.equals(this.resolverFields, resolverFields)) {
return this;
}
- resolverFields = Collections.unmodifiableSet(new HashSet(resolverFields));
+ resolverFields = Collections.unmodifiableSet(new HashSet<>(resolverFields));
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
*/
public void formatTo(TemporalAccessor temporal, Appendable appendable) {
- Jdk8Methods.requireNonNull(temporal, "temporal");
- Jdk8Methods.requireNonNull(appendable, "appendable");
+ Objects.requireNonNull(temporal, "temporal");
+ Objects.requireNonNull(appendable, "appendable");
try {
DateTimePrintContext context = new DateTimePrintContext(temporal, this);
if (appendable instanceof StringBuilder) {
@@ -1411,7 +1405,7 @@ public final class DateTimeFormatter {
* @throws DateTimeParseException if unable to parse the requested result
*/
public TemporalAccessor parse(CharSequence text) {
- Jdk8Methods.requireNonNull(text, "text");
+ Objects.requireNonNull(text, "text");
try {
return parseToBuilder(text, null).resolve(resolverStyle, resolverFields);
} catch (DateTimeParseException ex) {
@@ -1452,13 +1446,11 @@ public final class DateTimeFormatter {
* @throws IndexOutOfBoundsException if the position is invalid
*/
public TemporalAccessor parse(CharSequence text, ParsePosition position) {
- Jdk8Methods.requireNonNull(text, "text");
- Jdk8Methods.requireNonNull(position, "position");
+ Objects.requireNonNull(text, "text");
+ Objects.requireNonNull(position, "position");
try {
return parseToBuilder(text, position).resolve(resolverStyle, resolverFields);
- } catch (DateTimeParseException ex) {
- throw ex;
- } catch (IndexOutOfBoundsException ex) {
+ } catch (DateTimeParseException | IndexOutOfBoundsException ex) {
throw ex;
} catch (RuntimeException ex) {
throw createError(text, ex);
@@ -1485,8 +1477,8 @@ public final class DateTimeFormatter {
* @throws DateTimeParseException if unable to parse the requested result
*/
public T parse(CharSequence text, TemporalQuery type) {
- Jdk8Methods.requireNonNull(text, "text");
- Jdk8Methods.requireNonNull(type, "type");
+ Objects.requireNonNull(text, "text");
+ Objects.requireNonNull(type, "type");
try {
DateTimeBuilder builder = parseToBuilder(text, null).resolve(resolverStyle, resolverFields);
return builder.build(type);
@@ -1527,8 +1519,8 @@ public final class DateTimeFormatter {
* @throws DateTimeParseException if unable to parse the requested result
*/
public TemporalAccessor parseBest(CharSequence text, TemporalQuery>... types) {
- Jdk8Methods.requireNonNull(text, "text");
- Jdk8Methods.requireNonNull(types, "types");
+ Objects.requireNonNull(text, "text");
+ Objects.requireNonNull(types, "types");
if (types.length < 2) {
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) {
- Jdk8Methods.requireNonNull(text, "text");
- Jdk8Methods.requireNonNull(position, "position");
+ Objects.requireNonNull(text, "text");
+ Objects.requireNonNull(position, "position");
DateTimeParseContext context = new DateTimeParseContext(this);
int pos = position.getIndex();
pos = printerParser.parse(context, text, pos);
@@ -1696,7 +1688,7 @@ public final class DateTimeFormatter {
* @return this formatter as a classic format instance, not null
*/
public Format toFormat(TemporalQuery> query) {
- Jdk8Methods.requireNonNull(query, "query");
+ Objects.requireNonNull(query, "query");
return new ClassicFormat(this, query);
}
@@ -1731,10 +1723,10 @@ public final class DateTimeFormatter {
@Override
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
- Jdk8Methods.requireNonNull(obj, "obj");
- Jdk8Methods.requireNonNull(toAppendTo, "toAppendTo");
- Jdk8Methods.requireNonNull(pos, "pos");
- if (obj instanceof TemporalAccessor == false) {
+ Objects.requireNonNull(obj, "obj");
+ Objects.requireNonNull(toAppendTo, "toAppendTo");
+ Objects.requireNonNull(pos, "pos");
+ if (!(obj instanceof TemporalAccessor)) {
throw new IllegalArgumentException("Format target must implement TemporalAccessor");
}
pos.setBeginIndex(0);
@@ -1748,7 +1740,7 @@ public final class DateTimeFormatter {
}
@Override
public Object parseObject(String text) throws ParseException {
- Jdk8Methods.requireNonNull(text, "text");
+ Objects.requireNonNull(text, "text");
try {
if (query == null) {
return formatter.parseToBuilder(text, null)
@@ -1763,7 +1755,7 @@ public final class DateTimeFormatter {
}
@Override
public Object parseObject(String text, ParsePosition pos) {
- Jdk8Methods.requireNonNull(text, "text");
+ Objects.requireNonNull(text, "text");
Parsed unresolved;
try {
unresolved = formatter.parseUnresolved0(text, pos);
diff --git a/classlib/src/main/java/org/threeten/bp/format/DateTimeFormatterBuilder.java b/classlib/src/main/java/org/threeten/bp/format/DateTimeFormatterBuilder.java
index 2124102cd..cb3c76250 100644
--- a/classlib/src/main/java/org/threeten/bp/format/DateTimeFormatterBuilder.java
+++ b/classlib/src/main/java/org/threeten/bp/format/DateTimeFormatterBuilder.java
@@ -58,6 +58,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.MissingResourceException;
+import java.util.Objects;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.TimeZone;
@@ -166,8 +167,8 @@ public final class DateTimeFormatterBuilder {
*/
public static String getLocalizedDateTimePattern(
FormatStyle dateStyle, FormatStyle timeStyle, Chronology chrono, Locale locale) {
- Jdk8Methods.requireNonNull(locale, "locale");
- Jdk8Methods.requireNonNull(chrono, "chrono");
+ Objects.requireNonNull(locale, "locale");
+ Objects.requireNonNull(chrono, "chrono");
if (dateStyle == null && timeStyle == 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
*/
public DateTimeFormatterBuilder parseDefaulting(TemporalField field, long value) {
- Jdk8Methods.requireNonNull(field, "field");
+ Objects.requireNonNull(field, "field");
appendInternal(new DefaultingParser(field, value));
return this;
}
@@ -345,7 +346,7 @@ public final class DateTimeFormatterBuilder {
* @return this, for chaining, not null
*/
public DateTimeFormatterBuilder appendValue(TemporalField field) {
- Jdk8Methods.requireNonNull(field, "field");
+ Objects.requireNonNull(field, "field");
appendValue(new NumberPrinterParser(field, 1, 19, SignStyle.NORMAL));
return this;
}
@@ -399,7 +400,7 @@ public final class DateTimeFormatterBuilder {
* @throws IllegalArgumentException if the width is invalid
*/
public DateTimeFormatterBuilder appendValue(TemporalField field, int width) {
- Jdk8Methods.requireNonNull(field, "field");
+ Objects.requireNonNull(field, "field");
if (width < 1 || width > 19) {
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) {
return appendValue(field, maxWidth);
}
- Jdk8Methods.requireNonNull(field, "field");
- Jdk8Methods.requireNonNull(signStyle, "signStyle");
+ Objects.requireNonNull(field, "field");
+ Objects.requireNonNull(signStyle, "signStyle");
if (minWidth < 1 || minWidth > 19) {
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,
int width, int maxWidth, int baseValue) {
- Jdk8Methods.requireNonNull(field, "field");
+ Objects.requireNonNull(field, "field");
ReducedPrinterParser pp = new ReducedPrinterParser(field, width, maxWidth, baseValue, null);
appendValue(pp);
return this;
@@ -560,8 +561,8 @@ public final class DateTimeFormatterBuilder {
*/
public DateTimeFormatterBuilder appendValueReduced(
TemporalField field, int width, int maxWidth, ChronoLocalDate baseDate) {
- Jdk8Methods.requireNonNull(field, "field");
- Jdk8Methods.requireNonNull(baseDate, "baseDate");
+ Objects.requireNonNull(field, "field");
+ Objects.requireNonNull(baseDate, "baseDate");
ReducedPrinterParser pp = new ReducedPrinterParser(field, width, maxWidth, 0, baseDate);
appendValue(pp);
return this;
@@ -678,8 +679,8 @@ public final class DateTimeFormatterBuilder {
* @return this, for chaining, not null
*/
public DateTimeFormatterBuilder appendText(TemporalField field, TextStyle textStyle) {
- Jdk8Methods.requireNonNull(field, "field");
- Jdk8Methods.requireNonNull(textStyle, "textStyle");
+ Objects.requireNonNull(field, "field");
+ Objects.requireNonNull(textStyle, "textStyle");
appendInternal(new TextPrinterParser(field, textStyle, DateTimeTextProvider.getInstance()));
return this;
}
@@ -719,9 +720,9 @@ public final class DateTimeFormatterBuilder {
* @return this, for chaining, not null
*/
public DateTimeFormatterBuilder appendText(TemporalField field, Map textLookup) {
- Jdk8Methods.requireNonNull(field, "field");
- Jdk8Methods.requireNonNull(textLookup, "textLookup");
- Map copy = new LinkedHashMap(textLookup);
+ Objects.requireNonNull(field, "field");
+ Objects.requireNonNull(textLookup, "textLookup");
+ Map copy = new LinkedHashMap<>(textLookup);
Map> map = Collections.singletonMap(TextStyle.FULL, copy);
final LocaleStore store = new LocaleStore(map);
DateTimeTextProvider provider = new DateTimeTextProvider() {
@@ -898,7 +899,7 @@ public final class DateTimeFormatterBuilder {
* full} nor {@link TextStyle#SHORT short}
*/
public DateTimeFormatterBuilder appendLocalizedOffset(TextStyle style) {
- Jdk8Methods.requireNonNull(style, "style");
+ Objects.requireNonNull(style, "style");
if (style != TextStyle.FULL && style != TextStyle.SHORT) {
throw new IllegalArgumentException("Style must be either full or short");
}
@@ -1059,7 +1060,7 @@ public final class DateTimeFormatterBuilder {
public DateTimeFormatterBuilder appendZoneText(TextStyle textStyle,
Set preferredZones) {
// TODO: preferred zones currently ignored
- Jdk8Methods.requireNonNull(preferredZones, "preferredZones");
+ Objects.requireNonNull(preferredZones, "preferredZones");
appendInternal(new ZoneTextPrinterParser(textStyle));
return this;
}
@@ -1098,7 +1099,7 @@ public final class DateTimeFormatterBuilder {
* @return this, for chaining, not null
*/
public DateTimeFormatterBuilder appendChronologyText(TextStyle textStyle) {
- Jdk8Methods.requireNonNull(textStyle, "textStyle");
+ Objects.requireNonNull(textStyle, "textStyle");
appendInternal(new ChronoPrinterParser(textStyle));
return this;
}
@@ -1165,7 +1166,7 @@ public final class DateTimeFormatterBuilder {
* @return this, for chaining, not null
*/
public DateTimeFormatterBuilder appendLiteral(String literal) {
- Jdk8Methods.requireNonNull(literal, "literal");
+ Objects.requireNonNull(literal, "literal");
if (literal.length() > 0) {
if (literal.length() == 1) {
appendInternal(new CharLiteralPrinterParser(literal.charAt(0)));
@@ -1187,7 +1188,7 @@ public final class DateTimeFormatterBuilder {
* @return this, for chaining, not null
*/
public DateTimeFormatterBuilder append(DateTimeFormatter formatter) {
- Jdk8Methods.requireNonNull(formatter, "formatter");
+ Objects.requireNonNull(formatter, "formatter");
appendInternal(formatter.toPrinterParser(false));
return this;
}
@@ -1206,7 +1207,7 @@ public final class DateTimeFormatterBuilder {
* @return this, for chaining, not null
*/
public DateTimeFormatterBuilder appendOptional(DateTimeFormatter formatter) {
- Jdk8Methods.requireNonNull(formatter, "formatter");
+ Objects.requireNonNull(formatter, "formatter");
appendInternal(formatter.toPrinterParser(true));
return this;
}
@@ -1378,7 +1379,7 @@ public final class DateTimeFormatterBuilder {
* @throws IllegalArgumentException if the pattern is invalid
*/
public DateTimeFormatterBuilder appendPattern(String pattern) {
- Jdk8Methods.requireNonNull(pattern, "pattern");
+ Objects.requireNonNull(pattern, "pattern");
parsePattern(pattern);
return this;
}
@@ -1832,7 +1833,7 @@ public final class DateTimeFormatterBuilder {
* @return the index into the active parsers list
*/
private int appendInternal(DateTimePrinterParser pp) {
- Jdk8Methods.requireNonNull(pp, "pp");
+ Objects.requireNonNull(pp, "pp");
if (active.padNextWidth > 0) {
if (pp != null) {
pp = new PadPrinterParserDecorator(pp, active.padNextWidth, active.padNextChar);
@@ -1880,7 +1881,7 @@ public final class DateTimeFormatterBuilder {
* @return the created formatter, not null
*/
public DateTimeFormatter toFormatter(Locale locale) {
- Jdk8Methods.requireNonNull(locale, "locale");
+ Objects.requireNonNull(locale, "locale");
while (active.parent != null) {
optionalEnd();
}
@@ -2672,7 +2673,7 @@ public final class DateTimeFormatterBuilder {
* @param decimalPoint whether to output the localized decimal point symbol
*/
FractionPrinterParser(TemporalField field, int minWidth, int maxWidth, boolean decimalPoint) {
- Jdk8Methods.requireNonNull(field, "field");
+ Objects.requireNonNull(field, "field");
if (field.range().isFixed() == false) {
throw new IllegalArgumentException("Field must have a fixed set of values: " + field);
}
@@ -3069,8 +3070,8 @@ public final class DateTimeFormatterBuilder {
* @param pattern the pattern
*/
OffsetIdPrinterParser(String noOffsetText, String pattern) {
- Jdk8Methods.requireNonNull(noOffsetText, "noOffsetText");
- Jdk8Methods.requireNonNull(pattern, "pattern");
+ Objects.requireNonNull(noOffsetText, "noOffsetText");
+ Objects.requireNonNull(pattern, "pattern");
this.noOffsetText = noOffsetText;
this.type = checkPattern(pattern);
}
@@ -3353,7 +3354,7 @@ public final class DateTimeFormatterBuilder {
private final 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) {
// this is a poor implementation that handles some but not all of the spec
// JDK8 has a lot of extra information here
- Map ids = new TreeMap(LENGTH_COMPARATOR);
+ Map ids = new TreeMap<>(LENGTH_COMPARATOR);
for (String id : ZoneId.getAvailableZoneIds()) {
ids.put(id, id);
TimeZone tz = TimeZone.getTimeZone(id);
diff --git a/classlib/src/main/java/org/threeten/bp/format/DateTimeParseContext.java b/classlib/src/main/java/org/threeten/bp/format/DateTimeParseContext.java
index 59f11b74a..72b1f064d 100644
--- a/classlib/src/main/java/org/threeten/bp/format/DateTimeParseContext.java
+++ b/classlib/src/main/java/org/threeten/bp/format/DateTimeParseContext.java
@@ -36,14 +36,15 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Objects;
import org.threeten.bp.Period;
import org.threeten.bp.ZoneId;
import org.threeten.bp.chrono.Chronology;
import org.threeten.bp.chrono.IsoChronology;
import org.threeten.bp.format.DateTimeFormatterBuilder.ReducedPrinterParser;
-import org.threeten.bp.jdk8.DefaultInterfaceTemporalAccessor;
import org.threeten.bp.jdk8.Jdk8Methods;
+import org.threeten.bp.temporal.TemporalAccessor;
import org.threeten.bp.temporal.TemporalField;
import org.threeten.bp.temporal.TemporalQueries;
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
* is automatically created for each parse and parsing is single-threaded
*/
-final class DateTimeParseContext {
+public final class DateTimeParseContext {
/**
* The locale, not null.
@@ -110,7 +111,7 @@ final class DateTimeParseContext {
}
// for testing
- DateTimeParseContext(Locale locale, DecimalStyle symbols, Chronology chronology) {
+ public DateTimeParseContext(Locale locale, DecimalStyle symbols, Chronology chronology) {
super();
this.locale = locale;
this.symbols = symbols;
@@ -341,7 +342,7 @@ final class DateTimeParseContext {
* @return the new position
*/
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);
return (old != null && old.longValue() != value) ? ~errorPos : successPos;
}
@@ -355,7 +356,7 @@ final class DateTimeParseContext {
* @param chrono the parsed chronology, not null
*/
void setParsed(Chronology chrono) {
- Jdk8Methods.requireNonNull(chrono, "chrono");
+ Objects.requireNonNull(chrono, "chrono");
Parsed currentParsed = currentParsed();
currentParsed.chrono = chrono;
if (currentParsed.callbacks != null) {
@@ -385,7 +386,7 @@ final class DateTimeParseContext {
* @param zone the parsed zone, not null
*/
void setParsed(ZoneId zone) {
- Jdk8Methods.requireNonNull(zone, "zone");
+ Objects.requireNonNull(zone, "zone");
currentParsed().zone = zone;
}
@@ -422,10 +423,10 @@ final class DateTimeParseContext {
/**
* Temporary store of parsed data.
*/
- final class Parsed extends DefaultInterfaceTemporalAccessor {
+ final class Parsed implements TemporalAccessor {
Chronology chrono = null;
ZoneId zone = null;
- final Map fieldValues = new HashMap();
+ final Map fieldValues = new HashMap<>();
boolean leapSecond;
Period excessDays = Period.ZERO;
List