diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
index b41cb4279..c0cae6ecd 100644
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -55,7 +55,6 @@
-
@@ -106,7 +105,6 @@
-
@@ -123,7 +121,6 @@
-
diff --git a/classlib/src/main/java/org/threeten/bp/Clock.java b/classlib/src/main/java/org/threeten/bp/Clock.java
index 8b1fa132a..7005d9fbc 100644
--- a/classlib/src/main/java/org/threeten/bp/Clock.java
+++ b/classlib/src/main/java/org/threeten/bp/Clock.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -33,11 +48,9 @@ package org.threeten.bp;
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;
/**
diff --git a/classlib/src/main/java/org/threeten/bp/DateTimeException.java b/classlib/src/main/java/org/threeten/bp/DateTimeException.java
index 1c02e9113..6ff94e1df 100644
--- a/classlib/src/main/java/org/threeten/bp/DateTimeException.java
+++ b/classlib/src/main/java/org/threeten/bp/DateTimeException.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
diff --git a/classlib/src/main/java/org/threeten/bp/DayOfWeek.java b/classlib/src/main/java/org/threeten/bp/DayOfWeek.java
index dd1fe553a..0e38b1c9a 100644
--- a/classlib/src/main/java/org/threeten/bp/DayOfWeek.java
+++ b/classlib/src/main/java/org/threeten/bp/DayOfWeek.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -33,9 +48,7 @@ package org.threeten.bp;
import static org.threeten.bp.temporal.ChronoField.DAY_OF_WEEK;
import static org.threeten.bp.temporal.ChronoUnit.DAYS;
-
import java.util.Locale;
-
import org.threeten.bp.format.DateTimeFormatterBuilder;
import org.threeten.bp.format.TextStyle;
import org.threeten.bp.temporal.ChronoField;
@@ -169,8 +182,8 @@ public enum DayOfWeek implements TemporalAccessor, TemporalAdjuster {
try {
return of(temporal.get(DAY_OF_WEEK));
} catch (DateTimeException ex) {
- throw new DateTimeException("Unable to obtain DayOfWeek from TemporalAccessor: " +
- temporal + ", type " + temporal.getClass().getName(), ex);
+ throw new DateTimeException("Unable to obtain DayOfWeek from TemporalAccessor: "
+ + temporal + ", type " + temporal.getClass().getName(), ex);
}
}
@@ -179,7 +192,7 @@ public enum DayOfWeek implements TemporalAccessor, TemporalAdjuster {
* Gets the day-of-week {@code int} value.
*
* The values are numbered following the ISO-8601 standard, from 1 (Monday) to 7 (Sunday).
- * See {@link WeekFields#dayOfWeek} for localized week-numbering.
+ * See {@link WeekFields#dayOfWeek()} for localized week-numbering.
*
* @return the day-of-week, from 1 (Monday) to 7 (Sunday)
*/
@@ -382,8 +395,12 @@ public enum DayOfWeek implements TemporalAccessor, TemporalAdjuster {
public R query(TemporalQuery query) {
if (query == TemporalQueries.precision()) {
return (R) DAYS;
- } else if (query == TemporalQueries.localDate() || query == TemporalQueries.localTime() || query == TemporalQueries.chronology() ||
- query == TemporalQueries.zone() || query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) {
+ } else if (query == TemporalQueries.localDate()
+ || query == TemporalQueries.localTime()
+ || query == TemporalQueries.chronology()
+ || query == TemporalQueries.zone()
+ || query == TemporalQueries.zoneId()
+ || query == TemporalQueries.offset()) {
return null;
}
return query.queryFrom(this);
@@ -398,7 +415,7 @@ public enum DayOfWeek implements TemporalAccessor, TemporalAdjuster {
* The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
* passing {@link ChronoField#DAY_OF_WEEK} as the field.
* Note that this adjusts forwards or backwards within a Monday to Sunday week.
- * See {@link WeekFields#dayOfWeek} for localized week start days.
+ * See {@link WeekFields#dayOfWeek()} for localized week start days.
* See {@link TemporalAdjusters} for other adjusters
* with more control, such as {@code next(MONDAY)}.
*
diff --git a/classlib/src/main/java/org/threeten/bp/Duration.java b/classlib/src/main/java/org/threeten/bp/Duration.java
index 1b91250d6..0d597f4b9 100644
--- a/classlib/src/main/java/org/threeten/bp/Duration.java
+++ b/classlib/src/main/java/org/threeten/bp/Duration.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -38,7 +53,6 @@ import static org.threeten.bp.temporal.ChronoField.NANO_OF_SECOND;
import static org.threeten.bp.temporal.ChronoUnit.DAYS;
import static org.threeten.bp.temporal.ChronoUnit.NANOS;
import static org.threeten.bp.temporal.ChronoUnit.SECONDS;
-
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -49,7 +63,6 @@ import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import org.threeten.bp.format.DateTimeParseException;
import org.threeten.bp.jdk8.Jdk8Methods;
import org.threeten.bp.temporal.ChronoField;
@@ -108,9 +121,10 @@ public final class Duration
/**
* The pattern for parsing.
*/
+ // TODO: get rid of regexp
private final static Pattern PATTERN =
- Pattern.compile("([-+]?)P(?:([-+]?[0-9]+)D)?" +
- "(T(?:([-+]?[0-9]+)H)?(?:([-+]?[0-9]+)M)?(?:([-+]?[0-9]+)(?:[.,]([0-9]{0,9}))?S)?)?",
+ Pattern.compile("([-+]?)P(?:([-+]?[0-9]+)D)?"
+ + "(T(?:([-+]?[0-9]+)H)?(?:([-+]?[0-9]+)M)?(?:([-+]?[0-9]+)(?:[.,]([0-9]{0,9}))?S)?)?",
Pattern.CASE_INSENSITIVE);
/**
@@ -328,7 +342,7 @@ public final class Duration
} else if (secs == 0 && nanos != 0) {
// two possible meanings for result, so recalculate secs
Temporal adjustedEnd = endExclusive.with(NANO_OF_SECOND, startNos);
- secs = startInclusive.until(adjustedEnd, SECONDS);;
+ secs = startInclusive.until(adjustedEnd, SECONDS);
}
} catch (DateTimeException | ArithmeticException ex2) {
// ignore and only use seconds
@@ -387,7 +401,7 @@ public final class Duration
Matcher matcher = PATTERN.matcher(text);
if (matcher.matches()) {
// check for letter T but no time sections
- if ("T".equals(matcher.group(3)) == false) {
+ if (!"T".equals(matcher.group(3))) {
boolean negate = "-".equals(matcher.group(1));
String dayMatch = matcher.group(2);
String hourMatch = matcher.group(4);
@@ -404,7 +418,7 @@ public final class Duration
try {
return create(negate, daysAsSecs, hoursAsSecs, minsAsSecs, seconds, nanos);
} catch (ArithmeticException ex) {
- throw (DateTimeParseException) new DateTimeParseException("Text cannot be parsed to a Duration: overflow", text, 0).initCause(ex);
+ throw new DateTimeParseException("Text cannot be parsed to a Duration: overflow", text, 0, ex);
}
}
}
@@ -441,8 +455,10 @@ public final class Duration
}
}
- private static Duration create(boolean negate, long daysAsSecs, long hoursAsSecs, long minsAsSecs, long secs, int nanos) {
- long seconds = Jdk8Methods.safeAdd(daysAsSecs, Jdk8Methods.safeAdd(hoursAsSecs, Jdk8Methods.safeAdd(minsAsSecs, secs)));
+ private static Duration create(boolean negate, long daysAsSecs, long hoursAsSecs, long minsAsSecs,
+ long secs, int nanos) {
+ long seconds = Jdk8Methods.safeAdd(daysAsSecs, Jdk8Methods.safeAdd(hoursAsSecs,
+ Jdk8Methods.safeAdd(minsAsSecs, secs)));
if (negate) {
return ofSeconds(seconds, nanos).negated();
}
@@ -631,10 +647,15 @@ public final class Duration
}
if (unit instanceof ChronoUnit) {
switch ((ChronoUnit) unit) {
- case NANOS: return plusNanos(amountToAdd);
- case MICROS: return plusSeconds((amountToAdd / (1000000L * 1000)) * 1000).plusNanos((amountToAdd % (1000000L * 1000)) * 1000);
- case MILLIS: return plusMillis(amountToAdd);
- case SECONDS: return plusSeconds(amountToAdd);
+ case NANOS:
+ return plusNanos(amountToAdd);
+ case MICROS:
+ return plusSeconds((amountToAdd / (1000000L * 1000)) * 1000)
+ .plusNanos((amountToAdd % (1000000L * 1000)) * 1000);
+ case MILLIS:
+ return plusMillis(amountToAdd);
+ case SECONDS:
+ return plusSeconds(amountToAdd);
}
return plusSeconds(Jdk8Methods.safeMultiply(unit.getDuration().seconds, amountToAdd));
}
@@ -777,7 +798,9 @@ public final class Duration
* @throws ArithmeticException if numeric overflow occurs
*/
public Duration minus(long amountToSubtract, TemporalUnit unit) {
- return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit));
+ return amountToSubtract == Long.MIN_VALUE
+ ? plus(Long.MAX_VALUE, unit).plus(1, unit)
+ : plus(-amountToSubtract, unit);
}
//-----------------------------------------------------------------------
@@ -791,7 +814,7 @@ public final class Duration
* @throws ArithmeticException if numeric overflow occurs
*/
public Duration minusDays(long daysToSubtract) {
- return (daysToSubtract == Long.MIN_VALUE ? plusDays(Long.MAX_VALUE).plusDays(1) : plusDays(-daysToSubtract));
+ return daysToSubtract == Long.MIN_VALUE ? plusDays(Long.MAX_VALUE).plusDays(1) : plusDays(-daysToSubtract);
}
/**
@@ -804,7 +827,9 @@ public final class Duration
* @throws ArithmeticException if numeric overflow occurs
*/
public Duration minusHours(long hoursToSubtract) {
- return (hoursToSubtract == Long.MIN_VALUE ? plusHours(Long.MAX_VALUE).plusHours(1) : plusHours(-hoursToSubtract));
+ return hoursToSubtract == Long.MIN_VALUE
+ ? plusHours(Long.MAX_VALUE).plusHours(1)
+ : plusHours(-hoursToSubtract);
}
/**
@@ -817,7 +842,9 @@ public final class Duration
* @throws ArithmeticException if numeric overflow occurs
*/
public Duration minusMinutes(long minutesToSubtract) {
- return (minutesToSubtract == Long.MIN_VALUE ? plusMinutes(Long.MAX_VALUE).plusMinutes(1) : plusMinutes(-minutesToSubtract));
+ return minutesToSubtract == Long.MIN_VALUE
+ ? plusMinutes(Long.MAX_VALUE).plusMinutes(1)
+ : plusMinutes(-minutesToSubtract);
}
/**
@@ -830,7 +857,9 @@ public final class Duration
* @throws ArithmeticException if numeric overflow occurs
*/
public Duration minusSeconds(long secondsToSubtract) {
- return (secondsToSubtract == Long.MIN_VALUE ? plusSeconds(Long.MAX_VALUE).plusSeconds(1) : plusSeconds(-secondsToSubtract));
+ return secondsToSubtract == Long.MIN_VALUE
+ ? plusSeconds(Long.MAX_VALUE).plusSeconds(1)
+ : plusSeconds(-secondsToSubtract);
}
/**
@@ -843,7 +872,9 @@ public final class Duration
* @throws ArithmeticException if numeric overflow occurs
*/
public Duration minusMillis(long millisToSubtract) {
- return (millisToSubtract == Long.MIN_VALUE ? plusMillis(Long.MAX_VALUE).plusMillis(1) : plusMillis(-millisToSubtract));
+ return millisToSubtract == Long.MIN_VALUE
+ ? plusMillis(Long.MAX_VALUE).plusMillis(1)
+ : plusMillis(-millisToSubtract);
}
/**
@@ -856,7 +887,9 @@ public final class Duration
* @throws ArithmeticException if numeric overflow occurs
*/
public Duration minusNanos(long nanosToSubtract) {
- return (nanosToSubtract == Long.MIN_VALUE ? plusNanos(Long.MAX_VALUE).plusNanos(1) : plusNanos(-nanosToSubtract));
+ return nanosToSubtract == Long.MIN_VALUE
+ ? plusNanos(Long.MAX_VALUE).plusNanos(1)
+ : plusNanos(-nanosToSubtract);
}
//-----------------------------------------------------------------------
@@ -1140,8 +1173,7 @@ public final class Duration
}
if (otherDuration instanceof Duration) {
Duration other = (Duration) otherDuration;
- return this.seconds == other.seconds &&
- this.nanos == other.nanos;
+ return this.seconds == other.seconds && this.nanos == other.nanos;
}
return false;
}
@@ -1222,6 +1254,4 @@ public final class Duration
buf.append('S');
return buf.toString();
}
-
-
}
diff --git a/classlib/src/main/java/org/threeten/bp/Instant.java b/classlib/src/main/java/org/threeten/bp/Instant.java
index d67fc1410..66c0a8247 100644
--- a/classlib/src/main/java/org/threeten/bp/Instant.java
+++ b/classlib/src/main/java/org/threeten/bp/Instant.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -40,10 +55,8 @@ import static org.threeten.bp.temporal.ChronoField.MILLI_OF_SECOND;
import static org.threeten.bp.temporal.ChronoField.NANO_OF_SECOND;
import static org.threeten.bp.temporal.ChronoUnit.DAYS;
import static org.threeten.bp.temporal.ChronoUnit.NANOS;
-
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.Jdk8Methods;
@@ -331,8 +344,8 @@ public final class Instant
int nanoOfSecond = temporal.get(NANO_OF_SECOND);
return Instant.ofEpochSecond(instantSecs, nanoOfSecond);
} catch (DateTimeException ex) {
- throw new DateTimeException("Unable to obtain Instant from TemporalAccessor: " +
- temporal + ", type " + temporal.getClass().getName(), ex);
+ throw new DateTimeException("Unable to obtain Instant from TemporalAccessor: "
+ + temporal + ", type " + temporal.getClass().getName(), ex);
}
}
@@ -412,7 +425,8 @@ public final class Instant
@Override
public boolean isSupported(TemporalField field) {
if (field instanceof ChronoField) {
- return field == INSTANT_SECONDS || field == NANO_OF_SECOND || field == MICRO_OF_SECOND || field == MILLI_OF_SECOND;
+ return field == INSTANT_SECONDS || field == NANO_OF_SECOND || field == MICRO_OF_SECOND
+ || field == MILLI_OF_SECOND;
}
return field != null && field.isSupportedBy(this);
}
@@ -627,14 +641,16 @@ public final class Instant
switch (f) {
case MILLI_OF_SECOND: {
int nval = (int) newValue * NANOS_PER_MILLI;
- return (nval != nanos ? create(seconds, nval) : this);
+ return nval != nanos ? create(seconds, nval) : this;
}
case MICRO_OF_SECOND: {
int nval = (int) newValue * 1000;
- return (nval != nanos ? create(seconds, nval) : this);
+ return nval != nanos ? create(seconds, nval) : this;
}
- case NANO_OF_SECOND: return (newValue != nanos ? create(seconds, (int) newValue) : this);
- case INSTANT_SECONDS: return (newValue != seconds ? create(newValue, nanos) : this);
+ case NANO_OF_SECOND:
+ return newValue != nanos ? create(seconds, (int) newValue) : this;
+ case INSTANT_SECONDS:
+ return newValue != seconds ? create(newValue, nanos) : this;
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
@@ -797,7 +813,9 @@ public final class Instant
*/
@Override
public Instant minus(long amountToSubtract, TemporalUnit unit) {
- return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit));
+ return amountToSubtract == Long.MIN_VALUE
+ ? plus(Long.MAX_VALUE, unit).plus(1, unit)
+ : plus(-amountToSubtract, unit);
}
//-----------------------------------------------------------------------
@@ -878,9 +896,9 @@ public final class Instant
return (R) NANOS;
}
// inline TemporalAccessor.super.query(query) as an optimization
- if (query == TemporalQueries.localDate() || query == TemporalQueries.localTime() ||
- query == TemporalQueries.chronology() || query == TemporalQueries.zoneId() ||
- query == TemporalQueries.zone() || query == TemporalQueries.offset()) {
+ if (query == TemporalQueries.localDate() || query == TemporalQueries.localTime()
+ || query == TemporalQueries.chronology() || query == TemporalQueries.zoneId()
+ || query == TemporalQueries.zone() || query == TemporalQueries.offset()) {
return null;
}
return query.queryFrom(this);
@@ -970,7 +988,7 @@ public final class Instant
case MINUTES: return secondsUntil(end) / SECONDS_PER_MINUTE;
case HOURS: return secondsUntil(end) / SECONDS_PER_HOUR;
case HALF_DAYS: return secondsUntil(end) / (12 * SECONDS_PER_HOUR);
- case DAYS: return secondsUntil(end) / (SECONDS_PER_DAY);
+ case DAYS: return secondsUntil(end) / SECONDS_PER_DAY;
}
throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
}
@@ -1057,7 +1075,7 @@ public final class Instant
// that way we always stay in the valid long range
// seconds + 1 can not overflow because it is negative
long millis = Jdk8Methods.safeMultiply(seconds + 1, MILLIS_PER_SEC);
- return Jdk8Methods.safeSubtract(millis, (MILLIS_PER_SEC - nanos / NANOS_PER_MILLI));
+ return Jdk8Methods.safeSubtract(millis, MILLIS_PER_SEC - nanos / NANOS_PER_MILLI);
}
}
@@ -1123,8 +1141,7 @@ public final class Instant
}
if (otherInstant instanceof Instant) {
Instant other = (Instant) otherInstant;
- return this.seconds == other.seconds &&
- this.nanos == other.nanos;
+ return this.seconds == other.seconds && this.nanos == other.nanos;
}
return false;
}
diff --git a/classlib/src/main/java/org/threeten/bp/LocalDate.java b/classlib/src/main/java/org/threeten/bp/LocalDate.java
index 7139b175d..e0bc32713 100644
--- a/classlib/src/main/java/org/threeten/bp/LocalDate.java
+++ b/classlib/src/main/java/org/threeten/bp/LocalDate.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -43,10 +58,8 @@ import static org.threeten.bp.temporal.ChronoField.ERA;
import static org.threeten.bp.temporal.ChronoField.MONTH_OF_YEAR;
import static org.threeten.bp.temporal.ChronoField.PROLEPTIC_MONTH;
import static org.threeten.bp.temporal.ChronoField.YEAR;
-
import java.io.Serializable;
import java.util.Objects;
-
import org.threeten.bp.chrono.ChronoLocalDate;
import org.threeten.bp.chrono.Era;
import org.threeten.bp.chrono.IsoChronology;
@@ -238,7 +251,7 @@ public final class LocalDate
YEAR.checkValidValue(year);
DAY_OF_YEAR.checkValidValue(dayOfYear);
boolean leap = IsoChronology.INSTANCE.isLeapYear(year);
- if (dayOfYear == 366 && leap == false) {
+ if (dayOfYear == 366 && !leap) {
throw new DateTimeException("Invalid date 'DayOfYear 366' as '" + year + "' is not a leap year");
}
Month moy = Month.of((dayOfYear - 1) / 31 + 1);
@@ -314,8 +327,8 @@ public final class LocalDate
public static LocalDate from(TemporalAccessor temporal) {
LocalDate date = temporal.query(TemporalQueries.localDate());
if (date == null) {
- throw new DateTimeException("Unable to obtain LocalDate from TemporalAccessor: " +
- temporal + ", type " + temporal.getClass().getName());
+ throw new DateTimeException("Unable to obtain LocalDate from TemporalAccessor: "
+ + temporal + ", type " + temporal.getClass().getName());
}
return date;
}
@@ -477,11 +490,16 @@ public final class LocalDate
ChronoField f = (ChronoField) field;
if (f.isDateBased()) {
switch (f) {
- case DAY_OF_MONTH: return ValueRange.of(1, lengthOfMonth());
- case DAY_OF_YEAR: return ValueRange.of(1, lengthOfYear());
- case ALIGNED_WEEK_OF_MONTH: return ValueRange.of(1, getMonth() == Month.FEBRUARY && isLeapYear() == false ? 4 : 5);
+ case DAY_OF_MONTH:
+ return ValueRange.of(1, lengthOfMonth());
+ case DAY_OF_YEAR:
+ return ValueRange.of(1, lengthOfYear());
+ case ALIGNED_WEEK_OF_MONTH:
+ return ValueRange.of(1, getMonth() == Month.FEBRUARY && !isLeapYear() ? 4 : 5);
case YEAR_OF_ERA:
- return (getYear() <= 0 ? ValueRange.of(1, Year.MAX_VALUE + 1) : ValueRange.of(1, Year.MAX_VALUE));
+ return getYear() <= 0
+ ? ValueRange.of(1, Year.MAX_VALUE + 1)
+ : ValueRange.of(1, Year.MAX_VALUE);
}
return field.range();
}
@@ -570,9 +588,9 @@ public final class LocalDate
case ALIGNED_WEEK_OF_YEAR: return ((getDayOfYear() - 1) / 7) + 1;
case MONTH_OF_YEAR: return month;
case PROLEPTIC_MONTH: throw new DateTimeException("Field too large for an int: " + field);
- case YEAR_OF_ERA: return (year >= 1 ? year : 1 - year);
+ case YEAR_OF_ERA: return year >= 1 ? year : 1 - year;
case YEAR: return year;
- case ERA: return (year >= 1 ? 1 : 0);
+ case ERA: return year >= 1 ? 1 : 0;
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
@@ -739,7 +757,7 @@ public final class LocalDate
public int lengthOfMonth() {
switch (month) {
case 2:
- return (isLeapYear() ? 29 : 28);
+ return isLeapYear() ? 29 : 28;
case 4:
case 6:
case 9:
@@ -759,7 +777,7 @@ public final class LocalDate
*/
@Override // override for Javadoc and performance
public int lengthOfYear() {
- return (isLeapYear() ? 366 : 365);
+ return isLeapYear() ? 366 : 365;
}
//-----------------------------------------------------------------------
@@ -928,7 +946,7 @@ public final class LocalDate
case PROLEPTIC_MONTH: return plusMonths(newValue - getLong(PROLEPTIC_MONTH));
case YEAR_OF_ERA: return withYear((int) (year >= 1 ? newValue : 1 - newValue));
case YEAR: return withYear((int) newValue);
- case ERA: return (getLong(ERA) == newValue ? this : withYear(1 - year));
+ case ERA: return getLong(ERA) == newValue ? this : withYear(1 - year);
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
@@ -1205,7 +1223,9 @@ public final class LocalDate
*/
@Override
public LocalDate minus(long amountToSubtract, TemporalUnit unit) {
- return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit));
+ return amountToSubtract == Long.MIN_VALUE
+ ? plus(Long.MAX_VALUE, unit).plus(1, unit)
+ : plus(-amountToSubtract, unit);
}
//-----------------------------------------------------------------------
@@ -1230,7 +1250,9 @@ public final class LocalDate
* @throws DateTimeException if the result exceeds the supported date range
*/
public LocalDate minusYears(long yearsToSubtract) {
- return (yearsToSubtract == Long.MIN_VALUE ? plusYears(Long.MAX_VALUE).plusYears(1) : plusYears(-yearsToSubtract));
+ return yearsToSubtract == Long.MIN_VALUE
+ ? plusYears(Long.MAX_VALUE).plusYears(1)
+ : plusYears(-yearsToSubtract);
}
/**
@@ -1254,7 +1276,9 @@ public final class LocalDate
* @throws DateTimeException if the result exceeds the supported date range
*/
public LocalDate minusMonths(long monthsToSubtract) {
- return (monthsToSubtract == Long.MIN_VALUE ? plusMonths(Long.MAX_VALUE).plusMonths(1) : plusMonths(-monthsToSubtract));
+ return monthsToSubtract == Long.MIN_VALUE
+ ? plusMonths(Long.MAX_VALUE).plusMonths(1)
+ : plusMonths(-monthsToSubtract);
}
/**
@@ -1273,7 +1297,9 @@ public final class LocalDate
* @throws DateTimeException if the result exceeds the supported date range
*/
public LocalDate minusWeeks(long weeksToSubtract) {
- return (weeksToSubtract == Long.MIN_VALUE ? plusWeeks(Long.MAX_VALUE).plusWeeks(1) : plusWeeks(-weeksToSubtract));
+ return weeksToSubtract == Long.MIN_VALUE
+ ? plusWeeks(Long.MAX_VALUE).plusWeeks(1)
+ : plusWeeks(-weeksToSubtract);
}
/**
@@ -1292,7 +1318,9 @@ public final class LocalDate
* @throws DateTimeException if the result exceeds the supported date range
*/
public LocalDate minusDays(long daysToSubtract) {
- return (daysToSubtract == Long.MIN_VALUE ? plusDays(Long.MAX_VALUE).plusDays(1) : plusDays(-daysToSubtract));
+ return daysToSubtract == Long.MIN_VALUE
+ ? plusDays(Long.MAX_VALUE).plusDays(1)
+ : plusDays(-daysToSubtract);
}
//-----------------------------------------------------------------------
@@ -1602,7 +1630,7 @@ public final class LocalDate
// 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);
- if (zone instanceof ZoneOffset == false) {
+ if (!(zone instanceof ZoneOffset)) {
ZoneRules rules = zone.getRules();
ZoneOffsetTransition trans = rules.getTransition(ldt);
if (trans != null && trans.isGap()) {
@@ -1624,11 +1652,11 @@ public final class LocalDate
} else {
total -= y / -4 - y / -100 + y / -400;
}
- total += ((367 * m - 362) / 12);
+ total += (367 * m - 362) / 12;
total += day - 1;
if (m > 2) {
total--;
- if (isLeapYear() == false) {
+ if (!isLeapYear()) {
total--;
}
}
@@ -1659,11 +1687,11 @@ public final class LocalDate
}
int compareTo0(LocalDate otherDate) {
- int cmp = (year - otherDate.year);
+ int cmp = year - otherDate.year;
if (cmp == 0) {
- cmp = (month - otherDate.month);
+ cmp = month - otherDate.month;
if (cmp == 0) {
- cmp = (day - otherDate.day);
+ cmp = day - otherDate.day;
}
}
return cmp;
@@ -1790,7 +1818,7 @@ public final class LocalDate
int yearValue = year;
int monthValue = month;
int dayValue = day;
- return (yearValue & 0xFFFFF800) ^ ((yearValue << 11) + (monthValue << 6) + (dayValue));
+ return (yearValue & 0xFFFFF800) ^ ((yearValue << 11) + (monthValue << 6) + dayValue);
}
//-----------------------------------------------------------------------
diff --git a/classlib/src/main/java/org/threeten/bp/LocalDateTime.java b/classlib/src/main/java/org/threeten/bp/LocalDateTime.java
index 1cf27184e..1f50ddf57 100644
--- a/classlib/src/main/java/org/threeten/bp/LocalDateTime.java
+++ b/classlib/src/main/java/org/threeten/bp/LocalDateTime.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -40,10 +55,8 @@ import static org.threeten.bp.LocalTime.NANOS_PER_HOUR;
import static org.threeten.bp.LocalTime.NANOS_PER_MINUTE;
import static org.threeten.bp.LocalTime.NANOS_PER_SECOND;
import static org.threeten.bp.LocalTime.SECONDS_PER_DAY;
-
import java.io.Serializable;
import java.util.Objects;
-
import org.threeten.bp.chrono.ChronoLocalDateTime;
import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.format.DateTimeParseException;
@@ -230,7 +243,8 @@ public final class LocalDateTime
* @throws DateTimeException if the value of any field is out of range
* @throws DateTimeException if the day-of-month is invalid for the month-year
*/
- public static LocalDateTime of(int year, Month month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond) {
+ public static LocalDateTime of(int year, Month month, int dayOfMonth, int hour, int minute, int second,
+ int nanoOfSecond) {
LocalDate date = LocalDate.of(year, month, dayOfMonth);
LocalTime time = LocalTime.of(hour, minute, second, nanoOfSecond);
return new LocalDateTime(date, time);
@@ -299,7 +313,8 @@ public final class LocalDateTime
* @throws DateTimeException if the value of any field is out of range
* @throws DateTimeException if the day-of-month is invalid for the month-year
*/
- public static LocalDateTime of(int year, int month, int dayOfMonth, int hour, int minute, int second, int nanoOfSecond) {
+ public static LocalDateTime of(int year, int month, int dayOfMonth, int hour, int minute,
+ int second, int nanoOfSecond) {
LocalDate date = LocalDate.of(year, month, dayOfMonth);
LocalTime time = LocalTime.of(hour, minute, second, nanoOfSecond);
return new LocalDateTime(date, time);
@@ -391,8 +406,8 @@ public final class LocalDateTime
LocalTime time = LocalTime.from(temporal);
return new LocalDateTime(date, time);
} catch (DateTimeException ex) {
- throw new DateTimeException("Unable to obtain LocalDateTime from TemporalAccessor: " +
- temporal + ", type " + temporal.getClass().getName());
+ throw new DateTimeException("Unable to obtain LocalDateTime from TemporalAccessor: "
+ + temporal + ", type " + temporal.getClass().getName());
}
}
@@ -544,7 +559,7 @@ public final class LocalDateTime
@Override
public ValueRange range(TemporalField field) {
if (field instanceof ChronoField) {
- return (field.isTimeBased() ? time.range(field) : date.range(field));
+ return field.isTimeBased() ? time.range(field) : date.range(field);
}
return field.rangeRefinedBy(this);
}
@@ -577,7 +592,7 @@ public final class LocalDateTime
@Override
public int get(TemporalField field) {
if (field instanceof ChronoField) {
- return (field.isTimeBased() ? time.get(field) : date.get(field));
+ return field.isTimeBased() ? time.get(field) : date.get(field);
}
return super.get(field);
}
@@ -607,7 +622,7 @@ public final class LocalDateTime
@Override
public long getLong(TemporalField field) {
if (field instanceof ChronoField) {
- return (field.isTimeBased() ? time.getLong(field) : date.getLong(field));
+ return field.isTimeBased() ? time.getLong(field) : date.getLong(field);
}
return field.getFrom(this);
}
@@ -1018,13 +1033,21 @@ public final class LocalDateTime
if (unit instanceof ChronoUnit) {
ChronoUnit f = (ChronoUnit) unit;
switch (f) {
- case NANOS: return plusNanos(amountToAdd);
- case MICROS: return plusDays(amountToAdd / MICROS_PER_DAY).plusNanos((amountToAdd % MICROS_PER_DAY) * 1000);
- case MILLIS: return plusDays(amountToAdd / MILLIS_PER_DAY).plusNanos((amountToAdd % MILLIS_PER_DAY) * 1000000);
- case SECONDS: return plusSeconds(amountToAdd);
- case MINUTES: return plusMinutes(amountToAdd);
- case HOURS: return plusHours(amountToAdd);
- case HALF_DAYS: return plusDays(amountToAdd / 256).plusHours((amountToAdd % 256) * 12); // no overflow (256 is multiple of 2)
+ case NANOS:
+ return plusNanos(amountToAdd);
+ case MICROS:
+ return plusDays(amountToAdd / MICROS_PER_DAY).plusNanos((amountToAdd % MICROS_PER_DAY) * 1000);
+ case MILLIS:
+ return plusDays(amountToAdd / MILLIS_PER_DAY).plusNanos((amountToAdd % MILLIS_PER_DAY) * 1000000);
+ case SECONDS:
+ return plusSeconds(amountToAdd);
+ case MINUTES:
+ return plusMinutes(amountToAdd);
+ case HOURS:
+ return plusHours(amountToAdd);
+ case HALF_DAYS:
+ // no overflow (256 is multiple of 2)
+ return plusDays(amountToAdd / 256).plusHours((amountToAdd % 256) * 12);
}
return with(date.plus(amountToAdd, unit), time);
}
@@ -1214,7 +1237,9 @@ public final class LocalDateTime
*/
@Override
public LocalDateTime minus(long amountToSubtract, TemporalUnit unit) {
- return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit));
+ return amountToSubtract == Long.MIN_VALUE
+ ? plus(Long.MAX_VALUE, unit).plus(1, unit)
+ : plus(-amountToSubtract, unit);
}
//-----------------------------------------------------------------------
@@ -1239,7 +1264,9 @@ public final class LocalDateTime
* @throws DateTimeException if the result exceeds the supported date range
*/
public LocalDateTime minusYears(long years) {
- return (years == Long.MIN_VALUE ? plusYears(Long.MAX_VALUE).plusYears(1) : plusYears(-years));
+ return years == Long.MIN_VALUE
+ ? plusYears(Long.MAX_VALUE).plusYears(1)
+ : plusYears(-years);
}
/**
@@ -1263,7 +1290,9 @@ public final class LocalDateTime
* @throws DateTimeException if the result exceeds the supported date range
*/
public LocalDateTime minusMonths(long months) {
- return (months == Long.MIN_VALUE ? plusMonths(Long.MAX_VALUE).plusMonths(1) : plusMonths(-months));
+ return months == Long.MIN_VALUE
+ ? plusMonths(Long.MAX_VALUE).plusMonths(1)
+ : plusMonths(-months);
}
/**
@@ -1282,7 +1311,9 @@ public final class LocalDateTime
* @throws DateTimeException if the result exceeds the supported date range
*/
public LocalDateTime minusWeeks(long weeks) {
- return (weeks == Long.MIN_VALUE ? plusWeeks(Long.MAX_VALUE).plusWeeks(1) : plusWeeks(-weeks));
+ return weeks == Long.MIN_VALUE
+ ? plusWeeks(Long.MAX_VALUE).plusWeeks(1)
+ : plusWeeks(-weeks);
}
/**
@@ -1301,7 +1332,9 @@ public final class LocalDateTime
* @throws DateTimeException if the result exceeds the supported date range
*/
public LocalDateTime minusDays(long days) {
- return (days == Long.MIN_VALUE ? plusDays(Long.MAX_VALUE).plusDays(1) : plusDays(-days));
+ return days == Long.MIN_VALUE
+ ? plusDays(Long.MAX_VALUE).plusDays(1)
+ : plusDays(-days);
}
//-----------------------------------------------------------------------
@@ -1371,7 +1404,8 @@ public final class LocalDateTime
* @param sign the sign to determine add or subtract
* @return the combined result, not null
*/
- private LocalDateTime plusWithOverflow(LocalDate newDate, long hours, long minutes, long seconds, long nanos, int sign) {
+ private LocalDateTime plusWithOverflow(LocalDate newDate, long hours, long minutes, long seconds,
+ long nanos, int sign) {
// 9223372036854775808 long, 2147483648 int
if ((hours | minutes | seconds | nanos) == 0) {
return with(newDate, time);
@@ -1389,7 +1423,7 @@ public final class LocalDateTime
totNanos = totNanos * sign + curNoD; // total 432000000000000
totDays += Jdk8Methods.floorDiv(totNanos, NANOS_PER_DAY);
long newNoD = Jdk8Methods.floorMod(totNanos, NANOS_PER_DAY);
- LocalTime newTime = (newNoD == curNoD ? time : LocalTime.ofNanoOfDay(newNoD));
+ LocalTime newTime = newNoD == curNoD ? time : LocalTime.ofNanoOfDay(newNoD);
return with(newDate.plusDays(totDays), newTime);
}
diff --git a/classlib/src/main/java/org/threeten/bp/LocalTime.java b/classlib/src/main/java/org/threeten/bp/LocalTime.java
index 1bb7c6163..9dc12f536 100644
--- a/classlib/src/main/java/org/threeten/bp/LocalTime.java
+++ b/classlib/src/main/java/org/threeten/bp/LocalTime.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -39,10 +54,8 @@ import static org.threeten.bp.temporal.ChronoField.NANO_OF_SECOND;
import static org.threeten.bp.temporal.ChronoField.SECOND_OF_DAY;
import static org.threeten.bp.temporal.ChronoField.SECOND_OF_MINUTE;
import static org.threeten.bp.temporal.ChronoUnit.NANOS;
-
import java.io.Serializable;
import java.util.Objects;
-
import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.format.DateTimeParseException;
import org.threeten.bp.temporal.ChronoField;
@@ -389,8 +402,8 @@ public final class LocalTime
public static LocalTime from(TemporalAccessor temporal) {
LocalTime time = temporal.query(TemporalQueries.localTime());
if (time == null) {
- throw new DateTimeException("Unable to obtain LocalTime from TemporalAccessor: " +
- temporal + ", type " + temporal.getClass().getName());
+ throw new DateTimeException("Unable to obtain LocalTime from TemporalAccessor: "
+ + temporal + ", type " + temporal.getClass().getName());
}
return time;
}
@@ -620,9 +633,9 @@ public final class LocalTime
case MINUTE_OF_HOUR: return minute;
case MINUTE_OF_DAY: return hour * 60 + minute;
case HOUR_OF_AMPM: return hour % 12;
- case CLOCK_HOUR_OF_AMPM: int ham = hour % 12; return (ham % 12 == 0 ? 12 : ham);
+ case CLOCK_HOUR_OF_AMPM: int ham = hour % 12; return ham % 12 == 0 ? 12 : ham;
case HOUR_OF_DAY: return hour;
- case CLOCK_HOUR_OF_DAY: return (hour == 0 ? 24 : hour);
+ case CLOCK_HOUR_OF_DAY: return hour == 0 ? 24 : hour;
case AMPM_OF_DAY: return hour / 12;
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
@@ -1024,8 +1037,7 @@ public final class LocalTime
if (secondstoAdd == 0) {
return this;
}
- int sofd = hour * SECONDS_PER_HOUR +
- minute * SECONDS_PER_MINUTE + second;
+ int sofd = hour * SECONDS_PER_HOUR + minute * SECONDS_PER_MINUTE + second;
int newSofd = ((int) (secondstoAdd % SECONDS_PER_DAY) + sofd + SECONDS_PER_DAY) % SECONDS_PER_DAY;
if (sofd == newSofd) {
return this;
@@ -1089,7 +1101,8 @@ public final class LocalTime
* Returns a copy of this time with the specified period subtracted.
*
* This method returns a new time based on this time with the specified period subtracted.
- * This can be used to subtract any period that is defined by a unit, for example to subtract hours, minutes or seconds.
+ * This can be used to subtract any period that is defined by a unit, for example to subtract hours,
+ * minutes or seconds.
* The unit is responsible for the details of the calculation, including the resolution
* of any edge cases in the calculation.
*
@@ -1102,7 +1115,9 @@ public final class LocalTime
*/
@Override
public LocalTime minus(long amountToSubtract, TemporalUnit unit) {
- return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit));
+ return amountToSubtract == Long.MIN_VALUE
+ ? plus(Long.MAX_VALUE, unit).plus(1, unit)
+ : plus(-amountToSubtract, unit);
}
//-----------------------------------------------------------------------
@@ -1194,9 +1209,9 @@ public final class LocalTime
return (R) this;
}
// inline TemporalAccessor.super.query(query) as an optimization
- if (query == TemporalQueries.chronology() || query == TemporalQueries.zoneId() ||
- query == TemporalQueries.zone() || query == TemporalQueries.offset() ||
- query == TemporalQueries.localDate()) {
+ if (query == TemporalQueries.chronology() || query == TemporalQueries.zoneId()
+ || query == TemporalQueries.zone() || query == TemporalQueries.offset()
+ || query == TemporalQueries.localDate()) {
return null;
}
return query.queryFrom(this);
@@ -1420,8 +1435,7 @@ public final class LocalTime
}
if (obj instanceof LocalTime) {
LocalTime other = (LocalTime) obj;
- return hour == other.hour && minute == other.minute &&
- second == other.second && nano == other.nano;
+ return hour == other.hour && minute == other.minute && second == other.second && nano == other.nano;
}
return false;
}
diff --git a/classlib/src/main/java/org/threeten/bp/Month.java b/classlib/src/main/java/org/threeten/bp/Month.java
index cabd723c9..c663d1f40 100644
--- a/classlib/src/main/java/org/threeten/bp/Month.java
+++ b/classlib/src/main/java/org/threeten/bp/Month.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -33,9 +48,7 @@ package org.threeten.bp;
import static org.threeten.bp.temporal.ChronoField.MONTH_OF_YEAR;
import static org.threeten.bp.temporal.ChronoUnit.MONTHS;
-
import java.util.Locale;
-
import org.threeten.bp.chrono.Chronology;
import org.threeten.bp.chrono.IsoChronology;
import org.threeten.bp.format.DateTimeFormatterBuilder;
@@ -190,13 +203,13 @@ public enum Month implements TemporalAccessor, TemporalAdjuster {
return (Month) 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(MONTH_OF_YEAR));
} catch (DateTimeException ex) {
- throw new DateTimeException("Unable to obtain Month from TemporalAccessor: " +
- temporal + ", type " + temporal.getClass().getName(), ex);
+ throw new DateTimeException("Unable to obtain Month from TemporalAccessor: " + temporal
+ + ", type " + temporal.getClass().getName(), ex);
}
}
@@ -400,7 +413,7 @@ public enum Month implements TemporalAccessor, TemporalAdjuster {
public int length(boolean leapYear) {
switch (this) {
case FEBRUARY:
- return (leapYear ? 29 : 28);
+ return leapYear ? 29 : 28;
case APRIL:
case JUNE:
case SEPTEMBER:
@@ -540,8 +553,9 @@ public enum Month implements TemporalAccessor, TemporalAdjuster {
return (R) IsoChronology.INSTANCE;
} else if (query == TemporalQueries.precision()) {
return (R) MONTHS;
- } else if (query == TemporalQueries.localDate() || query == TemporalQueries.localTime() ||
- query == TemporalQueries.zone() || query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) {
+ } else if (query == TemporalQueries.localDate() || query == TemporalQueries.localTime()
+ || query == TemporalQueries.zone() || query == TemporalQueries.zoneId()
+ || query == TemporalQueries.offset()) {
return null;
}
return query.queryFrom(this);
@@ -584,7 +598,7 @@ public enum Month implements TemporalAccessor, TemporalAdjuster {
*/
@Override
public Temporal adjustInto(Temporal temporal) {
- if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) {
+ if (!Chronology.from(temporal).equals(IsoChronology.INSTANCE)) {
throw new DateTimeException("Adjustment only supported on ISO date-time");
}
return temporal.with(MONTH_OF_YEAR, getValue());
diff --git a/classlib/src/main/java/org/threeten/bp/MonthDay.java b/classlib/src/main/java/org/threeten/bp/MonthDay.java
index 93ce92ced..7e633118e 100644
--- a/classlib/src/main/java/org/threeten/bp/MonthDay.java
+++ b/classlib/src/main/java/org/threeten/bp/MonthDay.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -33,10 +48,8 @@ package org.threeten.bp;
import static org.threeten.bp.temporal.ChronoField.DAY_OF_MONTH;
import static org.threeten.bp.temporal.ChronoField.MONTH_OF_YEAR;
-
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;
@@ -170,8 +183,8 @@ public final class MonthDay
Objects.requireNonNull(month, "month");
DAY_OF_MONTH.checkValidValue(dayOfMonth);
if (dayOfMonth > month.maxLength()) {
- throw new DateTimeException("Illegal value for DayOfMonth field, value " + dayOfMonth +
- " is not valid for month " + month.name());
+ throw new DateTimeException("Illegal value for DayOfMonth field, value " + dayOfMonth
+ + " is not valid for month " + month.name());
}
return new MonthDay(month.getValue(), dayOfMonth);
}
@@ -219,13 +232,13 @@ public final class MonthDay
return (MonthDay) 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(MONTH_OF_YEAR), temporal.get(DAY_OF_MONTH));
} catch (DateTimeException ex) {
- throw new DateTimeException("Unable to obtain MonthDay from TemporalAccessor: " +
- temporal + ", type " + temporal.getClass().getName());
+ throw new DateTimeException("Unable to obtain MonthDay from TemporalAccessor: "
+ + temporal + ", type " + temporal.getClass().getName());
}
}
@@ -453,7 +466,7 @@ public final class MonthDay
* @see Year#isValidMonthDay(MonthDay)
*/
public boolean isValidYear(int year) {
- return (day == 29 && month == 2 && Year.isLeap(year) == false) == false;
+ return !(day == 29 && month == 2 && !Year.isLeap(year));
}
//-----------------------------------------------------------------------
@@ -572,7 +585,7 @@ public final class MonthDay
*/
@Override
public Temporal adjustInto(Temporal temporal) {
- if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) {
+ if (!Chronology.from(temporal).equals(IsoChronology.INSTANCE)) {
throw new DateTimeException("Adjustment only supported on ISO date-time");
}
temporal = temporal.with(MONTH_OF_YEAR, month);
@@ -608,10 +621,11 @@ public final class MonthDay
* @param other the other month-day to compare to, not null
* @return the comparator value, negative if less, positive if greater
*/
+ @Override
public int compareTo(MonthDay other) {
- int cmp = (month - other.month);
+ int cmp = month - other.month;
if (cmp == 0) {
- cmp = (day - other.day);
+ cmp = day - other.day;
}
return cmp;
}
diff --git a/classlib/src/main/java/org/threeten/bp/OffsetDateTime.java b/classlib/src/main/java/org/threeten/bp/OffsetDateTime.java
index 8776d1777..3fa3d145b 100644
--- a/classlib/src/main/java/org/threeten/bp/OffsetDateTime.java
+++ b/classlib/src/main/java/org/threeten/bp/OffsetDateTime.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -36,11 +51,9 @@ import static org.threeten.bp.temporal.ChronoField.INSTANT_SECONDS;
import static org.threeten.bp.temporal.ChronoField.NANO_OF_DAY;
import static org.threeten.bp.temporal.ChronoField.OFFSET_SECONDS;
import static org.threeten.bp.temporal.ChronoUnit.NANOS;
-
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;
@@ -303,8 +316,8 @@ public final class OffsetDateTime
return OffsetDateTime.ofInstant(instant, offset);
}
} catch (DateTimeException ex) {
- throw new DateTimeException("Unable to obtain OffsetDateTime from TemporalAccessor: " +
- temporal + ", type " + temporal.getClass().getName());
+ throw new DateTimeException("Unable to obtain OffsetDateTime from TemporalAccessor: "
+ + temporal + ", type " + temporal.getClass().getName());
}
}
@@ -1206,7 +1219,9 @@ public final class OffsetDateTime
*/
@Override
public OffsetDateTime minus(long amountToSubtract, TemporalUnit unit) {
- return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit));
+ return amountToSubtract == Long.MIN_VALUE
+ ? plus(Long.MAX_VALUE, unit).plus(1, unit)
+ : plus(-amountToSubtract, unit);
}
//-----------------------------------------------------------------------
@@ -1231,7 +1246,7 @@ public final class OffsetDateTime
* @throws DateTimeException if the result exceeds the supported date range
*/
public OffsetDateTime minusYears(long years) {
- return (years == Long.MIN_VALUE ? plusYears(Long.MAX_VALUE).plusYears(1) : plusYears(-years));
+ return years == Long.MIN_VALUE ? plusYears(Long.MAX_VALUE).plusYears(1) : plusYears(-years);
}
/**
@@ -1255,7 +1270,7 @@ public final class OffsetDateTime
* @throws DateTimeException if the result exceeds the supported date range
*/
public OffsetDateTime minusMonths(long months) {
- return (months == Long.MIN_VALUE ? plusMonths(Long.MAX_VALUE).plusMonths(1) : plusMonths(-months));
+ return months == Long.MIN_VALUE ? plusMonths(Long.MAX_VALUE).plusMonths(1) : plusMonths(-months);
}
/**
@@ -1274,7 +1289,7 @@ public final class OffsetDateTime
* @throws DateTimeException if the result exceeds the supported date range
*/
public OffsetDateTime minusWeeks(long weeks) {
- return (weeks == Long.MIN_VALUE ? plusWeeks(Long.MAX_VALUE).plusWeeks(1) : plusWeeks(-weeks));
+ return weeks == Long.MIN_VALUE ? plusWeeks(Long.MAX_VALUE).plusWeeks(1) : plusWeeks(-weeks);
}
/**
@@ -1293,7 +1308,9 @@ public final class OffsetDateTime
* @throws DateTimeException if the result exceeds the supported date range
*/
public OffsetDateTime minusDays(long days) {
- return (days == Long.MIN_VALUE ? plusDays(Long.MAX_VALUE).plusDays(1) : plusDays(-days));
+ return days == Long.MIN_VALUE
+ ? plusDays(Long.MAX_VALUE).plusDays(1)
+ : plusDays(-days);
}
/**
@@ -1306,7 +1323,7 @@ public final class OffsetDateTime
* @throws DateTimeException if the result exceeds the supported date range
*/
public OffsetDateTime minusHours(long hours) {
- return (hours == Long.MIN_VALUE ? plusHours(Long.MAX_VALUE).plusHours(1) : plusHours(-hours));
+ return hours == Long.MIN_VALUE ? plusHours(Long.MAX_VALUE).plusHours(1) : plusHours(-hours);
}
/**
@@ -1319,7 +1336,7 @@ public final class OffsetDateTime
* @throws DateTimeException if the result exceeds the supported date range
*/
public OffsetDateTime minusMinutes(long minutes) {
- return (minutes == Long.MIN_VALUE ? plusMinutes(Long.MAX_VALUE).plusMinutes(1) : plusMinutes(-minutes));
+ return minutes == Long.MIN_VALUE ? plusMinutes(Long.MAX_VALUE).plusMinutes(1) : plusMinutes(-minutes);
}
/**
@@ -1332,7 +1349,7 @@ public final class OffsetDateTime
* @throws DateTimeException if the result exceeds the supported date range
*/
public OffsetDateTime minusSeconds(long seconds) {
- return (seconds == Long.MIN_VALUE ? plusSeconds(Long.MAX_VALUE).plusSeconds(1) : plusSeconds(-seconds));
+ return seconds == Long.MIN_VALUE ? plusSeconds(Long.MAX_VALUE).plusSeconds(1) : plusSeconds(-seconds);
}
/**
@@ -1345,7 +1362,7 @@ public final class OffsetDateTime
* @throws DateTimeException if the result exceeds the supported date range
*/
public OffsetDateTime minusNanos(long nanos) {
- return (nanos == Long.MIN_VALUE ? plusNanos(Long.MAX_VALUE).plusNanos(1) : plusNanos(-nanos));
+ return nanos == Long.MIN_VALUE ? plusNanos(Long.MAX_VALUE).plusNanos(1) : plusNanos(-nanos);
}
//-----------------------------------------------------------------------
@@ -1665,8 +1682,8 @@ public final class OffsetDateTime
public boolean isAfter(OffsetDateTime other) {
long thisEpochSec = toEpochSecond();
long otherEpochSec = other.toEpochSecond();
- return thisEpochSec > otherEpochSec ||
- (thisEpochSec == otherEpochSec && toLocalTime().getNano() > other.toLocalTime().getNano());
+ return thisEpochSec > otherEpochSec
+ || (thisEpochSec == otherEpochSec && toLocalTime().getNano() > other.toLocalTime().getNano());
}
/**
@@ -1682,8 +1699,8 @@ public final class OffsetDateTime
public boolean isBefore(OffsetDateTime other) {
long thisEpochSec = toEpochSecond();
long otherEpochSec = other.toEpochSecond();
- return thisEpochSec < otherEpochSec ||
- (thisEpochSec == otherEpochSec && toLocalTime().getNano() < other.toLocalTime().getNano());
+ return thisEpochSec < otherEpochSec
+ || (thisEpochSec == otherEpochSec && toLocalTime().getNano() < other.toLocalTime().getNano());
}
/**
@@ -1697,8 +1714,8 @@ public final class OffsetDateTime
* @return true if the instant equals the instant of the specified date-time
*/
public boolean isEqual(OffsetDateTime other) {
- return toEpochSecond() == other.toEpochSecond() &&
- toLocalTime().getNano() == other.toLocalTime().getNano();
+ return toEpochSecond() == other.toEpochSecond()
+ && toLocalTime().getNano() == other.toLocalTime().getNano();
}
//-----------------------------------------------------------------------
diff --git a/classlib/src/main/java/org/threeten/bp/OffsetTime.java b/classlib/src/main/java/org/threeten/bp/OffsetTime.java
index 9f3f86c6f..4f9e1be49 100644
--- a/classlib/src/main/java/org/threeten/bp/OffsetTime.java
+++ b/classlib/src/main/java/org/threeten/bp/OffsetTime.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -38,10 +53,8 @@ import static org.threeten.bp.LocalTime.SECONDS_PER_DAY;
import static org.threeten.bp.temporal.ChronoField.NANO_OF_DAY;
import static org.threeten.bp.temporal.ChronoField.OFFSET_SECONDS;
import static org.threeten.bp.temporal.ChronoUnit.NANOS;
-
import java.io.Serializable;
import java.util.Objects;
-
import org.threeten.bp.format.DateTimeFormatter;
import org.threeten.bp.format.DateTimeParseException;
import org.threeten.bp.temporal.ChronoField;
@@ -252,8 +265,8 @@ public final class OffsetTime
ZoneOffset offset = ZoneOffset.from(temporal);
return new OffsetTime(time, offset);
} catch (DateTimeException ex) {
- throw new DateTimeException("Unable to obtain OffsetTime from TemporalAccessor: " +
- temporal + ", type " + temporal.getClass().getName());
+ throw new DateTimeException("Unable to obtain OffsetTime from TemporalAccessor: "
+ + temporal + ", type " + temporal.getClass().getName());
}
}
@@ -868,7 +881,8 @@ public final class OffsetTime
* Returns a copy of this time with the specified period subtracted.
*
* This method returns a new time based on this time with the specified period subtracted.
- * This can be used to subtract any period that is defined by a unit, for example to subtract hours, minutes or seconds.
+ * This can be used to subtract any period that is defined by a unit, for example to subtract hours,
+ * minutes or seconds.
* The unit is responsible for the details of the calculation, including the resolution
* of any edge cases in the calculation.
* The offset is not part of the calculation and will be unchanged in the result.
@@ -882,7 +896,9 @@ public final class OffsetTime
*/
@Override
public OffsetTime minus(long amountToSubtract, TemporalUnit unit) {
- return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit));
+ return amountToSubtract == Long.MIN_VALUE
+ ? plus(Long.MAX_VALUE, unit).plus(1, unit)
+ : plus(-amountToSubtract, unit);
}
//-----------------------------------------------------------------------
@@ -974,7 +990,8 @@ public final class OffsetTime
return (R) getOffset();
} else if (query == TemporalQueries.localTime()) {
return (R) time;
- } else if (query == TemporalQueries.chronology() || query == TemporalQueries.localDate() || query == TemporalQueries.zoneId()) {
+ } else if (query == TemporalQueries.chronology() || query == TemporalQueries.localDate()
+ || query == TemporalQueries.zoneId()) {
return null;
}
return Temporal.super.query(query);
diff --git a/classlib/src/main/java/org/threeten/bp/Period.java b/classlib/src/main/java/org/threeten/bp/Period.java
index 7621ebd86..cd3e66bcc 100644
--- a/classlib/src/main/java/org/threeten/bp/Period.java
+++ b/classlib/src/main/java/org/threeten/bp/Period.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -34,7 +49,6 @@ package org.threeten.bp;
import static org.threeten.bp.temporal.ChronoUnit.DAYS;
import static org.threeten.bp.temporal.ChronoUnit.MONTHS;
import static org.threeten.bp.temporal.ChronoUnit.YEARS;
-
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
@@ -42,7 +56,6 @@ import java.util.List;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import org.threeten.bp.chrono.ChronoLocalDate;
import org.threeten.bp.chrono.ChronoPeriod;
import org.threeten.bp.chrono.Chronology;
@@ -101,7 +114,8 @@ public final class Period
* The pattern for parsing.
*/
private final static Pattern PATTERN =
- Pattern.compile("([-+]?)P(?:([-+]?[0-9]+)Y)?(?:([-+]?[0-9]+)M)?(?:([-+]?[0-9]+)W)?(?:([-+]?[0-9]+)D)?", Pattern.CASE_INSENSITIVE);
+ Pattern.compile("([-+]?)P(?:([-+]?[0-9]+)Y)?(?:([-+]?[0-9]+)M)?(?:([-+]?[0-9]+)W)?(?:([-+]?[0-9]+)D)?",
+ Pattern.CASE_INSENSITIVE);
/**
* The number of years.
@@ -209,7 +223,7 @@ public final class Period
return (Period) amount;
}
if (amount instanceof ChronoPeriod) {
- if (IsoChronology.INSTANCE.equals(((ChronoPeriod) amount).getChronology()) == false) {
+ if (!IsoChronology.INSTANCE.equals(((ChronoPeriod) amount).getChronology())) {
throw new DateTimeException("Period requires ISO chronology: " + amount);
}
}
@@ -300,7 +314,7 @@ public final class Period
Objects.requireNonNull(text, "text");
Matcher matcher = PATTERN.matcher(text);
if (matcher.matches()) {
- int negate = ("-".equals(matcher.group(1)) ? -1 : 1);
+ int negate = "-".equals(matcher.group(1)) ? -1 : 1;
String yearMatch = matcher.group(2);
String monthMatch = matcher.group(3);
String weekMatch = matcher.group(4);
@@ -314,7 +328,7 @@ public final class Period
days = Jdk8Methods.safeAdd(days, Jdk8Methods.safeMultiply(weeks, 7));
return create(years, months, days);
} catch (NumberFormatException ex) {
- throw (DateTimeParseException) new DateTimeParseException("Text cannot be parsed to a Period", text, 0).initCause(ex);
+ throw new DateTimeParseException("Text cannot be parsed to a Period", text, 0, ex);
}
}
}
@@ -329,7 +343,7 @@ public final class Period
try {
return Jdk8Methods.safeMultiply(val, negate);
} catch (ArithmeticException ex) {
- throw (DateTimeParseException) new DateTimeParseException("Text cannot be parsed to a Period", text, 0).initCause(ex);
+ throw new DateTimeParseException("Text cannot be parsed to a Period", text, 0, ex);
}
}
@@ -406,8 +420,9 @@ public final class Period
*
* @return true if this period is zero-length
*/
+ @Override
public boolean isZero() {
- return (this == ZERO);
+ return this == ZERO;
}
/**
@@ -417,6 +432,7 @@ public final class Period
*
* @return true if any unit of this period is negative
*/
+ @Override
public boolean isNegative() {
return years < 0 || months < 0 || days < 0;
}
@@ -542,6 +558,7 @@ public final class Period
* @return a {@code Period} based on this period with the requested period added, not null
* @throws ArithmeticException if numeric overflow occurs
*/
+ @Override
public Period plus(TemporalAmount amountToAdd) {
Period amount = Period.from(amountToAdd);
return create(
@@ -626,6 +643,7 @@ public final class Period
* @return a {@code Period} based on this period with the requested period subtracted, not null
* @throws ArithmeticException if numeric overflow occurs
*/
+ @Override
public Period minus(TemporalAmount amountToSubtract) {
Period amount = Period.from(amountToSubtract);
return create(
@@ -648,7 +666,9 @@ public final class Period
* @throws ArithmeticException if numeric overflow occurs
*/
public Period minusYears(long yearsToSubtract) {
- return (yearsToSubtract == Long.MIN_VALUE ? plusYears(Long.MAX_VALUE).plusYears(1) : plusYears(-yearsToSubtract));
+ return yearsToSubtract == Long.MIN_VALUE
+ ? plusYears(Long.MAX_VALUE).plusYears(1)
+ : plusYears(-yearsToSubtract);
}
/**
@@ -665,7 +685,9 @@ public final class Period
* @throws ArithmeticException if numeric overflow occurs
*/
public Period minusMonths(long monthsToSubtract) {
- return (monthsToSubtract == Long.MIN_VALUE ? plusMonths(Long.MAX_VALUE).plusMonths(1) : plusMonths(-monthsToSubtract));
+ return monthsToSubtract == Long.MIN_VALUE
+ ? plusMonths(Long.MAX_VALUE).plusMonths(1)
+ : plusMonths(-monthsToSubtract);
}
/**
@@ -682,7 +704,9 @@ public final class Period
* @throws ArithmeticException if numeric overflow occurs
*/
public Period minusDays(long daysToSubtract) {
- return (daysToSubtract == Long.MIN_VALUE ? plusDays(Long.MAX_VALUE).plusDays(1) : plusDays(-daysToSubtract));
+ return daysToSubtract == Long.MIN_VALUE
+ ? plusDays(Long.MAX_VALUE).plusDays(1)
+ : plusDays(-daysToSubtract);
}
//-----------------------------------------------------------------------
@@ -697,6 +721,7 @@ public final class Period
* @return a {@code Period} based on this period with the amounts multiplied by the scalar, not null
* @throws ArithmeticException if numeric overflow occurs
*/
+ @Override
public Period multipliedBy(int scalar) {
if (this == ZERO || scalar == 1) {
return this;
@@ -713,6 +738,7 @@ public final class Period
* @return a {@code Period} based on this period with the amounts negated, not null
* @throws ArithmeticException if numeric overflow occurs
*/
+ @Override
public Period negated() {
return multipliedBy(-1);
}
@@ -738,6 +764,7 @@ public final class Period
* @return a {@code Period} based on this period with excess months normalized to years, not null
* @throws ArithmeticException if numeric overflow occurs
*/
+ @Override
public Period normalized() {
long totalMonths = toTotalMonths();
long splitYears = totalMonths / 12;
@@ -878,9 +905,7 @@ public final class Period
}
if (obj instanceof Period) {
Period other = (Period) obj;
- return years == other.years &&
- months == other.months &&
- days == other.days;
+ return years == other.years && months == other.months && days == other.days;
}
return false;
}
diff --git a/classlib/src/main/java/org/threeten/bp/Year.java b/classlib/src/main/java/org/threeten/bp/Year.java
index acf43f352..2453a26df 100644
--- a/classlib/src/main/java/org/threeten/bp/Year.java
+++ b/classlib/src/main/java/org/threeten/bp/Year.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -39,10 +54,8 @@ import static org.threeten.bp.temporal.ChronoUnit.DECADES;
import static org.threeten.bp.temporal.ChronoUnit.ERAS;
import static org.threeten.bp.temporal.ChronoUnit.MILLENNIA;
import static org.threeten.bp.temporal.ChronoUnit.YEARS;
-
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;
@@ -358,7 +371,7 @@ public final class Year
@Override
public ValueRange range(TemporalField field) {
if (field == YEAR_OF_ERA) {
- return (year <= 0 ? ValueRange.of(1, MAX_VALUE + 1) : ValueRange.of(1, MAX_VALUE));
+ return year <= 0 ? ValueRange.of(1, MAX_VALUE + 1) : ValueRange.of(1, MAX_VALUE);
}
return Temporal.super.range(field);
}
@@ -417,9 +430,9 @@ public final class Year
public long getLong(TemporalField field) {
if (field instanceof ChronoField) {
switch ((ChronoField) field) {
- case YEAR_OF_ERA: return (year < 1 ? 1 - year : year);
+ case YEAR_OF_ERA: return year < 1 ? 1 - year : year;
case YEAR: return year;
- case ERA: return (year < 1 ? 0 : 1);
+ case ERA: return year < 1 ? 0 : 1;
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
@@ -543,7 +556,7 @@ public final class Year
switch (f) {
case YEAR_OF_ERA: return Year.of((int) (year < 1 ? 1 - newValue : newValue));
case YEAR: return Year.of((int) newValue);
- case ERA: return (getLong(ERA) == newValue ? this : Year.of(1 - year));
+ case ERA: return getLong(ERA) == newValue ? this : Year.of(1 - year);
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
@@ -637,7 +650,9 @@ public final class Year
*/
@Override
public Year minus(long amountToSubtract, TemporalUnit unit) {
- return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit));
+ return amountToSubtract == Long.MIN_VALUE
+ ? plus(Long.MAX_VALUE, unit).plus(1, unit)
+ : plus(-amountToSubtract, unit);
}
/**
@@ -650,7 +665,9 @@ public final class Year
* @throws DateTimeException if the result exceeds the supported year range
*/
public Year minusYears(long yearsToSubtract) {
- return (yearsToSubtract == Long.MIN_VALUE ? plusYears(Long.MAX_VALUE).plusYears(1) : plusYears(-yearsToSubtract));
+ return yearsToSubtract == Long.MIN_VALUE
+ ? plusYears(Long.MAX_VALUE).plusYears(1)
+ : plusYears(-yearsToSubtract);
}
//-----------------------------------------------------------------------
@@ -679,8 +696,9 @@ public final class Year
return (R) IsoChronology.INSTANCE;
} else if (query == TemporalQueries.precision()) {
return (R) YEARS;
- } else if (query == TemporalQueries.localDate() || query == TemporalQueries.localTime() ||
- query == TemporalQueries.zone() || query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) {
+ } else if (query == TemporalQueries.localDate() || query == TemporalQueries.localTime()
+ || query == TemporalQueries.zone() || query == TemporalQueries.zoneId()
+ || query == TemporalQueries.offset()) {
return null;
}
return Temporal.super.query(query);
@@ -714,7 +732,7 @@ public final class Year
*/
@Override
public Temporal adjustInto(Temporal temporal) {
- if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) {
+ if (!Chronology.from(temporal).equals(IsoChronology.INSTANCE)) {
throw new DateTimeException("Adjustment only supported on ISO date-time");
}
return temporal.with(YEAR, year);
@@ -859,6 +877,7 @@ public final class Year
* @param other the other year to compare to, not null
* @return the comparator value, negative if less, positive if greater
*/
+ @Override
public int compareTo(Year other) {
return year - other.year;
}
diff --git a/classlib/src/main/java/org/threeten/bp/YearMonth.java b/classlib/src/main/java/org/threeten/bp/YearMonth.java
index 9ad94d738..e1174f49e 100644
--- a/classlib/src/main/java/org/threeten/bp/YearMonth.java
+++ b/classlib/src/main/java/org/threeten/bp/YearMonth.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -42,10 +57,8 @@ import static org.threeten.bp.temporal.ChronoUnit.ERAS;
import static org.threeten.bp.temporal.ChronoUnit.MILLENNIA;
import static org.threeten.bp.temporal.ChronoUnit.MONTHS;
import static org.threeten.bp.temporal.ChronoUnit.YEARS;
-
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;
@@ -88,6 +101,7 @@ import org.threeten.bp.temporal.ValueRange;
*/
public final class YearMonth
implements Temporal, TemporalAdjuster, Comparable, Serializable, TemporalAccessor {
+
/**
* Parser.
*/
@@ -206,13 +220,13 @@ public final class YearMonth
return (YearMonth) 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), temporal.get(MONTH_OF_YEAR));
} catch (DateTimeException ex) {
- throw new DateTimeException("Unable to obtain YearMonth from TemporalAccessor: " +
- temporal + ", type " + temporal.getClass().getName());
+ throw new DateTimeException("Unable to obtain YearMonth from TemporalAccessor: "
+ + temporal + ", type " + temporal.getClass().getName());
}
}
@@ -306,8 +320,8 @@ public final class YearMonth
@Override
public boolean isSupported(TemporalField field) {
if (field instanceof ChronoField) {
- return field == YEAR || field == MONTH_OF_YEAR ||
- field == PROLEPTIC_MONTH || field == YEAR_OF_ERA || field == ERA;
+ return field == YEAR || field == MONTH_OF_YEAR
+ || field == PROLEPTIC_MONTH || field == YEAR_OF_ERA || field == ERA;
}
return field != null && field.isSupportedBy(this);
}
@@ -315,7 +329,8 @@ public final class YearMonth
@Override
public boolean isSupported(TemporalUnit unit) {
if (unit instanceof ChronoUnit) {
- return unit == MONTHS || unit == YEARS || unit == DECADES || unit == CENTURIES || unit == MILLENNIA || unit == ERAS;
+ return unit == MONTHS || unit == YEARS || unit == DECADES || unit == CENTURIES || unit == MILLENNIA
+ || unit == ERAS;
}
return unit != null && unit.isSupportedBy(this);
}
@@ -345,7 +360,7 @@ public final class YearMonth
@Override
public ValueRange range(TemporalField field) {
if (field == YEAR_OF_ERA) {
- return (getYear() <= 0 ? ValueRange.of(1, Year.MAX_VALUE + 1) : ValueRange.of(1, Year.MAX_VALUE));
+ return getYear() <= 0 ? ValueRange.of(1, Year.MAX_VALUE + 1) : ValueRange.of(1, Year.MAX_VALUE);
}
return Temporal.super.range(field);
}
@@ -407,9 +422,9 @@ public final class YearMonth
switch ((ChronoField) field) {
case MONTH_OF_YEAR: return month;
case PROLEPTIC_MONTH: return getProlepticMonth();
- case YEAR_OF_ERA: return (year < 1 ? 1 - year : year);
+ case YEAR_OF_ERA: return year < 1 ? 1 - year : year;
case YEAR: return year;
- case ERA: return (year < 1 ? 0 : 1);
+ case ERA: return year < 1 ? 0 : 1;
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
@@ -518,7 +533,7 @@ public final class YearMonth
* @return 366 if the year is leap, 365 otherwise
*/
public int lengthOfYear() {
- return (isLeapYear() ? 366 : 365);
+ return isLeapYear() ? 366 : 365;
}
//-----------------------------------------------------------------------
@@ -606,7 +621,7 @@ public final class YearMonth
case PROLEPTIC_MONTH: return plusMonths(newValue - getLong(PROLEPTIC_MONTH));
case YEAR_OF_ERA: return withYear((int) (year < 1 ? 1 - newValue : newValue));
case YEAR: return withYear((int) newValue);
- case ERA: return (getLong(ERA) == newValue ? this : withYear(1 - year));
+ case ERA: return getLong(ERA) == newValue ? this : withYear(1 - year);
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
@@ -751,7 +766,9 @@ public final class YearMonth
*/
@Override
public YearMonth minus(long amountToSubtract, TemporalUnit unit) {
- return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit));
+ return amountToSubtract == Long.MIN_VALUE
+ ? plus(Long.MAX_VALUE, unit).plus(1, unit)
+ : plus(-amountToSubtract, unit);
}
/**
@@ -764,7 +781,9 @@ public final class YearMonth
* @throws DateTimeException if the result exceeds the supported range
*/
public YearMonth minusYears(long yearsToSubtract) {
- return (yearsToSubtract == Long.MIN_VALUE ? plusYears(Long.MAX_VALUE).plusYears(1) : plusYears(-yearsToSubtract));
+ return yearsToSubtract == Long.MIN_VALUE
+ ? plusYears(Long.MAX_VALUE).plusYears(1)
+ : plusYears(-yearsToSubtract);
}
/**
@@ -777,7 +796,9 @@ public final class YearMonth
* @throws DateTimeException if the result exceeds the supported range
*/
public YearMonth minusMonths(long monthsToSubtract) {
- return (monthsToSubtract == Long.MIN_VALUE ? plusMonths(Long.MAX_VALUE).plusMonths(1) : plusMonths(-monthsToSubtract));
+ return monthsToSubtract == Long.MIN_VALUE
+ ? plusMonths(Long.MAX_VALUE).plusMonths(1)
+ : plusMonths(-monthsToSubtract);
}
//-----------------------------------------------------------------------
@@ -806,8 +827,9 @@ public final class YearMonth
return (R) IsoChronology.INSTANCE;
} else if (query == TemporalQueries.precision()) {
return (R) MONTHS;
- } else if (query == TemporalQueries.localDate() || query == TemporalQueries.localTime() ||
- query == TemporalQueries.zone() || query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) {
+ } else if (query == TemporalQueries.localDate() || query == TemporalQueries.localTime()
+ || query == TemporalQueries.zone() || query == TemporalQueries.zoneId()
+ || query == TemporalQueries.offset()) {
return null;
}
return Temporal.super.query(query);
@@ -841,7 +863,7 @@ public final class YearMonth
*/
@Override
public Temporal adjustInto(Temporal temporal) {
- if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) {
+ if (!Chronology.from(temporal).equals(IsoChronology.INSTANCE)) {
throw new DateTimeException("Adjustment only supported on ISO date-time");
}
return temporal.with(PROLEPTIC_MONTH, getProlepticMonth());
@@ -960,9 +982,9 @@ public final class YearMonth
*/
@Override
public int compareTo(YearMonth other) {
- int cmp = (year - other.year);
+ int cmp = year - other.year;
if (cmp == 0) {
- cmp = (month - other.month);
+ cmp = month - other.month;
}
return cmp;
}
diff --git a/classlib/src/main/java/org/threeten/bp/ZoneId.java b/classlib/src/main/java/org/threeten/bp/ZoneId.java
index c19fb1cea..706254d85 100644
--- a/classlib/src/main/java/org/threeten/bp/ZoneId.java
+++ b/classlib/src/main/java/org/threeten/bp/ZoneId.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -40,7 +55,6 @@ 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.temporal.TemporalAccessor;
@@ -275,7 +289,7 @@ public abstract class ZoneId implements Serializable {
Objects.requireNonNull(zoneId, "zoneId");
Objects.requireNonNull(aliasMap, "aliasMap");
String id = aliasMap.get(zoneId);
- id = (id != null ? id : zoneId);
+ id = id != null ? id : zoneId;
return of(id);
}
@@ -333,8 +347,8 @@ public abstract class ZoneId implements Serializable {
if (zoneId.equals("UTC") || zoneId.equals("GMT") || zoneId.equals("UT")) {
return new ZoneRegion(zoneId, ZoneOffset.UTC.getRules());
}
- if (zoneId.startsWith("UTC+") || zoneId.startsWith("GMT+") ||
- zoneId.startsWith("UTC-") || zoneId.startsWith("GMT-")) {
+ if (zoneId.startsWith("UTC+") || zoneId.startsWith("GMT+")
+ || zoneId.startsWith("UTC-") || zoneId.startsWith("GMT-")) {
ZoneOffset offset = ZoneOffset.of(zoneId.substring(3));
if (offset.getTotalSeconds() == 0) {
return new ZoneRegion(zoneId.substring(0, 3), offset.getRules());
@@ -399,8 +413,8 @@ public abstract class ZoneId implements Serializable {
public static ZoneId from(TemporalAccessor temporal) {
ZoneId obj = temporal.query(TemporalQueries.zone());
if (obj == null) {
- throw new DateTimeException("Unable to obtain ZoneId from TemporalAccessor: " +
- temporal + ", type " + temporal.getClass().getName());
+ throw new DateTimeException("Unable to obtain ZoneId from TemporalAccessor: "
+ + temporal + ", type " + temporal.getClass().getName());
}
return obj;
}
diff --git a/classlib/src/main/java/org/threeten/bp/ZoneOffset.java b/classlib/src/main/java/org/threeten/bp/ZoneOffset.java
index 419035d81..bcda00b34 100644
--- a/classlib/src/main/java/org/threeten/bp/ZoneOffset.java
+++ b/classlib/src/main/java/org/threeten/bp/ZoneOffset.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -32,12 +47,10 @@
package org.threeten.bp;
import static org.threeten.bp.temporal.ChronoField.OFFSET_SECONDS;
-
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
-
import org.threeten.bp.temporal.ChronoField;
import org.threeten.bp.temporal.Temporal;
import org.threeten.bp.temporal.TemporalAccessor;
@@ -169,7 +182,9 @@ public final class ZoneOffset
}
// parse - +h, +hh, +hhmm, +hh:mm, +hhmmss, +hh:mm:ss
- final int hours, minutes, seconds;
+ final int hours;
+ final int minutes;
+ final int seconds;
switch (offsetId.length()) {
case 2:
offsetId = offsetId.charAt(0) + "0" + offsetId.charAt(1); // fallthru
@@ -300,8 +315,8 @@ public final class ZoneOffset
public static ZoneOffset from(TemporalAccessor temporal) {
ZoneOffset offset = temporal.query(TemporalQueries.offset());
if (offset == null) {
- throw new DateTimeException("Unable to obtain ZoneOffset from TemporalAccessor: " +
- temporal + ", type " + temporal.getClass().getName());
+ throw new DateTimeException("Unable to obtain ZoneOffset from TemporalAccessor: "
+ + temporal + ", type " + temporal.getClass().getName());
}
return offset;
}
@@ -317,27 +332,29 @@ public final class ZoneOffset
*/
private static void validate(int hours, int minutes, int seconds) {
if (hours < -18 || hours > 18) {
- throw new DateTimeException("Zone offset hours not in valid range: value " + hours +
- " is not in the range -18 to 18");
+ throw new DateTimeException("Zone offset hours not in valid range: value "
+ + hours + " is not in the range -18 to 18");
}
if (hours > 0) {
if (minutes < 0 || seconds < 0) {
- throw new DateTimeException("Zone offset minutes and seconds must be positive because hours is positive");
+ throw new DateTimeException("Zone offset minutes and seconds must be positive because hours"
+ + " is positive");
}
} else if (hours < 0) {
if (minutes > 0 || seconds > 0) {
- throw new DateTimeException("Zone offset minutes and seconds must be negative because hours is negative");
+ throw new DateTimeException("Zone offset minutes and seconds must be negative because hours "
+ + "is negative");
}
} else if ((minutes > 0 && seconds < 0) || (minutes < 0 && seconds > 0)) {
throw new DateTimeException("Zone offset minutes and seconds must have the same sign");
}
if (Math.abs(minutes) > 59) {
- throw new DateTimeException("Zone offset minutes not in valid range: abs(value) " +
- Math.abs(minutes) + " is not in the range 0 to 59");
+ throw new DateTimeException("Zone offset minutes not in valid range: abs(value) "
+ + Math.abs(minutes) + " is not in the range 0 to 59");
}
if (Math.abs(seconds) > 59) {
- throw new DateTimeException("Zone offset seconds not in valid range: abs(value) " +
- Math.abs(seconds) + " is not in the range 0 to 59");
+ throw new DateTimeException("Zone offset seconds not in valid range: abs(value) "
+ + Math.abs(seconds) + " is not in the range 0 to 59");
}
if (Math.abs(hours) == 18 && (Math.abs(minutes) > 0 || Math.abs(seconds) > 0)) {
throw new DateTimeException("Zone offset not in valid range: -18:00 to +18:00");
@@ -608,8 +625,9 @@ public final class ZoneOffset
public R query(TemporalQuery query) {
if (query == TemporalQueries.offset() || query == TemporalQueries.zone()) {
return (R) this;
- } else if (query == TemporalQueries.localDate() || query == TemporalQueries.localTime() ||
- query == TemporalQueries.precision() || query == TemporalQueries.chronology() || query == TemporalQueries.zoneId()) {
+ } else if (query == TemporalQueries.localDate() || query == TemporalQueries.localTime()
+ || query == TemporalQueries.precision() || query == TemporalQueries.chronology()
+ || query == TemporalQueries.zoneId()) {
return null;
}
return query.queryFrom(this);
diff --git a/classlib/src/main/java/org/threeten/bp/ZoneRegion.java b/classlib/src/main/java/org/threeten/bp/ZoneRegion.java
index 9bc77691a..eda77149c 100644
--- a/classlib/src/main/java/org/threeten/bp/ZoneRegion.java
+++ b/classlib/src/main/java/org/threeten/bp/ZoneRegion.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -33,7 +48,6 @@ package org.threeten.bp;
import java.io.Serializable;
import java.util.Objects;
-
import java.util.regex.Pattern;
import org.threeten.bp.zone.ZoneRules;
import org.threeten.bp.zone.ZoneRulesException;
@@ -96,8 +110,8 @@ final class ZoneRegion extends ZoneId implements Serializable {
if (zoneId.equals("UTC") || zoneId.equals("GMT") || zoneId.equals("UT")) {
return new ZoneRegion(zoneId, ZoneOffset.UTC.getRules());
}
- if (zoneId.startsWith("UTC+") || zoneId.startsWith("GMT+") ||
- zoneId.startsWith("UTC-") || zoneId.startsWith("GMT-")) {
+ if (zoneId.startsWith("UTC+") || zoneId.startsWith("GMT+")
+ || zoneId.startsWith("UTC-") || zoneId.startsWith("GMT-")) {
ZoneOffset offset = ZoneOffset.of(zoneId.substring(3));
if (offset.getTotalSeconds() == 0) {
return new ZoneRegion(zoneId.substring(0, 3), offset.getRules());
@@ -165,6 +179,6 @@ final class ZoneRegion extends ZoneId implements Serializable {
public ZoneRules getRules() {
// additional query for group provider when null allows for possibility
// that the provider was added after the ZoneId was created
- return (rules != null ? rules : ZoneRulesProvider.getRules(id, false));
+ return rules != null ? rules : ZoneRulesProvider.getRules(id, false);
}
}
diff --git a/classlib/src/main/java/org/threeten/bp/ZonedDateTime.java b/classlib/src/main/java/org/threeten/bp/ZonedDateTime.java
index 7f4bf37c2..107f67485 100644
--- a/classlib/src/main/java/org/threeten/bp/ZonedDateTime.java
+++ b/classlib/src/main/java/org/threeten/bp/ZonedDateTime.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -34,11 +49,9 @@ package org.threeten.bp;
import static org.threeten.bp.temporal.ChronoField.INSTANT_SECONDS;
import static org.threeten.bp.temporal.ChronoField.NANO_OF_SECOND;
import static org.threeten.bp.temporal.ChronoField.OFFSET_SECONDS;
-
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;
@@ -397,7 +410,8 @@ public final class ZonedDateTime
*/
private static ZonedDateTime create(long epochSecond, int nanoOfSecond, ZoneId zone) {
ZoneRules rules = zone.getRules();
- Instant instant = Instant.ofEpochSecond(epochSecond, nanoOfSecond); // TODO: rules should be queryable by epochSeconds
+ // TODO: rules should be queryable by epochSeconds
+ Instant instant = Instant.ofEpochSecond(epochSecond, nanoOfSecond);
ZoneOffset offset = rules.getOffset(instant);
LocalDateTime ldt = LocalDateTime.ofEpochSecond(epochSecond, nanoOfSecond, offset);
return new ZonedDateTime(ldt, offset, zone);
@@ -422,17 +436,17 @@ public final class ZonedDateTime
Objects.requireNonNull(offset, "offset");
Objects.requireNonNull(zone, "zone");
ZoneRules rules = zone.getRules();
- if (rules.isValidOffset(localDateTime, offset) == false) {
+ if (!rules.isValidOffset(localDateTime, offset)) {
ZoneOffsetTransition trans = rules.getTransition(localDateTime);
if (trans != null && trans.isGap()) {
// error message says daylight savings for simplicity
// even though there are other kinds of gaps
- throw new DateTimeException("LocalDateTime '" + localDateTime +
- "' does not exist in zone '" + zone +
- "' due to a gap in the local time-line, typically caused by daylight savings");
+ throw new DateTimeException("LocalDateTime '" + localDateTime
+ + "' does not exist in zone '" + zone
+ + "' due to a gap in the local time-line, typically caused by daylight savings");
}
- throw new DateTimeException("ZoneOffset '" + offset + "' is not valid for LocalDateTime '" +
- localDateTime + "' in zone '" + zone + "'");
+ throw new DateTimeException("ZoneOffset '" + offset + "' is not valid for LocalDateTime '"
+ + localDateTime + "' in zone '" + zone + "'");
}
return new ZonedDateTime(localDateTime, offset, zone);
}
@@ -462,7 +476,7 @@ public final class ZonedDateTime
Objects.requireNonNull(localDateTime, "localDateTime");
Objects.requireNonNull(offset, "offset");
Objects.requireNonNull(zone, "zone");
- if (zone instanceof ZoneOffset && offset.equals(zone) == false) {
+ if (zone instanceof ZoneOffset && !offset.equals(zone)) {
throw new IllegalArgumentException("ZoneId must match ZoneOffset");
}
return new ZonedDateTime(localDateTime, offset, zone);
@@ -506,8 +520,8 @@ public final class ZonedDateTime
LocalDateTime ldt = LocalDateTime.from(temporal);
return of(ldt, zone);
} catch (DateTimeException ex) {
- throw new DateTimeException("Unable to obtain ZonedDateTime from TemporalAccessor: " +
- temporal + ", type " + temporal.getClass().getName());
+ throw new DateTimeException("Unable to obtain ZonedDateTime from TemporalAccessor: "
+ + temporal + ", type " + temporal.getClass().getName());
}
}
@@ -585,7 +599,7 @@ public final class ZonedDateTime
* @return the zoned date-time, not null
*/
private ZonedDateTime resolveOffset(ZoneOffset offset) {
- if (offset.equals(this.offset) == false && zone.getRules().isValidOffset(dateTime, offset)) {
+ if (!offset.equals(this.offset) && zone.getRules().isValidOffset(dateTime, offset)) {
return new ZonedDateTime(dateTime, offset, zone);
}
return this;
@@ -794,7 +808,7 @@ public final class ZonedDateTime
ZoneOffsetTransition trans = getZone().getRules().getTransition(dateTime);
if (trans != null && trans.isOverlap()) {
ZoneOffset earlierOffset = trans.getOffsetBefore();
- if (earlierOffset.equals(offset) == false) {
+ if (!earlierOffset.equals(offset)) {
return new ZonedDateTime(dateTime, earlierOffset, zone);
}
}
@@ -822,7 +836,7 @@ public final class ZonedDateTime
ZoneOffsetTransition trans = getZone().getRules().getTransition(toLocalDateTime());
if (trans != null) {
ZoneOffset laterOffset = trans.getOffsetAfter();
- if (laterOffset.equals(offset) == false) {
+ if (!laterOffset.equals(offset)) {
return new ZonedDateTime(dateTime, laterOffset, zone);
}
}
@@ -891,8 +905,7 @@ public final class ZonedDateTime
@Override
public ZonedDateTime withZoneSameInstant(ZoneId zone) {
Objects.requireNonNull(zone, "zone");
- return this.zone.equals(zone) ? this :
- create(dateTime.toEpochSecond(offset), dateTime.getNano(), zone);
+ return this.zone.equals(zone) ? this : create(dateTime.toEpochSecond(offset), dateTime.getNano(), zone);
}
/**
@@ -1676,7 +1689,9 @@ public final class ZonedDateTime
*/
@Override
public ZonedDateTime minus(long amountToSubtract, TemporalUnit unit) {
- return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit));
+ return amountToSubtract == Long.MIN_VALUE
+ ? plus(Long.MAX_VALUE, unit).plus(1, unit)
+ : plus(-amountToSubtract, unit);
}
//-----------------------------------------------------------------------
@@ -1699,7 +1714,7 @@ public final class ZonedDateTime
* @throws DateTimeException if the result exceeds the supported date range
*/
public ZonedDateTime minusYears(long years) {
- return (years == Long.MIN_VALUE ? plusYears(Long.MAX_VALUE).plusYears(1) : plusYears(-years));
+ return years == Long.MIN_VALUE ? plusYears(Long.MAX_VALUE).plusYears(1) : plusYears(-years);
}
/**
@@ -1721,7 +1736,7 @@ public final class ZonedDateTime
* @throws DateTimeException if the result exceeds the supported date range
*/
public ZonedDateTime minusMonths(long months) {
- return (months == Long.MIN_VALUE ? plusMonths(Long.MAX_VALUE).plusMonths(1) : plusMonths(-months));
+ return months == Long.MIN_VALUE ? plusMonths(Long.MAX_VALUE).plusMonths(1) : plusMonths(-months);
}
/**
@@ -1743,7 +1758,9 @@ public final class ZonedDateTime
* @throws DateTimeException if the result exceeds the supported date range
*/
public ZonedDateTime minusWeeks(long weeks) {
- return (weeks == Long.MIN_VALUE ? plusWeeks(Long.MAX_VALUE).plusWeeks(1) : plusWeeks(-weeks));
+ return weeks == Long.MIN_VALUE
+ ? plusWeeks(Long.MAX_VALUE).plusWeeks(1)
+ : plusWeeks(-weeks);
}
/**
@@ -1765,7 +1782,9 @@ public final class ZonedDateTime
* @throws DateTimeException if the result exceeds the supported date range
*/
public ZonedDateTime minusDays(long days) {
- return (days == Long.MIN_VALUE ? plusDays(Long.MAX_VALUE).plusDays(1) : plusDays(-days));
+ return days == Long.MIN_VALUE
+ ? plusDays(Long.MAX_VALUE).plusDays(1)
+ : plusDays(-days);
}
//-----------------------------------------------------------------------
@@ -1794,7 +1813,9 @@ public final class ZonedDateTime
* @throws DateTimeException if the result exceeds the supported date range
*/
public ZonedDateTime minusHours(long hours) {
- return (hours == Long.MIN_VALUE ? plusHours(Long.MAX_VALUE).plusHours(1) : plusHours(-hours));
+ return hours == Long.MIN_VALUE
+ ? plusHours(Long.MAX_VALUE).plusHours(1)
+ : plusHours(-hours);
}
/**
@@ -1812,7 +1833,9 @@ public final class ZonedDateTime
* @throws DateTimeException if the result exceeds the supported date range
*/
public ZonedDateTime minusMinutes(long minutes) {
- return (minutes == Long.MIN_VALUE ? plusMinutes(Long.MAX_VALUE).plusMinutes(1) : plusMinutes(-minutes));
+ return minutes == Long.MIN_VALUE
+ ? plusMinutes(Long.MAX_VALUE).plusMinutes(1)
+ : plusMinutes(-minutes);
}
/**
@@ -1830,7 +1853,9 @@ public final class ZonedDateTime
* @throws DateTimeException if the result exceeds the supported date range
*/
public ZonedDateTime minusSeconds(long seconds) {
- return (seconds == Long.MIN_VALUE ? plusSeconds(Long.MAX_VALUE).plusSeconds(1) : plusSeconds(-seconds));
+ return seconds == Long.MIN_VALUE
+ ? plusSeconds(Long.MAX_VALUE).plusSeconds(1)
+ : plusSeconds(-seconds);
}
/**
@@ -1848,7 +1873,9 @@ public final class ZonedDateTime
* @throws DateTimeException if the result exceeds the supported date range
*/
public ZonedDateTime minusNanos(long nanos) {
- return (nanos == Long.MIN_VALUE ? plusNanos(Long.MAX_VALUE).plusNanos(1) : plusNanos(-nanos));
+ return nanos == Long.MIN_VALUE
+ ? plusNanos(Long.MAX_VALUE).plusNanos(1)
+ : plusNanos(-nanos);
}
//-----------------------------------------------------------------------
@@ -2024,9 +2051,9 @@ public final class ZonedDateTime
}
if (obj instanceof ZonedDateTime) {
ZonedDateTime other = (ZonedDateTime) obj;
- return dateTime.equals(other.dateTime) &&
- offset.equals(other.offset) &&
- zone.equals(other.zone);
+ return dateTime.equals(other.dateTime)
+ && offset.equals(other.offset)
+ && zone.equals(other.zone);
}
return false;
}
@@ -2075,6 +2102,4 @@ public final class ZonedDateTime
public String format(DateTimeFormatter formatter) {
return super.format(formatter);
}
-
-
}
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/AbstractChronology.java b/classlib/src/main/java/org/threeten/bp/chrono/AbstractChronology.java
index c6f3d310a..c937cb14b 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/AbstractChronology.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/AbstractChronology.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/ChronoDateImpl.java b/classlib/src/main/java/org/threeten/bp/chrono/ChronoDateImpl.java
index 3c5e0df10..6075a6289 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/ChronoDateImpl.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/ChronoDateImpl.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -32,7 +47,6 @@
package org.threeten.bp.chrono;
import java.io.Serializable;
-
import org.threeten.bp.DateTimeException;
import org.threeten.bp.LocalDate;
import org.threeten.bp.LocalTime;
@@ -98,7 +112,7 @@ import org.threeten.bp.temporal.TemporalUnit;
* {@code Chronology} must be registered as a Service implementing the {@code Chronology} interface
* in the {@code META-INF/Services} file as per the specification of {@link java.util.ServiceLoader}.
* The subclass must function according to the {@code Chronology} class description and must provide its
- * {@link Chronology#getID calendar name} and
+ * {@link Chronology#getId()} calendar name} and
* {@link Chronology#getCalendarType() calendar type}.
*
*
Specification for implementors
@@ -132,7 +146,8 @@ abstract class ChronoDateImpl
case DECADES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 10));
case CENTURIES: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 100));
case MILLENNIA: return plusYears(Jdk8Methods.safeMultiply(amountToAdd, 1000));
-// case ERAS: throw new DateTimeException("Unable to add era, standard calendar system only has one era");
+// case ERAS: throw new DateTimeException("Unable to add era,
+// standard calendar system only has one era");
// case FOREVER: return (period == 0 ? this : (period > 0 ? LocalDate.MAX_DATE : LocalDate.MIN_DATE));
}
throw new DateTimeException(unit + " not valid for chronology " + getChronology().getId());
@@ -223,7 +238,9 @@ abstract class ChronoDateImpl
* @throws DateTimeException if the result exceeds the supported date range
*/
ChronoDateImpl minusYears(long yearsToSubtract) {
- return (yearsToSubtract == Long.MIN_VALUE ? plusYears(Long.MAX_VALUE).plusYears(1) : plusYears(-yearsToSubtract));
+ return yearsToSubtract == Long.MIN_VALUE
+ ? plusYears(Long.MAX_VALUE).plusYears(1)
+ : plusYears(-yearsToSubtract);
}
/**
@@ -243,7 +260,9 @@ abstract class ChronoDateImpl
* @throws DateTimeException if the result exceeds the supported date range
*/
ChronoDateImpl minusMonths(long monthsToSubtract) {
- return (monthsToSubtract == Long.MIN_VALUE ? plusMonths(Long.MAX_VALUE).plusMonths(1) : plusMonths(-monthsToSubtract));
+ return monthsToSubtract == Long.MIN_VALUE
+ ? plusMonths(Long.MAX_VALUE).plusMonths(1)
+ : plusMonths(-monthsToSubtract);
}
/**
@@ -262,7 +281,9 @@ abstract class ChronoDateImpl
* @throws DateTimeException if the result exceeds the supported date range
*/
ChronoDateImpl minusWeeks(long weeksToSubtract) {
- return (weeksToSubtract == Long.MIN_VALUE ? plusWeeks(Long.MAX_VALUE).plusWeeks(1) : plusWeeks(-weeksToSubtract));
+ return weeksToSubtract == Long.MIN_VALUE
+ ? plusWeeks(Long.MAX_VALUE).plusWeeks(1)
+ : plusWeeks(-weeksToSubtract);
}
/**
@@ -279,7 +300,9 @@ abstract class ChronoDateImpl
* @throws DateTimeException if the result exceeds the supported date range
*/
ChronoDateImpl minusDays(long daysToSubtract) {
- return (daysToSubtract == Long.MIN_VALUE ? plusDays(Long.MAX_VALUE).plusDays(1) : plusDays(-daysToSubtract));
+ return daysToSubtract == Long.MIN_VALUE
+ ? plusDays(Long.MAX_VALUE).plusDays(1)
+ : plusDays(-daysToSubtract);
}
@Override
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 96652bd4e..7c9435aa6 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/ChronoLocalDate.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/ChronoLocalDate.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -37,7 +52,6 @@ import static org.threeten.bp.temporal.ChronoField.ERA;
import static org.threeten.bp.temporal.ChronoField.MONTH_OF_YEAR;
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;
@@ -338,7 +352,7 @@ public abstract class ChronoLocalDate
* @return the length of the year in days
*/
public int lengthOfYear() {
- return (isLeapYear() ? 366 : 365);
+ return isLeapYear() ? 366 : 365;
}
@Override
@@ -395,8 +409,8 @@ public abstract class ChronoLocalDate
return (R) ChronoUnit.DAYS;
} else if (query == TemporalQueries.localDate()) {
return (R) LocalDate.ofEpochDay(toEpochDay());
- } else if (query == TemporalQueries.localTime() || query == TemporalQueries.zone() ||
- query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) {
+ } else if (query == TemporalQueries.localTime() || query == TemporalQueries.zone()
+ || query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) {
return null;
}
return Temporal.super.query(query);
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 592e16066..a47233c60 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/ChronoLocalDateTime.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/ChronoLocalDateTime.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -34,10 +49,8 @@ package org.threeten.bp.chrono;
import static org.threeten.bp.temporal.ChronoField.EPOCH_DAY;
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;
import org.threeten.bp.LocalDate;
@@ -169,7 +182,7 @@ public abstract class ChronoLocalDateTime
*
* @return the date part of this date-time, not null
*/
- public abstract D toLocalDate() ;
+ public abstract D toLocalDate();
/**
* Gets the local time part of this date-time.
@@ -221,7 +234,8 @@ public abstract class ChronoLocalDateTime
return (R) LocalDate.ofEpochDay(toLocalDate().toEpochDay());
} else if (query == TemporalQueries.localTime()) {
return (R) toLocalTime();
- } else if (query == TemporalQueries.zone() || query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) {
+ } else if (query == TemporalQueries.zone() || query == TemporalQueries.zoneId()
+ || query == TemporalQueries.offset()) {
return null;
}
return Temporal.super.query(query);
@@ -367,8 +381,8 @@ public abstract class ChronoLocalDateTime
public boolean isAfter(ChronoLocalDateTime> other) {
long thisEpDay = this.toLocalDate().toEpochDay();
long otherEpDay = other.toLocalDate().toEpochDay();
- return thisEpDay > otherEpDay ||
- (thisEpDay == otherEpDay && this.toLocalTime().toNanoOfDay() > other.toLocalTime().toNanoOfDay());
+ return thisEpDay > otherEpDay
+ || (thisEpDay == otherEpDay && this.toLocalTime().toNanoOfDay() > other.toLocalTime().toNanoOfDay());
}
/**
@@ -385,8 +399,8 @@ public abstract class ChronoLocalDateTime
public boolean isBefore(ChronoLocalDateTime> other) {
long thisEpDay = this.toLocalDate().toEpochDay();
long otherEpDay = other.toLocalDate().toEpochDay();
- return thisEpDay < otherEpDay ||
- (thisEpDay == otherEpDay && this.toLocalTime().toNanoOfDay() < other.toLocalTime().toNanoOfDay());
+ return thisEpDay < otherEpDay
+ || (thisEpDay == otherEpDay && this.toLocalTime().toNanoOfDay() < other.toLocalTime().toNanoOfDay());
}
/**
@@ -402,8 +416,8 @@ public abstract class ChronoLocalDateTime
*/
public boolean isEqual(ChronoLocalDateTime> other) {
// Do the time check first, it is cheaper than computing EPOCH day.
- return this.toLocalTime().toNanoOfDay() == other.toLocalTime().toNanoOfDay() &&
- this.toLocalDate().toEpochDay() == other.toLocalDate().toEpochDay();
+ return this.toLocalTime().toNanoOfDay() == other.toLocalTime().toNanoOfDay()
+ && this.toLocalDate().toEpochDay() == other.toLocalDate().toEpochDay();
}
//-----------------------------------------------------------------------
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 64cfb887b..6c952b4eb 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/ChronoLocalDateTimeImpl.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/ChronoLocalDateTimeImpl.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -32,10 +47,8 @@
package org.threeten.bp.chrono;
import static org.threeten.bp.temporal.ChronoField.EPOCH_DAY;
-
import java.io.Serializable;
import java.util.Objects;
-
import org.threeten.bp.LocalTime;
import org.threeten.bp.ZoneId;
import org.threeten.bp.jdk8.Jdk8Methods;
@@ -198,7 +211,7 @@ final class ChronoLocalDateTimeImpl
@Override
public ValueRange range(TemporalField field) {
if (field instanceof ChronoField) {
- return (field.isTimeBased() ? time.range(field) : date.range(field));
+ return field.isTimeBased() ? time.range(field) : date.range(field);
}
return field.rangeRefinedBy(this);
}
@@ -206,7 +219,7 @@ final class ChronoLocalDateTimeImpl
@Override
public int get(TemporalField field) {
if (field instanceof ChronoField) {
- return (field.isTimeBased() ? time.get(field) : date.get(field));
+ return field.isTimeBased() ? time.get(field) : date.get(field);
}
return range(field).checkValidIntValue(getLong(field), field);
}
@@ -214,7 +227,7 @@ final class ChronoLocalDateTimeImpl
@Override
public long getLong(TemporalField field) {
if (field instanceof ChronoField) {
- return (field.isTimeBased() ? time.getLong(field) : date.getLong(field));
+ return field.isTimeBased() ? time.getLong(field) : date.getLong(field);
}
return field.getFrom(this);
}
@@ -252,12 +265,16 @@ final class ChronoLocalDateTimeImpl
ChronoUnit f = (ChronoUnit) unit;
switch (f) {
case NANOS: return plusNanos(amountToAdd);
- case MICROS: return plusDays(amountToAdd / MICROS_PER_DAY).plusNanos((amountToAdd % MICROS_PER_DAY) * 1000);
- case MILLIS: return plusDays(amountToAdd / MILLIS_PER_DAY).plusNanos((amountToAdd % MILLIS_PER_DAY) * 1000000);
+ case MICROS: return plusDays(amountToAdd / MICROS_PER_DAY)
+ .plusNanos((amountToAdd % MICROS_PER_DAY) * 1000);
+ case MILLIS: return plusDays(amountToAdd / MILLIS_PER_DAY)
+ .plusNanos((amountToAdd % MILLIS_PER_DAY) * 1000000);
case SECONDS: return plusSeconds(amountToAdd);
case MINUTES: return plusMinutes(amountToAdd);
case HOURS: return plusHours(amountToAdd);
- case HALF_DAYS: return plusDays(amountToAdd / 256).plusHours((amountToAdd % 256) * 12); // no overflow (256 is multiple of 2)
+ case HALF_DAYS:
+ // no overflow (256 is multiple of 2)
+ return plusDays(amountToAdd / 256).plusHours((amountToAdd % 256) * 12);
}
return with(date.plus(amountToAdd, unit), time);
}
@@ -302,7 +319,7 @@ final class ChronoLocalDateTimeImpl
totNanos = totNanos + curNoD; // total 432000000000000
totDays += Jdk8Methods.floorDiv(totNanos, NANOS_PER_DAY);
long newNoD = Jdk8Methods.floorMod(totNanos, NANOS_PER_DAY);
- LocalTime newTime = (newNoD == curNoD ? time : LocalTime.ofNanoOfDay(newNoD));
+ LocalTime newTime = newNoD == curNoD ? time : LocalTime.ofNanoOfDay(newNoD);
return with(newDate.plus(totDays, ChronoUnit.DAYS), newTime);
}
@@ -340,5 +357,4 @@ final class ChronoLocalDateTimeImpl
}
return unit.between(this, end);
}
-
}
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 1361c6ff2..49d1ac556 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/ChronoPeriod.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/ChronoPeriod.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -33,7 +48,6 @@ package org.threeten.bp.chrono;
import java.util.List;
import java.util.Objects;
-
import org.threeten.bp.DateTimeException;
import org.threeten.bp.temporal.ChronoUnit;
import org.threeten.bp.temporal.Temporal;
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 af41963bc..da9278f3d 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/ChronoPeriodImpl.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/ChronoPeriodImpl.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -34,13 +49,11 @@ package org.threeten.bp.chrono;
import static org.threeten.bp.temporal.ChronoUnit.DAYS;
import static org.threeten.bp.temporal.ChronoUnit.MONTHS;
import static org.threeten.bp.temporal.ChronoUnit.YEARS;
-
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;
import org.threeten.bp.temporal.ChronoField;
@@ -137,7 +150,8 @@ final class ChronoPeriodImpl
@Override
public ChronoPeriod normalized() {
if (chronology.range(ChronoField.MONTH_OF_YEAR).isFixed()) {
- long monthLength = chronology.range(ChronoField.MONTH_OF_YEAR).getMaximum() - chronology.range(ChronoField.MONTH_OF_YEAR).getMinimum() + 1;
+ long monthLength = chronology.range(ChronoField.MONTH_OF_YEAR).getMaximum()
+ - chronology.range(ChronoField.MONTH_OF_YEAR).getMinimum() + 1;
long total = years * monthLength + months;
int years = Jdk8Methods.safeToInt(total / monthLength);
int months = Jdk8Methods.safeToInt(total % monthLength);
@@ -150,8 +164,9 @@ final class ChronoPeriodImpl
public Temporal addTo(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());
+ if (temporalChrono != null && !chronology.equals(temporalChrono)) {
+ throw new DateTimeException("Invalid chronology, required: " + chronology.getId() + ", but was: "
+ + temporalChrono.getId());
}
if (years != 0) {
temporal = temporal.plus(years, YEARS);
@@ -169,8 +184,9 @@ final class ChronoPeriodImpl
public Temporal subtractFrom(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());
+ if (temporalChrono != null && !chronology.equals(temporalChrono)) {
+ throw new DateTimeException("Invalid chronology, required: " + chronology.getId()
+ + ", but was: " + temporalChrono.getId());
}
if (years != 0) {
temporal = temporal.minus(years, YEARS);
@@ -192,8 +208,8 @@ final class ChronoPeriodImpl
}
if (obj instanceof ChronoPeriodImpl) {
ChronoPeriodImpl other = (ChronoPeriodImpl) obj;
- return years == other.years && months == other.months &&
- days == other.days && chronology.equals(other.chronology);
+ return years == other.years && months == other.months
+ && days == other.days && chronology.equals(other.chronology);
}
return false;
}
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 9f7ed9523..c2b612bf1 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/ChronoZonedDateTime.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/ChronoZonedDateTime.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -34,11 +49,9 @@ package org.threeten.bp.chrono;
import static org.threeten.bp.temporal.ChronoField.INSTANT_SECONDS;
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;
import org.threeten.bp.LocalDate;
@@ -166,8 +179,10 @@ public abstract class ChronoZonedDateTime
public int get(TemporalField field) {
if (field instanceof ChronoField) {
switch ((ChronoField) field) {
- case INSTANT_SECONDS: throw new UnsupportedTemporalTypeException("Field too large for an int: " + field);
- case OFFSET_SECONDS: return getOffset().getTotalSeconds();
+ case INSTANT_SECONDS:
+ throw new UnsupportedTemporalTypeException("Field too large for an int: " + field);
+ case OFFSET_SECONDS:
+ return getOffset().getTotalSeconds();
}
return toLocalDateTime().get(field);
}
@@ -468,8 +483,8 @@ public abstract class ChronoZonedDateTime
public boolean isAfter(ChronoZonedDateTime> other) {
long thisEpochSec = toEpochSecond();
long otherEpochSec = other.toEpochSecond();
- return thisEpochSec > otherEpochSec ||
- (thisEpochSec == otherEpochSec && toLocalTime().getNano() > other.toLocalTime().getNano());
+ return thisEpochSec > otherEpochSec
+ || (thisEpochSec == otherEpochSec && toLocalTime().getNano() > other.toLocalTime().getNano());
}
/**
@@ -485,8 +500,8 @@ public abstract class ChronoZonedDateTime
public boolean isBefore(ChronoZonedDateTime> other) {
long thisEpochSec = toEpochSecond();
long otherEpochSec = other.toEpochSecond();
- return thisEpochSec < otherEpochSec ||
- (thisEpochSec == otherEpochSec && toLocalTime().getNano() < other.toLocalTime().getNano());
+ return thisEpochSec < otherEpochSec
+ || (thisEpochSec == otherEpochSec && toLocalTime().getNano() < other.toLocalTime().getNano());
}
/**
@@ -500,8 +515,8 @@ public abstract class ChronoZonedDateTime
* @return true if the instant equals the instant of the specified date-time
*/
public boolean isEqual(ChronoZonedDateTime> other) {
- return toEpochSecond() == other.toEpochSecond() &&
- toLocalTime().getNano() == other.toLocalTime().getNano();
+ return toEpochSecond() == other.toEpochSecond()
+ && toLocalTime().getNano() == other.toLocalTime().getNano();
}
//-----------------------------------------------------------------------
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 5ebb7f442..e5a9db520 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/ChronoZonedDateTimeImpl.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/ChronoZonedDateTimeImpl.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -32,11 +47,9 @@
package org.threeten.bp.chrono;
import static org.threeten.bp.temporal.ChronoUnit.SECONDS;
-
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;
@@ -127,7 +140,8 @@ final class ChronoZonedDateTimeImpl
* @param zone the zone identifier, not null
* @return the zoned date-time, not null
*/
- static ChronoZonedDateTimeImpl ofInstant(Chronology chrono, Instant instant, ZoneId zone) {
+ static ChronoZonedDateTimeImpl ofInstant(Chronology chrono, Instant instant,
+ ZoneId zone) {
ZoneRules rules = zone.getRules();
ZoneOffset offset = rules.getOffset(instant);
Objects.requireNonNull(offset, "offset"); // protect against bad ZoneRules
@@ -171,6 +185,7 @@ final class ChronoZonedDateTimeImpl
return unit != null && unit.isSupportedBy(this);
}
+ @Override
public ZoneOffset getOffset() {
return offset;
}
@@ -180,8 +195,8 @@ final class ChronoZonedDateTimeImpl
ZoneOffsetTransition trans = getZone().getRules().getTransition(LocalDateTime.from(this));
if (trans != null && trans.isOverlap()) {
ZoneOffset earlierOffset = trans.getOffsetBefore();
- if (earlierOffset.equals(offset) == false) {
- return new ChronoZonedDateTimeImpl(dateTime, earlierOffset, zone);
+ if (!earlierOffset.equals(offset)) {
+ return new ChronoZonedDateTimeImpl<>(dateTime, earlierOffset, zone);
}
}
return this;
@@ -192,7 +207,7 @@ final class ChronoZonedDateTimeImpl
ZoneOffsetTransition trans = getZone().getRules().getTransition(LocalDateTime.from(this));
if (trans != null) {
ZoneOffset offset = trans.getOffsetAfter();
- if (offset.equals(getOffset()) == false) {
+ if (!offset.equals(getOffset())) {
return new ChronoZonedDateTimeImpl<>(dateTime, offset, zone);
}
}
@@ -205,10 +220,12 @@ final class ChronoZonedDateTimeImpl
return dateTime;
}
+ @Override
public ZoneId getZone() {
return zone;
}
+ @Override
public ChronoZonedDateTime withZoneSameLocal(ZoneId zone) {
return ofBest(dateTime, zone, offset);
}
@@ -248,7 +265,8 @@ final class ChronoZonedDateTimeImpl
if (unit instanceof ChronoUnit) {
return with(dateTime.plus(amountToAdd, unit));
}
- return toLocalDate().getChronology().ensureChronoZonedDateTime(unit.addTo(this, amountToAdd)); /// TODO: Generics replacement Risk!
+ /// TODO: Generics replacement Risk!
+ return toLocalDate().getChronology().ensureChronoZonedDateTime(unit.addTo(this, amountToAdd));
}
//-----------------------------------------------------------------------
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 743b88927..ee28add6d 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/Chronology.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/Chronology.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -39,7 +54,6 @@ import java.util.Map;
import java.util.Objects;
import java.util.ServiceLoader;
import java.util.Set;
-
import org.threeten.bp.Clock;
import org.threeten.bp.DateTimeException;
import org.threeten.bp.Instant;
@@ -161,7 +175,7 @@ public abstract class Chronology implements Comparable {
public static Chronology from(TemporalAccessor temporal) {
Objects.requireNonNull(temporal, "temporal");
Chronology obj = temporal.query(TemporalQueries.chronology());
- return (obj != null ? obj : IsoChronology.INSTANCE);
+ return obj != null ? obj : IsoChronology.INSTANCE;
}
//-----------------------------------------------------------------------
@@ -315,8 +329,9 @@ public abstract class Chronology implements Comparable {
D ensureChronoLocalDate(Temporal temporal) {
@SuppressWarnings("unchecked")
D other = (D) temporal;
- if (this.equals(other.getChronology()) == false) {
- throw new ClassCastException("Chrono mismatch, expected: " + getId() + ", actual: " + other.getChronology().getId());
+ if (!this.equals(other.getChronology())) {
+ throw new ClassCastException("Chrono mismatch, expected: " + getId() + ", actual: "
+ + other.getChronology().getId());
}
return other;
}
@@ -332,7 +347,7 @@ public abstract class Chronology implements Comparable {
ChronoLocalDateTimeImpl ensureChronoLocalDateTime(Temporal temporal) {
@SuppressWarnings("unchecked")
ChronoLocalDateTimeImpl other = (ChronoLocalDateTimeImpl) temporal;
- if (this.equals(other.toLocalDate().getChronology()) == false) {
+ if (!this.equals(other.toLocalDate().getChronology())) {
throw new ClassCastException("Chrono mismatch, required: " + getId()
+ ", supplied: " + other.toLocalDate().getChronology().getId());
}
@@ -347,10 +362,11 @@ public abstract class Chronology implements Comparable {
* @throws ClassCastException if the date-time cannot be cast to ChronoZonedDateTimeImpl
* or the chronology is not equal this Chrono
*/
+ @SuppressWarnings("checkstyle:SimplifyBooleanExpression")
ChronoZonedDateTimeImpl ensureChronoZonedDateTime(Temporal temporal) {
@SuppressWarnings("unchecked")
ChronoZonedDateTimeImpl other = (ChronoZonedDateTimeImpl) temporal;
- if (this.equals(other.toLocalDate().getChronology()) == false) {
+ if (!this.equals(other.toLocalDate().getChronology())) {
throw new ClassCastException("Chrono mismatch, required: " + getId()
+ ", supplied: " + other.toLocalDate().getChronology().getId());
}
@@ -536,7 +552,8 @@ public abstract class Chronology implements Comparable {
ChronoLocalDate date = date(temporal);
return date.atTime(LocalTime.from(temporal));
} catch (DateTimeException ex) {
- throw new DateTimeException("Unable to obtain ChronoLocalDateTime from TemporalAccessor: " + temporal.getClass(), ex);
+ throw new DateTimeException("Unable to obtain ChronoLocalDateTime from TemporalAccessor: "
+ + temporal.getClass(), ex);
}
}
@@ -567,7 +584,8 @@ public abstract class Chronology implements Comparable {
return ChronoZonedDateTimeImpl.ofBest(cldtImpl, zone, null);
}
} catch (DateTimeException ex) {
- throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass(), ex);
+ throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: "
+ + temporal.getClass(), ex);
}
}
@@ -582,8 +600,7 @@ public abstract class Chronology implements Comparable {
* @throws DateTimeException if the result exceeds the supported range
*/
public ChronoZonedDateTime> zonedDateTime(Instant instant, ZoneId zone) {
- ChronoZonedDateTime extends ChronoLocalDate> result = ChronoZonedDateTimeImpl.ofInstant(this, instant, zone);
- return result;
+ return ChronoZonedDateTimeImpl.ofInstant(this, instant, zone);
}
//-----------------------------------------------------------------------
@@ -760,8 +777,9 @@ public abstract class Chronology implements Comparable {
*/
void updateResolveMap(Map fieldValues, ChronoField field, long value) {
Long current = fieldValues.get(field);
- if (current != null && current.longValue() != value) {
- throw new DateTimeException("Invalid state, field: " + field + " " + current + " conflicts with " + field + " " + value);
+ if (current != null && current != value) {
+ throw new DateTimeException("Invalid state, field: " + field + " " + current + " conflicts with "
+ + field + " " + value);
}
fieldValues.put(field, value);
}
@@ -829,5 +847,4 @@ public abstract class Chronology implements Comparable {
public String toString() {
return getId();
}
-
}
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 17c0f7b4d..0f42503d1 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/Era.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/Era.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
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 22e6230a8..6f1db05e2 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/HijrahChronology.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/HijrahChronology.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -49,7 +64,6 @@ import static org.threeten.bp.temporal.ChronoUnit.DAYS;
import static org.threeten.bp.temporal.ChronoUnit.MONTHS;
import static org.threeten.bp.temporal.ChronoUnit.WEEKS;
import static org.threeten.bp.temporal.TemporalAdjusters.nextOrSame;
-
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
@@ -57,7 +71,6 @@ 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;
import org.threeten.bp.DayOfWeek;
@@ -331,10 +344,10 @@ public final class HijrahChronology extends Chronology implements Serializable {
@Override
public int prolepticYear(Era era, int yearOfEra) {
- if (era instanceof HijrahEra == false) {
+ if (!(era instanceof HijrahEra)) {
throw new ClassCastException("Era must be HijrahEra");
}
- return (era == HijrahEra.AH ? yearOfEra : 1 - yearOfEra);
+ return era == HijrahEra.AH ? yearOfEra : 1 - yearOfEra;
}
@Override
@@ -388,18 +401,19 @@ public final class HijrahChronology extends Chronology implements Serializable {
if (resolverStyle == ResolverStyle.STRICT) {
// do not invent era if strict, but do cross-check with year
if (year != null) {
- updateResolveMap(fieldValues, YEAR, (year > 0 ? yoeLong: Jdk8Methods.safeSubtract(1, yoeLong)));
+ updateResolveMap(fieldValues, YEAR, year > 0 ? yoeLong : Jdk8Methods.safeSubtract(1, yoeLong));
} else {
// reinstate the field removed earlier, no cross-check issues
fieldValues.put(YEAR_OF_ERA, yoeLong);
}
} else {
// invent era
- updateResolveMap(fieldValues, YEAR, (year == null || year > 0 ? yoeLong: Jdk8Methods.safeSubtract(1, yoeLong)));
+ updateResolveMap(fieldValues, YEAR,
+ year == null || year > 0 ? yoeLong : Jdk8Methods.safeSubtract(1, yoeLong));
}
- } else if (era.longValue() == 1L) {
+ } else if (era == 1L) {
updateResolveMap(fieldValues, YEAR, yoeLong);
- } else if (era.longValue() == 0L) {
+ } else if (era == 0L) {
updateResolveMap(fieldValues, YEAR, Jdk8Methods.safeSubtract(1, yoeLong));
} else {
throw new DateTimeException("Invalid value for era: " + era);
@@ -418,8 +432,10 @@ public final class HijrahChronology extends Chronology implements Serializable {
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_MONTH), 1);
return date(y, 1, 1).plusMonths(months).plusDays(days);
} else {
- int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
- int dom = range(DAY_OF_MONTH).checkValidIntValue(fieldValues.remove(DAY_OF_MONTH), DAY_OF_MONTH);
+ int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR),
+ MONTH_OF_YEAR);
+ int dom = range(DAY_OF_MONTH).checkValidIntValue(fieldValues.remove(DAY_OF_MONTH),
+ DAY_OF_MONTH);
if (resolverStyle == ResolverStyle.SMART && dom > 28) {
dom = Math.min(dom, date(y, moy, 1).lengthOfMonth());
}
@@ -437,7 +453,8 @@ public final class HijrahChronology extends Chronology implements Serializable {
}
int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR));
int aw = ALIGNED_WEEK_OF_MONTH.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_MONTH));
- int ad = ALIGNED_DAY_OF_WEEK_IN_MONTH.checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH));
+ int ad = ALIGNED_DAY_OF_WEEK_IN_MONTH.checkValidIntValue(
+ fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH));
HijrahDate date = date(y, moy, 1).plus((aw - 1) * 7 + (ad - 1), DAYS);
if (resolverStyle == ResolverStyle.STRICT && date.get(MONTH_OF_YEAR) != moy) {
throw new DateTimeException("Strict mode rejected date parsed to a different month");
@@ -481,7 +498,8 @@ public final class HijrahChronology extends Chronology implements Serializable {
return date(y, 1, 1).plus(weeks, WEEKS).plus(days, DAYS);
}
int aw = ALIGNED_WEEK_OF_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR));
- int ad = ALIGNED_DAY_OF_WEEK_IN_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR));
+ int ad = ALIGNED_DAY_OF_WEEK_IN_YEAR.checkValidIntValue(
+ fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR));
HijrahDate date = date(y, 1, 1).plusDays((aw - 1) * 7 + (ad - 1));
if (resolverStyle == ResolverStyle.STRICT && date.get(YEAR) != y) {
throw new DateTimeException("Strict mode rejected date parsed to a different year");
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 90a5bd83c..e0ceb1932 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/HijrahDate.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/HijrahDate.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -35,7 +50,6 @@ import static org.threeten.bp.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH;
import static org.threeten.bp.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR;
import static org.threeten.bp.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH;
import static org.threeten.bp.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR;
-
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
@@ -49,7 +63,6 @@ import java.util.Objects;
import java.util.StringTokenizer;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
-
import org.threeten.bp.Clock;
import org.threeten.bp.DateTimeException;
import org.threeten.bp.DayOfWeek;
@@ -124,22 +137,22 @@ public final class HijrahDate
* 0-based, for number of day-of-year in the beginning of month in normal
* year.
*/
- private static final int NUM_DAYS[] =
+ private static final int[] NUM_DAYS =
{0, 30, 59, 89, 118, 148, 177, 207, 236, 266, 295, 325};
/**
* 0-based, for number of day-of-year in the beginning of month in leap year.
*/
- private static final int LEAP_NUM_DAYS[] =
+ private static final int[] LEAP_NUM_DAYS =
{0, 30, 59, 89, 118, 148, 177, 207, 236, 266, 295, 325};
/**
* 0-based, for day-of-month in normal year.
*/
- private static final int MONTH_LENGTH[] =
+ private static final int[] MONTH_LENGTH =
{30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 30, 29};
/**
* 0-based, for day-of-month in leap year.
*/
- private static final int LEAP_MONTH_LENGTH[] =
+ private static final int[] LEAP_MONTH_LENGTH =
{30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 30, 30};
/**
@@ -156,7 +169,7 @@ public final class HijrahDate
*
* Minimum values.
*/
- private static final int MIN_VALUES[] =
+ private static final int[] MIN_VALUES =
{
0,
MIN_VALUE_OF_ERA,
@@ -170,7 +183,7 @@ public final class HijrahDate
/**
* Least maximum values.
*/
- private static final int LEAST_MAX_VALUES[] =
+ private static final int[] LEAST_MAX_VALUES =
{
1,
MAX_VALUE_OF_ERA,
@@ -184,7 +197,7 @@ public final class HijrahDate
/**
* Maximum values.
*/
- private static final int MAX_VALUES[] =
+ private static final int[] MAX_VALUES =
{
1,
MAX_VALUE_OF_ERA,
@@ -208,7 +221,7 @@ public final class HijrahDate
/**
* Zero-based start date of cycle year.
*/
- private static final int CYCLEYEAR_START_DATE[] =
+ private static final int[] CYCLEYEAR_START_DATE =
{
0,
354,
@@ -257,23 +270,24 @@ public final class HijrahDate
/**
* Default path to the config file.
*/
- private static final String DEFAULT_CONFIG_PATH = "org" + FILE_SEP + "threeten" + FILE_SEP + "bp" + FILE_SEP + "chrono";
+ private static final String DEFAULT_CONFIG_PATH = "org" + FILE_SEP + "threeten" + FILE_SEP + "bp"
+ + FILE_SEP + "chrono";
/**
* Holding the adjusted month days in year. The key is a year (Integer) and
* the value is the all the month days in year (Integer[]).
*/
- private static final HashMap ADJUSTED_MONTH_DAYS = new HashMap();
+ private static final HashMap ADJUSTED_MONTH_DAYS = new HashMap<>();
/**
* Holding the adjusted month length in year. The key is a year (Integer)
* and the value is the all the month length in year (Integer[]).
*/
- private static final HashMap ADJUSTED_MONTH_LENGTHS = new HashMap();
+ private static final HashMap ADJUSTED_MONTH_LENGTHS = new HashMap<>();
/**
* Holding the adjusted days in the 30 year cycle. The key is a cycle number
* (Integer) and the value is the all the starting days of the year in the
* cycle (Integer[]).
*/
- private static final HashMap ADJUSTED_CYCLE_YEARS = new HashMap();
+ private static final HashMap ADJUSTED_CYCLE_YEARS = new HashMap<>();
/**
* Holding the adjusted cycle in the 1 - 30000 year. The key is the cycle
* number (Integer) and the value is the starting days in the cycle in the
@@ -321,52 +335,49 @@ public final class HijrahDate
DEFAULT_MONTH_DAYS = new Integer[NUM_DAYS.length];
for (int i = 0; i < NUM_DAYS.length; i++) {
- DEFAULT_MONTH_DAYS[i] = Integer.valueOf(NUM_DAYS[i]);
+ DEFAULT_MONTH_DAYS[i] = NUM_DAYS[i];
}
DEFAULT_LEAP_MONTH_DAYS = new Integer[LEAP_NUM_DAYS.length];
for (int i = 0; i < LEAP_NUM_DAYS.length; i++) {
- DEFAULT_LEAP_MONTH_DAYS[i] = Integer.valueOf(LEAP_NUM_DAYS[i]);
+ DEFAULT_LEAP_MONTH_DAYS[i] = LEAP_NUM_DAYS[i];
}
DEFAULT_MONTH_LENGTHS = new Integer[MONTH_LENGTH.length];
for (int i = 0; i < MONTH_LENGTH.length; i++) {
- DEFAULT_MONTH_LENGTHS[i] = Integer.valueOf(MONTH_LENGTH[i]);
+ DEFAULT_MONTH_LENGTHS[i] = MONTH_LENGTH[i];
}
DEFAULT_LEAP_MONTH_LENGTHS = new Integer[LEAP_MONTH_LENGTH.length];
for (int i = 0; i < LEAP_MONTH_LENGTH.length; i++) {
- DEFAULT_LEAP_MONTH_LENGTHS[i] = Integer.valueOf(LEAP_MONTH_LENGTH[i]);
+ DEFAULT_LEAP_MONTH_LENGTHS[i] = LEAP_MONTH_LENGTH[i];
}
DEFAULT_CYCLE_YEARS = new Integer[CYCLEYEAR_START_DATE.length];
for (int i = 0; i < CYCLEYEAR_START_DATE.length; i++) {
- DEFAULT_CYCLE_YEARS[i] = Integer.valueOf(CYCLEYEAR_START_DATE[i]);
+ DEFAULT_CYCLE_YEARS[i] = CYCLEYEAR_START_DATE[i];
}
ADJUSTED_CYCLES = new Long[MAX_ADJUSTED_CYCLE];
for (int i = 0; i < ADJUSTED_CYCLES.length; i++) {
- ADJUSTED_CYCLES[i] = Long.valueOf(10631 * i);
+ ADJUSTED_CYCLES[i] = (long) (10631 * i);
}
// Initialize min values, least max values and max values.
ADJUSTED_MIN_VALUES = new Integer[MIN_VALUES.length];
for (int i = 0; i < MIN_VALUES.length; i++) {
- ADJUSTED_MIN_VALUES[i] = Integer.valueOf(MIN_VALUES[i]);
+ ADJUSTED_MIN_VALUES[i] = MIN_VALUES[i];
}
ADJUSTED_LEAST_MAX_VALUES = new Integer[LEAST_MAX_VALUES.length];
for (int i = 0; i < LEAST_MAX_VALUES.length; i++) {
- ADJUSTED_LEAST_MAX_VALUES[i] = Integer.valueOf(LEAST_MAX_VALUES[i]);
+ ADJUSTED_LEAST_MAX_VALUES[i] = LEAST_MAX_VALUES[i];
}
ADJUSTED_MAX_VALUES = new Integer[MAX_VALUES.length];
for (int i = 0; i < MAX_VALUES.length; i++) {
- ADJUSTED_MAX_VALUES[i] = Integer.valueOf(MAX_VALUES[i]);
+ ADJUSTED_MAX_VALUES[i] = MAX_VALUES[i];
}
try {
readDeviationConfig();
- } catch (IOException e) {
- // do nothing. Ignore deviation config.
- // e.printStackTrace();
- } catch (ParseException e) {
+ } catch (IOException | ParseException e) {
// do nothing. Ignore deviation config.
// e.printStackTrace();
}
@@ -471,13 +482,11 @@ public final class HijrahDate
* @param monthOfYear the month-of-year to represent, from 1 to 12
* @param dayOfMonth the day-of-month to represent, from 1 to 30
* @return the Hijrah date, never null
- * @throws IllegalCalendarFieldValueException if the value of any field is out of range
- * @throws InvalidCalendarFieldException if the day-of-month is invalid for the month-year
*/
public static HijrahDate of(int prolepticYear, int monthOfYear, int dayOfMonth) {
- return (prolepticYear >= 1) ?
- HijrahDate.of(HijrahEra.AH, prolepticYear, monthOfYear, dayOfMonth) :
- HijrahDate.of(HijrahEra.BEFORE_AH, 1 - prolepticYear, monthOfYear, dayOfMonth);
+ return (prolepticYear >= 1)
+ ? HijrahDate.of(HijrahEra.AH, prolepticYear, monthOfYear, dayOfMonth)
+ : HijrahDate.of(HijrahEra.BEFORE_AH, 1 - prolepticYear, monthOfYear, dayOfMonth);
}
/**
@@ -489,8 +498,6 @@ public final class HijrahDate
* @param monthOfYear the month-of-year to represent, from 1 to 12
* @param dayOfMonth the day-of-month to represent, from 1 to 31
* @return the Hijrah date, never null
- * @throws IllegalCalendarFieldValueException if the value of any field is out of range
- * @throws InvalidCalendarFieldException if the day-of-month is invalid for the month-year
*/
static HijrahDate of(HijrahEra era, int yearOfEra, int monthOfYear, int dayOfMonth) {
Objects.requireNonNull(era, "era");
@@ -506,15 +513,13 @@ public final class HijrahDate
* @param yearOfEra the year to check
*/
private static void checkValidYearOfEra(int yearOfEra) {
- if (yearOfEra < MIN_VALUE_OF_ERA ||
- yearOfEra > MAX_VALUE_OF_ERA) {
+ if (yearOfEra < MIN_VALUE_OF_ERA || yearOfEra > MAX_VALUE_OF_ERA) {
throw new DateTimeException("Invalid year of Hijrah Era");
}
}
private static void checkValidDayOfYear(int dayOfYear) {
- if (dayOfYear < 1 ||
- dayOfYear > getMaximumDayOfYear()) {
+ if (dayOfYear < 1 || dayOfYear > getMaximumDayOfYear()) {
throw new DateTimeException("Invalid day of year of Hijrah date");
}
}
@@ -526,8 +531,7 @@ public final class HijrahDate
}
private static void checkValidDayOfMonth(int dayOfMonth) {
- if (dayOfMonth < 1 ||
- dayOfMonth > getMaximumDayOfMonth()) {
+ if (dayOfMonth < 1 || dayOfMonth > getMaximumDayOfMonth()) {
throw new DateTimeException("Invalid day of month of Hijrah date, day "
+ dayOfMonth + " greater than " + getMaximumDayOfMonth() + " or less than 1");
}
@@ -538,7 +542,6 @@ public final class HijrahDate
*
* @param date the date to use, not null
* @return the Hijrah date, never null
- * @throws IllegalCalendarFieldValueException if the year is invalid
*/
static HijrahDate of(LocalDate date) {
long gregorianDays = date.toEpochDay();
@@ -627,18 +630,29 @@ public final class HijrahDate
public long getLong(TemporalField field) {
if (field instanceof ChronoField) {
switch ((ChronoField) field) {
- case DAY_OF_WEEK: return dayOfWeek.getValue();
- case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((dayOfMonth - 1) % 7) + 1;
- case ALIGNED_DAY_OF_WEEK_IN_YEAR: return ((dayOfYear - 1) % 7) + 1;
- case DAY_OF_MONTH: return this.dayOfMonth;
- case DAY_OF_YEAR: return this.dayOfYear;
- case EPOCH_DAY: return toEpochDay();
- case ALIGNED_WEEK_OF_MONTH: return ((dayOfMonth - 1) / 7) + 1;
- case ALIGNED_WEEK_OF_YEAR: return ((dayOfYear - 1) / 7) + 1;
- case MONTH_OF_YEAR: return monthOfYear;
- case YEAR_OF_ERA: return yearOfEra;
- case YEAR: return yearOfEra;
- case ERA: return era.getValue();
+ case DAY_OF_WEEK:
+ return dayOfWeek.getValue();
+ case ALIGNED_DAY_OF_WEEK_IN_MONTH:
+ return ((dayOfMonth - 1) % 7) + 1;
+ case ALIGNED_DAY_OF_WEEK_IN_YEAR:
+ return ((dayOfYear - 1) % 7) + 1;
+ case DAY_OF_MONTH:
+ return this.dayOfMonth;
+ case DAY_OF_YEAR:
+ return this.dayOfYear;
+ case EPOCH_DAY:
+ return toEpochDay();
+ case ALIGNED_WEEK_OF_MONTH:
+ return ((dayOfMonth - 1) / 7) + 1;
+ case ALIGNED_WEEK_OF_YEAR:
+ return ((dayOfYear - 1) / 7) + 1;
+ case MONTH_OF_YEAR:
+ return monthOfYear;
+ case YEAR_OF_ERA:
+ case YEAR:
+ return yearOfEra;
+ case ERA:
+ return era.getValue();
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
@@ -658,18 +672,30 @@ public final class HijrahDate
f.checkValidValue(newValue); // TODO: validate value
int nvalue = (int) newValue;
switch (f) {
- case DAY_OF_WEEK: return plusDays(newValue - dayOfWeek.getValue());
- case ALIGNED_DAY_OF_WEEK_IN_MONTH: return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_MONTH));
- case ALIGNED_DAY_OF_WEEK_IN_YEAR: return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_YEAR));
- case DAY_OF_MONTH: return resolvePreviousValid(yearOfEra, monthOfYear, nvalue);
- case DAY_OF_YEAR: return resolvePreviousValid(yearOfEra, ((nvalue - 1) / 30) + 1, ((nvalue - 1) % 30) + 1);
- case EPOCH_DAY: return new HijrahDate(nvalue);
- case ALIGNED_WEEK_OF_MONTH: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_MONTH)) * 7);
- case ALIGNED_WEEK_OF_YEAR: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_YEAR)) * 7);
- case MONTH_OF_YEAR: return resolvePreviousValid(yearOfEra, nvalue, dayOfMonth);
- case YEAR_OF_ERA: return resolvePreviousValid(yearOfEra >= 1 ? nvalue : 1 - nvalue, monthOfYear, dayOfMonth);
- case YEAR: return resolvePreviousValid(nvalue, monthOfYear, dayOfMonth);
- case ERA: return resolvePreviousValid(1 - yearOfEra, monthOfYear, dayOfMonth);
+ case DAY_OF_WEEK:
+ return plusDays(newValue - dayOfWeek.getValue());
+ case ALIGNED_DAY_OF_WEEK_IN_MONTH:
+ return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_MONTH));
+ case ALIGNED_DAY_OF_WEEK_IN_YEAR:
+ return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_YEAR));
+ case DAY_OF_MONTH:
+ return resolvePreviousValid(yearOfEra, monthOfYear, nvalue);
+ case DAY_OF_YEAR:
+ return resolvePreviousValid(yearOfEra, ((nvalue - 1) / 30) + 1, ((nvalue - 1) % 30) + 1);
+ case EPOCH_DAY:
+ return new HijrahDate(nvalue);
+ case ALIGNED_WEEK_OF_MONTH:
+ return plusDays((newValue - getLong(ALIGNED_WEEK_OF_MONTH)) * 7);
+ case ALIGNED_WEEK_OF_YEAR:
+ return plusDays((newValue - getLong(ALIGNED_WEEK_OF_YEAR)) * 7);
+ case MONTH_OF_YEAR:
+ return resolvePreviousValid(yearOfEra, nvalue, dayOfMonth);
+ case YEAR_OF_ERA:
+ return resolvePreviousValid(yearOfEra >= 1 ? nvalue : 1 - nvalue, monthOfYear, dayOfMonth);
+ case YEAR:
+ return resolvePreviousValid(nvalue, monthOfYear, dayOfMonth);
+ case ERA:
+ return resolvePreviousValid(1 - yearOfEra, monthOfYear, dayOfMonth);
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
@@ -733,7 +759,7 @@ public final class HijrahDate
if (years == 0) {
return this;
}
- int newYear = Jdk8Methods.safeAdd(this.yearOfEra, (int)years);
+ int newYear = Jdk8Methods.safeAdd(this.yearOfEra, (int) years);
return HijrahDate.of(this.era, newYear, this.monthOfYear, this.dayOfMonth);
}
@@ -743,7 +769,7 @@ public final class HijrahDate
return this;
}
int newMonth = this.monthOfYear - 1;
- newMonth = newMonth + (int)months;
+ newMonth = newMonth + (int) months;
int years = newMonth / 12;
newMonth = newMonth % 12;
while (newMonth < 0) {
@@ -770,12 +796,19 @@ public final class HijrahDate
* int[4] = DAY_OF_YEAR
* int[5] = DAY_OF_WEEK
*
- * @param julianDay a julian day.
+ * @param gregorianDays a julian day.
*/
private static int[] getHijrahDateInfo(long gregorianDays) {
- int era, year, month, date, dayOfWeek, dayOfYear;
+ int era;
+ int year;
+ int month;
+ int date;
+ int dayOfWeek;
+ int dayOfYear;
- int cycleNumber, yearInCycle, dayOfCycle;
+ int cycleNumber;
+ int yearInCycle;
+ int dayOfCycle;
long epochDay = gregorianDays - HIJRAH_JAN_1_1_GREGORIAN_DAY;
@@ -801,8 +834,7 @@ public final class HijrahDate
dayOfYear = getDayOfYear(cycleNumber, dayOfCycle, yearInCycle);
year = cycleNumber * 30 - yearInCycle; // negative number.
year = 1 - year;
- dayOfYear = (isLeapYear(year) ? (dayOfYear + 355)
- : (dayOfYear + 354));
+ dayOfYear = isLeapYear(year) ? dayOfYear + 355 : dayOfYear + 354;
month = getMonthOfYear(dayOfYear, year);
date = getDayOfMonth(dayOfYear, month, year);
++date; // Convert from 0-based to 1-based
@@ -812,7 +844,7 @@ public final class HijrahDate
dayOfWeek = (int) ((epochDay + 5) % 7);
dayOfWeek += (dayOfWeek <= 0) ? 7 : 0;
- int dateInfo[] = new int[6];
+ int[] dateInfo = new int[6];
dateInfo[0] = era;
dateInfo[1] = year;
dateInfo[2] = month + 1; // change to 1-based.
@@ -847,8 +879,7 @@ public final class HijrahDate
int cycleNumber = (prolepticYear - 1) / 30; // 0-based.
int yearInCycle = (prolepticYear - 1) % 30; // 0-based.
- int dayInCycle = getAdjustedCycle(cycleNumber)[Math.abs(yearInCycle)]
- .intValue();
+ int dayInCycle = getAdjustedCycle(cycleNumber)[Math.abs(yearInCycle)];
if (yearInCycle < 0) {
dayInCycle = -dayInCycle;
@@ -863,10 +894,10 @@ public final class HijrahDate
}
if (cycleDays == null) {
- cycleDays = Long.valueOf(cycleNumber * 10631);
+ cycleDays = (long) (cycleNumber * 10631);
}
- return (cycleDays.longValue() + dayInCycle + HIJRAH_JAN_1_1_GREGORIAN_DAY - 1);
+ return cycleDays + dayInCycle + HIJRAH_JAN_1_1_GREGORIAN_DAY - 1;
}
/**
@@ -880,7 +911,7 @@ public final class HijrahDate
int cycleNumber;
try {
for (int i = 0; i < days.length; i++) {
- if (epochDay < days[i].longValue()) {
+ if (epochDay < days[i]) {
return i - 1;
}
}
@@ -908,9 +939,9 @@ public final class HijrahDate
day = null;
}
if (day == null) {
- day = Long.valueOf(cycleNumber * 10631);
+ day = (long) (cycleNumber * 10631);
}
- return (int) (epochDay - day.longValue());
+ return (int) (epochDay - day);
}
/**
@@ -928,7 +959,7 @@ public final class HijrahDate
if (dayOfCycle > 0) {
for (int i = 0; i < cycles.length; i++) {
- if (dayOfCycle < cycles[i].intValue()) {
+ if (dayOfCycle < cycles[i]) {
return i - 1;
}
}
@@ -936,7 +967,7 @@ public final class HijrahDate
} else {
dayOfCycle = -dayOfCycle;
for (int i = 0; i < cycles.length; i++) {
- if (dayOfCycle <= cycles[i].intValue()) {
+ if (dayOfCycle <= cycles[i]) {
return i - 1;
}
}
@@ -954,7 +985,7 @@ public final class HijrahDate
private static Integer[] getAdjustedCycle(int cycleNumber) {
Integer[] cycles;
try {
- cycles = ADJUSTED_CYCLE_YEARS.get(Integer.valueOf(cycleNumber));
+ cycles = ADJUSTED_CYCLE_YEARS.get(cycleNumber);
} catch (ArrayIndexOutOfBoundsException e) {
cycles = null;
}
@@ -973,7 +1004,7 @@ public final class HijrahDate
private static Integer[] getAdjustedMonthDays(int year) {
Integer[] newMonths;
try {
- newMonths = ADJUSTED_MONTH_DAYS.get(Integer.valueOf(year));
+ newMonths = ADJUSTED_MONTH_DAYS.get(year);
} catch (ArrayIndexOutOfBoundsException e) {
newMonths = null;
}
@@ -996,7 +1027,7 @@ public final class HijrahDate
private static Integer[] getAdjustedMonthLength(int year) {
Integer[] newMonths;
try {
- newMonths = ADJUSTED_MONTH_LENGTHS.get(Integer.valueOf(year));
+ newMonths = ADJUSTED_MONTH_LENGTHS.get(year);
} catch (ArrayIndexOutOfBoundsException e) {
newMonths = null;
}
@@ -1022,9 +1053,9 @@ public final class HijrahDate
Integer[] cycles = getAdjustedCycle(cycleNumber);
if (dayOfCycle > 0) {
- return dayOfCycle - cycles[yearInCycle].intValue();
+ return dayOfCycle - cycles[yearInCycle];
} else {
- return cycles[yearInCycle].intValue() + dayOfCycle;
+ return cycles[yearInCycle] + dayOfCycle;
}
}
@@ -1041,16 +1072,15 @@ public final class HijrahDate
if (dayOfYear >= 0) {
for (int i = 0; i < newMonths.length; i++) {
- if (dayOfYear < newMonths[i].intValue()) {
+ if (dayOfYear < newMonths[i]) {
return i - 1;
}
}
return 11;
} else {
- dayOfYear = (isLeapYear(year) ? (dayOfYear + 355)
- : (dayOfYear + 354));
+ dayOfYear = isLeapYear(year) ? (dayOfYear + 355) : (dayOfYear + 354);
for (int i = 0; i < newMonths.length; i++) {
- if (dayOfYear < newMonths[i].intValue()) {
+ if (dayOfYear < newMonths[i]) {
return i - 1;
}
}
@@ -1072,15 +1102,14 @@ public final class HijrahDate
if (dayOfYear >= 0) {
if (month > 0) {
- return dayOfYear - newMonths[month].intValue();
+ return dayOfYear - newMonths[month];
} else {
return dayOfYear;
}
} else {
- dayOfYear = (isLeapYear(year) ? (dayOfYear + 355)
- : (dayOfYear + 354));
+ dayOfYear = isLeapYear(year) ? dayOfYear + 355 : dayOfYear + 354;
if (month > 0) {
- return dayOfYear - newMonths[month].intValue();
+ return dayOfYear - newMonths[month];
} else {
return dayOfYear;
}
@@ -1101,12 +1130,12 @@ public final class HijrahDate
* Returns month days from the beginning of year.
*
* @param month month (0-based)
- * @parma year year
+ * @param year year
* @return month days from the beginning of year
*/
private static int getMonthDays(int month, int year) {
Integer[] newMonths = getAdjustedMonthDays(year);
- return newMonths[month].intValue();
+ return newMonths[month];
}
/**
@@ -1118,7 +1147,7 @@ public final class HijrahDate
*/
static int getMonthLength(int month, int year) {
Integer[] newMonths = getAdjustedMonthLength(year);
- return newMonths[month].intValue();
+ return newMonths[month];
}
@Override
@@ -1146,10 +1175,9 @@ public final class HijrahDate
if (yearInCycle == 29) {
return ADJUSTED_CYCLES[cycleNumber + 1].intValue()
- ADJUSTED_CYCLES[cycleNumber].intValue()
- - cycleYears[yearInCycle].intValue();
+ - cycleYears[yearInCycle];
}
- return cycleYears[yearInCycle + 1].intValue()
- - cycleYears[yearInCycle].intValue();
+ return cycleYears[yearInCycle + 1] - cycleYears[yearInCycle];
} else {
return isLeapYear(year) ? 355 : 354;
}
@@ -1244,18 +1272,17 @@ public final class HijrahDate
boolean isStartYLeap = isLeapYear(startYear);
// Adjusting the number of month.
- Integer[] orgStartMonthNums = ADJUSTED_MONTH_DAYS.get(Integer.valueOf(
- startYear));
+ Integer[] orgStartMonthNums = ADJUSTED_MONTH_DAYS.get(startYear);
if (orgStartMonthNums == null) {
if (isStartYLeap) {
orgStartMonthNums = new Integer[LEAP_NUM_DAYS.length];
for (int l = 0; l < LEAP_NUM_DAYS.length; l++) {
- orgStartMonthNums[l] = Integer.valueOf(LEAP_NUM_DAYS[l]);
+ orgStartMonthNums[l] = LEAP_NUM_DAYS[l];
}
} else {
orgStartMonthNums = new Integer[NUM_DAYS.length];
for (int l = 0; l < NUM_DAYS.length; l++) {
- orgStartMonthNums[l] = Integer.valueOf(NUM_DAYS[l]);
+ orgStartMonthNums[l] = NUM_DAYS[l];
}
}
}
@@ -1264,31 +1291,27 @@ public final class HijrahDate
for (int month = 0; month < 12; month++) {
if (month > startMonth) {
- newStartMonthNums[month] = Integer.valueOf(orgStartMonthNums[month]
- .intValue()
- - offset);
+ newStartMonthNums[month] = orgStartMonthNums[month] - offset;
} else {
- newStartMonthNums[month] = Integer.valueOf(orgStartMonthNums[month]
- .intValue());
+ newStartMonthNums[month] = orgStartMonthNums[month].intValue();
}
}
- ADJUSTED_MONTH_DAYS.put(Integer.valueOf(startYear), newStartMonthNums);
+ ADJUSTED_MONTH_DAYS.put(startYear, newStartMonthNums);
// Adjusting the days of month.
- Integer[] orgStartMonthLengths = ADJUSTED_MONTH_LENGTHS.get(Integer.valueOf(
- startYear));
+ Integer[] orgStartMonthLengths = ADJUSTED_MONTH_LENGTHS.get(startYear);
if (orgStartMonthLengths == null) {
if (isStartYLeap) {
orgStartMonthLengths = new Integer[LEAP_MONTH_LENGTH.length];
for (int l = 0; l < LEAP_MONTH_LENGTH.length; l++) {
- orgStartMonthLengths[l] = Integer.valueOf(LEAP_MONTH_LENGTH[l]);
+ orgStartMonthLengths[l] = LEAP_MONTH_LENGTH[l];
}
} else {
orgStartMonthLengths = new Integer[MONTH_LENGTH.length];
for (int l = 0; l < MONTH_LENGTH.length; l++) {
- orgStartMonthLengths[l] = Integer.valueOf(MONTH_LENGTH[l]);
+ orgStartMonthLengths[l] = MONTH_LENGTH[l];
}
}
}
@@ -1297,36 +1320,33 @@ public final class HijrahDate
for (int month = 0; month < 12; month++) {
if (month == startMonth) {
- newStartMonthLengths[month] = Integer.valueOf(
- orgStartMonthLengths[month].intValue() - offset);
+ newStartMonthLengths[month] = orgStartMonthLengths[month] - offset;
} else {
- newStartMonthLengths[month] = Integer.valueOf(
- orgStartMonthLengths[month].intValue());
+ newStartMonthLengths[month] = orgStartMonthLengths[month].intValue();
}
}
- ADJUSTED_MONTH_LENGTHS.put(Integer.valueOf(startYear), newStartMonthLengths);
+ ADJUSTED_MONTH_LENGTHS.put(startYear, newStartMonthLengths);
if (startYear != endYear) {
// System.out.println("over year");
// Adjusting starting 30 year cycle.
int sCycleNumber = (startYear - 1) / 30;
int sYearInCycle = (startYear - 1) % 30; // 0-based.
- Integer[] startCycles = ADJUSTED_CYCLE_YEARS.get(Integer.valueOf(
- sCycleNumber));
+ Integer[] startCycles = ADJUSTED_CYCLE_YEARS.get(sCycleNumber);
if (startCycles == null) {
startCycles = new Integer[CYCLEYEAR_START_DATE.length];
for (int j = 0; j < startCycles.length; j++) {
- startCycles[j] = Integer.valueOf(CYCLEYEAR_START_DATE[j]);
+ startCycles[j] = CYCLEYEAR_START_DATE[j];
}
}
for (int j = sYearInCycle + 1; j < CYCLEYEAR_START_DATE.length; j++) {
- startCycles[j] = Integer.valueOf(startCycles[j].intValue() - offset);
+ startCycles[j] = startCycles[j] - offset;
}
// System.out.println(sCycleNumber + ":" + sYearInCycle);
- ADJUSTED_CYCLE_YEARS.put(Integer.valueOf(sCycleNumber), startCycles);
+ ADJUSTED_CYCLE_YEARS.put(sCycleNumber, startCycles);
int sYearInMaxY = (startYear - 1) / 30;
int sEndInMaxY = (endYear - 1) / 30;
@@ -1337,49 +1357,46 @@ public final class HijrahDate
// System.out.println(sYearInMaxY);
for (int j = sYearInMaxY + 1; j < ADJUSTED_CYCLES.length; j++) {
- ADJUSTED_CYCLES[j] = Long.valueOf(ADJUSTED_CYCLES[j].longValue()
- - offset);
+ ADJUSTED_CYCLES[j] = ADJUSTED_CYCLES[j] - offset;
}
// Adjusting ending 30 * MAX_ADJUSTED_CYCLE year cycles.
for (int j = sEndInMaxY + 1; j < ADJUSTED_CYCLES.length; j++) {
- ADJUSTED_CYCLES[j] = Long.valueOf(ADJUSTED_CYCLES[j].longValue()
- + offset);
+ ADJUSTED_CYCLES[j] = ADJUSTED_CYCLES[j] + offset;
}
}
// Adjusting ending 30 year cycle.
int eCycleNumber = (endYear - 1) / 30;
int sEndInCycle = (endYear - 1) % 30; // 0-based.
- Integer[] endCycles = ADJUSTED_CYCLE_YEARS.get(Integer.valueOf(
- eCycleNumber));
+ Integer[] endCycles = ADJUSTED_CYCLE_YEARS.get(eCycleNumber);
if (endCycles == null) {
endCycles = new Integer[CYCLEYEAR_START_DATE.length];
for (int j = 0; j < endCycles.length; j++) {
- endCycles[j] = Integer.valueOf(CYCLEYEAR_START_DATE[j]);
+ endCycles[j] = CYCLEYEAR_START_DATE[j];
}
}
for (int j = sEndInCycle + 1; j < CYCLEYEAR_START_DATE.length; j++) {
- endCycles[j] = Integer.valueOf(endCycles[j].intValue() + offset);
+ endCycles[j] = endCycles[j].intValue() + offset;
}
- ADJUSTED_CYCLE_YEARS.put(Integer.valueOf(eCycleNumber), endCycles);
+ ADJUSTED_CYCLE_YEARS.put(eCycleNumber, endCycles);
}
// Adjusting ending year.
boolean isEndYLeap = isLeapYear(endYear);
- Integer[] orgEndMonthDays = ADJUSTED_MONTH_DAYS.get(Integer.valueOf(endYear));
+ Integer[] orgEndMonthDays = ADJUSTED_MONTH_DAYS.get(endYear);
if (orgEndMonthDays == null) {
if (isEndYLeap) {
orgEndMonthDays = new Integer[LEAP_NUM_DAYS.length];
for (int l = 0; l < LEAP_NUM_DAYS.length; l++) {
- orgEndMonthDays[l] = Integer.valueOf(LEAP_NUM_DAYS[l]);
+ orgEndMonthDays[l] = LEAP_NUM_DAYS[l];
}
} else {
orgEndMonthDays = new Integer[NUM_DAYS.length];
for (int l = 0; l < NUM_DAYS.length; l++) {
- orgEndMonthDays[l] = Integer.valueOf(NUM_DAYS[l]);
+ orgEndMonthDays[l] = NUM_DAYS[l];
}
}
}
@@ -1388,31 +1405,27 @@ public final class HijrahDate
for (int month = 0; month < 12; month++) {
if (month > endMonth) {
- newEndMonthDays[month] = Integer.valueOf(orgEndMonthDays[month]
- .intValue()
- + offset);
+ newEndMonthDays[month] = orgEndMonthDays[month] + offset;
} else {
- newEndMonthDays[month] = Integer.valueOf(orgEndMonthDays[month]
- .intValue());
+ newEndMonthDays[month] = orgEndMonthDays[month].intValue();
}
}
- ADJUSTED_MONTH_DAYS.put(Integer.valueOf(endYear), newEndMonthDays);
+ ADJUSTED_MONTH_DAYS.put(endYear, newEndMonthDays);
// Adjusting the days of month.
- Integer[] orgEndMonthLengths = ADJUSTED_MONTH_LENGTHS.get(Integer.valueOf(
- endYear));
+ Integer[] orgEndMonthLengths = ADJUSTED_MONTH_LENGTHS.get(endYear);
if (orgEndMonthLengths == null) {
if (isEndYLeap) {
orgEndMonthLengths = new Integer[LEAP_MONTH_LENGTH.length];
for (int l = 0; l < LEAP_MONTH_LENGTH.length; l++) {
- orgEndMonthLengths[l] = Integer.valueOf(LEAP_MONTH_LENGTH[l]);
+ orgEndMonthLengths[l] = LEAP_MONTH_LENGTH[l];
}
} else {
orgEndMonthLengths = new Integer[MONTH_LENGTH.length];
for (int l = 0; l < MONTH_LENGTH.length; l++) {
- orgEndMonthLengths[l] = Integer.valueOf(MONTH_LENGTH[l]);
+ orgEndMonthLengths[l] = MONTH_LENGTH[l];
}
}
}
@@ -1421,35 +1434,26 @@ public final class HijrahDate
for (int month = 0; month < 12; month++) {
if (month == endMonth) {
- newEndMonthLengths[month] = Integer.valueOf(
- orgEndMonthLengths[month].intValue() + offset);
+ newEndMonthLengths[month] = orgEndMonthLengths[month].intValue() + offset;
} else {
- newEndMonthLengths[month] = Integer.valueOf(
- orgEndMonthLengths[month].intValue());
+ newEndMonthLengths[month] = orgEndMonthLengths[month].intValue();
}
}
- ADJUSTED_MONTH_LENGTHS.put(Integer.valueOf(endYear), newEndMonthLengths);
+ ADJUSTED_MONTH_LENGTHS.put(endYear, newEndMonthLengths);
- Integer[] startMonthLengths = ADJUSTED_MONTH_LENGTHS.get(Integer.valueOf(
- startYear));
- Integer[] endMonthLengths = ADJUSTED_MONTH_LENGTHS.get(Integer.valueOf(
- endYear));
- Integer[] startMonthDays = ADJUSTED_MONTH_DAYS
- .get(Integer.valueOf(startYear));
- Integer[] endMonthDays = ADJUSTED_MONTH_DAYS.get(Integer.valueOf(endYear));
+ Integer[] startMonthLengths = ADJUSTED_MONTH_LENGTHS.get(startYear);
+ Integer[] endMonthLengths = ADJUSTED_MONTH_LENGTHS.get(endYear);
+ Integer[] startMonthDays = ADJUSTED_MONTH_DAYS.get(startYear);
+ Integer[] endMonthDays = ADJUSTED_MONTH_DAYS.get(endYear);
- int startMonthLength = startMonthLengths[startMonth].intValue();
- int endMonthLength = endMonthLengths[endMonth].intValue();
- int startMonthDay = startMonthDays[11].intValue()
- + startMonthLengths[11].intValue();
- int endMonthDay = endMonthDays[11].intValue()
- + endMonthLengths[11].intValue();
+ int startMonthLength = startMonthLengths[startMonth];
+ int endMonthLength = endMonthLengths[endMonth];
+ int startMonthDay = startMonthDays[11] + startMonthLengths[11];
+ int endMonthDay = endMonthDays[11] + endMonthLengths[11];
- int maxMonthLength = ADJUSTED_MAX_VALUES[POSITION_DAY_OF_MONTH]
- .intValue();
- int leastMaxMonthLength = ADJUSTED_LEAST_MAX_VALUES[POSITION_DAY_OF_MONTH]
- .intValue();
+ int maxMonthLength = ADJUSTED_MAX_VALUES[POSITION_DAY_OF_MONTH];
+ int leastMaxMonthLength = ADJUSTED_LEAST_MAX_VALUES[POSITION_DAY_OF_MONTH];
if (maxMonthLength < startMonthLength) {
maxMonthLength = startMonthLength;
@@ -1457,7 +1461,7 @@ public final class HijrahDate
if (maxMonthLength < endMonthLength) {
maxMonthLength = endMonthLength;
}
- ADJUSTED_MAX_VALUES[POSITION_DAY_OF_MONTH] = Integer.valueOf(maxMonthLength);
+ ADJUSTED_MAX_VALUES[POSITION_DAY_OF_MONTH] = maxMonthLength;
if (leastMaxMonthLength > startMonthLength) {
leastMaxMonthLength = startMonthLength;
@@ -1465,12 +1469,10 @@ public final class HijrahDate
if (leastMaxMonthLength > endMonthLength) {
leastMaxMonthLength = endMonthLength;
}
- ADJUSTED_LEAST_MAX_VALUES[POSITION_DAY_OF_MONTH] = Integer.valueOf(
- leastMaxMonthLength);
+ ADJUSTED_LEAST_MAX_VALUES[POSITION_DAY_OF_MONTH] = leastMaxMonthLength;
- int maxMonthDay = ADJUSTED_MAX_VALUES[POSITION_DAY_OF_YEAR].intValue();
- int leastMaxMonthDay = ADJUSTED_LEAST_MAX_VALUES[POSITION_DAY_OF_YEAR]
- .intValue();
+ int maxMonthDay = ADJUSTED_MAX_VALUES[POSITION_DAY_OF_YEAR];
+ int leastMaxMonthDay = ADJUSTED_LEAST_MAX_VALUES[POSITION_DAY_OF_YEAR];
if (maxMonthDay < startMonthDay) {
maxMonthDay = startMonthDay;
@@ -1479,7 +1481,7 @@ public final class HijrahDate
maxMonthDay = endMonthDay;
}
- ADJUSTED_MAX_VALUES[POSITION_DAY_OF_YEAR] = Integer.valueOf(maxMonthDay);
+ ADJUSTED_MAX_VALUES[POSITION_DAY_OF_YEAR] = maxMonthDay;
if (leastMaxMonthDay > startMonthDay) {
leastMaxMonthDay = startMonthDay;
@@ -1487,8 +1489,7 @@ public final class HijrahDate
if (leastMaxMonthDay > endMonthDay) {
leastMaxMonthDay = endMonthDay;
}
- ADJUSTED_LEAST_MAX_VALUES[POSITION_DAY_OF_YEAR] = Integer.valueOf(
- leastMaxMonthDay);
+ ADJUSTED_LEAST_MAX_VALUES[POSITION_DAY_OF_YEAR] = leastMaxMonthDay;
}
/**
@@ -1544,7 +1545,7 @@ public final class HijrahDate
int offsetIndex = deviationElement.indexOf(':');
if (offsetIndex != -1) {
String offsetString = deviationElement.substring(
- offsetIndex + 1, deviationElement.length());
+ offsetIndex + 1);
int offset;
try {
offset = Integer.parseInt(offsetString);
@@ -1569,8 +1570,7 @@ public final class HijrahDate
String startYearStg = startDateStg.substring(0,
startDateYearSepIndex);
String startMonthStg = startDateStg.substring(
- startDateYearSepIndex + 1, startDateStg
- .length());
+ startDateYearSepIndex + 1);
try {
startYear = Integer.parseInt(startYearStg);
} catch (NumberFormatException ex) {
@@ -1594,7 +1594,7 @@ public final class HijrahDate
String endYearStg = endDateStg.substring(0,
endDateYearSepIndex);
String endMonthStg = endDateStg.substring(
- endDateYearSepIndex + 1, endDateStg.length());
+ endDateYearSepIndex + 1);
try {
endYear = Integer.parseInt(endYearStg);
} catch (NumberFormatException ex) {
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/HijrahEra.java b/classlib/src/main/java/org/threeten/bp/chrono/HijrahEra.java
index 879095b42..167253147 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/HijrahEra.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/HijrahEra.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -32,9 +47,7 @@
package org.threeten.bp.chrono;
import static org.threeten.bp.temporal.ChronoField.ERA;
-
import java.util.Locale;
-
import org.threeten.bp.DateTimeException;
import org.threeten.bp.format.DateTimeFormatterBuilder;
import org.threeten.bp.format.TextStyle;
@@ -156,9 +169,9 @@ public enum HijrahEra implements Era {
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()) {
+ 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);
@@ -177,7 +190,6 @@ public enum HijrahEra implements Era {
* @return the computed prolepticYear
*/
int prolepticYear(int yearOfEra) {
- return (this == HijrahEra.AH ? yearOfEra : 1 - yearOfEra);
+ return this == HijrahEra.AH ? yearOfEra : 1 - yearOfEra;
}
-
}
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 b069195bd..568830574 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/IsoChronology.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/IsoChronology.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -45,14 +60,12 @@ import static org.threeten.bp.temporal.ChronoField.PROLEPTIC_MONTH;
import static org.threeten.bp.temporal.ChronoField.YEAR;
import static org.threeten.bp.temporal.ChronoField.YEAR_OF_ERA;
import static org.threeten.bp.temporal.TemporalAdjusters.nextOrSame;
-
import java.io.Serializable;
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;
import org.threeten.bp.DayOfWeek;
@@ -355,10 +368,10 @@ public final class IsoChronology extends Chronology implements Serializable {
@Override
public int prolepticYear(Era era, int yearOfEra) {
- if (era instanceof IsoEra == false) {
+ if (!(era instanceof IsoEra)) {
throw new ClassCastException("Era must be IsoEra");
}
- return (era == IsoEra.CE ? yearOfEra : 1 - yearOfEra);
+ return era == IsoEra.CE ? yearOfEra : 1 - yearOfEra;
}
@Override
@@ -405,18 +418,19 @@ public final class IsoChronology extends Chronology implements Serializable {
if (resolverStyle == ResolverStyle.STRICT) {
// do not invent era if strict, but do cross-check with year
if (year != null) {
- updateResolveMap(fieldValues, YEAR, (year > 0 ? yoeLong: Jdk8Methods.safeSubtract(1, yoeLong)));
+ updateResolveMap(fieldValues, YEAR, year > 0 ? yoeLong : Jdk8Methods.safeSubtract(1, yoeLong));
} else {
// reinstate the field removed earlier, no cross-check issues
fieldValues.put(YEAR_OF_ERA, yoeLong);
}
} else {
// invent era
- updateResolveMap(fieldValues, YEAR, (year == null || year > 0 ? yoeLong: Jdk8Methods.safeSubtract(1, yoeLong)));
+ updateResolveMap(fieldValues, YEAR,
+ year == null || year > 0 ? yoeLong : Jdk8Methods.safeSubtract(1, yoeLong));
}
- } else if (era.longValue() == 1L) {
+ } else if (era == 1L) {
updateResolveMap(fieldValues, YEAR, yoeLong);
- } else if (era.longValue() == 0L) {
+ } else if (era == 0L) {
updateResolveMap(fieldValues, YEAR, Jdk8Methods.safeSubtract(1, yoeLong));
} else {
throw new DateTimeException("Invalid value for era: " + era);
@@ -459,7 +473,8 @@ public final class IsoChronology extends Chronology implements Serializable {
}
int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR));
int aw = ALIGNED_WEEK_OF_MONTH.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_MONTH));
- int ad = ALIGNED_DAY_OF_WEEK_IN_MONTH.checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH));
+ int ad = ALIGNED_DAY_OF_WEEK_IN_MONTH.checkValidIntValue(
+ fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH));
LocalDate date = LocalDate.of(y, moy, 1).plusDays((aw - 1) * 7 + (ad - 1));
if (resolverStyle == ResolverStyle.STRICT && date.get(MONTH_OF_YEAR) != moy) {
throw new DateTimeException("Strict mode rejected date parsed to a different month");
@@ -503,7 +518,8 @@ public final class IsoChronology extends Chronology implements Serializable {
return LocalDate.of(y, 1, 1).plusWeeks(weeks).plusDays(days);
}
int aw = ALIGNED_WEEK_OF_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR));
- int ad = ALIGNED_DAY_OF_WEEK_IN_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR));
+ int ad = ALIGNED_DAY_OF_WEEK_IN_YEAR.checkValidIntValue(
+ fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR));
LocalDate date = LocalDate.of(y, 1, 1).plusDays((aw - 1) * 7 + (ad - 1));
if (resolverStyle == ResolverStyle.STRICT && date.get(YEAR) != y) {
throw new DateTimeException("Strict mode rejected date parsed to a different year");
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/IsoEra.java b/classlib/src/main/java/org/threeten/bp/chrono/IsoEra.java
index aef4e8254..2b9f56d48 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/IsoEra.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/IsoEra.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -32,9 +47,7 @@
package org.threeten.bp.chrono;
import static org.threeten.bp.temporal.ChronoField.ERA;
-
import java.util.Locale;
-
import org.threeten.bp.DateTimeException;
import org.threeten.bp.format.DateTimeFormatterBuilder;
import org.threeten.bp.format.TextStyle;
@@ -161,9 +174,9 @@ public enum IsoEra implements Era {
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()) {
+ 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);
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 8eb2c2148..06a877e48 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/JapaneseChronology.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/JapaneseChronology.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -48,7 +63,6 @@ import static org.threeten.bp.temporal.ChronoUnit.DAYS;
import static org.threeten.bp.temporal.ChronoUnit.MONTHS;
import static org.threeten.bp.temporal.ChronoUnit.WEEKS;
import static org.threeten.bp.temporal.TemporalAdjusters.nextOrSame;
-
import java.io.Serializable;
import java.util.Arrays;
import java.util.Calendar;
@@ -57,7 +71,6 @@ 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;
import org.threeten.bp.DayOfWeek;
@@ -141,7 +154,8 @@ public final class JapaneseChronology extends Chronology implements Serializable
ERA_SHORT_NAMES.put(TARGET_LANGUAGE, new String[]{"Unknown", "\u6176", "\u660e", "\u5927", "\u662d", "\u5e73"});
ERA_FULL_NAMES.put(FALLBACK_LANGUAGE, new String[]{"Unknown", "Keio", "Meiji", "Taisho", "Showa", "Heisei"});
ERA_FULL_NAMES.put(TARGET_LANGUAGE,
- new String[]{"Unknown", "\u6176\u5fdc", "\u660e\u6cbb", "\u5927\u6b63", "\u662d\u548c", "\u5e73\u6210"});
+ new String[]{"Unknown", "\u6176\u5fdc", "\u660e\u6cbb", "\u5927\u6b63", "\u662d\u548c",
+ "\u5e73\u6210"});
}
//-----------------------------------------------------------------------
@@ -195,7 +209,7 @@ public final class JapaneseChronology extends Chronology implements Serializable
//-----------------------------------------------------------------------
@Override // override with covariant return type
public JapaneseDate date(Era era, int yearOfEra, int month, int dayOfMonth) {
- if (era instanceof JapaneseEra == false) {
+ if (!(era instanceof JapaneseEra)) {
throw new ClassCastException("Era must be JapaneseEra");
}
return JapaneseDate.of((JapaneseEra) era, yearOfEra, month, dayOfMonth);
@@ -230,7 +244,7 @@ public final class JapaneseChronology extends Chronology implements Serializable
*/
@Override
public JapaneseDate dateYearDay(Era era, int yearOfEra, int dayOfYear) {
- if (era instanceof JapaneseEra == false) {
+ if (!(era instanceof JapaneseEra)) {
throw new ClassCastException("Era must be JapaneseEra");
}
return JapaneseDate.ofYearDay((JapaneseEra) era, yearOfEra, dayOfYear);
@@ -322,7 +336,7 @@ public final class JapaneseChronology extends Chronology implements Serializable
@Override
public int prolepticYear(Era era, int yearOfEra) {
- if (era instanceof JapaneseEra == false) {
+ if (!(era instanceof JapaneseEra)) {
throw new ClassCastException("Era must be JapaneseEra");
}
JapaneseEra jera = (JapaneseEra) era;
@@ -399,7 +413,7 @@ public final class JapaneseChronology extends Chronology implements Serializable
}
case MONTH_OF_YEAR:
return ValueRange.of(jcal.getMinimum(Calendar.MONTH) + 1, jcal.getGreatestMinimum(Calendar.MONTH) + 1,
- jcal.getLeastMaximum(Calendar.MONTH) + 1, jcal.getMaximum(Calendar.MONTH) + 1);
+ jcal.getLeastMaximum(Calendar.MONTH) + 1, jcal.getMaximum(Calendar.MONTH) + 1);
case DAY_OF_YEAR: {
JapaneseEra[] eras = JapaneseEra.values();
int min = 366;
@@ -438,8 +452,8 @@ public final class JapaneseChronology extends Chronology implements Serializable
}
Long yoeLong = fieldValues.get(YEAR_OF_ERA);
if (yoeLong != null) {
- int yoe= range(YEAR_OF_ERA).checkValidIntValue(yoeLong, YEAR_OF_ERA);
- if (era == null && resolverStyle != ResolverStyle.STRICT && fieldValues.containsKey(YEAR) == false) {
+ int yoe = range(YEAR_OF_ERA).checkValidIntValue(yoeLong, YEAR_OF_ERA);
+ if (era == null && resolverStyle != ResolverStyle.STRICT && !fieldValues.containsKey(YEAR)) {
List eras = eras();
era = (JapaneseEra) eras.get(eras.size() - 1);
}
@@ -466,8 +480,10 @@ public final class JapaneseChronology extends Chronology implements Serializable
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_MONTH), 1);
return date(y, 1, 1).plusMonths(months).plusDays(days);
} else {
- int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
- int dom = range(DAY_OF_MONTH).checkValidIntValue(fieldValues.remove(DAY_OF_MONTH), DAY_OF_MONTH);
+ int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR),
+ MONTH_OF_YEAR);
+ int dom = range(DAY_OF_MONTH).checkValidIntValue(fieldValues.remove(DAY_OF_MONTH),
+ DAY_OF_MONTH);
if (resolverStyle == ResolverStyle.SMART && dom > 28) {
dom = Math.min(dom, date(y, moy, 1).lengthOfMonth());
}
@@ -485,7 +501,8 @@ public final class JapaneseChronology extends Chronology implements Serializable
}
int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR));
int aw = ALIGNED_WEEK_OF_MONTH.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_MONTH));
- int ad = ALIGNED_DAY_OF_WEEK_IN_MONTH.checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH));
+ int ad = ALIGNED_DAY_OF_WEEK_IN_MONTH.checkValidIntValue(
+ fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH));
JapaneseDate date = date(y, moy, 1).plus((aw - 1) * 7 + (ad - 1), DAYS);
if (resolverStyle == ResolverStyle.STRICT && date.get(MONTH_OF_YEAR) != moy) {
throw new DateTimeException("Strict mode rejected date parsed to a different month");
@@ -529,7 +546,8 @@ public final class JapaneseChronology extends Chronology implements Serializable
return date(y, 1, 1).plus(weeks, WEEKS).plus(days, DAYS);
}
int aw = ALIGNED_WEEK_OF_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR));
- int ad = ALIGNED_DAY_OF_WEEK_IN_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR));
+ int ad = ALIGNED_DAY_OF_WEEK_IN_YEAR.checkValidIntValue(
+ fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR));
JapaneseDate date = date(y, 1, 1).plusDays((aw - 1) * 7 + (ad - 1));
if (resolverStyle == ResolverStyle.STRICT && date.get(YEAR) != y) {
throw new DateTimeException("Strict mode rejected date parsed to a different year");
@@ -556,7 +574,8 @@ public final class JapaneseChronology extends Chronology implements Serializable
return null;
}
- private JapaneseDate resolveEYMD(Map fieldValues, ResolverStyle resolverStyle, JapaneseEra era, int yoe) {
+ private JapaneseDate resolveEYMD(Map fieldValues, ResolverStyle resolverStyle,
+ JapaneseEra era, int yoe) {
if (resolverStyle == ResolverStyle.LENIENT) {
int y = era.startDate().getYear() + yoe - 1;
long months = Jdk8Methods.safeSubtract(fieldValues.remove(MONTH_OF_YEAR), 1);
@@ -588,7 +607,8 @@ public final class JapaneseChronology extends Chronology implements Serializable
return date(era, yoe, moy, dom);
}
- private JapaneseDate resolveEYD(Map fieldValues, ResolverStyle resolverStyle, JapaneseEra era, int yoe) {
+ private JapaneseDate resolveEYD(Map fieldValues, ResolverStyle resolverStyle,
+ JapaneseEra era, int yoe) {
if (resolverStyle == ResolverStyle.LENIENT) {
int y = era.startDate().getYear() + yoe - 1;
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_YEAR), 1);
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 1742a8215..6fe95bd5f 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/JapaneseDate.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/JapaneseDate.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -34,7 +49,6 @@ package org.threeten.bp.chrono;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Objects;
-
import org.threeten.bp.Clock;
import org.threeten.bp.DateTimeException;
import org.threeten.bp.LocalDate;
@@ -351,10 +365,10 @@ public final class JapaneseDate
*/
@Override
public boolean isSupported(TemporalField field) {
- if (field == ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH ||
- field == ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR ||
- field == ChronoField.ALIGNED_WEEK_OF_MONTH ||
- field == ChronoField.ALIGNED_WEEK_OF_YEAR) {
+ if (field == ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH
+ || field == ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR
+ || field == ChronoField.ALIGNED_WEEK_OF_MONTH
+ || field == ChronoField.ALIGNED_WEEK_OF_YEAR) {
return false;
}
return super.isSupported(field);
@@ -522,13 +536,13 @@ public final class JapaneseDate
}
private JapaneseDate with(LocalDate newDate) {
- return (newDate.equals(isoDate) ? this : new JapaneseDate(newDate));
+ return newDate.equals(isoDate) ? this : new JapaneseDate(newDate);
}
@Override
@SuppressWarnings("unchecked")
- public final ChronoLocalDateTime atTime(LocalTime localTime) {
- return (ChronoLocalDateTime)super.atTime(localTime);
+ public ChronoLocalDateTime atTime(LocalTime localTime) {
+ return (ChronoLocalDateTime) super.atTime(localTime);
}
@Override
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 cbb7f4e6f..151bdf651 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/JapaneseEra.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/JapaneseEra.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -34,7 +49,6 @@ package org.threeten.bp.chrono;
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.temporal.ChronoField;
@@ -93,7 +107,7 @@ public final class JapaneseEra
private static final int ADDITIONAL_VALUE = 4;
// array for the singleton JapaneseEra instances
- private static JapaneseEra[] KNOWN_ERAS;
+ private static JapaneseEra[] knownEras;
static {
JapaneseEra[] array = new JapaneseEra[5];
@@ -102,7 +116,7 @@ public final class JapaneseEra
array[2] = SHOWA;
array[3] = HEISEI;
array[4] = REIWA;
- KNOWN_ERAS = array;
+ knownEras = array;
}
/**
@@ -146,7 +160,7 @@ public final class JapaneseEra
* @throws DateTimeException if an additional era has already been registered
*/
public static JapaneseEra registerEra(LocalDate since, String name) {
- JapaneseEra[] known = KNOWN_ERAS;
+ JapaneseEra[] known = knownEras;
if (known.length > 5) {
throw new DateTimeException("Only one additional Japanese era can be added");
}
@@ -158,7 +172,7 @@ public final class JapaneseEra
JapaneseEra era = new JapaneseEra(ADDITIONAL_VALUE, since, name);
JapaneseEra[] newArray = Arrays.copyOf(known, 6);
newArray[5] = era;
- KNOWN_ERAS = newArray;
+ knownEras = newArray;
return era;
}
@@ -174,7 +188,7 @@ public final class JapaneseEra
* @throws DateTimeException if the value is invalid
*/
public static JapaneseEra of(int japaneseEra) {
- JapaneseEra[] known = KNOWN_ERAS;
+ JapaneseEra[] known = knownEras;
if (japaneseEra < MEIJI.eraValue || japaneseEra > known[known.length - 1].eraValue) {
throw new DateTimeException("japaneseEra is invalid");
}
@@ -193,7 +207,7 @@ public final class JapaneseEra
*/
public static JapaneseEra valueOf(String japaneseEra) {
Objects.requireNonNull(japaneseEra, "japaneseEra");
- JapaneseEra[] known = KNOWN_ERAS;
+ JapaneseEra[] known = knownEras;
for (JapaneseEra era : known) {
if (japaneseEra.equals(era.name)) {
return era;
@@ -214,7 +228,7 @@ public final class JapaneseEra
* @return an array of JapaneseEras
*/
public static JapaneseEra[] values() {
- JapaneseEra[] known = KNOWN_ERAS;
+ JapaneseEra[] known = knownEras;
return Arrays.copyOf(known, known.length);
}
@@ -229,7 +243,7 @@ public final class JapaneseEra
if (date.isBefore(MEIJI.since)) {
throw new DateTimeException("Date too early: " + date);
}
- JapaneseEra[] known = KNOWN_ERAS;
+ JapaneseEra[] known = knownEras;
for (int i = known.length - 1; i >= 0; i--) {
JapaneseEra era = known[i];
if (date.compareTo(era.since) >= 0) {
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 5af1f37ca..6d88a0e43 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/MinguoChronology.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/MinguoChronology.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -48,14 +63,12 @@ import static org.threeten.bp.temporal.ChronoUnit.DAYS;
import static org.threeten.bp.temporal.ChronoUnit.MONTHS;
import static org.threeten.bp.temporal.ChronoUnit.WEEKS;
import static org.threeten.bp.temporal.TemporalAdjusters.nextOrSame;
-
import java.io.Serializable;
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;
import org.threeten.bp.DayOfWeek;
@@ -242,10 +255,10 @@ public final class MinguoChronology extends Chronology implements Serializable {
@Override
public int prolepticYear(Era era, int yearOfEra) {
- if (era instanceof MinguoEra == false) {
+ if (!(era instanceof MinguoEra)) {
throw new ClassCastException("Era must be MinguoEra");
}
- return (era == MinguoEra.ROC ? yearOfEra : 1 - yearOfEra);
+ return era == MinguoEra.ROC ? yearOfEra : 1 - yearOfEra;
}
@Override
@@ -264,11 +277,13 @@ public final class MinguoChronology extends Chronology implements Serializable {
switch (field) {
case PROLEPTIC_MONTH: {
ValueRange range = PROLEPTIC_MONTH.range();
- return ValueRange.of(range.getMinimum() - YEARS_DIFFERENCE * 12L, range.getMaximum() - YEARS_DIFFERENCE * 12L);
+ return ValueRange.of(range.getMinimum() - YEARS_DIFFERENCE * 12L,
+ range.getMaximum() - YEARS_DIFFERENCE * 12L);
}
case YEAR_OF_ERA: {
ValueRange range = YEAR.range();
- return ValueRange.of(1, range.getMaximum() - YEARS_DIFFERENCE, -range.getMinimum() + 1 + YEARS_DIFFERENCE);
+ return ValueRange.of(1, range.getMaximum() - YEARS_DIFFERENCE,
+ -range.getMinimum() + 1 + YEARS_DIFFERENCE);
}
case YEAR: {
ValueRange range = YEAR.range();
@@ -306,18 +321,20 @@ public final class MinguoChronology extends Chronology implements Serializable {
if (resolverStyle == ResolverStyle.STRICT) {
// do not invent era if strict, but do cross-check with year
if (year != null) {
- updateResolveMap(fieldValues, YEAR, (year > 0 ? yoeLong: Jdk8Methods.safeSubtract(1, yoeLong)));
+ updateResolveMap(fieldValues, YEAR, year > 0 ? yoeLong : Jdk8Methods.safeSubtract(1, yoeLong));
} else {
// reinstate the field removed earlier, no cross-check issues
fieldValues.put(YEAR_OF_ERA, yoeLong);
}
} else {
// invent era
- updateResolveMap(fieldValues, YEAR, (year == null || year > 0 ? yoeLong: Jdk8Methods.safeSubtract(1, yoeLong)));
+ updateResolveMap(fieldValues, YEAR, year == null || year > 0
+ ? yoeLong
+ : Jdk8Methods.safeSubtract(1, yoeLong));
}
- } else if (era.longValue() == 1L) {
+ } else if (era == 1L) {
updateResolveMap(fieldValues, YEAR, yoeLong);
- } else if (era.longValue() == 0L) {
+ } else if (era == 0L) {
updateResolveMap(fieldValues, YEAR, Jdk8Methods.safeSubtract(1, yoeLong));
} else {
throw new DateTimeException("Invalid value for era: " + era);
@@ -336,8 +353,10 @@ public final class MinguoChronology extends Chronology implements Serializable {
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_MONTH), 1);
return date(y, 1, 1).plusMonths(months).plusDays(days);
} else {
- int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
- int dom = range(DAY_OF_MONTH).checkValidIntValue(fieldValues.remove(DAY_OF_MONTH), DAY_OF_MONTH);
+ int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR),
+ MONTH_OF_YEAR);
+ int dom = range(DAY_OF_MONTH).checkValidIntValue(fieldValues.remove(DAY_OF_MONTH),
+ DAY_OF_MONTH);
if (resolverStyle == ResolverStyle.SMART && dom > 28) {
dom = Math.min(dom, date(y, moy, 1).lengthOfMonth());
}
@@ -355,7 +374,8 @@ public final class MinguoChronology extends Chronology implements Serializable {
}
int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR));
int aw = ALIGNED_WEEK_OF_MONTH.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_MONTH));
- int ad = ALIGNED_DAY_OF_WEEK_IN_MONTH.checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH));
+ int ad = ALIGNED_DAY_OF_WEEK_IN_MONTH.checkValidIntValue(
+ fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH));
MinguoDate date = date(y, moy, 1).plus((aw - 1) * 7 + (ad - 1), DAYS);
if (resolverStyle == ResolverStyle.STRICT && date.get(MONTH_OF_YEAR) != moy) {
throw new DateTimeException("Strict mode rejected date parsed to a different month");
@@ -399,7 +419,8 @@ public final class MinguoChronology extends Chronology implements Serializable {
return date(y, 1, 1).plus(weeks, WEEKS).plus(days, DAYS);
}
int aw = ALIGNED_WEEK_OF_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR));
- int ad = ALIGNED_DAY_OF_WEEK_IN_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR));
+ int ad = ALIGNED_DAY_OF_WEEK_IN_YEAR.checkValidIntValue(
+ fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR));
MinguoDate date = date(y, 1, 1).plusDays((aw - 1) * 7 + (ad - 1));
if (resolverStyle == ResolverStyle.STRICT && date.get(YEAR) != y) {
throw new DateTimeException("Strict mode rejected date parsed to a different year");
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 b824110bf..cc034c2a4 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/MinguoDate.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/MinguoDate.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -33,10 +48,8 @@ package org.threeten.bp.chrono;
import static org.threeten.bp.chrono.MinguoChronology.YEARS_DIFFERENCE;
import static org.threeten.bp.temporal.ChronoField.YEAR;
-
import java.io.Serializable;
import java.util.Objects;
-
import org.threeten.bp.Clock;
import org.threeten.bp.DateTimeException;
import org.threeten.bp.LocalDate;
@@ -162,7 +175,7 @@ public final class MinguoDate
/**
* Creates an instance from an ISO date.
*
- * @param isoDate the standard local date, validated not null
+ * @param date the standard local date, validated not null
*/
MinguoDate(LocalDate date) {
Objects.requireNonNull(date, "date");
@@ -197,7 +210,9 @@ public final class MinguoDate
return isoDate.range(field);
case YEAR_OF_ERA: {
ValueRange range = YEAR.range();
- long max = (getProlepticYear() <= 0 ? -range.getMinimum() + 1 + YEARS_DIFFERENCE : range.getMaximum() - YEARS_DIFFERENCE);
+ long max = getProlepticYear() <= 0
+ ? -range.getMinimum() + 1 + YEARS_DIFFERENCE
+ : range.getMaximum() - YEARS_DIFFERENCE;
return ValueRange.of(1, max);
}
}
@@ -216,12 +231,12 @@ public final class MinguoDate
return getProlepticMonth();
case YEAR_OF_ERA: {
int prolepticYear = getProlepticYear();
- return (prolepticYear >= 1 ? prolepticYear : 1 - prolepticYear);
+ return prolepticYear >= 1 ? prolepticYear : 1 - prolepticYear;
}
case YEAR:
return getProlepticYear();
case ERA:
- return (getProlepticYear() >= 1 ? 1 : 0);
+ return getProlepticYear() >= 1 ? 1 : 0;
}
return isoDate.getLong(field);
}
@@ -259,7 +274,9 @@ public final class MinguoDate
int nvalue = getChronology().range(f).checkValidIntValue(newValue, f);
switch (f) {
case YEAR_OF_ERA:
- return with(isoDate.withYear(getProlepticYear() >= 1 ? nvalue + YEARS_DIFFERENCE : (1 - nvalue) + YEARS_DIFFERENCE));
+ return with(isoDate.withYear(getProlepticYear() >= 1
+ ? nvalue + YEARS_DIFFERENCE
+ : (1 - nvalue) + YEARS_DIFFERENCE));
case YEAR:
return with(isoDate.withYear(nvalue + YEARS_DIFFERENCE));
case ERA:
@@ -309,12 +326,12 @@ public final class MinguoDate
}
private MinguoDate with(LocalDate newDate) {
- return (newDate.equals(isoDate) ? this : new MinguoDate(newDate));
+ return newDate.equals(isoDate) ? this : new MinguoDate(newDate);
}
@Override
@SuppressWarnings("unchecked")
- public final ChronoLocalDateTime atTime(LocalTime localTime) {
+ public ChronoLocalDateTime atTime(LocalTime localTime) {
return (ChronoLocalDateTime) super.atTime(localTime);
}
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/MinguoEra.java b/classlib/src/main/java/org/threeten/bp/chrono/MinguoEra.java
index fd5a85245..977bc1a94 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/MinguoEra.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/MinguoEra.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -32,9 +47,7 @@
package org.threeten.bp.chrono;
import static org.threeten.bp.temporal.ChronoField.ERA;
-
import java.util.Locale;
-
import org.threeten.bp.DateTimeException;
import org.threeten.bp.format.DateTimeFormatterBuilder;
import org.threeten.bp.format.TextStyle;
@@ -156,9 +169,9 @@ public enum MinguoEra implements Era {
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()) {
+ 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);
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 994ec8f75..26c6270d5 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/ThaiBuddhistChronology.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/ThaiBuddhistChronology.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -48,7 +63,6 @@ import static org.threeten.bp.temporal.ChronoUnit.DAYS;
import static org.threeten.bp.temporal.ChronoUnit.MONTHS;
import static org.threeten.bp.temporal.ChronoUnit.WEEKS;
import static org.threeten.bp.temporal.TemporalAdjusters.nextOrSame;
-
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
@@ -56,7 +70,6 @@ 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;
import org.threeten.bp.DayOfWeek;
@@ -136,11 +149,13 @@ public final class ThaiBuddhistChronology extends Chronology implements Serializ
ERA_SHORT_NAMES.put(FALLBACK_LANGUAGE, new String[]{"B.B.", "B.E."});
ERA_SHORT_NAMES.put(TARGET_LANGUAGE,
new String[]{"\u0e1e.\u0e28.",
- "\u0e1b\u0e35\u0e01\u0e48\u0e2d\u0e19\u0e04\u0e23\u0e34\u0e2a\u0e15\u0e4c\u0e01\u0e32\u0e25\u0e17\u0e35\u0e48"});
+ "\u0e1b\u0e35\u0e01\u0e48\u0e2d\u0e19\u0e04\u0e23\u0e34\u0e2a\u0e15\u0e4c\u0e01\u0e32"
+ + "\u0e25\u0e17\u0e35\u0e48"});
ERA_FULL_NAMES.put(FALLBACK_LANGUAGE, new String[]{"Before Buddhist", "Budhhist Era"});
ERA_FULL_NAMES.put(TARGET_LANGUAGE,
new String[]{"\u0e1e\u0e38\u0e17\u0e18\u0e28\u0e31\u0e01\u0e23\u0e32\u0e0a",
- "\u0e1b\u0e35\u0e01\u0e48\u0e2d\u0e19\u0e04\u0e23\u0e34\u0e2a\u0e15\u0e4c\u0e01\u0e32\u0e25\u0e17\u0e35\u0e48"});
+ "\u0e1b\u0e35\u0e01\u0e48\u0e2d\u0e19\u0e04\u0e23\u0e34\u0e2a\u0e15\u0e4c\u0e01\u0e32\u0e25"
+ + "\u0e17\u0e35\u0e48"});
}
/**
@@ -278,10 +293,10 @@ public final class ThaiBuddhistChronology extends Chronology implements Serializ
@Override
public int prolepticYear(Era era, int yearOfEra) {
- if (era instanceof ThaiBuddhistEra == false) {
+ if (!(era instanceof ThaiBuddhistEra)) {
throw new ClassCastException("Era must be BuddhistEra");
}
- return (era == ThaiBuddhistEra.BE ? yearOfEra : 1 - yearOfEra);
+ return era == ThaiBuddhistEra.BE ? yearOfEra : 1 - yearOfEra;
}
@Override
@@ -300,11 +315,13 @@ public final class ThaiBuddhistChronology extends Chronology implements Serializ
switch (field) {
case PROLEPTIC_MONTH: {
ValueRange range = PROLEPTIC_MONTH.range();
- return ValueRange.of(range.getMinimum() + YEARS_DIFFERENCE * 12L, range.getMaximum() + YEARS_DIFFERENCE * 12L);
+ return ValueRange.of(range.getMinimum() + YEARS_DIFFERENCE * 12L,
+ range.getMaximum() + YEARS_DIFFERENCE * 12L);
}
case YEAR_OF_ERA: {
ValueRange range = YEAR.range();
- return ValueRange.of(1, -(range.getMinimum() + YEARS_DIFFERENCE) + 1, range.getMaximum() + YEARS_DIFFERENCE);
+ return ValueRange.of(1, -(range.getMinimum() + YEARS_DIFFERENCE) + 1,
+ range.getMaximum() + YEARS_DIFFERENCE);
}
case YEAR: {
ValueRange range = YEAR.range();
@@ -342,18 +359,22 @@ public final class ThaiBuddhistChronology extends Chronology implements Serializ
if (resolverStyle == ResolverStyle.STRICT) {
// do not invent era if strict, but do cross-check with year
if (year != null) {
- updateResolveMap(fieldValues, YEAR, (year > 0 ? yoeLong: Jdk8Methods.safeSubtract(1, yoeLong)));
+ updateResolveMap(fieldValues, YEAR, year > 0
+ ? yoeLong
+ : Jdk8Methods.safeSubtract(1, yoeLong));
} else {
// reinstate the field removed earlier, no cross-check issues
fieldValues.put(YEAR_OF_ERA, yoeLong);
}
} else {
// invent era
- updateResolveMap(fieldValues, YEAR, (year == null || year > 0 ? yoeLong: Jdk8Methods.safeSubtract(1, yoeLong)));
+ updateResolveMap(fieldValues, YEAR, year == null || year > 0
+ ? yoeLong
+ : Jdk8Methods.safeSubtract(1, yoeLong));
}
- } else if (era.longValue() == 1L) {
+ } else if (era == 1L) {
updateResolveMap(fieldValues, YEAR, yoeLong);
- } else if (era.longValue() == 0L) {
+ } else if (era == 0L) {
updateResolveMap(fieldValues, YEAR, Jdk8Methods.safeSubtract(1, yoeLong));
} else {
throw new DateTimeException("Invalid value for era: " + era);
@@ -372,8 +393,10 @@ public final class ThaiBuddhistChronology extends Chronology implements Serializ
long days = Jdk8Methods.safeSubtract(fieldValues.remove(DAY_OF_MONTH), 1);
return date(y, 1, 1).plusMonths(months).plusDays(days);
} else {
- int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
- int dom = range(DAY_OF_MONTH).checkValidIntValue(fieldValues.remove(DAY_OF_MONTH), DAY_OF_MONTH);
+ int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR),
+ MONTH_OF_YEAR);
+ int dom = range(DAY_OF_MONTH).checkValidIntValue(fieldValues.remove(DAY_OF_MONTH),
+ DAY_OF_MONTH);
if (resolverStyle == ResolverStyle.SMART && dom > 28) {
dom = Math.min(dom, date(y, moy, 1).lengthOfMonth());
}
@@ -391,7 +414,8 @@ public final class ThaiBuddhistChronology extends Chronology implements Serializ
}
int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR));
int aw = ALIGNED_WEEK_OF_MONTH.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_MONTH));
- int ad = ALIGNED_DAY_OF_WEEK_IN_MONTH.checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH));
+ int ad = ALIGNED_DAY_OF_WEEK_IN_MONTH.checkValidIntValue(
+ fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH));
ThaiBuddhistDate date = date(y, moy, 1).plus((aw - 1) * 7 + (ad - 1), DAYS);
if (resolverStyle == ResolverStyle.STRICT && date.get(MONTH_OF_YEAR) != moy) {
throw new DateTimeException("Strict mode rejected date parsed to a different month");
@@ -435,7 +459,8 @@ public final class ThaiBuddhistChronology extends Chronology implements Serializ
return date(y, 1, 1).plus(weeks, WEEKS).plus(days, DAYS);
}
int aw = ALIGNED_WEEK_OF_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR));
- int ad = ALIGNED_DAY_OF_WEEK_IN_YEAR.checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR));
+ int ad = ALIGNED_DAY_OF_WEEK_IN_YEAR.checkValidIntValue(
+ fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR));
ThaiBuddhistDate date = date(y, 1, 1).plusDays((aw - 1) * 7 + (ad - 1));
if (resolverStyle == ResolverStyle.STRICT && date.get(YEAR) != y) {
throw new DateTimeException("Strict mode rejected date parsed to a different year");
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 c015dc90e..d86ad9a74 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/ThaiBuddhistDate.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/ThaiBuddhistDate.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -32,13 +47,9 @@
package org.threeten.bp.chrono;
import static org.threeten.bp.chrono.ThaiBuddhistChronology.YEARS_DIFFERENCE;
-import static org.threeten.bp.temporal.ChronoField.DAY_OF_MONTH;
-import static org.threeten.bp.temporal.ChronoField.MONTH_OF_YEAR;
import static org.threeten.bp.temporal.ChronoField.YEAR;
-
import java.io.Serializable;
import java.util.Objects;
-
import org.threeten.bp.Clock;
import org.threeten.bp.DateTimeException;
import org.threeten.bp.LocalDate;
@@ -164,7 +175,7 @@ public final class ThaiBuddhistDate
/**
* Creates an instance from an ISO date.
*
- * @param isoDate the standard local date, validated not null
+ * @param date the standard local date, validated not null
*/
ThaiBuddhistDate(LocalDate date) {
Objects.requireNonNull(date, "date");
@@ -199,7 +210,9 @@ public final class ThaiBuddhistDate
return isoDate.range(field);
case YEAR_OF_ERA: {
ValueRange range = YEAR.range();
- long max = (getProlepticYear() <= 0 ? -(range.getMinimum() + YEARS_DIFFERENCE) + 1 : range.getMaximum() + YEARS_DIFFERENCE);
+ long max = getProlepticYear() <= 0
+ ? -(range.getMinimum() + YEARS_DIFFERENCE) + 1
+ : range.getMaximum() + YEARS_DIFFERENCE;
return ValueRange.of(1, max);
}
}
@@ -218,12 +231,12 @@ public final class ThaiBuddhistDate
return getProlepticMonth();
case YEAR_OF_ERA: {
int prolepticYear = getProlepticYear();
- return (prolepticYear >= 1 ? prolepticYear : 1 - prolepticYear);
+ return prolepticYear >= 1 ? prolepticYear : 1 - prolepticYear;
}
case YEAR:
return getProlepticYear();
case ERA:
- return (getProlepticYear() >= 1 ? 1 : 0);
+ return getProlepticYear() >= 1 ? 1 : 0;
}
return isoDate.getLong(field);
}
@@ -261,7 +274,8 @@ public final class ThaiBuddhistDate
int nvalue = getChronology().range(f).checkValidIntValue(newValue, f);
switch (f) {
case YEAR_OF_ERA:
- return with(isoDate.withYear((getProlepticYear() >= 1 ? nvalue : 1 - nvalue) - YEARS_DIFFERENCE));
+ return with(isoDate.withYear((getProlepticYear() >= 1 ? nvalue : 1 - nvalue)
+ - YEARS_DIFFERENCE));
case YEAR:
return with(isoDate.withYear(nvalue - YEARS_DIFFERENCE));
case ERA:
@@ -311,12 +325,12 @@ public final class ThaiBuddhistDate
}
private ThaiBuddhistDate with(LocalDate newDate) {
- return (newDate.equals(isoDate) ? this : new ThaiBuddhistDate(newDate));
+ return newDate.equals(isoDate) ? this : new ThaiBuddhistDate(newDate);
}
@Override
@SuppressWarnings("unchecked")
- public final ChronoLocalDateTime atTime(LocalTime localTime) {
+ public ChronoLocalDateTime atTime(LocalTime localTime) {
return (ChronoLocalDateTime) super.atTime(localTime);
}
diff --git a/classlib/src/main/java/org/threeten/bp/chrono/ThaiBuddhistEra.java b/classlib/src/main/java/org/threeten/bp/chrono/ThaiBuddhistEra.java
index 0d06cca65..0b0d5d5de 100644
--- a/classlib/src/main/java/org/threeten/bp/chrono/ThaiBuddhistEra.java
+++ b/classlib/src/main/java/org/threeten/bp/chrono/ThaiBuddhistEra.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -32,9 +47,7 @@
package org.threeten.bp.chrono;
import static org.threeten.bp.temporal.ChronoField.ERA;
-
import java.util.Locale;
-
import org.threeten.bp.DateTimeException;
import org.threeten.bp.format.DateTimeFormatterBuilder;
import org.threeten.bp.format.TextStyle;
@@ -79,7 +92,6 @@ public enum ThaiBuddhistEra implements Era {
*
* @param thaiBuddhistEra the era to represent, from 0 to 1
* @return the BuddhistEra singleton, never null
- * @throws IllegalCalendarFieldValueException if the era is invalid
*/
public static ThaiBuddhistEra of(int thaiBuddhistEra) {
switch (thaiBuddhistEra) {
@@ -155,9 +167,9 @@ public enum ThaiBuddhistEra implements Era {
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()) {
+ 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);
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 b353dd443..dd06c21a7 100644
--- a/classlib/src/main/java/org/threeten/bp/format/DateTimeBuilder.java
+++ b/classlib/src/main/java/org/threeten/bp/format/DateTimeBuilder.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -49,14 +64,12 @@ import static org.threeten.bp.temporal.ChronoField.NANO_OF_SECOND;
import static org.threeten.bp.temporal.ChronoField.OFFSET_SECONDS;
import static org.threeten.bp.temporal.ChronoField.SECOND_OF_DAY;
import static org.threeten.bp.temporal.ChronoField.SECOND_OF_MINUTE;
-
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;
import org.threeten.bp.Instant;
import org.threeten.bp.LocalDate;
@@ -165,8 +178,9 @@ public final class DateTimeBuilder
DateTimeBuilder addFieldValue(TemporalField field, long value) {
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);
+ if (old != null && old != value) {
+ throw new DateTimeException("Conflict found: " + field + " " + old + " differs from " + field + " "
+ + value + ": " + this);
}
return putFieldValue0(field, value);
}
@@ -211,7 +225,7 @@ public final class DateTimeBuilder
}
resolveTimeInferZeroes(resolverStyle);
crossCheck();
- if (excessDays != null && excessDays.isZero() == false && date != null && time != null) {
+ if (excessDays != null && !excessDays.isZero() && date != null && time != null) {
date = date.plus(excessDays);
excessDays = Period.ZERO;
}
@@ -232,8 +246,9 @@ public final class DateTimeBuilder
ChronoZonedDateTime> czdt = (ChronoZonedDateTime>) resolvedObject;
if (zone == null) {
zone = czdt.getZone();
- } else if (zone.equals(czdt.getZone()) == false) {
- throw new DateTimeException("ChronoZonedDateTime must use the effective parsed zone: " + zone);
+ } else if (!zone.equals(czdt.getZone())) {
+ throw new DateTimeException("ChronoZonedDateTime must use the effective parsed zone: "
+ + zone);
}
resolvedObject = czdt.toLocalDateTime();
}
@@ -255,7 +270,7 @@ public final class DateTimeBuilder
continue outer; // have to restart to avoid concurrent modification
}
throw new DateTimeException("Unknown type: " + resolvedObject.getClass().getName());
- } else if (fieldValues.containsKey(targetField) == false) {
+ } else if (!fieldValues.containsKey(targetField)) {
changes++;
continue outer; // have to restart to avoid concurrent modification
}
@@ -269,25 +284,25 @@ public final class DateTimeBuilder
}
private void resolveMakeChanges(TemporalField targetField, ChronoLocalDate date) {
- if (chrono.equals(date.getChronology()) == false) {
+ if (!chrono.equals(date.getChronology())) {
throw new DateTimeException("ChronoLocalDate must use the effective parsed chronology: " + chrono);
}
long epochDay = date.toEpochDay();
Long old = fieldValues.put(ChronoField.EPOCH_DAY, epochDay);
- if (old != null && old.longValue() != epochDay) {
- throw new DateTimeException("Conflict found: " + LocalDate.ofEpochDay(old) +
- " differs from " + LocalDate.ofEpochDay(epochDay) +
- " while resolving " + targetField);
+ if (old != null && old != epochDay) {
+ throw new DateTimeException("Conflict found: " + LocalDate.ofEpochDay(old)
+ + " differs from " + LocalDate.ofEpochDay(epochDay)
+ + " while resolving " + targetField);
}
}
private void resolveMakeChanges(TemporalField targetField, LocalTime time) {
long nanOfDay = time.toNanoOfDay();
Long old = fieldValues.put(ChronoField.NANO_OF_DAY, nanOfDay);
- if (old != null && old.longValue() != nanOfDay) {
- throw new DateTimeException("Conflict found: " + LocalTime.ofNanoOfDay(old) +
- " differs from " + time +
- " while resolving " + targetField);
+ if (old != null && old != nanOfDay) {
+ throw new DateTimeException("Conflict found: " + LocalTime.ofNanoOfDay(old)
+ + " differs from " + time
+ + " while resolving " + targetField);
}
}
@@ -297,7 +312,6 @@ public final class DateTimeBuilder
} else {
if (fieldValues.containsKey(EPOCH_DAY)) {
checkDate(LocalDate.ofEpochDay(fieldValues.remove(EPOCH_DAY)));
- return;
}
}
}
@@ -316,7 +330,8 @@ public final class DateTimeBuilder
}
Long val2 = fieldValues.get(field);
if (val1 != val2) {
- throw new DateTimeException("Conflict found: Field " + field + " " + val1 + " differs from " + field + " " + val2 + " derived from " + date);
+ throw new DateTimeException("Conflict found: Field " + field + " " + val1
+ + " differs from " + field + " " + val2 + " derived from " + date);
}
}
}
@@ -465,11 +480,11 @@ public final class DateTimeBuilder
}
if (resolverStyle != ResolverStyle.LENIENT) {
if (hod != null) {
- if (resolverStyle == ResolverStyle.SMART &&
- hod.longValue() == 24 &&
- (moh == null || moh.longValue() == 0) &&
- (som == null || som.longValue() == 0) &&
- (nos == null || nos.longValue() == 0)) {
+ if (resolverStyle == ResolverStyle.SMART
+ && hod == 24
+ && (moh == null || moh == 0)
+ && (som == null || som == 0)
+ && (nos == null || nos == 0)) {
hod = 0L;
excessDays = Period.ofDays(1);
}
@@ -556,7 +571,7 @@ public final class DateTimeBuilder
} else {
resolveMakeChanges(INSTANT_SECONDS, zdt.toLocalDate());
}
- addFieldValue(SECOND_OF_DAY, (long) zdt.toLocalTime().toSecondOfDay());
+ addFieldValue(SECOND_OF_DAY, zdt.toLocalTime().toSecondOfDay());
}
//-----------------------------------------------------------------------
@@ -586,8 +601,8 @@ public final class DateTimeBuilder
continue;
}
if (temporalValue != value) {
- throw new DateTimeException("Cross check failed: " +
- field + " " + temporalValue + " vs " + field + " " + value);
+ throw new DateTimeException("Cross check failed: "
+ + field + " " + temporalValue + " vs " + field + " " + value);
}
it.remove();
}
@@ -595,10 +610,10 @@ public final class DateTimeBuilder
}
private void resolveFractional() {
- if (time == null &&
- (fieldValues.containsKey(INSTANT_SECONDS) ||
- fieldValues.containsKey(SECOND_OF_DAY) ||
- fieldValues.containsKey(SECOND_OF_MINUTE))) {
+ if (time == null
+ && (fieldValues.containsKey(INSTANT_SECONDS)
+ || fieldValues.containsKey(SECOND_OF_DAY)
+ || fieldValues.containsKey(SECOND_OF_MINUTE))) {
if (fieldValues.containsKey(NANO_OF_SECOND)) {
long nos = fieldValues.get(NANO_OF_SECOND);
fieldValues.put(MICRO_OF_SECOND, nos / 1000);
@@ -647,9 +662,9 @@ public final class DateTimeBuilder
if (field == null) {
return false;
}
- return fieldValues.containsKey(field) ||
- (date != null && date.isSupported(field)) ||
- (time != null && time.isSupported(field));
+ return fieldValues.containsKey(field)
+ || (date != null && date.isSupported(field))
+ || (time != null && time.isSupported(field));
}
@Override
diff --git a/classlib/src/main/java/org/threeten/bp/format/DateTimeFormatStyleProvider.java b/classlib/src/main/java/org/threeten/bp/format/DateTimeFormatStyleProvider.java
index 5c9724f1f..2aeadb550 100644
--- a/classlib/src/main/java/org/threeten/bp/format/DateTimeFormatStyleProvider.java
+++ b/classlib/src/main/java/org/threeten/bp/format/DateTimeFormatStyleProvider.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -32,7 +47,6 @@
package org.threeten.bp.format;
import java.util.Locale;
-
import org.threeten.bp.chrono.Chronology;
/**
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 bf2996284..a376ffaa6 100644
--- a/classlib/src/main/java/org/threeten/bp/format/DateTimeFormatter.java
+++ b/classlib/src/main/java/org/threeten/bp/format/DateTimeFormatter.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -40,7 +55,6 @@ import static org.threeten.bp.temporal.ChronoField.MONTH_OF_YEAR;
import static org.threeten.bp.temporal.ChronoField.NANO_OF_SECOND;
import static org.threeten.bp.temporal.ChronoField.SECOND_OF_MINUTE;
import static org.threeten.bp.temporal.ChronoField.YEAR;
-
import java.io.IOException;
import java.text.FieldPosition;
import java.text.Format;
@@ -54,7 +68,6 @@ import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
-
import org.threeten.bp.DateTimeException;
import org.threeten.bp.Period;
import org.threeten.bp.ZoneId;
@@ -1533,7 +1546,8 @@ public final class DateTimeFormatter {
// continue
}
}
- throw new DateTimeException("Unable to convert parsed text to any specified type: " + Arrays.toString(types));
+ throw new DateTimeException("Unable to convert parsed text to any specified type: "
+ + Arrays.toString(types));
} catch (DateTimeParseException ex) {
throw ex;
} catch (RuntimeException ex) {
@@ -1566,7 +1580,7 @@ public final class DateTimeFormatter {
* @throws DateTimeParseException if the parse fails
*/
private DateTimeBuilder parseToBuilder(final CharSequence text, final ParsePosition position) {
- ParsePosition pos = (position != null ? position : new ParsePosition(0));
+ ParsePosition pos = position != null ? position : new ParsePosition(0);
Parsed result = parseUnresolved0(text, pos);
if (result == null || pos.getErrorIndex() >= 0 || (position == null && pos.getIndex() < text.length())) {
String abbr = "";
@@ -1576,11 +1590,12 @@ public final class DateTimeFormatter {
abbr = text.toString();
}
if (pos.getErrorIndex() >= 0) {
- throw new DateTimeParseException("Text '" + abbr + "' could not be parsed at index " +
- pos.getErrorIndex(), text, pos.getErrorIndex());
+ throw new DateTimeParseException("Text '" + abbr + "' could not be parsed at index "
+ + pos.getErrorIndex(), text, pos.getErrorIndex());
} else {
- throw new DateTimeParseException("Text '" + abbr + "' could not be parsed, unparsed text found at index " +
- pos.getIndex(), text, pos.getIndex());
+ throw new DateTimeParseException("Text '" + abbr
+ + "' could not be parsed, unparsed text found at index "
+ + pos.getIndex(), text, pos.getIndex());
}
}
return result.toBuilder();
@@ -1744,7 +1759,7 @@ public final class DateTimeFormatter {
try {
if (query == null) {
return formatter.parseToBuilder(text, null)
- .resolve(formatter.getResolverStyle(), formatter.getResolverFields());
+ .resolve(formatter.getResolverStyle(), formatter.getResolverFields());
}
return formatter.parse(text, query);
} catch (DateTimeParseException ex) {
@@ -1773,7 +1788,7 @@ public final class DateTimeFormatter {
}
try {
DateTimeBuilder builder = unresolved.toBuilder()
- .resolve(formatter.getResolverStyle(), formatter.getResolverFields());
+ .resolve(formatter.getResolverStyle(), formatter.getResolverFields());
if (query == null) {
return builder;
}
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 cb3c76250..2eeae6d1b 100644
--- a/classlib/src/main/java/org/threeten/bp/format/DateTimeFormatterBuilder.java
+++ b/classlib/src/main/java/org/threeten/bp/format/DateTimeFormatterBuilder.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -40,7 +55,6 @@ import static org.threeten.bp.temporal.ChronoField.NANO_OF_SECOND;
import static org.threeten.bp.temporal.ChronoField.OFFSET_SECONDS;
import static org.threeten.bp.temporal.ChronoField.SECOND_OF_MINUTE;
import static org.threeten.bp.temporal.ChronoField.YEAR;
-
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
@@ -63,7 +77,6 @@ import java.util.ResourceBundle;
import java.util.Set;
import java.util.TimeZone;
import java.util.TreeMap;
-
import org.threeten.bp.DateTimeException;
import org.threeten.bp.Instant;
import org.threeten.bp.LocalDate;
@@ -117,11 +130,9 @@ public final class DateTimeFormatterBuilder {
/**
* Query for a time-zone that is region-only.
*/
- private static final TemporalQuery QUERY_REGION_ONLY = new TemporalQuery() {
- public ZoneId queryFrom(TemporalAccessor temporal) {
- ZoneId zone = temporal.query(TemporalQueries.zoneId());
- return (zone != null && zone instanceof ZoneOffset == false ? zone : null);
- }
+ private static final TemporalQuery QUERY_REGION_ONLY = temporal -> {
+ ZoneId zone = temporal.query(TemporalQueries.zoneId());
+ return zone != null && !(zone instanceof ZoneOffset) ? zone : null;
};
/**
@@ -135,7 +146,7 @@ public final class DateTimeFormatterBuilder {
/**
* The list of printers that will be used.
*/
- private final List printerParsers = new ArrayList();
+ private final List printerParsers = new ArrayList<>();
/**
* Whether this builder produces an optional formatter.
*/
@@ -452,8 +463,8 @@ public final class DateTimeFormatterBuilder {
throw new IllegalArgumentException("The maximum width must be from 1 to 19 inclusive but was " + maxWidth);
}
if (maxWidth < minWidth) {
- throw new IllegalArgumentException("The maximum width must exceed or equal the minimum width but " +
- maxWidth + " < " + minWidth);
+ throw new IllegalArgumentException("The maximum width must exceed or equal the minimum width but "
+ + maxWidth + " < " + minWidth);
}
NumberPrinterParser pp = new NumberPrinterParser(field, minWidth, maxWidth, signStyle);
appendValue(pp);
@@ -571,13 +582,12 @@ public final class DateTimeFormatterBuilder {
/**
* Appends a fixed width printer-parser.
*
- * @param width the width
* @param pp the printer-parser, not null
* @return this, for chaining, not null
*/
private DateTimeFormatterBuilder appendValue(NumberPrinterParser pp) {
- if (active.valueParserIndex >= 0 &&
- active.printerParsers.get(active.valueParserIndex) instanceof NumberPrinterParser) {
+ if (active.valueParserIndex >= 0
+ && active.printerParsers.get(active.valueParserIndex) instanceof NumberPrinterParser) {
final int activeValueParser = active.valueParserIndex;
// adjacent parsing mode, update setting in previous parsers
@@ -1057,8 +1067,7 @@ public final class DateTimeFormatterBuilder {
* @param preferredZones the set of preferred zone ids, not null
* @return this, for chaining, not null
*/
- public DateTimeFormatterBuilder appendZoneText(TextStyle textStyle,
- Set preferredZones) {
+ public DateTimeFormatterBuilder appendZoneText(TextStyle textStyle, Set preferredZones) {
// TODO: preferred zones currently ignored
Objects.requireNonNull(preferredZones, "preferredZones");
appendInternal(new ZoneTextPrinterParser(textStyle));
@@ -1389,7 +1398,9 @@ public final class DateTimeFormatterBuilder {
char cur = pattern.charAt(pos);
if ((cur >= 'A' && cur <= 'Z') || (cur >= 'a' && cur <= 'z')) {
int start = pos++;
- for ( ; pos < pattern.length() && pattern.charAt(pos) == cur; pos++); // short loop
+ while (pos < pattern.length() && pattern.charAt(pos) == cur) {
+ pos++;
+ }
int count = pos - start;
// padding
if (cur == 'p') {
@@ -1399,7 +1410,9 @@ public final class DateTimeFormatterBuilder {
if ((cur >= 'A' && cur <= 'Z') || (cur >= 'a' && cur <= 'z')) {
pad = count;
start = pos++;
- for ( ; pos < pattern.length() && pattern.charAt(pos) == cur; pos++); // short loop
+ while (pos < pattern.length() && pattern.charAt(pos) == cur) {
+ pos++;
+ }
count = pos - start;
}
}
@@ -1432,7 +1445,7 @@ public final class DateTimeFormatterBuilder {
} else if (count == 4) {
appendLocalizedOffset(TextStyle.FULL);
} else if (count == 5) {
- appendOffset("+HH:MM:ss","Z");
+ appendOffset("+HH:MM:ss", "Z");
} else {
throw new IllegalArgumentException("Too many pattern letters: " + cur);
}
@@ -1453,7 +1466,7 @@ public final class DateTimeFormatterBuilder {
if (count > 5) {
throw new IllegalArgumentException("Too many pattern letters: " + cur);
}
- String zero = (count == 1 ? "+00" : (count % 2 == 0 ? "+0000" : "+00:00"));
+ String zero = count == 1 ? "+00" : (count % 2 == 0 ? "+0000" : "+00:00");
appendOffset(OffsetIdPrinterParser.PATTERNS[count + (count == 1 ? 0 : 1)], zero);
} else if (cur == 'W') {
if (count > 1) {
@@ -1475,7 +1488,7 @@ public final class DateTimeFormatterBuilder {
} else if (cur == '\'') {
// parse literals
int start = pos++;
- for ( ; pos < pattern.length(); pos++) {
+ for (; pos < pattern.length(); pos++) {
if (pattern.charAt(pos) == '\'') {
if (pos + 1 < pattern.length() && pattern.charAt(pos + 1) == '\'') {
pos++;
@@ -1813,7 +1826,8 @@ public final class DateTimeFormatterBuilder {
*/
public DateTimeFormatterBuilder optionalEnd() {
if (active.parent == null) {
- throw new IllegalStateException("Cannot call optionalEnd() as there was no previous call to optionalStart()");
+ throw new IllegalStateException("Cannot call optionalEnd() as there was no previous call "
+ + "to optionalStart()");
}
if (active.printerParsers.size() > 0) {
CompositePrinterParser cpp = new CompositePrinterParser(active.printerParsers, active.optional);
@@ -1993,7 +2007,7 @@ public final class DateTimeFormatterBuilder {
}
try {
for (DateTimePrinterParser pp : printerParsers) {
- if (pp.print(context, buf) == false) {
+ if (!pp.print(context, buf)) {
buf.setLength(length); // reset buffer
return true;
}
@@ -2071,7 +2085,7 @@ public final class DateTimeFormatterBuilder {
@Override
public boolean print(DateTimePrintContext context, StringBuilder buf) {
int preLen = buf.length();
- if (printerParser.print(context, buf) == false) {
+ if (!printerParser.print(context, buf)) {
return false;
}
int len = buf.length() - preLen;
@@ -2105,8 +2119,8 @@ public final class DateTimeFormatterBuilder {
endPos = text.length();
}
int pos = position;
- while (pos < endPos &&
- (caseSensitive ? text.charAt(pos) == padChar : context.charEquals(text.charAt(pos), padChar))) {
+ while (pos < endPos
+ && (caseSensitive ? text.charAt(pos) == padChar : context.charEquals(text.charAt(pos), padChar))) {
pos++;
}
text = text.subSequence(0, endPos);
@@ -2127,7 +2141,7 @@ public final class DateTimeFormatterBuilder {
/**
* Enumeration to apply simple parse settings.
*/
- static enum SettingsParser implements DateTimePrinterParser {
+ enum SettingsParser implements DateTimePrinterParser {
SENSITIVE,
INSENSITIVE,
STRICT,
@@ -2176,10 +2190,12 @@ public final class DateTimeFormatterBuilder {
this.value = value;
}
+ @Override
public boolean print(DateTimePrintContext context, StringBuilder buf) {
return true;
}
+ @Override
public int parse(DateTimeParseContext context, CharSequence text, int position) {
if (context.getParsed(field) == null) {
context.setParsedField(field, value, position, position);
@@ -2212,7 +2228,7 @@ public final class DateTimeFormatterBuilder {
return ~position;
}
char ch = text.charAt(position);
- if (context.charEquals(literal, ch) == false) {
+ if (!context.charEquals(literal, ch)) {
return ~position;
}
return position + 1;
@@ -2250,7 +2266,7 @@ public final class DateTimeFormatterBuilder {
if (position > length || position < 0) {
throw new IndexOutOfBoundsException();
}
- if (context.subSequenceEquals(text, position, literal, 0, literal.length()) == false) {
+ if (!context.subSequenceEquals(text, position, literal, 0, literal.length())) {
return ~position;
}
return position + literal.length();
@@ -2318,7 +2334,8 @@ public final class DateTimeFormatterBuilder {
* @param subsequentWidth the width of subsequent non-negative numbers, 0 or greater,
* -1 if fixed width due to active adjacent parsing
*/
- private NumberPrinterParser(TemporalField field, int minWidth, int maxWidth, SignStyle signStyle, int subsequentWidth) {
+ private NumberPrinterParser(TemporalField field, int minWidth, int maxWidth, SignStyle signStyle,
+ int subsequentWidth) {
// validated by caller
this.field = field;
this.minWidth = minWidth;
@@ -2346,7 +2363,8 @@ public final class DateTimeFormatterBuilder {
* @return a new updated printer-parser, not null
*/
NumberPrinterParser withSubsequentWidth(int subsequentWidth) {
- return new NumberPrinterParser(field, minWidth, maxWidth, signStyle, this.subsequentWidth + subsequentWidth);
+ return new NumberPrinterParser(field, minWidth, maxWidth, signStyle,
+ this.subsequentWidth + subsequentWidth);
}
@Override
@@ -2357,11 +2375,11 @@ public final class DateTimeFormatterBuilder {
}
long value = getValue(context, valueLong);
DecimalStyle symbols = context.getSymbols();
- String str = (value == Long.MIN_VALUE ? "9223372036854775808" : Long.toString(Math.abs(value)));
+ String str = value == Long.MIN_VALUE ? "9223372036854775808" : Long.toString(Math.abs(value));
if (str.length() > maxWidth) {
- throw new DateTimeException("Field " + field +
- " cannot be printed as the value " + value +
- " exceeds the maximum print width of " + maxWidth);
+ throw new DateTimeException("Field " + field
+ + " cannot be printed as the value " + value
+ + " exceeds the maximum print width of " + maxWidth);
}
str = symbols.convertNumberToI18N(str);
@@ -2384,9 +2402,9 @@ public final class DateTimeFormatterBuilder {
buf.append(symbols.getNegativeSign());
break;
case NOT_NEGATIVE:
- throw new DateTimeException("Field " + field +
- " cannot be printed as the value " + value +
- " cannot be negative according to the SignStyle");
+ throw new DateTimeException("Field " + field
+ + " cannot be printed as the value " + value
+ + " cannot be negative according to the SignStyle");
}
}
for (int i = 0; i < minWidth - str.length(); i++) {
@@ -2408,8 +2426,8 @@ public final class DateTimeFormatterBuilder {
}
boolean isFixedWidth(DateTimeParseContext context) {
- return subsequentWidth == -1 ||
- (subsequentWidth > 0 && minWidth == maxWidth && signStyle == SignStyle.NOT_NEGATIVE);
+ return subsequentWidth == -1
+ || (subsequentWidth > 0 && minWidth == maxWidth && signStyle == SignStyle.NOT_NEGATIVE);
}
@Override
@@ -2422,13 +2440,13 @@ public final class DateTimeFormatterBuilder {
boolean negative = false;
boolean positive = false;
if (sign == context.getSymbols().getPositiveSign()) {
- if (signStyle.parse(true, context.isStrict(), minWidth == maxWidth) == false) {
+ if (!signStyle.parse(true, context.isStrict(), minWidth == maxWidth)) {
return ~position;
}
positive = true;
position++;
} else if (sign == context.getSymbols().getNegativeSign()) {
- if (signStyle.parse(false, context.isStrict(), minWidth == maxWidth) == false) {
+ if (!signStyle.parse(false, context.isStrict(), minWidth == maxWidth)) {
return ~position;
}
negative = true;
@@ -2438,12 +2456,13 @@ public final class DateTimeFormatterBuilder {
return ~position;
}
}
- int effMinWidth = (context.isStrict() || isFixedWidth(context) ? minWidth : 1);
+ int effMinWidth = context.isStrict() || isFixedWidth(context) ? minWidth : 1;
int minEndPos = position + effMinWidth;
if (minEndPos > length) {
return ~position;
}
- int effMaxWidth = (context.isStrict() || isFixedWidth(context) ? maxWidth : 9) + Math.max(subsequentWidth, 0);
+ int effMaxWidth = (context.isStrict() || isFixedWidth(context) ? maxWidth : 9)
+ + Math.max(subsequentWidth, 0);
long total = 0;
BigInteger totalBig = null;
int pos = position;
@@ -2569,11 +2588,12 @@ public final class DateTimeFormatterBuilder {
throw new IllegalArgumentException("The maxWidth must be greater than the width");
}
if (baseDate == null) {
- if (field.range().isValidValue(baseValue) == false) {
+ if (!field.range().isValidValue(baseValue)) {
throw new IllegalArgumentException("The base value must be within the range of the field");
}
if ((((long) baseValue) + EXCEED_POINTS[width]) > Integer.MAX_VALUE) {
- throw new DateTimeException("Unable to add printer-parser as the range exceeds the capacity of an int");
+ throw new DateTimeException("Unable to add printer-parser as the range exceeds "
+ + "the capacity of an int");
}
}
this.baseValue = baseValue;
@@ -2642,7 +2662,7 @@ public final class DateTimeFormatterBuilder {
@Override
boolean isFixedWidth(DateTimeParseContext context) {
- if (context.isStrict() == false) {
+ if (!context.isStrict()) {
return false;
}
return super.isFixedWidth(context);
@@ -2650,7 +2670,8 @@ public final class DateTimeFormatterBuilder {
@Override
public String toString() {
- return "ReducedValue(" + field + "," + minWidth + "," + maxWidth + "," + (baseDate != null ? baseDate : baseValue) + ")";
+ return "ReducedValue(" + field + "," + minWidth + "," + maxWidth + ","
+ + (baseDate != null ? baseDate : baseValue) + ")";
}
}
@@ -2674,7 +2695,7 @@ public final class DateTimeFormatterBuilder {
*/
FractionPrinterParser(TemporalField field, int minWidth, int maxWidth, boolean decimalPoint) {
Objects.requireNonNull(field, "field");
- if (field.range().isFixed() == false) {
+ if (!field.range().isFixed()) {
throw new IllegalArgumentException("Field must have a fixed set of values: " + field);
}
if (minWidth < 0 || minWidth > 9) {
@@ -2684,8 +2705,8 @@ public final class DateTimeFormatterBuilder {
throw new IllegalArgumentException("Maximum width must be from 1 to 9 inclusive but was " + maxWidth);
}
if (maxWidth < minWidth) {
- throw new IllegalArgumentException("Maximum width must exceed or equal the minimum width but " +
- maxWidth + " < " + minWidth);
+ throw new IllegalArgumentException("Maximum width must exceed or equal the minimum width but "
+ + maxWidth + " < " + minWidth);
}
this.field = field;
this.minWidth = minWidth;
@@ -2725,17 +2746,17 @@ public final class DateTimeFormatterBuilder {
@Override
public int parse(DateTimeParseContext context, CharSequence text, int position) {
- int effectiveMin = (context.isStrict() ? minWidth : 0);
- int effectiveMax = (context.isStrict() ? maxWidth : 9);
+ int effectiveMin = context.isStrict() ? minWidth : 0;
+ int effectiveMax = context.isStrict() ? maxWidth : 9;
int length = text.length();
if (position == length) {
// valid if whole field is optional, invalid if minimum width
- return (effectiveMin > 0 ? ~position : position);
+ return effectiveMin > 0 ? ~position : position;
}
if (decimalPoint) {
if (text.charAt(position) != context.getSymbols().getDecimalSeparator()) {
// valid if whole field is optional, invalid if minimum width
- return (effectiveMin > 0 ? ~position : position);
+ return effectiveMin > 0 ? ~position : position;
}
position++;
}
@@ -2816,7 +2837,7 @@ public final class DateTimeFormatterBuilder {
@Override
public String toString() {
- String decimal = (decimalPoint ? ",DecimalPoint" : "");
+ String decimal = decimalPoint ? ",DecimalPoint" : "";
return "Fraction(" + field + "," + minWidth + "," + maxWidth + decimal + ")";
}
}
@@ -2869,7 +2890,7 @@ public final class DateTimeFormatterBuilder {
if (position < 0 || position > length) {
throw new IndexOutOfBoundsException();
}
- TextStyle style = (context.isStrict() ? textStyle : null);
+ TextStyle style = context.isStrict() ? textStyle : null;
Iterator> it = provider.getTextIterator(field, style, context.getLocale());
if (it != null) {
while (it.hasNext()) {
@@ -2927,7 +2948,7 @@ public final class DateTimeFormatterBuilder {
public boolean print(DateTimePrintContext context, StringBuilder buf) {
// use INSTANT_SECONDS, thus this code is not bound by Instant.MAX
Long inSecs = context.getValue(INSTANT_SECONDS);
- Long inNanos = 0L;
+ long inNanos = 0L;
if (context.getTemporal().isSupported(NANO_OF_SECOND)) {
inNanos = context.getTemporal().getLong(NANO_OF_SECOND);
}
@@ -2979,13 +3000,13 @@ public final class DateTimeFormatterBuilder {
} else if (inNano % 1000 == 0) {
buf.append(Integer.toString((inNano / 1000) + 1000000).substring(1));
} else {
- buf.append(Integer.toString((inNano) + 1000000000).substring(1));
+ buf.append(Integer.toString(inNano + 1000000000).substring(1));
}
}
} else if (fractionalDigits > 0 || (fractionalDigits == -1 && inNano > 0)) {
buf.append('.');
int div = 100000000;
- for (int i = 0; ((fractionalDigits == -1 && inNano > 0) || i < fractionalDigits); i++) {
+ for (int i = 0; (fractionalDigits == -1 && inNano > 0) || i < fractionalDigits; i++) {
int digit = inNano / div;
buf.append((char) (digit + '0'));
inNano = inNano - (digit * div);
@@ -3000,12 +3021,13 @@ public final class DateTimeFormatterBuilder {
public int parse(DateTimeParseContext context, CharSequence text, int position) {
// new context to avoid overwriting fields like year/month/day
DateTimeParseContext newContext = context.copy();
- int minDigits = (fractionalDigits < 0 ? 0 : fractionalDigits);
- int maxDigits = (fractionalDigits < 0 ? 9 : fractionalDigits);
+ int minDigits = fractionalDigits < 0 ? 0 : fractionalDigits;
+ int maxDigits = fractionalDigits < 0 ? 9 : fractionalDigits;
CompositePrinterParser parser = new DateTimeFormatterBuilder()
.append(DateTimeFormatter.ISO_LOCAL_DATE).appendLiteral('T')
.appendValue(HOUR_OF_DAY, 2).appendLiteral(':').appendValue(MINUTE_OF_HOUR, 2).appendLiteral(':')
- .appendValue(SECOND_OF_MINUTE, 2).appendFraction(NANO_OF_SECOND, minDigits, maxDigits, true).appendLiteral('Z')
+ .appendValue(SECOND_OF_MINUTE, 2).appendFraction(NANO_OF_SECOND, minDigits, maxDigits, true)
+ .appendLiteral('Z')
.toFormatter().toPrinterParser(false);
int pos = parser.parse(newContext, text, position);
if (pos < 0) {
@@ -3020,8 +3042,8 @@ public final class DateTimeFormatterBuilder {
int min = newContext.getParsed(MINUTE_OF_HOUR).intValue();
Long secVal = newContext.getParsed(SECOND_OF_MINUTE);
Long nanoVal = newContext.getParsed(NANO_OF_SECOND);
- int sec = (secVal != null ? secVal.intValue() : 0);
- int nano = (nanoVal != null ? nanoVal.intValue() : 0);
+ int sec = secVal != null ? secVal.intValue() : 0;
+ int nano = nanoVal != null ? nanoVal.intValue() : 0;
int year = (int) yearParsed % 10000;
int days = 0;
if (hour == 24 && min == 0 && sec == 0 && nano == 0) {
@@ -3141,12 +3163,12 @@ public final class DateTimeFormatterBuilder {
char sign = text.charAt(position); // IOOBE if invalid position
if (sign == '+' || sign == '-') {
// starts
- int negative = (sign == '-' ? -1 : 1);
+ int negative = sign == '-' ? -1 : 1;
int[] array = new int[4];
array[0] = position + 1;
- if ((parseNumber(array, 1, text, true) ||
- parseNumber(array, 2, text, type >=3) ||
- parseNumber(array, 3, text, false)) == false) {
+ if (!(parseNumber(array, 1, text, true)
+ || parseNumber(array, 2, text, type >= 3)
+ || parseNumber(array, 3, text, false))) {
// success
long offsetSecs = negative * (array[1] * 3600L + array[2] * 60L + array[3]);
return context.setParsedField(OFFSET_SECONDS, offsetSecs, position, array[0]);
@@ -3244,7 +3266,7 @@ public final class DateTimeFormatterBuilder {
@Override
public int parse(DateTimeParseContext context, CharSequence text, int position) {
- if (context.subSequenceEquals(text, position, "GMT", 0, 3) == false) {
+ if (!context.subSequenceEquals(text, position, "GMT", 0, 3)) {
return ~position;
}
position += 3;
@@ -3259,7 +3281,7 @@ public final class DateTimeFormatterBuilder {
if (sign != '+' && sign != '-') {
return context.setParsedField(OFFSET_SECONDS, 0, position, position);
}
- int negative = (sign == '-' ? -1 : 1);
+ int negative = sign == '-' ? -1 : 1;
if (position == end) {
return ~position;
}
@@ -3270,11 +3292,11 @@ public final class DateTimeFormatterBuilder {
return ~position;
}
position++;
- int hour = ((int) (ch - 48));
+ int hour = ch - 48;
if (position != end) {
ch = text.charAt(position);
if (ch >= '0' && ch <= '9') {
- hour = hour * 10 + ((int) (ch - 48));
+ hour = hour * 10 + ch - 48;
if (hour > 23) {
return ~position;
}
@@ -3295,13 +3317,13 @@ public final class DateTimeFormatterBuilder {
return ~position;
}
position++;
- int min = ((int) (ch - 48));
+ int min = ch - 48;
ch = text.charAt(position);
if (ch < '0' || ch > '9') {
return ~position;
}
position++;
- min = min * 10 + ((int) (ch - 48));
+ min = min * 10 + ch - 48;
if (min > 59) {
return ~position;
}
@@ -3319,13 +3341,13 @@ public final class DateTimeFormatterBuilder {
return ~position;
}
position++;
- int sec = ((int) (ch - 48));
+ int sec = ch - 48;
ch = text.charAt(position);
if (ch < '0' || ch > '9') {
return ~position;
}
position++;
- sec = sec * 10 + ((int) (ch - 48));
+ sec = sec * 10 + ch - 48;
if (sec > 59) {
return ~position;
}
@@ -3340,15 +3362,12 @@ public final class DateTimeFormatterBuilder {
*/
static final class ZoneTextPrinterParser implements DateTimePrinterParser {
/** The text style to output. */
- private static final Comparator LENGTH_COMPARATOR = new Comparator() {
- @Override
- public int compare(String str1, String str2) {
- int cmp = str2.length() - str1.length();
- if (cmp == 0) {
- cmp = str1.compareTo(str2);
- }
- return cmp;
+ private static final Comparator LENGTH_COMPARATOR = (str1, str2) -> {
+ int cmp = str2.length() - str1.length();
+ if (cmp == 0) {
+ cmp = str1.compareTo(str2);
}
+ return cmp;
};
/** The text style to output. */
private final TextStyle textStyle;
@@ -3375,7 +3394,7 @@ public final class DateTimeFormatterBuilder {
daylight = zone.getRules().isDaylightSavings(instant);
}
TimeZone tz = TimeZone.getTimeZone(zone.getId());
- int tzstyle = (textStyle.asNormal() == TextStyle.FULL ? TimeZone.LONG : TimeZone.SHORT);
+ int tzstyle = textStyle.asNormal() == TextStyle.FULL ? TimeZone.LONG : TimeZone.SHORT;
String text = tz.getDisplayName(daylight, tzstyle, context.getLocale());
buf.append(text);
return true;
@@ -3389,7 +3408,7 @@ public final class DateTimeFormatterBuilder {
for (String id : ZoneId.getAvailableZoneIds()) {
ids.put(id, id);
TimeZone tz = TimeZone.getTimeZone(id);
- int tzstyle = (textStyle.asNormal() == TextStyle.FULL ? TimeZone.LONG : TimeZone.SHORT);
+ int tzstyle = textStyle.asNormal() == TextStyle.FULL ? TimeZone.LONG : TimeZone.SHORT;
String textWinter = tz.getDisplayName(false, tzstyle, context.getLocale());
if (id.startsWith("Etc/") || (!textWinter.startsWith("GMT+") && !textWinter.startsWith("GMT+"))) {
ids.put(textWinter, id);
@@ -3479,17 +3498,15 @@ public final class DateTimeFormatterBuilder {
return endPos;
} else if (length >= position + 2) {
char nextNextChar = text.charAt(position + 1);
- if (context.charEquals(nextChar, 'U') &&
- context.charEquals(nextNextChar, 'T')) {
- if (length >= position + 3 &&
- context.charEquals(text.charAt(position + 2), 'C')) {
+ if (context.charEquals(nextChar, 'U') && context.charEquals(nextNextChar, 'T')) {
+ if (length >= position + 3 && context.charEquals(text.charAt(position + 2), 'C')) {
return parsePrefixedOffset(context, text, position, position + 3);
}
return parsePrefixedOffset(context, text, position, position + 2);
- } else if (context.charEquals(nextChar, 'G') &&
- length >= position + 3 &&
- context.charEquals(nextNextChar, 'M') &&
- context.charEquals(text.charAt(position + 2), 'T')) {
+ } else if (context.charEquals(nextChar, 'G')
+ && length >= position + 3
+ && context.charEquals(nextNextChar, 'M')
+ && context.charEquals(text.charAt(position + 2), 'T')) {
return parsePrefixedOffset(context, text, position, position + 3);
}
}
@@ -3502,7 +3519,8 @@ public final class DateTimeFormatterBuilder {
synchronized (this) {
cached = cachedSubstringTree;
if (cached == null || cached.getKey() != regionIdsSize) {
- cachedSubstringTree = cached = new SimpleImmutableEntry(regionIdsSize, prepareParser(regionIds));
+ cached = new SimpleImmutableEntry<>(regionIdsSize, prepareParser(regionIds));
+ cachedSubstringTree = cached;
}
}
}
@@ -3541,7 +3559,7 @@ public final class DateTimeFormatterBuilder {
return null;
}
if (caseSensitive) {
- return (regionIds.contains(parsedZoneId) ? ZoneId.of(parsedZoneId) : null);
+ return regionIds.contains(parsedZoneId) ? ZoneId.of(parsedZoneId) : null;
} else {
for (String regionId : regionIds) {
if (regionId.equalsIgnoreCase(parsedZoneId)) {
@@ -3601,11 +3619,11 @@ public final class DateTimeFormatterBuilder {
/**
* Map of a substring to a set of substrings that contain the key.
*/
- private final Map substringMap = new HashMap();
+ private final Map substringMap = new HashMap<>();
/**
* Map of a substring to a set of substrings that contain the key.
*/
- private final Map substringMapCI = new HashMap();
+ private final Map substringMapCI = new HashMap<>();
/**
* Constructor.
@@ -3695,8 +3713,10 @@ public final class DateTimeFormatterBuilder {
if (textStyle == null) {
buf.append(chrono.getId());
} else {
+ // TODO: replace with supported bundle type
ResourceBundle bundle = ResourceBundle.getBundle(
- "org.threeten.bp.format.ChronologyText", context.getLocale(), DateTimeFormatterBuilder.class.getClassLoader());
+ "org.threeten.bp.format.ChronologyText", context.getLocale(),
+ DateTimeFormatterBuilder.class.getClassLoader());
try {
String text = bundle.getString(chrono.getId());
buf.append(text);
@@ -3778,8 +3798,8 @@ public final class DateTimeFormatterBuilder {
@Override
public String toString() {
- return "Localized(" + (dateStyle != null ? dateStyle : "") + "," +
- (timeStyle != null ? timeStyle : "") + ")";
+ return "Localized(" + (dateStyle != null ? dateStyle : "") + ","
+ + (timeStyle != null ? timeStyle : "") + ")";
}
}
@@ -3827,7 +3847,8 @@ public final class DateTimeFormatterBuilder {
break;
case 'Y': // weekyear
if (count == 2) {
- pp = new ReducedPrinterParser(weekFields.weekBasedYear(), 2, 2, 0, ReducedPrinterParser.BASE_DATE);
+ pp = new ReducedPrinterParser(weekFields.weekBasedYear(), 2, 2, 0,
+ ReducedPrinterParser.BASE_DATE);
} else {
pp = new NumberPrinterParser(weekFields.weekBasedYear(), count, 19,
(count < 4) ? SignStyle.NORMAL : SignStyle.EXCEEDS_PAD, -1);
@@ -3871,11 +3892,7 @@ public final class DateTimeFormatterBuilder {
/**
* Length comparator.
*/
- static final Comparator LENGTH_SORT = new Comparator() {
- @Override
- public int compare(String str1, String str2) {
- return str1.length() == str2.length() ? str1.compareTo(str2) : str1.length() - str2.length();
- }
- };
+ static final Comparator LENGTH_SORT =
+ (str1, str2) -> str1.length() == str2.length() ? str1.compareTo(str2) : str1.length() - str2.length();
}
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 72b1f064d..fcfb14141 100644
--- a/classlib/src/main/java/org/threeten/bp/format/DateTimeParseContext.java
+++ b/classlib/src/main/java/org/threeten/bp/format/DateTimeParseContext.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2020 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/*
* Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
*
@@ -37,7 +52,6 @@ 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;
@@ -224,8 +238,8 @@ public final class DateTimeParseContext {
for (int i = 0; i < length; i++) {
char ch1 = cs1.charAt(offset1 + i);
char ch2 = cs2.charAt(offset2 + i);
- if (ch1 != ch2 && Character.toUpperCase(ch1) != Character.toUpperCase(ch2) &&
- Character.toLowerCase(ch1) != Character.toLowerCase(ch2)) {
+ if (ch1 != ch2 && Character.toUpperCase(ch1) != Character.toUpperCase(ch2)
+ && Character.toLowerCase(ch1) != Character.toLowerCase(ch2)) {
return false;
}
}
@@ -256,9 +270,9 @@ public final class DateTimeParseContext {
* @return true if equal
*/
static boolean charEqualsIgnoreCase(char c1, char c2) {
- return c1 == c2 ||
- Character.toUpperCase(c1) == Character.toUpperCase(c2) ||
- Character.toLowerCase(c1) == Character.toLowerCase(c2);
+ return c1 == c2
+ || Character.toUpperCase(c1) == Character.toUpperCase(c2)
+ || Character.toLowerCase(c1) == Character.toLowerCase(c2);
}
//-----------------------------------------------------------------------
@@ -369,7 +383,8 @@ public final class DateTimeParseContext {
}
}
- void addChronologyChangedParser(ReducedPrinterParser reducedPrinterParser, long value, int errorPos, int successPos) {
+ void addChronologyChangedParser(ReducedPrinterParser reducedPrinterParser, long value, int errorPos,
+ int successPos) {
Parsed currentParsed = currentParsed();
if (currentParsed.callbacks == null) {
currentParsed.callbacks = new ArrayList