This commit is contained in:
Chris Hegarty 2013-10-15 20:47:21 +01:00
commit 1f0c182672
79 changed files with 1645 additions and 1647 deletions

View File

@ -71,6 +71,7 @@ import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.UnsupportedTemporalTypeException;
import java.time.temporal.ValueRange;
@ -403,7 +404,7 @@ public enum DayOfWeek implements TemporalAccessor, TemporalAdjuster {
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.precision()) {
if (query == TemporalQueries.precision()) {
return (R) DAYS;
}
return TemporalAccessor.super.query(query);

View File

@ -76,7 +76,6 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
@ -87,6 +86,7 @@ import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
@ -1050,12 +1050,12 @@ public final class Instant
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.precision()) {
if (query == TemporalQueries.precision()) {
return (R) NANOS;
}
// inline TemporalAccessor.super.query(query) as an optimization
if (query == TemporalQuery.chronology() || query == TemporalQuery.zoneId() ||
query == TemporalQuery.zone() || query == TemporalQuery.offset()) {
if (query == TemporalQueries.chronology() || query == TemporalQueries.zoneId() ||
query == TemporalQueries.zone() || query == TemporalQueries.offset()) {
return null;
}
return query.queryFrom(this);

View File

@ -78,7 +78,6 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.chrono.ChronoLocalDate;
import java.time.chrono.Era;
@ -92,6 +91,7 @@ import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
@ -342,7 +342,7 @@ public final class LocalDate
* A {@code TemporalAccessor} represents an arbitrary set of date and time information,
* which this factory converts to an instance of {@code LocalDate}.
* <p>
* The conversion uses the {@link TemporalQuery#localDate()} query, which relies
* The conversion uses the {@link TemporalQueries#localDate()} query, which relies
* on extracting the {@link ChronoField#EPOCH_DAY EPOCH_DAY} field.
* <p>
* This method matches the signature of the functional interface {@link TemporalQuery}
@ -354,7 +354,7 @@ public final class LocalDate
*/
public static LocalDate from(TemporalAccessor temporal) {
Objects.requireNonNull(temporal, "temporal");
LocalDate date = temporal.query(TemporalQuery.localDate());
LocalDate date = temporal.query(TemporalQueries.localDate());
if (date == null) {
throw new DateTimeException("Unable to obtain LocalDate from TemporalAccessor: " +
temporal + " of type " + temporal.getClass().getName());
@ -1501,7 +1501,7 @@ public final class LocalDate
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.localDate()) {
if (query == TemporalQueries.localDate()) {
return (R) this;
}
return ChronoLocalDate.super.query(query);

View File

@ -76,7 +76,6 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.chrono.ChronoLocalDateTime;
import java.time.format.DateTimeFormatter;
@ -88,6 +87,7 @@ import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
@ -1579,7 +1579,7 @@ public final class LocalDateTime
@SuppressWarnings("unchecked")
@Override // override for Javadoc
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.localDate()) {
if (query == TemporalQueries.localDate()) {
return (R) date;
}
return ChronoLocalDateTime.super.query(query);

View File

@ -74,7 +74,6 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
@ -85,6 +84,7 @@ import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
@ -383,7 +383,7 @@ public final class LocalTime
* A {@code TemporalAccessor} represents an arbitrary set of date and time information,
* which this factory converts to an instance of {@code LocalTime}.
* <p>
* The conversion uses the {@link TemporalQuery#localTime()} query, which relies
* The conversion uses the {@link TemporalQueries#localTime()} query, which relies
* on extracting the {@link ChronoField#NANO_OF_DAY NANO_OF_DAY} field.
* <p>
* This method matches the signature of the functional interface {@link TemporalQuery}
@ -395,7 +395,7 @@ public final class LocalTime
*/
public static LocalTime from(TemporalAccessor temporal) {
Objects.requireNonNull(temporal, "temporal");
LocalTime time = temporal.query(TemporalQuery.localTime());
LocalTime time = temporal.query(TemporalQueries.localTime());
if (time == null) {
throw new DateTimeException("Unable to obtain LocalTime from TemporalAccessor: " +
temporal + " of type " + temporal.getClass().getName());
@ -1281,14 +1281,14 @@ public final class LocalTime
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.chronology() || query == TemporalQuery.zoneId() ||
query == TemporalQuery.zone() || query == TemporalQuery.offset()) {
if (query == TemporalQueries.chronology() || query == TemporalQueries.zoneId() ||
query == TemporalQueries.zone() || query == TemporalQueries.offset()) {
return null;
} else if (query == TemporalQuery.localTime()) {
} else if (query == TemporalQueries.localTime()) {
return (R) this;
} else if (query == TemporalQuery.localDate()) {
} else if (query == TemporalQueries.localDate()) {
return null;
} else if (query == TemporalQuery.precision()) {
} else if (query == TemporalQueries.precision()) {
return (R) NANOS;
}
// inline TemporalAccessor.super.query(query) as an optimization

View File

@ -73,6 +73,7 @@ import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.UnsupportedTemporalTypeException;
import java.time.temporal.ValueRange;
@ -560,9 +561,9 @@ public enum Month implements TemporalAccessor, TemporalAdjuster {
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.chronology()) {
if (query == TemporalQueries.chronology()) {
return (R) IsoChronology.INSTANCE;
} else if (query == TemporalQuery.precision()) {
} else if (query == TemporalQueries.precision()) {
return (R) MONTHS;
}
return TemporalAccessor.super.query(query);

View File

@ -68,7 +68,6 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.chrono.Chronology;
import java.time.chrono.IsoChronology;
@ -80,6 +79,7 @@ import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.UnsupportedTemporalTypeException;
import java.time.temporal.ValueRange;
@ -582,7 +582,7 @@ public final class MonthDay
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.chronology()) {
if (query == TemporalQueries.chronology()) {
return (R) IsoChronology.INSTANCE;
}
return TemporalAccessor.super.query(query);

View File

@ -69,7 +69,6 @@ import static java.time.temporal.ChronoUnit.FOREVER;
import static java.time.temporal.ChronoUnit.NANOS;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.InvalidObjectException;
@ -84,6 +83,7 @@ import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
@ -1527,17 +1527,17 @@ public final class OffsetDateTime
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.offset() || query == TemporalQuery.zone()) {
if (query == TemporalQueries.offset() || query == TemporalQueries.zone()) {
return (R) getOffset();
} else if (query == TemporalQuery.zoneId()) {
} else if (query == TemporalQueries.zoneId()) {
return null;
} else if (query == TemporalQuery.localDate()) {
} else if (query == TemporalQueries.localDate()) {
return (R) toLocalDate();
} else if (query == TemporalQuery.localTime()) {
} else if (query == TemporalQueries.localTime()) {
return (R) toLocalTime();
} else if (query == TemporalQuery.chronology()) {
} else if (query == TemporalQueries.chronology()) {
return (R) IsoChronology.INSTANCE;
} else if (query == TemporalQuery.precision()) {
} else if (query == TemporalQueries.precision()) {
return (R) NANOS;
}
// inline TemporalAccessor.super.query(query) as an optimization

View File

@ -70,7 +70,6 @@ import static java.time.temporal.ChronoField.OFFSET_SECONDS;
import static java.time.temporal.ChronoUnit.NANOS;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.InvalidObjectException;
@ -84,6 +83,7 @@ import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
@ -1068,13 +1068,13 @@ public final class OffsetTime
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.offset() || query == TemporalQuery.zone()) {
if (query == TemporalQueries.offset() || query == TemporalQueries.zone()) {
return (R) offset;
} else if (query == TemporalQuery.zoneId() | query == TemporalQuery.chronology() || query == TemporalQuery.localDate()) {
} else if (query == TemporalQueries.zoneId() | query == TemporalQueries.chronology() || query == TemporalQueries.localDate()) {
return null;
} else if (query == TemporalQuery.localTime()) {
} else if (query == TemporalQueries.localTime()) {
return (R) time;
} else if (query == TemporalQuery.precision()) {
} else if (query == TemporalQueries.precision()) {
return (R) NANOS;
}
// inline TemporalAccessor.super.query(query) as an optimization

View File

@ -79,7 +79,7 @@ import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
import java.util.Arrays;
@ -958,7 +958,7 @@ public final class Period
*/
private void validateChrono(TemporalAccessor temporal) {
Objects.requireNonNull(temporal, "temporal");
Chronology temporalChrono = temporal.query(TemporalQuery.chronology());
Chronology temporalChrono = temporal.query(TemporalQueries.chronology());
if (temporalChrono != null && IsoChronology.INSTANCE.equals(temporalChrono) == false) {
throw new DateTimeException("Chronology mismatch, expected: ISO, actual: " + temporalChrono.getId());
}

View File

@ -74,7 +74,6 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.chrono.Chronology;
import java.time.chrono.IsoChronology;
@ -89,6 +88,7 @@ import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
@ -812,9 +812,9 @@ public final class Year
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.chronology()) {
if (query == TemporalQueries.chronology()) {
return (R) IsoChronology.INSTANCE;
} else if (query == TemporalQuery.precision()) {
} else if (query == TemporalQueries.precision()) {
return (R) YEARS;
}
return Temporal.super.query(query);

View File

@ -77,7 +77,6 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.chrono.Chronology;
import java.time.chrono.IsoChronology;
@ -92,6 +91,7 @@ import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
@ -945,9 +945,9 @@ public final class YearMonth
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.chronology()) {
if (query == TemporalQueries.chronology()) {
return (R) IsoChronology.INSTANCE;
} else if (query == TemporalQuery.precision()) {
} else if (query == TemporalQueries.precision()) {
return (R) MONTHS;
}
return Temporal.super.query(query);

View File

@ -69,6 +69,7 @@ import java.time.format.DateTimeFormatterBuilder;
import java.time.format.TextStyle;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.UnsupportedTemporalTypeException;
import java.time.zone.ZoneRules;
@ -492,7 +493,7 @@ public abstract class ZoneId implements Serializable {
* This factory converts the arbitrary temporal object to an instance of {@code ZoneId}.
* <p>
* The conversion will try to obtain the zone in a way that favours region-based
* zones over offset-based zones using {@link TemporalQuery#zone()}.
* zones over offset-based zones using {@link TemporalQueries#zone()}.
* <p>
* This method matches the signature of the functional interface {@link TemporalQuery}
* allowing it to be used in queries via method reference, {@code ZoneId::from}.
@ -502,7 +503,7 @@ public abstract class ZoneId implements Serializable {
* @throws DateTimeException if unable to convert to a {@code ZoneId}
*/
public static ZoneId from(TemporalAccessor temporal) {
ZoneId obj = temporal.query(TemporalQuery.zone());
ZoneId obj = temporal.query(TemporalQueries.zone());
if (obj == null) {
throw new DateTimeException("Unable to obtain ZoneId from TemporalAccessor: " +
temporal + " of type " + temporal.getClass().getName());
@ -558,7 +559,7 @@ public abstract class ZoneId implements Serializable {
* methods on the interface have no meaning to {@code ZoneId}.
* <p>
* The returned temporal has no supported fields, with the query method
* supporting the return of the zone using {@link TemporalQuery#zoneId()}.
* supporting the return of the zone using {@link TemporalQueries#zoneId()}.
*
* @return a temporal equivalent to this zone, not null
*/
@ -575,7 +576,7 @@ public abstract class ZoneId implements Serializable {
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.zoneId()) {
if (query == TemporalQueries.zoneId()) {
return (R) ZoneId.this;
}
return TemporalAccessor.super.query(query);

View File

@ -70,13 +70,13 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.temporal.ChronoField;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.UnsupportedTemporalTypeException;
import java.time.temporal.ValueRange;
@ -322,7 +322,7 @@ public final class ZoneOffset
* A {@code TemporalAccessor} represents some form of date and time information.
* This factory converts the arbitrary temporal object to an instance of {@code ZoneOffset}.
* <p>
* The conversion uses the {@link TemporalQuery#offset()} query, which relies
* The conversion uses the {@link TemporalQueries#offset()} query, which relies
* on extracting the {@link ChronoField#OFFSET_SECONDS OFFSET_SECONDS} field.
* <p>
* This method matches the signature of the functional interface {@link TemporalQuery}
@ -334,7 +334,7 @@ public final class ZoneOffset
*/
public static ZoneOffset from(TemporalAccessor temporal) {
Objects.requireNonNull(temporal, "temporal");
ZoneOffset offset = temporal.query(TemporalQuery.offset());
ZoneOffset offset = temporal.query(TemporalQueries.offset());
if (offset == null) {
throw new DateTimeException("Unable to obtain ZoneOffset from TemporalAccessor: " +
temporal + " of type " + temporal.getClass().getName());
@ -642,7 +642,7 @@ public final class ZoneOffset
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.offset() || query == TemporalQuery.zone()) {
if (query == TemporalQueries.offset() || query == TemporalQueries.zone()) {
return (R) this;
}
return TemporalAccessor.super.query(query);

View File

@ -0,0 +1,783 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* This file is available under and governed by the GNU General Public
* License version 2 only, as published by the Free Software Foundation.
* However, the following notice accompanied the original version of this
* file:
*
* Copyright (c) 2012, Stephen Colebourne & Michael Nascimento Santos
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of JSR-310 nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package java.time.chrono;
import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH;
import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR;
import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH;
import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR;
import static java.time.temporal.ChronoField.DAY_OF_MONTH;
import static java.time.temporal.ChronoField.DAY_OF_WEEK;
import static java.time.temporal.ChronoField.DAY_OF_YEAR;
import static java.time.temporal.ChronoField.EPOCH_DAY;
import static java.time.temporal.ChronoField.ERA;
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
import static java.time.temporal.ChronoField.PROLEPTIC_MONTH;
import static java.time.temporal.ChronoField.YEAR;
import static java.time.temporal.ChronoField.YEAR_OF_ERA;
import static java.time.temporal.ChronoUnit.DAYS;
import static java.time.temporal.ChronoUnit.MONTHS;
import static java.time.temporal.ChronoUnit.WEEKS;
import static java.time.temporal.TemporalAdjusters.nextOrSame;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.time.DateTimeException;
import java.time.DayOfWeek;
import java.time.format.ResolverStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.TemporalField;
import java.time.temporal.ValueRange;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import sun.util.logging.PlatformLogger;
/**
* An abstract implementation of a calendar system, used to organize and identify dates.
* <p>
* The main date and time API is built on the ISO calendar system.
* The chronology operates behind the scenes to represent the general concept of a calendar system.
* <p>
* See {@link Chronology} for more details.
*
* @implSpec
* This class is separated from the {@code Chronology} interface so that the static methods
* are not inherited. While {@code Chronology} can be implemented directly, it is strongly
* recommended to extend this abstract class instead.
* <p>
* This class must be implemented with care to ensure other classes operate correctly.
* All implementations that can be instantiated must be final, immutable and thread-safe.
* Subclasses should be Serializable wherever possible.
*
* @since 1.8
*/
public abstract class AbstractChronology implements Chronology {
/**
* ChronoLocalDate order constant.
*/
static final Comparator<ChronoLocalDate> DATE_ORDER =
(Comparator<ChronoLocalDate> & Serializable) (date1, date2) -> {
return Long.compare(date1.toEpochDay(), date2.toEpochDay());
};
/**
* ChronoLocalDateTime order constant.
*/
static final Comparator<ChronoLocalDateTime<? extends ChronoLocalDate>> DATE_TIME_ORDER =
(Comparator<ChronoLocalDateTime<? extends ChronoLocalDate>> & Serializable) (dateTime1, dateTime2) -> {
int cmp = Long.compare(dateTime1.toLocalDate().toEpochDay(), dateTime2.toLocalDate().toEpochDay());
if (cmp == 0) {
cmp = Long.compare(dateTime1.toLocalTime().toNanoOfDay(), dateTime2.toLocalTime().toNanoOfDay());
}
return cmp;
};
/**
* ChronoZonedDateTime order constant.
*/
static final Comparator<ChronoZonedDateTime<?>> INSTANT_ORDER =
(Comparator<ChronoZonedDateTime<?>> & Serializable) (dateTime1, dateTime2) -> {
int cmp = Long.compare(dateTime1.toEpochSecond(), dateTime2.toEpochSecond());
if (cmp == 0) {
cmp = Long.compare(dateTime1.toLocalTime().getNano(), dateTime2.toLocalTime().getNano());
}
return cmp;
};
/**
* Map of available calendars by ID.
*/
private static final ConcurrentHashMap<String, Chronology> CHRONOS_BY_ID = new ConcurrentHashMap<>();
/**
* Map of available calendars by calendar type.
*/
private static final ConcurrentHashMap<String, Chronology> CHRONOS_BY_TYPE = new ConcurrentHashMap<>();
/**
* Register a Chronology by its ID and type for lookup by {@link #of(String)}.
* Chronologies must not be registered until they are completely constructed.
* Specifically, not in the constructor of Chronology.
*
* @param chrono the chronology to register; not null
* @return the already registered Chronology if any, may be null
*/
static Chronology registerChrono(Chronology chrono) {
return registerChrono(chrono, chrono.getId());
}
/**
* Register a Chronology by ID and type for lookup by {@link #of(String)}.
* Chronos must not be registered until they are completely constructed.
* Specifically, not in the constructor of Chronology.
*
* @param chrono the chronology to register; not null
* @param id the ID to register the chronology; not null
* @return the already registered Chronology if any, may be null
*/
static Chronology registerChrono(Chronology chrono, String id) {
Chronology prev = CHRONOS_BY_ID.putIfAbsent(id, chrono);
if (prev == null) {
String type = chrono.getCalendarType();
if (type != null) {
CHRONOS_BY_TYPE.putIfAbsent(type, chrono);
}
}
return prev;
}
/**
* Initialization of the maps from id and type to Chronology.
* The ServiceLoader is used to find and register any implementations
* of {@link java.time.chrono.AbstractChronology} found in the bootclass loader.
* The built-in chronologies are registered explicitly.
* Calendars configured via the Thread's context classloader are local
* to that thread and are ignored.
* <p>
* The initialization is done only once using the registration
* of the IsoChronology as the test and the final step.
* Multiple threads may perform the initialization concurrently.
* Only the first registration of each Chronology is retained by the
* ConcurrentHashMap.
* @return true if the cache was initialized
*/
private static boolean initCache() {
if (CHRONOS_BY_ID.get("ISO") == null) {
// Initialization is incomplete
// Register built-in Chronologies
registerChrono(HijrahChronology.INSTANCE);
registerChrono(JapaneseChronology.INSTANCE);
registerChrono(MinguoChronology.INSTANCE);
registerChrono(ThaiBuddhistChronology.INSTANCE);
// Register Chronologies from the ServiceLoader
@SuppressWarnings("rawtypes")
ServiceLoader<AbstractChronology> loader = ServiceLoader.load(AbstractChronology.class, null);
for (AbstractChronology chrono : loader) {
String id = chrono.getId();
if (id.equals("ISO") || registerChrono(chrono) != null) {
// Log the attempt to replace an existing Chronology
PlatformLogger logger = PlatformLogger.getLogger("java.time.chrono");
logger.warning("Ignoring duplicate Chronology, from ServiceLoader configuration " + id);
}
}
// finally, register IsoChronology to mark initialization is complete
registerChrono(IsoChronology.INSTANCE);
return true;
}
return false;
}
//-----------------------------------------------------------------------
/**
* Obtains an instance of {@code Chronology} from a locale.
* <p>
* See {@link Chronology#ofLocale(Locale)}.
*
* @param locale the locale to use to obtain the calendar system, not null
* @return the calendar system associated with the locale, not null
* @throws java.time.DateTimeException if the locale-specified calendar cannot be found
*/
static Chronology ofLocale(Locale locale) {
Objects.requireNonNull(locale, "locale");
String type = locale.getUnicodeLocaleType("ca");
if (type == null || "iso".equals(type) || "iso8601".equals(type)) {
return IsoChronology.INSTANCE;
}
// Not pre-defined; lookup by the type
do {
Chronology chrono = CHRONOS_BY_TYPE.get(type);
if (chrono != null) {
return chrono;
}
// If not found, do the initialization (once) and repeat the lookup
} while (initCache());
// Look for a Chronology using ServiceLoader of the Thread's ContextClassLoader
// Application provided Chronologies must not be cached
@SuppressWarnings("rawtypes")
ServiceLoader<Chronology> loader = ServiceLoader.load(Chronology.class);
for (Chronology chrono : loader) {
if (type.equals(chrono.getCalendarType())) {
return chrono;
}
}
throw new DateTimeException("Unknown calendar system: " + type);
}
//-----------------------------------------------------------------------
/**
* Obtains an instance of {@code Chronology} from a chronology ID or
* calendar system type.
* <p>
* See {@link Chronology#of(String)}.
*
* @param id the chronology ID or calendar system type, not null
* @return the chronology with the identifier requested, not null
* @throws java.time.DateTimeException if the chronology cannot be found
*/
static Chronology of(String id) {
Objects.requireNonNull(id, "id");
do {
Chronology chrono = of0(id);
if (chrono != null) {
return chrono;
}
// If not found, do the initialization (once) and repeat the lookup
} while (initCache());
// Look for a Chronology using ServiceLoader of the Thread's ContextClassLoader
// Application provided Chronologies must not be cached
@SuppressWarnings("rawtypes")
ServiceLoader<Chronology> loader = ServiceLoader.load(Chronology.class);
for (Chronology chrono : loader) {
if (id.equals(chrono.getId()) || id.equals(chrono.getCalendarType())) {
return chrono;
}
}
throw new DateTimeException("Unknown chronology: " + id);
}
/**
* Obtains an instance of {@code Chronology} from a chronology ID or
* calendar system type.
*
* @param id the chronology ID or calendar system type, not null
* @return the chronology with the identifier requested, or {@code null} if not found
*/
private static Chronology of0(String id) {
Chronology chrono = CHRONOS_BY_ID.get(id);
if (chrono == null) {
chrono = CHRONOS_BY_TYPE.get(id);
}
return chrono;
}
/**
* Returns the available chronologies.
* <p>
* Each returned {@code Chronology} is available for use in the system.
* The set of chronologies includes the system chronologies and
* any chronologies provided by the application via ServiceLoader
* configuration.
*
* @return the independent, modifiable set of the available chronology IDs, not null
*/
static Set<Chronology> getAvailableChronologies() {
initCache(); // force initialization
HashSet<Chronology> chronos = new HashSet<>(CHRONOS_BY_ID.values());
/// Add in Chronologies from the ServiceLoader configuration
@SuppressWarnings("rawtypes")
ServiceLoader<Chronology> loader = ServiceLoader.load(Chronology.class);
for (Chronology chrono : loader) {
chronos.add(chrono);
}
return chronos;
}
//-----------------------------------------------------------------------
/**
* Creates an instance.
*/
protected AbstractChronology() {
}
//-----------------------------------------------------------------------
/**
* Resolves parsed {@code ChronoField} values into a date during parsing.
* <p>
* Most {@code TemporalField} implementations are resolved using the
* resolve method on the field. By contrast, the {@code ChronoField} class
* defines fields that only have meaning relative to the chronology.
* As such, {@code ChronoField} date fields are resolved here in the
* context of a specific chronology.
* <p>
* {@code ChronoField} instances are resolved by this method, which may
* be overridden in subclasses.
* <ul>
* <li>{@code EPOCH_DAY} - If present, this is converted to a date and
* all other date fields are then cross-checked against the date.
* <li>{@code PROLEPTIC_MONTH} - If present, then it is split into the
* {@code YEAR} and {@code MONTH_OF_YEAR}. If the mode is strict or smart
* then the field is validated.
* <li>{@code YEAR_OF_ERA} and {@code ERA} - If both are present, then they
* are combined to form a {@code YEAR}. In lenient mode, the {@code YEAR_OF_ERA}
* range is not validated, in smart and strict mode it is. The {@code ERA} is
* validated for range in all three modes. If only the {@code YEAR_OF_ERA} is
* present, and the mode is smart or lenient, then the last available era
* is assumed. In strict mode, no era is assumed and the {@code YEAR_OF_ERA} is
* left untouched. If only the {@code ERA} is present, then it is left untouched.
* <li>{@code YEAR}, {@code MONTH_OF_YEAR} and {@code DAY_OF_MONTH} -
* If all three are present, then they are combined to form a date.
* In all three modes, the {@code YEAR} is validated.
* If the mode is smart or strict, then the month and day are validated.
* If the mode is lenient, then the date is combined in a manner equivalent to
* creating a date on the first day of the first month in the requested year,
* then adding the difference in months, then the difference in days.
* If the mode is smart, and the day-of-month is greater than the maximum for
* the year-month, then the day-of-month is adjusted to the last day-of-month.
* If the mode is strict, then the three fields must form a valid date.
* <li>{@code YEAR} and {@code DAY_OF_YEAR} -
* If both are present, then they are combined to form a date.
* In all three modes, the {@code YEAR} is validated.
* If the mode is lenient, then the date is combined in a manner equivalent to
* creating a date on the first day of the requested year, then adding
* the difference in days.
* If the mode is smart or strict, then the two fields must form a valid date.
* <li>{@code YEAR}, {@code MONTH_OF_YEAR}, {@code ALIGNED_WEEK_OF_MONTH} and
* {@code ALIGNED_DAY_OF_WEEK_IN_MONTH} -
* If all four are present, then they are combined to form a date.
* In all three modes, the {@code YEAR} is validated.
* If the mode is lenient, then the date is combined in a manner equivalent to
* creating a date on the first day of the first month in the requested year, then adding
* the difference in months, then the difference in weeks, then in days.
* If the mode is smart or strict, then the all four fields are validated to
* their outer ranges. The date is then combined in a manner equivalent to
* creating a date on the first day of the requested year and month, then adding
* the amount in weeks and days to reach their values. If the mode is strict,
* the date is additionally validated to check that the day and week adjustment
* did not change the month.
* <li>{@code YEAR}, {@code MONTH_OF_YEAR}, {@code ALIGNED_WEEK_OF_MONTH} and
* {@code DAY_OF_WEEK} - If all four are present, then they are combined to
* form a date. The approach is the same as described above for
* years, months and weeks in {@code ALIGNED_DAY_OF_WEEK_IN_MONTH}.
* The day-of-week is adjusted as the next or same matching day-of-week once
* the years, months and weeks have been handled.
* <li>{@code YEAR}, {@code ALIGNED_WEEK_OF_YEAR} and {@code ALIGNED_DAY_OF_WEEK_IN_YEAR} -
* If all three are present, then they are combined to form a date.
* In all three modes, the {@code YEAR} is validated.
* If the mode is lenient, then the date is combined in a manner equivalent to
* creating a date on the first day of the requested year, then adding
* the difference in weeks, then in days.
* If the mode is smart or strict, then the all three fields are validated to
* their outer ranges. The date is then combined in a manner equivalent to
* creating a date on the first day of the requested year, then adding
* the amount in weeks and days to reach their values. If the mode is strict,
* the date is additionally validated to check that the day and week adjustment
* did not change the year.
* <li>{@code YEAR}, {@code ALIGNED_WEEK_OF_YEAR} and {@code DAY_OF_WEEK} -
* If all three are present, then they are combined to form a date.
* The approach is the same as described above for years and weeks in
* {@code ALIGNED_DAY_OF_WEEK_IN_YEAR}. The day-of-week is adjusted as the
* next or same matching day-of-week once the years and weeks have been handled.
* </ul>
* <p>
* The default implementation is suitable for most calendar systems.
* If {@link java.time.temporal.ChronoField#YEAR_OF_ERA} is found without an {@link java.time.temporal.ChronoField#ERA}
* then the last era in {@link #eras()} is used.
* The implementation assumes a 7 day week, that the first day-of-month
* has the value 1, that first day-of-year has the value 1, and that the
* first of the month and year always exists.
*
* @param fieldValues the map of fields to values, which can be updated, not null
* @param resolverStyle the requested type of resolve, not null
* @return the resolved date, null if insufficient information to create a date
* @throws java.time.DateTimeException if the date cannot be resolved, typically
* because of a conflict in the input data
*/
@Override
public ChronoLocalDate resolveDate(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
// check epoch-day before inventing era
if (fieldValues.containsKey(EPOCH_DAY)) {
return dateEpochDay(fieldValues.remove(EPOCH_DAY));
}
// fix proleptic month before inventing era
resolveProlepticMonth(fieldValues, resolverStyle);
// invent era if necessary to resolve year-of-era
ChronoLocalDate resolved = resolveYearOfEra(fieldValues, resolverStyle);
if (resolved != null) {
return resolved;
}
// build date
if (fieldValues.containsKey(YEAR)) {
if (fieldValues.containsKey(MONTH_OF_YEAR)) {
if (fieldValues.containsKey(DAY_OF_MONTH)) {
return resolveYMD(fieldValues, resolverStyle);
}
if (fieldValues.containsKey(ALIGNED_WEEK_OF_MONTH)) {
if (fieldValues.containsKey(ALIGNED_DAY_OF_WEEK_IN_MONTH)) {
return resolveYMAA(fieldValues, resolverStyle);
}
if (fieldValues.containsKey(DAY_OF_WEEK)) {
return resolveYMAD(fieldValues, resolverStyle);
}
}
}
if (fieldValues.containsKey(DAY_OF_YEAR)) {
return resolveYD(fieldValues, resolverStyle);
}
if (fieldValues.containsKey(ALIGNED_WEEK_OF_YEAR)) {
if (fieldValues.containsKey(ALIGNED_DAY_OF_WEEK_IN_YEAR)) {
return resolveYAA(fieldValues, resolverStyle);
}
if (fieldValues.containsKey(DAY_OF_WEEK)) {
return resolveYAD(fieldValues, resolverStyle);
}
}
}
return null;
}
void resolveProlepticMonth(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
Long pMonth = fieldValues.remove(PROLEPTIC_MONTH);
if (pMonth != null) {
if (resolverStyle != ResolverStyle.LENIENT) {
PROLEPTIC_MONTH.checkValidValue(pMonth);
}
// first day-of-month is likely to be safest for setting proleptic-month
// cannot add to year zero, as not all chronologies have a year zero
ChronoLocalDate chronoDate = dateNow()
.with(DAY_OF_MONTH, 1).with(PROLEPTIC_MONTH, pMonth);
addFieldValue(fieldValues, MONTH_OF_YEAR, chronoDate.get(MONTH_OF_YEAR));
addFieldValue(fieldValues, YEAR, chronoDate.get(YEAR));
}
}
ChronoLocalDate resolveYearOfEra(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
Long yoeLong = fieldValues.remove(YEAR_OF_ERA);
if (yoeLong != null) {
Long eraLong = fieldValues.remove(ERA);
int yoe;
if (resolverStyle != ResolverStyle.LENIENT) {
yoe = range(YEAR_OF_ERA).checkValidIntValue(yoeLong, YEAR_OF_ERA);
} else {
yoe = Math.toIntExact(yoeLong);
}
if (eraLong != null) {
Era eraObj = eraOf(range(ERA).checkValidIntValue(eraLong, ERA));
addFieldValue(fieldValues, YEAR, prolepticYear(eraObj, yoe));
} else {
if (fieldValues.containsKey(YEAR)) {
int year = range(YEAR).checkValidIntValue(fieldValues.get(YEAR), YEAR);
ChronoLocalDate chronoDate = dateYearDay(year, 1);
addFieldValue(fieldValues, YEAR, prolepticYear(chronoDate.getEra(), yoe));
} else if (resolverStyle == ResolverStyle.STRICT) {
// do not invent era if strict
// reinstate the field removed earlier, no cross-check issues
fieldValues.put(YEAR_OF_ERA, yoeLong);
} else {
List<Era> eras = eras();
if (eras.isEmpty()) {
addFieldValue(fieldValues, YEAR, yoe);
} else {
Era eraObj = eras.get(eras.size() - 1);
addFieldValue(fieldValues, YEAR, prolepticYear(eraObj, yoe));
}
}
}
} else if (fieldValues.containsKey(ERA)) {
range(ERA).checkValidValue(fieldValues.get(ERA), ERA); // always validated
}
return null;
}
ChronoLocalDate resolveYMD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
if (resolverStyle == ResolverStyle.LENIENT) {
long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
return date(y, 1, 1).plus(months, MONTHS).plus(days, DAYS);
}
int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
ValueRange domRange = range(DAY_OF_MONTH);
int dom = domRange.checkValidIntValue(fieldValues.remove(DAY_OF_MONTH), DAY_OF_MONTH);
if (resolverStyle == ResolverStyle.SMART) { // previous valid
try {
return date(y, moy, dom);
} catch (DateTimeException ex) {
return date(y, moy, 1).with(TemporalAdjusters.lastDayOfMonth());
}
}
return date(y, moy, dom);
}
ChronoLocalDate resolveYD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
if (resolverStyle == ResolverStyle.LENIENT) {
long days = Math.subtractExact(fieldValues.remove(DAY_OF_YEAR), 1);
return dateYearDay(y, 1).plus(days, DAYS);
}
int doy = range(DAY_OF_YEAR).checkValidIntValue(fieldValues.remove(DAY_OF_YEAR), DAY_OF_YEAR);
return dateYearDay(y, doy); // smart is same as strict
}
ChronoLocalDate resolveYMAA(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
if (resolverStyle == ResolverStyle.LENIENT) {
long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
long days = Math.subtractExact(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH), 1);
return date(y, 1, 1).plus(months, MONTHS).plus(weeks, WEEKS).plus(days, DAYS);
}
int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
int aw = range(ALIGNED_WEEK_OF_MONTH).checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), ALIGNED_WEEK_OF_MONTH);
int ad = range(ALIGNED_DAY_OF_WEEK_IN_MONTH).checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_MONTH), ALIGNED_DAY_OF_WEEK_IN_MONTH);
ChronoLocalDate 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 resolved date as it is in a different month");
}
return date;
}
ChronoLocalDate resolveYMAD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
if (resolverStyle == ResolverStyle.LENIENT) {
long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), 1);
long dow = Math.subtractExact(fieldValues.remove(DAY_OF_WEEK), 1);
return resolveAligned(date(y, 1, 1), months, weeks, dow);
}
int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
int aw = range(ALIGNED_WEEK_OF_MONTH).checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_MONTH), ALIGNED_WEEK_OF_MONTH);
int dow = range(DAY_OF_WEEK).checkValidIntValue(fieldValues.remove(DAY_OF_WEEK), DAY_OF_WEEK);
ChronoLocalDate date = date(y, moy, 1).plus((aw - 1) * 7, DAYS).with(nextOrSame(DayOfWeek.of(dow)));
if (resolverStyle == ResolverStyle.STRICT && date.get(MONTH_OF_YEAR) != moy) {
throw new DateTimeException("Strict mode rejected resolved date as it is in a different month");
}
return date;
}
ChronoLocalDate resolveYAA(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
if (resolverStyle == ResolverStyle.LENIENT) {
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
long days = Math.subtractExact(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR), 1);
return dateYearDay(y, 1).plus(weeks, WEEKS).plus(days, DAYS);
}
int aw = range(ALIGNED_WEEK_OF_YEAR).checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), ALIGNED_WEEK_OF_YEAR);
int ad = range(ALIGNED_DAY_OF_WEEK_IN_YEAR).checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR), ALIGNED_DAY_OF_WEEK_IN_YEAR);
ChronoLocalDate date = dateYearDay(y, 1).plus((aw - 1) * 7 + (ad - 1), DAYS);
if (resolverStyle == ResolverStyle.STRICT && date.get(YEAR) != y) {
throw new DateTimeException("Strict mode rejected resolved date as it is in a different year");
}
return date;
}
ChronoLocalDate resolveYAD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
if (resolverStyle == ResolverStyle.LENIENT) {
long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1);
long dow = Math.subtractExact(fieldValues.remove(DAY_OF_WEEK), 1);
return resolveAligned(dateYearDay(y, 1), 0, weeks, dow);
}
int aw = range(ALIGNED_WEEK_OF_YEAR).checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), ALIGNED_WEEK_OF_YEAR);
int dow = range(DAY_OF_WEEK).checkValidIntValue(fieldValues.remove(DAY_OF_WEEK), DAY_OF_WEEK);
ChronoLocalDate date = dateYearDay(y, 1).plus((aw - 1) * 7, DAYS).with(nextOrSame(DayOfWeek.of(dow)));
if (resolverStyle == ResolverStyle.STRICT && date.get(YEAR) != y) {
throw new DateTimeException("Strict mode rejected resolved date as it is in a different year");
}
return date;
}
ChronoLocalDate resolveAligned(ChronoLocalDate base, long months, long weeks, long dow) {
ChronoLocalDate date = base.plus(months, MONTHS).plus(weeks, WEEKS);
if (dow > 7) {
date = date.plus((dow - 1) / 7, WEEKS);
dow = ((dow - 1) % 7) + 1;
} else if (dow < 1) {
date = date.plus(Math.subtractExact(dow, 7) / 7, WEEKS);
dow = ((dow + 6) % 7) + 1;
}
return date.with(nextOrSame(DayOfWeek.of((int) dow)));
}
/**
* Adds a field-value pair to the map, checking for conflicts.
* <p>
* If the field is not already present, then the field-value pair is added to the map.
* If the field is already present and it has the same value as that specified, no action occurs.
* If the field is already present and it has a different value to that specified, then
* an exception is thrown.
*
* @param field the field to add, not null
* @param value the value to add, not null
* @throws java.time.DateTimeException if the field is already present with a different value
*/
void addFieldValue(Map<TemporalField, Long> fieldValues, ChronoField field, long value) {
Long old = fieldValues.get(field); // check first for better error message
if (old != null && old.longValue() != value) {
throw new DateTimeException("Conflict found: " + field + " " + old + " differs from " + field + " " + value);
}
fieldValues.put(field, value);
}
//-----------------------------------------------------------------------
/**
* Compares this chronology to another chronology.
* <p>
* The comparison order first by the chronology ID string, then by any
* additional information specific to the subclass.
* It is "consistent with equals", as defined by {@link Comparable}.
*
* @implSpec
* This implementation compares the chronology ID.
* Subclasses must compare any additional state that they store.
*
* @param other the other chronology to compare to, not null
* @return the comparator value, negative if less, positive if greater
*/
@Override
public int compareTo(Chronology other) {
return getId().compareTo(other.getId());
}
/**
* Checks if this chronology is equal to another chronology.
* <p>
* The comparison is based on the entire state of the object.
*
* @implSpec
* This implementation checks the type and calls
* {@link #compareTo(java.time.chrono.Chronology)}.
*
* @param obj the object to check, null returns false
* @return true if this is equal to the other chronology
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof AbstractChronology) {
return compareTo((AbstractChronology) obj) == 0;
}
return false;
}
/**
* A hash code for this chronology.
* <p>
* The hash code should be based on the entire state of the object.
*
* @implSpec
* This implementation is based on the chronology ID and class.
* Subclasses should add any additional state that they store.
*
* @return a suitable hash code
*/
@Override
public int hashCode() {
return getClass().hashCode() ^ getId().hashCode();
}
//-----------------------------------------------------------------------
/**
* Outputs this chronology as a {@code String}, using the chronology ID.
*
* @return a string representation of this chronology, not null
*/
@Override
public String toString() {
return getId();
}
//-----------------------------------------------------------------------
/**
* Writes the Chronology using a
* <a href="../../../serialized-form.html#java.time.chrono.Ser">dedicated serialized form</a>.
* <pre>
* out.writeByte(1); // identifies this as a Chronology
* out.writeUTF(getId());
* </pre>
*
* @return the instance of {@code Ser}, not null
*/
Object writeReplace() {
return new Ser(Ser.CHRONO_TYPE, this);
}
/**
* Defend against malicious streams.
* @return never
* @throws java.io.InvalidObjectException always
*/
private Object readResolve() throws ObjectStreamException {
throw new InvalidObjectException("Deserialization via serialization delegate");
}
void writeExternal(DataOutput out) throws IOException {
out.writeUTF(getId());
}
static Chronology readExternal(DataInput in) throws IOException {
String id = in.readUTF();
return Chronology.of(id);
}
}

View File

@ -77,6 +77,7 @@ import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
@ -262,7 +263,7 @@ public interface ChronoLocalDate
* @see #isEqual
*/
static Comparator<ChronoLocalDate> timeLineOrder() {
return Chronology.DATE_ORDER;
return AbstractChronology.DATE_ORDER;
}
//-----------------------------------------------------------------------
@ -292,7 +293,7 @@ public interface ChronoLocalDate
return (ChronoLocalDate) temporal;
}
Objects.requireNonNull(temporal, "temporal");
Chronology chrono = temporal.query(TemporalQuery.chronology());
Chronology chrono = temporal.query(TemporalQueries.chronology());
if (chrono == null) {
throw new DateTimeException("Unable to obtain ChronoLocalDate from TemporalAccessor: " + temporal.getClass());
}
@ -511,13 +512,13 @@ public interface ChronoLocalDate
@SuppressWarnings("unchecked")
@Override
default <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.zoneId() || query == TemporalQuery.zone() || query == TemporalQuery.offset()) {
if (query == TemporalQueries.zoneId() || query == TemporalQueries.zone() || query == TemporalQueries.offset()) {
return null;
} else if (query == TemporalQuery.localTime()) {
} else if (query == TemporalQueries.localTime()) {
return null;
} else if (query == TemporalQuery.chronology()) {
} else if (query == TemporalQueries.chronology()) {
return (R) getChronology();
} else if (query == TemporalQuery.precision()) {
} else if (query == TemporalQueries.precision()) {
return (R) DAYS;
}
// inline TemporalAccessor.super.query(query) as an optimization

View File

@ -80,6 +80,7 @@ import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;
import java.time.zone.ZoneRules;
@ -136,7 +137,7 @@ public interface ChronoLocalDateTime<D extends ChronoLocalDate>
* @see #isEqual
*/
static Comparator<ChronoLocalDateTime<?>> timeLineOrder() {
return Chronology.DATE_TIME_ORDER;
return AbstractChronology.DATE_TIME_ORDER;
}
//-----------------------------------------------------------------------
@ -166,7 +167,7 @@ public interface ChronoLocalDateTime<D extends ChronoLocalDate>
return (ChronoLocalDateTime<?>) temporal;
}
Objects.requireNonNull(temporal, "temporal");
Chronology chrono = temporal.query(TemporalQuery.chronology());
Chronology chrono = temporal.query(TemporalQueries.chronology());
if (chrono == null) {
throw new DateTimeException("Unable to obtain ChronoLocalDateTime from TemporalAccessor: " + temporal.getClass());
}
@ -334,13 +335,13 @@ public interface ChronoLocalDateTime<D extends ChronoLocalDate>
@SuppressWarnings("unchecked")
@Override
default <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.zoneId() || query == TemporalQuery.zone() || query == TemporalQuery.offset()) {
if (query == TemporalQueries.zoneId() || query == TemporalQueries.zone() || query == TemporalQueries.offset()) {
return null;
} else if (query == TemporalQuery.localTime()) {
} else if (query == TemporalQueries.localTime()) {
return (R) toLocalTime();
} else if (query == TemporalQuery.chronology()) {
} else if (query == TemporalQueries.chronology()) {
return (R) getChronology();
} else if (query == TemporalQuery.precision()) {
} else if (query == TemporalQueries.precision()) {
return (R) NANOS;
}
// inline TemporalAccessor.super.query(query) as an optimization

View File

@ -72,7 +72,7 @@ import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
import java.time.temporal.ValueRange;
@ -308,7 +308,7 @@ final class ChronoPeriodImpl
*/
private void validateChrono(TemporalAccessor temporal) {
Objects.requireNonNull(temporal, "temporal");
Chronology temporalChrono = temporal.query(TemporalQuery.chronology());
Chronology temporalChrono = temporal.query(TemporalQueries.chronology());
if (temporalChrono != null && chrono.equals(temporalChrono) == false) {
throw new DateTimeException("Chronology mismatch, expected: " + chrono.getId() + ", actual: " + temporalChrono.getId());
}

View File

@ -80,6 +80,7 @@ import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
@ -137,7 +138,7 @@ public interface ChronoZonedDateTime<D extends ChronoLocalDate>
* @see #isEqual
*/
static Comparator<ChronoZonedDateTime<?>> timeLineOrder() {
return Chronology.INSTANT_ORDER;
return AbstractChronology.INSTANT_ORDER;
}
//-----------------------------------------------------------------------
@ -167,7 +168,7 @@ public interface ChronoZonedDateTime<D extends ChronoLocalDate>
return (ChronoZonedDateTime<?>) temporal;
}
Objects.requireNonNull(temporal, "temporal");
Chronology chrono = temporal.query(TemporalQuery.chronology());
Chronology chrono = temporal.query(TemporalQueries.chronology());
if (chrono == null) {
throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass());
}
@ -481,15 +482,15 @@ public interface ChronoZonedDateTime<D extends ChronoLocalDate>
@SuppressWarnings("unchecked")
@Override
default <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.zone() || query == TemporalQuery.zoneId()) {
if (query == TemporalQueries.zone() || query == TemporalQueries.zoneId()) {
return (R) getZone();
} else if (query == TemporalQuery.offset()) {
} else if (query == TemporalQueries.offset()) {
return (R) getOffset();
} else if (query == TemporalQuery.localTime()) {
} else if (query == TemporalQueries.localTime()) {
return (R) toLocalTime();
} else if (query == TemporalQuery.chronology()) {
} else if (query == TemporalQueries.chronology()) {
return (R) getChronology();
} else if (query == TemporalQuery.precision()) {
} else if (query == TemporalQueries.precision()) {
return (R) NANOS;
}
// inline TemporalAccessor.super.query(query) as an optimization

File diff suppressed because it is too large Load Diff

View File

@ -73,6 +73,7 @@ import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.ValueRange;
import java.util.Locale;
@ -265,7 +266,7 @@ public interface Era extends TemporalAccessor, TemporalAdjuster {
@SuppressWarnings("unchecked")
@Override
default <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.precision()) {
if (query == TemporalQueries.precision()) {
return (R) ERAS;
}
return TemporalAccessor.super.query(query);

View File

@ -214,7 +214,7 @@ import sun.util.logging.PlatformLogger;
*
* @since 1.8
*/
public final class HijrahChronology extends Chronology implements Serializable {
public final class HijrahChronology extends AbstractChronology implements Serializable {
/**
* The Hijrah Calendar id.
@ -308,8 +308,8 @@ public final class HijrahChronology extends Chronology implements Serializable {
try {
INSTANCE = new HijrahChronology("Hijrah-umalqura");
// Register it by its aliases
Chronology.registerChrono(INSTANCE, "Hijrah");
Chronology.registerChrono(INSTANCE, "islamic");
AbstractChronology.registerChrono(INSTANCE, "Hijrah");
AbstractChronology.registerChrono(INSTANCE, "islamic");
} catch (DateTimeException ex) {
// Absence of Hijrah calendar is fatal to initializing this class.
PlatformLogger logger = PlatformLogger.getLogger("java.time.chrono");
@ -336,7 +336,7 @@ public final class HijrahChronology extends Chronology implements Serializable {
try {
// Create and register the variant
HijrahChronology chrono = new HijrahChronology(id);
Chronology.registerChrono(chrono);
AbstractChronology.registerChrono(chrono);
} catch (DateTimeException ex) {
// Log error and continue
PlatformLogger logger = PlatformLogger.getLogger("java.time.chrono");

View File

@ -120,7 +120,7 @@ import java.util.Objects;
*
* @since 1.8
*/
public final class IsoChronology extends Chronology implements Serializable {
public final class IsoChronology extends AbstractChronology implements Serializable {
/**
* Singleton instance of the ISO chronology.

View File

@ -56,8 +56,6 @@
*/
package java.time.chrono;
import java.io.InvalidObjectException;
import java.io.ObjectStreamException;
import static java.time.temporal.ChronoField.DAY_OF_MONTH;
import static java.time.temporal.ChronoField.DAY_OF_YEAR;
import static java.time.temporal.ChronoField.ERA;
@ -67,6 +65,7 @@ import static java.time.temporal.ChronoField.YEAR_OF_ERA;
import static java.time.temporal.ChronoUnit.DAYS;
import static java.time.temporal.ChronoUnit.MONTHS;
import java.io.InvalidObjectException;
import java.io.Serializable;
import java.time.Clock;
import java.time.DateTimeException;
@ -77,7 +76,7 @@ import java.time.ZoneId;
import java.time.format.ResolverStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.TemporalField;
import java.time.temporal.UnsupportedTemporalTypeException;
import java.time.temporal.ValueRange;
@ -120,7 +119,7 @@ import sun.util.calendar.LocalGregorianCalendar;
*
* @since 1.8
*/
public final class JapaneseChronology extends Chronology implements Serializable {
public final class JapaneseChronology extends AbstractChronology implements Serializable {
static final LocalGregorianCalendar JCAL =
(LocalGregorianCalendar) CalendarSystem.forName("japanese");
@ -480,7 +479,7 @@ public final class JapaneseChronology extends Chronology implements Serializable
try {
result = date(y, moy, dom);
} catch (DateTimeException ex) {
result = date(y, moy, 1).with(TemporalAdjuster.lastDayOfMonth());
result = date(y, moy, 1).with(TemporalAdjusters.lastDayOfMonth());
}
// handle the era being changed
// only allow if the new date is in the same Jan-Dec as the era change

View File

@ -105,7 +105,7 @@ import java.util.Map;
*
* @since 1.8
*/
public final class MinguoChronology extends Chronology implements Serializable {
public final class MinguoChronology extends AbstractChronology implements Serializable {
/**
* Singleton instance for the Minguo chronology.

View File

@ -161,7 +161,7 @@ final class Ser implements Externalizable {
out.writeByte(type);
switch (type) {
case CHRONO_TYPE:
((Chronology) object).writeExternal(out);
((AbstractChronology) object).writeExternal(out);
break;
case CHRONO_LOCAL_DATE_TIME_TYPE:
((ChronoLocalDateTimeImpl<?>) object).writeExternal(out);
@ -231,7 +231,7 @@ final class Ser implements Externalizable {
private static Object readInternal(byte type, ObjectInput in) throws IOException, ClassNotFoundException {
switch (type) {
case CHRONO_TYPE: return Chronology.readExternal(in);
case CHRONO_TYPE: return AbstractChronology.readExternal(in);
case CHRONO_LOCAL_DATE_TIME_TYPE: return ChronoLocalDateTimeImpl.readExternal(in);
case CHRONO_ZONE_DATE_TIME_TYPE: return ChronoZonedDateTimeImpl.readExternal(in);
case JAPANESE_DATE_TYPE: return JapaneseDate.readExternal(in);

View File

@ -106,7 +106,7 @@ import java.util.Map;
*
* @since 1.8
*/
public final class ThaiBuddhistChronology extends Chronology implements Serializable {
public final class ThaiBuddhistChronology extends AbstractChronology implements Serializable {
/**
* Singleton instance of the Buddhist chronology.

View File

@ -90,6 +90,7 @@ import java.time.temporal.ChronoField;
import java.time.temporal.IsoFields;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.ValueRange;
import java.time.temporal.WeekFields;
@ -155,7 +156,7 @@ public final class DateTimeFormatterBuilder {
* Query for a time-zone that is region-only.
*/
private static final TemporalQuery<ZoneId> QUERY_REGION_ONLY = (temporal) -> {
ZoneId zone = temporal.query(TemporalQuery.zoneId());
ZoneId zone = temporal.query(TemporalQueries.zoneId());
return (zone != null && zone instanceof ZoneOffset == false ? zone : null);
};
@ -877,7 +878,7 @@ public final class DateTimeFormatterBuilder {
* This appends an instruction to format/parse the offset ID to the builder.
* <p>
* During formatting, the offset is obtained using a mechanism equivalent
* to querying the temporal with {@link TemporalQuery#offset()}.
* to querying the temporal with {@link TemporalQueries#offset()}.
* It will be printed using the format defined below.
* If the offset cannot be obtained then an exception is thrown unless the
* section of the formatter is optional.
@ -930,7 +931,7 @@ public final class DateTimeFormatterBuilder {
* </ul><p>
* <p>
* During formatting, the offset is obtained using a mechanism equivalent
* to querying the temporal with {@link TemporalQuery#offset()}.
* to querying the temporal with {@link TemporalQueries#offset()}.
* If the offset cannot be obtained then an exception is thrown unless the
* section of the formatter is optional.
* <p>
@ -962,7 +963,7 @@ public final class DateTimeFormatterBuilder {
* for use with this method, see {@link #appendZoneOrOffsetId()}.
* <p>
* During formatting, the zone is obtained using a mechanism equivalent
* to querying the temporal with {@link TemporalQuery#zoneId()}.
* to querying the temporal with {@link TemporalQueries#zoneId()}.
* It will be printed using the result of {@link ZoneId#getId()}.
* If the zone cannot be obtained then an exception is thrown unless the
* section of the formatter is optional.
@ -1000,7 +1001,7 @@ public final class DateTimeFormatterBuilder {
* @see #appendZoneRegionId()
*/
public DateTimeFormatterBuilder appendZoneId() {
appendInternal(new ZoneIdPrinterParser(TemporalQuery.zoneId(), "ZoneId()"));
appendInternal(new ZoneIdPrinterParser(TemporalQueries.zoneId(), "ZoneId()"));
return this;
}
@ -1012,7 +1013,7 @@ public final class DateTimeFormatterBuilder {
* only if it is a region-based ID.
* <p>
* During formatting, the zone is obtained using a mechanism equivalent
* to querying the temporal with {@link TemporalQuery#zoneId()}.
* to querying the temporal with {@link TemporalQueries#zoneId()}.
* If the zone is a {@code ZoneOffset} or it cannot be obtained then
* an exception is thrown unless the section of the formatter is optional.
* If the zone is not an offset, then the zone will be printed using
@ -1071,7 +1072,7 @@ public final class DateTimeFormatterBuilder {
* then attempts to find an offset, such as that on {@code OffsetDateTime}.
* <p>
* During formatting, the zone is obtained using a mechanism equivalent
* to querying the temporal with {@link TemporalQuery#zone()}.
* to querying the temporal with {@link TemporalQueries#zone()}.
* It will be printed using the result of {@link ZoneId#getId()}.
* If the zone cannot be obtained then an exception is thrown unless the
* section of the formatter is optional.
@ -1112,7 +1113,7 @@ public final class DateTimeFormatterBuilder {
* @see #appendZoneId()
*/
public DateTimeFormatterBuilder appendZoneOrOffsetId() {
appendInternal(new ZoneIdPrinterParser(TemporalQuery.zone(), "ZoneOrOffsetId()"));
appendInternal(new ZoneIdPrinterParser(TemporalQueries.zone(), "ZoneOrOffsetId()"));
return this;
}
@ -1123,7 +1124,7 @@ public final class DateTimeFormatterBuilder {
* the builder.
* <p>
* During formatting, the zone is obtained using a mechanism equivalent
* to querying the temporal with {@link TemporalQuery#zoneId()}.
* to querying the temporal with {@link TemporalQueries#zoneId()}.
* If the zone is a {@code ZoneOffset} it will be printed using the
* result of {@link ZoneOffset#getId()}.
* If the zone is not an offset, the textual name will be looked up
@ -1159,7 +1160,7 @@ public final class DateTimeFormatterBuilder {
* the builder.
* <p>
* During formatting, the zone is obtained using a mechanism equivalent
* to querying the temporal with {@link TemporalQuery#zoneId()}.
* to querying the temporal with {@link TemporalQueries#zoneId()}.
* If the zone is a {@code ZoneOffset} it will be printed using the
* result of {@link ZoneOffset#getId()}.
* If the zone is not an offset, the textual name will be looked up
@ -1202,7 +1203,7 @@ public final class DateTimeFormatterBuilder {
* This appends an instruction to format/parse the chronology ID to the builder.
* <p>
* During formatting, the chronology is obtained using a mechanism equivalent
* to querying the temporal with {@link TemporalQuery#chronology()}.
* to querying the temporal with {@link TemporalQueries#chronology()}.
* It will be printed using the result of {@link Chronology#getId()}.
* If the chronology cannot be obtained then an exception is thrown unless the
* section of the formatter is optional.
@ -3062,7 +3063,7 @@ public final class DateTimeFormatterBuilder {
return false;
}
String text;
Chronology chrono = context.getTemporal().query(TemporalQuery.chronology());
Chronology chrono = context.getTemporal().query(TemporalQueries.chronology());
if (chrono == null || chrono == IsoChronology.INSTANCE) {
text = provider.getText(field, value, textStyle, context.getLocale());
} else {
@ -3590,7 +3591,7 @@ public final class DateTimeFormatterBuilder {
private Set<String> preferredZones;
ZoneTextPrinterParser(TextStyle textStyle, Set<ZoneId> preferredZones) {
super(TemporalQuery.zone(), "ZoneText(" + textStyle + ")");
super(TemporalQueries.zone(), "ZoneText(" + textStyle + ")");
this.textStyle = Objects.requireNonNull(textStyle, "textStyle");
if (preferredZones != null && preferredZones.size() != 0) {
this.preferredZones = new HashSet<>();
@ -3647,7 +3648,7 @@ public final class DateTimeFormatterBuilder {
@Override
public boolean format(DateTimePrintContext context, StringBuilder buf) {
ZoneId zone = context.getValue(TemporalQuery.zoneId());
ZoneId zone = context.getValue(TemporalQueries.zoneId());
if (zone == null) {
return false;
}
@ -4228,7 +4229,7 @@ public final class DateTimeFormatterBuilder {
@Override
public boolean format(DateTimePrintContext context, StringBuilder buf) {
Chronology chrono = context.getValue(TemporalQuery.chronology());
Chronology chrono = context.getValue(TemporalQueries.chronology());
if (chrono == null) {
return false;
}

View File

@ -75,6 +75,7 @@ import java.time.chrono.IsoChronology;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.ValueRange;
import java.util.Locale;
@ -128,8 +129,8 @@ final class DateTimePrintContext {
}
// ensure minimal change (early return is an optimization)
Chronology temporalChrono = temporal.query(TemporalQuery.chronology());
ZoneId temporalZone = temporal.query(TemporalQuery.zoneId());
Chronology temporalChrono = temporal.query(TemporalQueries.chronology());
ZoneId temporalZone = temporal.query(TemporalQueries.zoneId());
if (Objects.equals(overrideChrono, temporalChrono)) {
overrideChrono = null;
}
@ -206,13 +207,13 @@ final class DateTimePrintContext {
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.chronology()) {
if (query == TemporalQueries.chronology()) {
return (R) effectiveChrono;
}
if (query == TemporalQuery.zoneId()) {
if (query == TemporalQueries.zoneId()) {
return (R) effectiveZone;
}
if (query == TemporalQuery.precision()) {
if (query == TemporalQueries.precision()) {
return temporal.query(query);
}
return query.queryFrom(this);

View File

@ -89,6 +89,7 @@ import java.time.chrono.Chronology;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.UnsupportedTemporalTypeException;
import java.util.HashMap;
@ -207,17 +208,17 @@ final class Parsed implements TemporalAccessor {
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.zoneId()) {
if (query == TemporalQueries.zoneId()) {
return (R) zone;
} else if (query == TemporalQuery.chronology()) {
} else if (query == TemporalQueries.chronology()) {
return (R) chrono;
} else if (query == TemporalQuery.localDate()) {
} else if (query == TemporalQueries.localDate()) {
return (R) (date != null ? LocalDate.from(date) : null);
} else if (query == TemporalQuery.localTime()) {
} else if (query == TemporalQueries.localTime()) {
return (R) time;
} else if (query == TemporalQuery.zone() || query == TemporalQuery.offset()) {
} else if (query == TemporalQueries.zone() || query == TemporalQueries.offset()) {
return query.queryFrom(this);
} else if (query == TemporalQuery.precision()) {
} else if (query == TemporalQueries.precision()) {
return null; // not a complete date/time
}
// inline TemporalAccessor.super.query(query) as an optimization
@ -262,7 +263,7 @@ final class Parsed implements TemporalAccessor {
while (changedCount < 50) {
for (Map.Entry<TemporalField, Long> entry : fieldValues.entrySet()) {
TemporalField targetField = entry.getKey();
TemporalAccessor resolvedObject = targetField.resolve(fieldValues, chrono, zone, resolverStyle);
TemporalAccessor resolvedObject = targetField.resolve(fieldValues, this, resolverStyle);
if (resolvedObject != null) {
if (resolvedObject instanceof ChronoZonedDateTime) {
ChronoZonedDateTime czdt = (ChronoZonedDateTime) resolvedObject;

View File

@ -69,6 +69,7 @@ import static java.time.temporal.ChronoUnit.MONTHS;
import static java.time.temporal.ChronoUnit.WEEKS;
import static java.time.temporal.ChronoUnit.YEARS;
import java.time.DateTimeException;
import java.time.Duration;
import java.time.LocalDate;
import java.time.ZoneId;
@ -343,7 +344,7 @@ public final class IsoFields {
}
@Override
public ChronoLocalDate resolve(
Map<TemporalField, Long> fieldValues, Chronology chronology, ZoneId zone, ResolverStyle resolverStyle) {
Map<TemporalField, Long> fieldValues, TemporalAccessor partialTemporal, ResolverStyle resolverStyle) {
Long yearLong = fieldValues.get(YEAR);
Long qoyLong = fieldValues.get(QUARTER_OF_YEAR);
if (yearLong == null || qoyLong == null) {
@ -351,6 +352,7 @@ public final class IsoFields {
}
int y = YEAR.checkValidIntValue(yearLong); // always validate
long doq = fieldValues.get(DAY_OF_QUARTER);
ensureIso(partialTemporal);
LocalDate date;
if (resolverStyle == ResolverStyle.LENIENT) {
date = LocalDate.of(y, 1, 1).plusMonths(Math.multiplyExact(Math.subtractExact(qoyLong, 1), 3));
@ -464,7 +466,7 @@ public final class IsoFields {
}
@Override
public ChronoLocalDate resolve(
Map<TemporalField, Long> fieldValues, Chronology chronology, ZoneId zone, ResolverStyle resolverStyle) {
Map<TemporalField, Long> fieldValues, TemporalAccessor partialTemporal, ResolverStyle resolverStyle) {
Long wbyLong = fieldValues.get(WEEK_BASED_YEAR);
Long dowLong = fieldValues.get(DAY_OF_WEEK);
if (wbyLong == null || dowLong == null) {
@ -472,6 +474,7 @@ public final class IsoFields {
}
int wby = WEEK_BASED_YEAR.range().checkValidIntValue(wbyLong, WEEK_BASED_YEAR); // always validate
long wowby = fieldValues.get(WEEK_OF_WEEK_BASED_YEAR);
ensureIso(partialTemporal);
LocalDate date = LocalDate.of(wby, 1, 4);
if (resolverStyle == ResolverStyle.LENIENT) {
long dow = dowLong; // unvalidated
@ -568,6 +571,12 @@ public final class IsoFields {
return Chronology.from(temporal).equals(IsoChronology.INSTANCE);
}
private static void ensureIso(TemporalAccessor temporal) {
if (isIso(temporal) == false) {
throw new DateTimeException("Resolve requires IsoChronology");
}
}
private static ValueRange getWeekRange(LocalDate date) {
int wby = getWeekBasedYear(date);
date = date.withDayOfYear(1).withYear(wby);

View File

@ -291,13 +291,14 @@ public final class JulianFields {
//-----------------------------------------------------------------------
@Override
public ChronoLocalDate resolve(
Map<TemporalField, Long> fieldValues, Chronology chronology, ZoneId zone, ResolverStyle resolverStyle) {
Map<TemporalField, Long> fieldValues, TemporalAccessor partialTemporal, ResolverStyle resolverStyle) {
long value = fieldValues.remove(this);
Chronology chrono = Chronology.from(partialTemporal);
if (resolverStyle == ResolverStyle.LENIENT) {
return chronology.dateEpochDay(Math.subtractExact(value, offset));
return chrono.dateEpochDay(Math.subtractExact(value, offset));
}
range().checkValidValue(value, this);
return chronology.dateEpochDay(value - offset);
return chrono.dateEpochDay(value - offset);
}
//-----------------------------------------------------------------------

View File

@ -272,8 +272,8 @@ public interface TemporalAccessor {
* @implSpec
* The default implementation must behave equivalent to this code:
* <pre>
* if (query == TemporalQuery.zoneId() ||
* query == TemporalQuery.chronology() || query == TemporalQuery.precision()) {
* if (query == TemporalQueries.zoneId() ||
* query == TemporalQueries.chronology() || query == TemporalQueries.precision()) {
* return null;
* }
* return query.queryFrom(this);
@ -290,7 +290,7 @@ public interface TemporalAccessor {
* For example, an application-defined {@code HourMin} class storing the hour
* and minute must override this method as follows:
* <pre>
* if (query == TemporalQuery.precision()) {
* if (query == TemporalQueries.precision()) {
* return MINUTES;
* }
* return TemporalAccessor.super.query(query);
@ -306,7 +306,9 @@ public interface TemporalAccessor {
* @throws ArithmeticException if numeric overflow occurs
*/
default <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.zoneId() || query == TemporalQuery.chronology() || query == TemporalQuery.precision()) {
if (query == TemporalQueries.zoneId()
|| query == TemporalQueries.chronology()
|| query == TemporalQueries.precision()) {
return null;
}
return query.queryFrom(this);

View File

@ -62,9 +62,6 @@
package java.time.temporal;
import java.time.DateTimeException;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.function.UnaryOperator;
/**
* Strategy for adjusting a temporal object.
@ -86,7 +83,8 @@ import java.util.function.UnaryOperator;
* It is recommended to use the second approach, {@code with(TemporalAdjuster)},
* as it is a lot clearer to read in code.
* <p>
* This class also contains a standard set of adjusters, available as static methods.
* The {@link TemporalAdjusters} class contains a standard set of adjusters,
* available as static methods.
* These include:
* <ul>
* <li>finding the first or last day of the month
@ -100,9 +98,8 @@ import java.util.function.UnaryOperator;
* @implSpec
* This interface places no restrictions on the mutability of implementations,
* however immutability is strongly recommended.
* <p>
* All the implementations supplied by the static methods on this interface are immutable.
*
* @see TemporalAdjusters
* @since 1.8
*/
@FunctionalInterface
@ -140,7 +137,7 @@ public interface TemporalAdjuster {
* <p>
* The input temporal object may be in a calendar system other than ISO.
* Implementations may choose to document compatibility with other calendar systems,
* or reject non-ISO temporal objects by {@link TemporalQuery#chronology() querying the chronology}.
* or reject non-ISO temporal objects by {@link TemporalQueries#chronology() querying the chronology}.
* <p>
* This method may be called from multiple threads in parallel.
* It must be thread-safe when invoked.
@ -152,311 +149,4 @@ public interface TemporalAdjuster {
*/
Temporal adjustInto(Temporal temporal);
//-----------------------------------------------------------------------
/**
* Obtains a {@code TemporalAdjuster} that wraps a date adjuster.
* <p>
* The {@code TemporalAdjuster} is based on the low level {@code Temporal} interface.
* This method allows an adjustment from {@code LocalDate} to {@code LocalDate}
* to be wrapped to match the temporal-based interface.
* This is provided for convenience to make user-written adjusters simpler.
* <p>
* In general, user-written adjusters should be static constants:
* <pre>{@code
* static TemporalAdjuster TWO_DAYS_LATER = TemporalAdjuster.ofDateAdjuster(
* date -> date.plusDays(2));
* }</pre>
*
* @param dateBasedAdjuster the date-based adjuster, not null
* @return the temporal adjuster wrapping on the date adjuster, not null
*/
static TemporalAdjuster ofDateAdjuster(UnaryOperator<LocalDate> dateBasedAdjuster) {
return TemporalAdjusters.ofDateAdjuster(dateBasedAdjuster);
}
//-----------------------------------------------------------------------
/**
* Returns the "first day of month" adjuster, which returns a new date set to
* the first day of the current month.
* <p>
* The ISO calendar system behaves as follows:<br>
* The input 2011-01-15 will return 2011-01-01.<br>
* The input 2011-02-15 will return 2011-02-01.
* <p>
* The behavior is suitable for use with most calendar systems.
* It is equivalent to:
* <pre>
* temporal.with(DAY_OF_MONTH, 1);
* </pre>
*
* @return the first day-of-month adjuster, not null
*/
static TemporalAdjuster firstDayOfMonth() {
return TemporalAdjusters.firstDayOfMonth();
}
/**
* Returns the "last day of month" adjuster, which returns a new date set to
* the last day of the current month.
* <p>
* The ISO calendar system behaves as follows:<br>
* The input 2011-01-15 will return 2011-01-31.<br>
* The input 2011-02-15 will return 2011-02-28.<br>
* The input 2012-02-15 will return 2012-02-29 (leap year).<br>
* The input 2011-04-15 will return 2011-04-30.
* <p>
* The behavior is suitable for use with most calendar systems.
* It is equivalent to:
* <pre>
* long lastDay = temporal.range(DAY_OF_MONTH).getMaximum();
* temporal.with(DAY_OF_MONTH, lastDay);
* </pre>
*
* @return the last day-of-month adjuster, not null
*/
static TemporalAdjuster lastDayOfMonth() {
return TemporalAdjusters.lastDayOfMonth();
}
/**
* Returns the "first day of next month" adjuster, which returns a new date set to
* the first day of the next month.
* <p>
* The ISO calendar system behaves as follows:<br>
* The input 2011-01-15 will return 2011-02-01.<br>
* The input 2011-02-15 will return 2011-03-01.
* <p>
* The behavior is suitable for use with most calendar systems.
* It is equivalent to:
* <pre>
* temporal.with(DAY_OF_MONTH, 1).plus(1, MONTHS);
* </pre>
*
* @return the first day of next month adjuster, not null
*/
static TemporalAdjuster firstDayOfNextMonth() {
return TemporalAdjusters.firstDayOfNextMonth();
}
//-----------------------------------------------------------------------
/**
* Returns the "first day of year" adjuster, which returns a new date set to
* the first day of the current year.
* <p>
* The ISO calendar system behaves as follows:<br>
* The input 2011-01-15 will return 2011-01-01.<br>
* The input 2011-02-15 will return 2011-01-01.<br>
* <p>
* The behavior is suitable for use with most calendar systems.
* It is equivalent to:
* <pre>
* temporal.with(DAY_OF_YEAR, 1);
* </pre>
*
* @return the first day-of-year adjuster, not null
*/
static TemporalAdjuster firstDayOfYear() {
return TemporalAdjusters.firstDayOfYear();
}
/**
* Returns the "last day of year" adjuster, which returns a new date set to
* the last day of the current year.
* <p>
* The ISO calendar system behaves as follows:<br>
* The input 2011-01-15 will return 2011-12-31.<br>
* The input 2011-02-15 will return 2011-12-31.<br>
* <p>
* The behavior is suitable for use with most calendar systems.
* It is equivalent to:
* <pre>
* long lastDay = temporal.range(DAY_OF_YEAR).getMaximum();
* temporal.with(DAY_OF_YEAR, lastDay);
* </pre>
*
* @return the last day-of-year adjuster, not null
*/
static TemporalAdjuster lastDayOfYear() {
return TemporalAdjusters.lastDayOfYear();
}
/**
* Returns the "first day of next year" adjuster, which returns a new date set to
* the first day of the next year.
* <p>
* The ISO calendar system behaves as follows:<br>
* The input 2011-01-15 will return 2012-01-01.
* <p>
* The behavior is suitable for use with most calendar systems.
* It is equivalent to:
* <pre>
* temporal.with(DAY_OF_YEAR, 1).plus(1, YEARS);
* </pre>
*
* @return the first day of next month adjuster, not null
*/
static TemporalAdjuster firstDayOfNextYear() {
return TemporalAdjusters.firstDayOfNextYear();
}
//-----------------------------------------------------------------------
/**
* Returns the first in month adjuster, which returns a new date
* in the same month with the first matching day-of-week.
* This is used for expressions like 'first Tuesday in March'.
* <p>
* The ISO calendar system behaves as follows:<br>
* The input 2011-12-15 for (MONDAY) will return 2011-12-05.<br>
* The input 2011-12-15 for (FRIDAY) will return 2011-12-02.<br>
* <p>
* The behavior is suitable for use with most calendar systems.
* It uses the {@code DAY_OF_WEEK} and {@code DAY_OF_MONTH} fields
* and the {@code DAYS} unit, and assumes a seven day week.
*
* @param dayOfWeek the day-of-week, not null
* @return the first in month adjuster, not null
*/
static TemporalAdjuster firstInMonth(DayOfWeek dayOfWeek) {
return TemporalAdjuster.dayOfWeekInMonth(1, dayOfWeek);
}
/**
* Returns the last in month adjuster, which returns a new date
* in the same month with the last matching day-of-week.
* This is used for expressions like 'last Tuesday in March'.
* <p>
* The ISO calendar system behaves as follows:<br>
* The input 2011-12-15 for (MONDAY) will return 2011-12-26.<br>
* The input 2011-12-15 for (FRIDAY) will return 2011-12-30.<br>
* <p>
* The behavior is suitable for use with most calendar systems.
* It uses the {@code DAY_OF_WEEK} and {@code DAY_OF_MONTH} fields
* and the {@code DAYS} unit, and assumes a seven day week.
*
* @param dayOfWeek the day-of-week, not null
* @return the first in month adjuster, not null
*/
static TemporalAdjuster lastInMonth(DayOfWeek dayOfWeek) {
return TemporalAdjuster.dayOfWeekInMonth(-1, dayOfWeek);
}
/**
* Returns the day-of-week in month adjuster, which returns a new date
* in the same month with the ordinal day-of-week.
* This is used for expressions like the 'second Tuesday in March'.
* <p>
* The ISO calendar system behaves as follows:<br>
* The input 2011-12-15 for (1,TUESDAY) will return 2011-12-06.<br>
* The input 2011-12-15 for (2,TUESDAY) will return 2011-12-13.<br>
* The input 2011-12-15 for (3,TUESDAY) will return 2011-12-20.<br>
* The input 2011-12-15 for (4,TUESDAY) will return 2011-12-27.<br>
* The input 2011-12-15 for (5,TUESDAY) will return 2012-01-03.<br>
* The input 2011-12-15 for (-1,TUESDAY) will return 2011-12-27 (last in month).<br>
* The input 2011-12-15 for (-4,TUESDAY) will return 2011-12-06 (3 weeks before last in month).<br>
* The input 2011-12-15 for (-5,TUESDAY) will return 2011-11-29 (4 weeks before last in month).<br>
* The input 2011-12-15 for (0,TUESDAY) will return 2011-11-29 (last in previous month).<br>
* <p>
* For a positive or zero ordinal, the algorithm is equivalent to finding the first
* day-of-week that matches within the month and then adding a number of weeks to it.
* For a negative ordinal, the algorithm is equivalent to finding the last
* day-of-week that matches within the month and then subtracting a number of weeks to it.
* The ordinal number of weeks is not validated and is interpreted leniently
* according to this algorithm. This definition means that an ordinal of zero finds
* the last matching day-of-week in the previous month.
* <p>
* The behavior is suitable for use with most calendar systems.
* It uses the {@code DAY_OF_WEEK} and {@code DAY_OF_MONTH} fields
* and the {@code DAYS} unit, and assumes a seven day week.
*
* @param ordinal the week within the month, unbounded but typically from -5 to 5
* @param dayOfWeek the day-of-week, not null
* @return the day-of-week in month adjuster, not null
*/
static TemporalAdjuster dayOfWeekInMonth(final int ordinal, DayOfWeek dayOfWeek) {
return TemporalAdjusters.dayOfWeekInMonth(ordinal, dayOfWeek);
}
//-----------------------------------------------------------------------
/**
* Returns the next day-of-week adjuster, which adjusts the date to the
* first occurrence of the specified day-of-week after the date being adjusted.
* <p>
* The ISO calendar system behaves as follows:<br>
* The input 2011-01-15 (a Saturday) for parameter (MONDAY) will return 2011-01-17 (two days later).<br>
* The input 2011-01-15 (a Saturday) for parameter (WEDNESDAY) will return 2011-01-19 (four days later).<br>
* The input 2011-01-15 (a Saturday) for parameter (SATURDAY) will return 2011-01-22 (seven days later).
* <p>
* The behavior is suitable for use with most calendar systems.
* It uses the {@code DAY_OF_WEEK} field and the {@code DAYS} unit,
* and assumes a seven day week.
*
* @param dayOfWeek the day-of-week to move the date to, not null
* @return the next day-of-week adjuster, not null
*/
static TemporalAdjuster next(DayOfWeek dayOfWeek) {
return TemporalAdjusters.next(dayOfWeek);
}
/**
* Returns the next-or-same day-of-week adjuster, which adjusts the date to the
* first occurrence of the specified day-of-week after the date being adjusted
* unless it is already on that day in which case the same object is returned.
* <p>
* The ISO calendar system behaves as follows:<br>
* The input 2011-01-15 (a Saturday) for parameter (MONDAY) will return 2011-01-17 (two days later).<br>
* The input 2011-01-15 (a Saturday) for parameter (WEDNESDAY) will return 2011-01-19 (four days later).<br>
* The input 2011-01-15 (a Saturday) for parameter (SATURDAY) will return 2011-01-15 (same as input).
* <p>
* The behavior is suitable for use with most calendar systems.
* It uses the {@code DAY_OF_WEEK} field and the {@code DAYS} unit,
* and assumes a seven day week.
*
* @param dayOfWeek the day-of-week to check for or move the date to, not null
* @return the next-or-same day-of-week adjuster, not null
*/
static TemporalAdjuster nextOrSame(DayOfWeek dayOfWeek) {
return TemporalAdjusters.nextOrSame(dayOfWeek);
}
/**
* Returns the previous day-of-week adjuster, which adjusts the date to the
* first occurrence of the specified day-of-week before the date being adjusted.
* <p>
* The ISO calendar system behaves as follows:<br>
* The input 2011-01-15 (a Saturday) for parameter (MONDAY) will return 2011-01-10 (five days earlier).<br>
* The input 2011-01-15 (a Saturday) for parameter (WEDNESDAY) will return 2011-01-12 (three days earlier).<br>
* The input 2011-01-15 (a Saturday) for parameter (SATURDAY) will return 2011-01-08 (seven days earlier).
* <p>
* The behavior is suitable for use with most calendar systems.
* It uses the {@code DAY_OF_WEEK} field and the {@code DAYS} unit,
* and assumes a seven day week.
*
* @param dayOfWeek the day-of-week to move the date to, not null
* @return the previous day-of-week adjuster, not null
*/
static TemporalAdjuster previous(DayOfWeek dayOfWeek) {
return TemporalAdjusters.previous(dayOfWeek);
}
/**
* Returns the previous-or-same day-of-week adjuster, which adjusts the date to the
* first occurrence of the specified day-of-week before the date being adjusted
* unless it is already on that day in which case the same object is returned.
* <p>
* The ISO calendar system behaves as follows:<br>
* The input 2011-01-15 (a Saturday) for parameter (MONDAY) will return 2011-01-10 (five days earlier).<br>
* The input 2011-01-15 (a Saturday) for parameter (WEDNESDAY) will return 2011-01-12 (three days earlier).<br>
* The input 2011-01-15 (a Saturday) for parameter (SATURDAY) will return 2011-01-15 (same as input).
* <p>
* The behavior is suitable for use with most calendar systems.
* It uses the {@code DAY_OF_WEEK} field and the {@code DAYS} unit,
* and assumes a seven day week.
*
* @param dayOfWeek the day-of-week to check for or move the date to, not null
* @return the previous-or-same day-of-week adjuster, not null
*/
static TemporalAdjuster previousOrSame(DayOfWeek dayOfWeek) {
return TemporalAdjusters.previousOrSame(dayOfWeek);
}
}

View File

@ -74,13 +74,47 @@ import java.util.Objects;
import java.util.function.UnaryOperator;
/**
* Implementations of the static methods in {@code TemporalAdjuster}
* Common and useful TemporalAdjusters.
* <p>
* Adjusters are a key tool for modifying temporal objects.
* They exist to externalize the process of adjustment, permitting different
* approaches, as per the strategy design pattern.
* Examples might be an adjuster that sets the date avoiding weekends, or one that
* sets the date to the last day of the month.
* <p>
* There are two equivalent ways of using a {@code TemporalAdjuster}.
* The first is to invoke the method on the interface directly.
* The second is to use {@link Temporal#with(TemporalAdjuster)}:
* <pre>
* // these two lines are equivalent, but the second approach is recommended
* temporal = thisAdjuster.adjustInto(temporal);
* temporal = temporal.with(thisAdjuster);
* </pre>
* It is recommended to use the second approach, {@code with(TemporalAdjuster)},
* as it is a lot clearer to read in code.
* <p>
* This class contains a standard set of adjusters, available as static methods.
* These include:
* <ul>
* <li>finding the first or last day of the month
* <li>finding the first day of next month
* <li>finding the first or last day of the year
* <li>finding the first day of next year
* <li>finding the first or last day-of-week within a month, such as "first Wednesday in June"
* <li>finding the next or previous day-of-week, such as "next Thursday"
* </ul>
*
* @implSpec
* All the implementations supplied by the static methods are immutable.
*
* @see TemporalAdjuster
* @since 1.8
*/
final class TemporalAdjusters {
// work around compiler bug not allowing lambdas in static methods
public final class TemporalAdjusters {
/**
* Private constructor since this is a utility class.
*/
private TemporalAdjusters() {
}
@ -94,15 +128,15 @@ final class TemporalAdjusters {
* This is provided for convenience to make user-written adjusters simpler.
* <p>
* In general, user-written adjusters should be static constants:
* <pre>
* public static TemporalAdjuster TWO_DAYS_LATER = TemporalAdjuster.ofDateAdjuster(
* date -> date.plusDays(2));
* </pre>
* <pre>{@code
* static TemporalAdjuster TWO_DAYS_LATER =
* TemporalAdjusters.ofDateAdjuster(date -> date.plusDays(2));
* }</pre>
*
* @param dateBasedAdjuster the date-based adjuster, not null
* @return the temporal adjuster wrapping on the date adjuster, not null
*/
static TemporalAdjuster ofDateAdjuster(UnaryOperator<LocalDate> dateBasedAdjuster) {
public static TemporalAdjuster ofDateAdjuster(UnaryOperator<LocalDate> dateBasedAdjuster) {
Objects.requireNonNull(dateBasedAdjuster, "dateBasedAdjuster");
return (temporal) -> {
LocalDate input = LocalDate.from(temporal);
@ -128,7 +162,7 @@ final class TemporalAdjusters {
*
* @return the first day-of-month adjuster, not null
*/
static TemporalAdjuster firstDayOfMonth() {
public static TemporalAdjuster firstDayOfMonth() {
return (temporal) -> temporal.with(DAY_OF_MONTH, 1);
}
@ -151,7 +185,7 @@ final class TemporalAdjusters {
*
* @return the last day-of-month adjuster, not null
*/
static TemporalAdjuster lastDayOfMonth() {
public static TemporalAdjuster lastDayOfMonth() {
return (temporal) -> temporal.with(DAY_OF_MONTH, temporal.range(DAY_OF_MONTH).getMaximum());
}
@ -171,7 +205,7 @@ final class TemporalAdjusters {
*
* @return the first day of next month adjuster, not null
*/
static TemporalAdjuster firstDayOfNextMonth() {
public static TemporalAdjuster firstDayOfNextMonth() {
return (temporal) -> temporal.with(DAY_OF_MONTH, 1).plus(1, MONTHS);
}
@ -192,7 +226,7 @@ final class TemporalAdjusters {
*
* @return the first day-of-year adjuster, not null
*/
static TemporalAdjuster firstDayOfYear() {
public static TemporalAdjuster firstDayOfYear() {
return (temporal) -> temporal.with(DAY_OF_YEAR, 1);
}
@ -213,7 +247,7 @@ final class TemporalAdjusters {
*
* @return the last day-of-year adjuster, not null
*/
static TemporalAdjuster lastDayOfYear() {
public static TemporalAdjuster lastDayOfYear() {
return (temporal) -> temporal.with(DAY_OF_YEAR, temporal.range(DAY_OF_YEAR).getMaximum());
}
@ -232,7 +266,7 @@ final class TemporalAdjusters {
*
* @return the first day of next month adjuster, not null
*/
static TemporalAdjuster firstDayOfNextYear() {
public static TemporalAdjuster firstDayOfNextYear() {
return (temporal) -> temporal.with(DAY_OF_YEAR, 1).plus(1, YEARS);
}
@ -253,7 +287,7 @@ final class TemporalAdjusters {
* @param dayOfWeek the day-of-week, not null
* @return the first in month adjuster, not null
*/
static TemporalAdjuster firstInMonth(DayOfWeek dayOfWeek) {
public static TemporalAdjuster firstInMonth(DayOfWeek dayOfWeek) {
return TemporalAdjusters.dayOfWeekInMonth(1, dayOfWeek);
}
@ -273,7 +307,7 @@ final class TemporalAdjusters {
* @param dayOfWeek the day-of-week, not null
* @return the first in month adjuster, not null
*/
static TemporalAdjuster lastInMonth(DayOfWeek dayOfWeek) {
public static TemporalAdjuster lastInMonth(DayOfWeek dayOfWeek) {
return TemporalAdjusters.dayOfWeekInMonth(-1, dayOfWeek);
}
@ -309,7 +343,7 @@ final class TemporalAdjusters {
* @param dayOfWeek the day-of-week, not null
* @return the day-of-week in month adjuster, not null
*/
static TemporalAdjuster dayOfWeekInMonth(int ordinal, DayOfWeek dayOfWeek) {
public static TemporalAdjuster dayOfWeekInMonth(int ordinal, DayOfWeek dayOfWeek) {
Objects.requireNonNull(dayOfWeek, "dayOfWeek");
int dowValue = dayOfWeek.getValue();
if (ordinal >= 0) {
@ -349,7 +383,7 @@ final class TemporalAdjusters {
* @param dayOfWeek the day-of-week to move the date to, not null
* @return the next day-of-week adjuster, not null
*/
static TemporalAdjuster next(DayOfWeek dayOfWeek) {
public static TemporalAdjuster next(DayOfWeek dayOfWeek) {
int dowValue = dayOfWeek.getValue();
return (temporal) -> {
int calDow = temporal.get(DAY_OF_WEEK);
@ -375,7 +409,7 @@ final class TemporalAdjusters {
* @param dayOfWeek the day-of-week to check for or move the date to, not null
* @return the next-or-same day-of-week adjuster, not null
*/
static TemporalAdjuster nextOrSame(DayOfWeek dayOfWeek) {
public static TemporalAdjuster nextOrSame(DayOfWeek dayOfWeek) {
int dowValue = dayOfWeek.getValue();
return (temporal) -> {
int calDow = temporal.get(DAY_OF_WEEK);
@ -403,7 +437,7 @@ final class TemporalAdjusters {
* @param dayOfWeek the day-of-week to move the date to, not null
* @return the previous day-of-week adjuster, not null
*/
static TemporalAdjuster previous(DayOfWeek dayOfWeek) {
public static TemporalAdjuster previous(DayOfWeek dayOfWeek) {
int dowValue = dayOfWeek.getValue();
return (temporal) -> {
int calDow = temporal.get(DAY_OF_WEEK);
@ -429,7 +463,7 @@ final class TemporalAdjusters {
* @param dayOfWeek the day-of-week to check for or move the date to, not null
* @return the previous-or-same day-of-week adjuster, not null
*/
static TemporalAdjuster previousOrSame(DayOfWeek dayOfWeek) {
public static TemporalAdjuster previousOrSame(DayOfWeek dayOfWeek) {
int dowValue = dayOfWeek.getValue();
return (temporal) -> {
int calDow = temporal.get(DAY_OF_WEEK);

View File

@ -163,7 +163,7 @@ public interface TemporalAmount {
* <p>
* The input temporal object may be in a calendar system other than ISO.
* Implementations may choose to document compatibility with other calendar systems,
* or reject non-ISO temporal objects by {@link TemporalQuery#chronology() querying the chronology}.
* or reject non-ISO temporal objects by {@link TemporalQueries#chronology() querying the chronology}.
* <p>
* This method may be called from multiple threads in parallel.
* It must be thread-safe when invoked.
@ -205,7 +205,7 @@ public interface TemporalAmount {
* <p>
* The input temporal object may be in a calendar system other than ISO.
* Implementations may choose to document compatibility with other calendar systems,
* or reject non-ISO temporal objects by {@link TemporalQuery#chronology() querying the chronology}.
* or reject non-ISO temporal objects by {@link TemporalQueries#chronology() querying the chronology}.
* <p>
* This method may be called from multiple threads in parallel.
* It must be thread-safe when invoked.

View File

@ -62,7 +62,6 @@
package java.time.temporal;
import java.time.DateTimeException;
import java.time.ZoneId;
import java.time.chrono.Chronology;
import java.time.format.ResolverStyle;
import java.util.Locale;
@ -338,6 +337,13 @@ public interface TemporalField {
* complete {@code LocalDate}. The resolve method will remove all three
* fields from the map before returning the {@code LocalDate}.
* <p>
* A partially complete temporal is used to allow the chronology and zone
* to be queried. In general, only the chronology will be needed.
* Querying items other than the zone or chronology is undefined and
* must not be relied on.
* The behavior of other methods such as {@code get}, {@code getLong},
* {@code range} and {@code isSupported} is unpredictable and the results undefined.
* <p>
* If resolution should be possible, but the data is invalid, the resolver
* style should be used to determine an appropriate level of leniency, which
* may require throwing a {@code DateTimeException} or {@code ArithmeticException}.
@ -350,16 +356,14 @@ public interface TemporalField {
* instances that can produce a date, such as {@code EPOCH_DAY}.
* <p>
* Not all {@code TemporalAccessor} implementations are accepted as return values.
* Implementations must accept {@code ChronoLocalDate}, {@code ChronoLocalDateTime},
* {@code ChronoZonedDateTime} and {@code LocalTime}.
* <p>
* The zone is not normally required for resolution, but is provided for completeness.
* Implementations that call this method must accept {@code ChronoLocalDate},
* {@code ChronoLocalDateTime}, {@code ChronoZonedDateTime} and {@code LocalTime}.
* <p>
* The default implementation must return null.
*
* @param fieldValues the map of fields to values, which can be updated, not null
* @param chronology the effective chronology, not null
* @param zone the effective zone, not null
* @param partialTemporal the partially complete temporal to query for zone and
* chronology; querying for other things is undefined and not recommended, not null
* @param resolverStyle the requested type of resolve, not null
* @return the resolved temporal object; null if resolving only
* changed the map, or no resolve occurred
@ -368,8 +372,9 @@ public interface TemporalField {
* by querying a field on the temporal without first checking if it is supported
*/
default TemporalAccessor resolve(
Map<TemporalField, Long> fieldValues, Chronology chronology,
ZoneId zone, ResolverStyle resolverStyle) {
Map<TemporalField, Long> fieldValues,
TemporalAccessor partialTemporal,
ResolverStyle resolverStyle) {
return null;
}

View File

@ -78,10 +78,44 @@ import java.time.chrono.Chronology;
* These are defined here as they must be constants, and the definition
* of lambdas does not guarantee that. By assigning them once here,
* they become 'normal' Java constants.
* <p>
* Queries are a key tool for extracting information from temporal objects.
* They exist to externalize the process of querying, permitting different
* approaches, as per the strategy design pattern.
* Examples might be a query that checks if the date is the day before February 29th
* in a leap year, or calculates the number of days to your next birthday.
* <p>
* The {@link TemporalField} interface provides another mechanism for querying
* temporal objects. That interface is limited to returning a {@code long}.
* By contrast, queries can return any type.
* <p>
* There are two equivalent ways of using a {@code TemporalQuery}.
* The first is to invoke the method on this interface directly.
* The second is to use {@link TemporalAccessor#query(TemporalQuery)}:
* <pre>
* // these two lines are equivalent, but the second approach is recommended
* temporal = thisQuery.queryFrom(temporal);
* temporal = temporal.query(thisQuery);
* </pre>
* It is recommended to use the second approach, {@code query(TemporalQuery)},
* as it is a lot clearer to read in code.
* <p>
* The most common implementations are method references, such as
* {@code LocalDate::from} and {@code ZoneId::from}.
* Additional common queries are provided to return:
* <ul>
* <li> a Chronology,
* <li> a LocalDate,
* <li> a LocalTime,
* <li> a ZoneOffset,
* <li> a precision,
* <li> a zone, or
* <li> a zoneId.
* </ul>
*
* @since 1.8
*/
final class TemporalQueries {
public final class TemporalQueries {
// note that it is vital that each method supplies a constant, not a
// calculated value, as they will be checked for using ==
// it is also vital that each constant is different (due to the == checking)
@ -93,6 +127,216 @@ final class TemporalQueries {
private TemporalQueries() {
}
//-----------------------------------------------------------------------
// special constants should be used to extract information from a TemporalAccessor
// that cannot be derived in other ways
// Javadoc added here, so as to pretend they are more normal than they really are
/**
* A strict query for the {@code ZoneId}.
* <p>
* This queries a {@code TemporalAccessor} for the zone.
* The zone is only returned if the date-time conceptually contains a {@code ZoneId}.
* It will not be returned if the date-time only conceptually has an {@code ZoneOffset}.
* Thus a {@link java.time.ZonedDateTime} will return the result of {@code getZone()},
* but an {@link java.time.OffsetDateTime} will return null.
* <p>
* In most cases, applications should use {@link #zone()} as this query is too strict.
* <p>
* The result from JDK classes implementing {@code TemporalAccessor} is as follows:<br>
* {@code LocalDate} returns null<br>
* {@code LocalTime} returns null<br>
* {@code LocalDateTime} returns null<br>
* {@code ZonedDateTime} returns the associated zone<br>
* {@code OffsetTime} returns null<br>
* {@code OffsetDateTime} returns null<br>
* {@code ChronoLocalDate} returns null<br>
* {@code ChronoLocalDateTime} returns null<br>
* {@code ChronoZonedDateTime} returns the associated zone<br>
* {@code Era} returns null<br>
* {@code DayOfWeek} returns null<br>
* {@code Month} returns null<br>
* {@code Year} returns null<br>
* {@code YearMonth} returns null<br>
* {@code MonthDay} returns null<br>
* {@code ZoneOffset} returns null<br>
* {@code Instant} returns null<br>
*
* @return a query that can obtain the zone ID of a temporal, not null
*/
public static TemporalQuery<ZoneId> zoneId() {
return TemporalQueries.ZONE_ID;
}
/**
* A query for the {@code Chronology}.
* <p>
* This queries a {@code TemporalAccessor} for the chronology.
* If the target {@code TemporalAccessor} represents a date, or part of a date,
* then it should return the chronology that the date is expressed in.
* As a result of this definition, objects only representing time, such as
* {@code LocalTime}, will return null.
* <p>
* The result from JDK classes implementing {@code TemporalAccessor} is as follows:<br>
* {@code LocalDate} returns {@code IsoChronology.INSTANCE}<br>
* {@code LocalTime} returns null (does not represent a date)<br>
* {@code LocalDateTime} returns {@code IsoChronology.INSTANCE}<br>
* {@code ZonedDateTime} returns {@code IsoChronology.INSTANCE}<br>
* {@code OffsetTime} returns null (does not represent a date)<br>
* {@code OffsetDateTime} returns {@code IsoChronology.INSTANCE}<br>
* {@code ChronoLocalDate} returns the associated chronology<br>
* {@code ChronoLocalDateTime} returns the associated chronology<br>
* {@code ChronoZonedDateTime} returns the associated chronology<br>
* {@code Era} returns the associated chronology<br>
* {@code DayOfWeek} returns null (shared across chronologies)<br>
* {@code Month} returns {@code IsoChronology.INSTANCE}<br>
* {@code Year} returns {@code IsoChronology.INSTANCE}<br>
* {@code YearMonth} returns {@code IsoChronology.INSTANCE}<br>
* {@code MonthDay} returns null {@code IsoChronology.INSTANCE}<br>
* {@code ZoneOffset} returns null (does not represent a date)<br>
* {@code Instant} returns null (does not represent a date)<br>
* <p>
* The method {@link java.time.chrono.Chronology#from(TemporalAccessor)} can be used as a
* {@code TemporalQuery} via a method reference, {@code Chronology::from}.
* That method is equivalent to this query, except that it throws an
* exception if a chronology cannot be obtained.
*
* @return a query that can obtain the chronology of a temporal, not null
*/
public static TemporalQuery<Chronology> chronology() {
return TemporalQueries.CHRONO;
}
/**
* A query for the smallest supported unit.
* <p>
* This queries a {@code TemporalAccessor} for the time precision.
* If the target {@code TemporalAccessor} represents a consistent or complete date-time,
* date or time then this must return the smallest precision actually supported.
* Note that fields such as {@code NANO_OF_DAY} and {@code NANO_OF_SECOND}
* are defined to always return ignoring the precision, thus this is the only
* way to find the actual smallest supported unit.
* For example, were {@code GregorianCalendar} to implement {@code TemporalAccessor}
* it would return a precision of {@code MILLIS}.
* <p>
* The result from JDK classes implementing {@code TemporalAccessor} is as follows:<br>
* {@code LocalDate} returns {@code DAYS}<br>
* {@code LocalTime} returns {@code NANOS}<br>
* {@code LocalDateTime} returns {@code NANOS}<br>
* {@code ZonedDateTime} returns {@code NANOS}<br>
* {@code OffsetTime} returns {@code NANOS}<br>
* {@code OffsetDateTime} returns {@code NANOS}<br>
* {@code ChronoLocalDate} returns {@code DAYS}<br>
* {@code ChronoLocalDateTime} returns {@code NANOS}<br>
* {@code ChronoZonedDateTime} returns {@code NANOS}<br>
* {@code Era} returns {@code ERAS}<br>
* {@code DayOfWeek} returns {@code DAYS}<br>
* {@code Month} returns {@code MONTHS}<br>
* {@code Year} returns {@code YEARS}<br>
* {@code YearMonth} returns {@code MONTHS}<br>
* {@code MonthDay} returns null (does not represent a complete date or time)<br>
* {@code ZoneOffset} returns null (does not represent a date or time)<br>
* {@code Instant} returns {@code NANOS}<br>
*
* @return a query that can obtain the precision of a temporal, not null
*/
public static TemporalQuery<TemporalUnit> precision() {
return TemporalQueries.PRECISION;
}
//-----------------------------------------------------------------------
// non-special constants are standard queries that derive information from other information
/**
* A lenient query for the {@code ZoneId}, falling back to the {@code ZoneOffset}.
* <p>
* This queries a {@code TemporalAccessor} for the zone.
* It first tries to obtain the zone, using {@link #zoneId()}.
* If that is not found it tries to obtain the {@link #offset()}.
* Thus a {@link java.time.ZonedDateTime} will return the result of {@code getZone()},
* while an {@link java.time.OffsetDateTime} will return the result of {@code getOffset()}.
* <p>
* In most cases, applications should use this query rather than {@code #zoneId()}.
* <p>
* The method {@link ZoneId#from(TemporalAccessor)} can be used as a
* {@code TemporalQuery} via a method reference, {@code ZoneId::from}.
* That method is equivalent to this query, except that it throws an
* exception if a zone cannot be obtained.
*
* @return a query that can obtain the zone ID or offset of a temporal, not null
*/
public static TemporalQuery<ZoneId> zone() {
return TemporalQueries.ZONE;
}
/**
* A query for {@code ZoneOffset} returning null if not found.
* <p>
* This returns a {@code TemporalQuery} that can be used to query a temporal
* object for the offset. The query will return null if the temporal
* object cannot supply an offset.
* <p>
* The query implementation examines the {@link ChronoField#OFFSET_SECONDS OFFSET_SECONDS}
* field and uses it to create a {@code ZoneOffset}.
* <p>
* The method {@link java.time.ZoneOffset#from(TemporalAccessor)} can be used as a
* {@code TemporalQuery} via a method reference, {@code ZoneOffset::from}.
* This query and {@code ZoneOffset::from} will return the same result if the
* temporal object contains an offset. If the temporal object does not contain
* an offset, then the method reference will throw an exception, whereas this
* query will return null.
*
* @return a query that can obtain the offset of a temporal, not null
*/
public static TemporalQuery<ZoneOffset> offset() {
return TemporalQueries.OFFSET;
}
/**
* A query for {@code LocalDate} returning null if not found.
* <p>
* This returns a {@code TemporalQuery} that can be used to query a temporal
* object for the local date. The query will return null if the temporal
* object cannot supply a local date.
* <p>
* The query implementation examines the {@link ChronoField#EPOCH_DAY EPOCH_DAY}
* field and uses it to create a {@code LocalDate}.
* <p>
* The method {@link ZoneOffset#from(TemporalAccessor)} can be used as a
* {@code TemporalQuery} via a method reference, {@code LocalDate::from}.
* This query and {@code LocalDate::from} will return the same result if the
* temporal object contains a date. If the temporal object does not contain
* a date, then the method reference will throw an exception, whereas this
* query will return null.
*
* @return a query that can obtain the date of a temporal, not null
*/
public static TemporalQuery<LocalDate> localDate() {
return TemporalQueries.LOCAL_DATE;
}
/**
* A query for {@code LocalTime} returning null if not found.
* <p>
* This returns a {@code TemporalQuery} that can be used to query a temporal
* object for the local time. The query will return null if the temporal
* object cannot supply a local time.
* <p>
* The query implementation examines the {@link ChronoField#NANO_OF_DAY NANO_OF_DAY}
* field and uses it to create a {@code LocalTime}.
* <p>
* The method {@link ZoneOffset#from(TemporalAccessor)} can be used as a
* {@code TemporalQuery} via a method reference, {@code LocalTime::from}.
* This query and {@code LocalTime::from} will return the same result if the
* temporal object contains a time. If the temporal object does not contain
* a time, then the method reference will throw an exception, whereas this
* query will return null.
*
* @return a query that can obtain the time of a temporal, not null
*/
public static TemporalQuery<LocalTime> localTime() {
return TemporalQueries.LOCAL_TIME;
}
//-----------------------------------------------------------------------
/**
* A strict query for the {@code ZoneId}.

View File

@ -62,11 +62,6 @@
package java.time.temporal;
import java.time.DateTimeException;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.chrono.Chronology;
/**
* Strategy for querying a temporal object.
@ -94,12 +89,14 @@ import java.time.chrono.Chronology;
* <p>
* The most common implementations are method references, such as
* {@code LocalDate::from} and {@code ZoneId::from}.
* Additional common implementations are provided on this interface as static methods.
* Additional common queries are provided as static methods in {@link TemporalQueries}.
*
* @implSpec
* This interface places no restrictions on the mutability of implementations,
* however immutability is strongly recommended.
*
* @param <R> the type returned from the query
*
* @since 1.8
*/
@FunctionalInterface
@ -133,7 +130,7 @@ public interface TemporalQuery<R> {
* <p>
* The input temporal object may be in a calendar system other than ISO.
* Implementations may choose to document compatibility with other calendar systems,
* or reject non-ISO temporal objects by {@link TemporalQuery#chronology() querying the chronology}.
* or reject non-ISO temporal objects by {@link TemporalQueries#chronology() querying the chronology}.
* <p>
* This method may be called from multiple threads in parallel.
* It must be thread-safe when invoked.
@ -145,214 +142,4 @@ public interface TemporalQuery<R> {
*/
R queryFrom(TemporalAccessor temporal);
//-----------------------------------------------------------------------
// special constants should be used to extract information from a TemporalAccessor
// that cannot be derived in other ways
// Javadoc added here, so as to pretend they are more normal than they really are
/**
* A strict query for the {@code ZoneId}.
* <p>
* This queries a {@code TemporalAccessor} for the zone.
* The zone is only returned if the date-time conceptually contains a {@code ZoneId}.
* It will not be returned if the date-time only conceptually has an {@code ZoneOffset}.
* Thus a {@link java.time.ZonedDateTime} will return the result of {@code getZone()},
* but an {@link java.time.OffsetDateTime} will return null.
* <p>
* In most cases, applications should use {@link #zone()} as this query is too strict.
* <p>
* The result from JDK classes implementing {@code TemporalAccessor} is as follows:<br>
* {@code LocalDate} returns null<br>
* {@code LocalTime} returns null<br>
* {@code LocalDateTime} returns null<br>
* {@code ZonedDateTime} returns the associated zone<br>
* {@code OffsetTime} returns null<br>
* {@code OffsetDateTime} returns null<br>
* {@code ChronoLocalDate} returns null<br>
* {@code ChronoLocalDateTime} returns null<br>
* {@code ChronoZonedDateTime} returns the associated zone<br>
* {@code Era} returns null<br>
* {@code DayOfWeek} returns null<br>
* {@code Month} returns null<br>
* {@code Year} returns null<br>
* {@code YearMonth} returns null<br>
* {@code MonthDay} returns null<br>
* {@code ZoneOffset} returns null<br>
* {@code Instant} returns null<br>
*
* @return a query that can obtain the zone ID of a temporal, not null
*/
static TemporalQuery<ZoneId> zoneId() {
return TemporalQueries.ZONE_ID;
}
/**
* A query for the {@code Chronology}.
* <p>
* This queries a {@code TemporalAccessor} for the chronology.
* If the target {@code TemporalAccessor} represents a date, or part of a date,
* then it should return the chronology that the date is expressed in.
* As a result of this definition, objects only representing time, such as
* {@code LocalTime}, will return null.
* <p>
* The result from JDK classes implementing {@code TemporalAccessor} is as follows:<br>
* {@code LocalDate} returns {@code IsoChronology.INSTANCE}<br>
* {@code LocalTime} returns null (does not represent a date)<br>
* {@code LocalDateTime} returns {@code IsoChronology.INSTANCE}<br>
* {@code ZonedDateTime} returns {@code IsoChronology.INSTANCE}<br>
* {@code OffsetTime} returns null (does not represent a date)<br>
* {@code OffsetDateTime} returns {@code IsoChronology.INSTANCE}<br>
* {@code ChronoLocalDate} returns the associated chronology<br>
* {@code ChronoLocalDateTime} returns the associated chronology<br>
* {@code ChronoZonedDateTime} returns the associated chronology<br>
* {@code Era} returns the associated chronology<br>
* {@code DayOfWeek} returns null (shared across chronologies)<br>
* {@code Month} returns {@code IsoChronology.INSTANCE}<br>
* {@code Year} returns {@code IsoChronology.INSTANCE}<br>
* {@code YearMonth} returns {@code IsoChronology.INSTANCE}<br>
* {@code MonthDay} returns null {@code IsoChronology.INSTANCE}<br>
* {@code ZoneOffset} returns null (does not represent a date)<br>
* {@code Instant} returns null (does not represent a date)<br>
* <p>
* The method {@link java.time.chrono.Chronology#from(TemporalAccessor)} can be used as a
* {@code TemporalQuery} via a method reference, {@code Chronology::from}.
* That method is equivalent to this query, except that it throws an
* exception if a chronology cannot be obtained.
*
* @return a query that can obtain the chronology of a temporal, not null
*/
static TemporalQuery<Chronology> chronology() {
return TemporalQueries.CHRONO;
}
/**
* A query for the smallest supported unit.
* <p>
* This queries a {@code TemporalAccessor} for the time precision.
* If the target {@code TemporalAccessor} represents a consistent or complete date-time,
* date or time then this must return the smallest precision actually supported.
* Note that fields such as {@code NANO_OF_DAY} and {@code NANO_OF_SECOND}
* are defined to always return ignoring the precision, thus this is the only
* way to find the actual smallest supported unit.
* For example, were {@code GregorianCalendar} to implement {@code TemporalAccessor}
* it would return a precision of {@code MILLIS}.
* <p>
* The result from JDK classes implementing {@code TemporalAccessor} is as follows:<br>
* {@code LocalDate} returns {@code DAYS}<br>
* {@code LocalTime} returns {@code NANOS}<br>
* {@code LocalDateTime} returns {@code NANOS}<br>
* {@code ZonedDateTime} returns {@code NANOS}<br>
* {@code OffsetTime} returns {@code NANOS}<br>
* {@code OffsetDateTime} returns {@code NANOS}<br>
* {@code ChronoLocalDate} returns {@code DAYS}<br>
* {@code ChronoLocalDateTime} returns {@code NANOS}<br>
* {@code ChronoZonedDateTime} returns {@code NANOS}<br>
* {@code Era} returns {@code ERAS}<br>
* {@code DayOfWeek} returns {@code DAYS}<br>
* {@code Month} returns {@code MONTHS}<br>
* {@code Year} returns {@code YEARS}<br>
* {@code YearMonth} returns {@code MONTHS}<br>
* {@code MonthDay} returns null (does not represent a complete date or time)<br>
* {@code ZoneOffset} returns null (does not represent a date or time)<br>
* {@code Instant} returns {@code NANOS}<br>
*
* @return a query that can obtain the precision of a temporal, not null
*/
static TemporalQuery<TemporalUnit> precision() {
return TemporalQueries.PRECISION;
}
//-----------------------------------------------------------------------
// non-special constants are standard queries that derive information from other information
/**
* A lenient query for the {@code ZoneId}, falling back to the {@code ZoneOffset}.
* <p>
* This queries a {@code TemporalAccessor} for the zone.
* It first tries to obtain the zone, using {@link #zoneId()}.
* If that is not found it tries to obtain the {@link #offset()}.
* Thus a {@link java.time.ZonedDateTime} will return the result of {@code getZone()},
* while an {@link java.time.OffsetDateTime} will return the result of {@code getOffset()}.
* <p>
* In most cases, applications should use this query rather than {@code #zoneId()}.
* <p>
* The method {@link ZoneId#from(TemporalAccessor)} can be used as a
* {@code TemporalQuery} via a method reference, {@code ZoneId::from}.
* That method is equivalent to this query, except that it throws an
* exception if a zone cannot be obtained.
*
* @return a query that can obtain the zone ID or offset of a temporal, not null
*/
static TemporalQuery<ZoneId> zone() {
return TemporalQueries.ZONE;
}
/**
* A query for {@code ZoneOffset} returning null if not found.
* <p>
* This returns a {@code TemporalQuery} that can be used to query a temporal
* object for the offset. The query will return null if the temporal
* object cannot supply an offset.
* <p>
* The query implementation examines the {@link ChronoField#OFFSET_SECONDS OFFSET_SECONDS}
* field and uses it to create a {@code ZoneOffset}.
* <p>
* The method {@link java.time.ZoneOffset#from(TemporalAccessor)} can be used as a
* {@code TemporalQuery} via a method reference, {@code ZoneOffset::from}.
* This query and {@code ZoneOffset::from} will return the same result if the
* temporal object contains an offset. If the temporal object does not contain
* an offset, then the method reference will throw an exception, whereas this
* query will return null.
*
* @return a query that can obtain the offset of a temporal, not null
*/
static TemporalQuery<ZoneOffset> offset() {
return TemporalQueries.OFFSET;
}
/**
* A query for {@code LocalDate} returning null if not found.
* <p>
* This returns a {@code TemporalQuery} that can be used to query a temporal
* object for the local date. The query will return null if the temporal
* object cannot supply a local date.
* <p>
* The query implementation examines the {@link ChronoField#EPOCH_DAY EPOCH_DAY}
* field and uses it to create a {@code LocalDate}.
* <p>
* The method {@link ZoneOffset#from(TemporalAccessor)} can be used as a
* {@code TemporalQuery} via a method reference, {@code LocalDate::from}.
* This query and {@code LocalDate::from} will return the same result if the
* temporal object contains a date. If the temporal object does not contain
* a date, then the method reference will throw an exception, whereas this
* query will return null.
*
* @return a query that can obtain the date of a temporal, not null
*/
static TemporalQuery<LocalDate> localDate() {
return TemporalQueries.LOCAL_DATE;
}
/**
* A query for {@code LocalTime} returning null if not found.
* <p>
* This returns a {@code TemporalQuery} that can be used to query a temporal
* object for the local time. The query will return null if the temporal
* object cannot supply a local time.
* <p>
* The query implementation examines the {@link ChronoField#NANO_OF_DAY NANO_OF_DAY}
* field and uses it to create a {@code LocalTime}.
* <p>
* The method {@link ZoneOffset#from(TemporalAccessor)} can be used as a
* {@code TemporalQuery} via a method reference, {@code LocalTime::from}.
* This query and {@code LocalTime::from} will return the same result if the
* temporal object contains a time. If the temporal object does not contain
* a time, then the method reference will throw an exception, whereas this
* query will return null.
*
* @return a query that can obtain the time of a temporal, not null
*/
static TemporalQuery<LocalTime> localTime() {
return TemporalQueries.LOCAL_TIME;
}
}

View File

@ -892,7 +892,7 @@ public final class WeekFields implements Serializable {
@Override
public ChronoLocalDate resolve(
Map<TemporalField, Long> fieldValues, Chronology chronology, ZoneId zone, ResolverStyle resolverStyle) {
Map<TemporalField, Long> fieldValues, TemporalAccessor partialTemporal, ResolverStyle resolverStyle) {
final long value = fieldValues.get(this);
final int newValue = Math.toIntExact(value); // broad limit makes overflow checking lighter
// first convert localized day-of-week to ISO day-of-week
@ -915,19 +915,20 @@ public final class WeekFields implements Serializable {
int dow = localizedDayOfWeek(isoDow);
// build date
Chronology chrono = Chronology.from(partialTemporal);
if (fieldValues.containsKey(YEAR)) {
int year = YEAR.checkValidIntValue(fieldValues.get(YEAR)); // validate
if (rangeUnit == MONTHS && fieldValues.containsKey(MONTH_OF_YEAR)) { // week-of-month
long month = fieldValues.get(MONTH_OF_YEAR); // not validated yet
return resolveWoM(fieldValues, chronology, year, month, newValue, dow, resolverStyle);
return resolveWoM(fieldValues, chrono, year, month, newValue, dow, resolverStyle);
}
if (rangeUnit == YEARS) { // week-of-year
return resolveWoY(fieldValues, chronology, year, newValue, dow, resolverStyle);
return resolveWoY(fieldValues, chrono, year, newValue, dow, resolverStyle);
}
} else if ((rangeUnit == WEEK_BASED_YEARS || rangeUnit == FOREVER) &&
fieldValues.containsKey(weekDef.weekBasedYear) &&
fieldValues.containsKey(weekDef.weekOfWeekBasedYear)) { // week-of-week-based-year and year-of-week-based-year
return resolveWBY(fieldValues, chronology, dow, resolverStyle);
return resolveWBY(fieldValues, chrono, dow, resolverStyle);
}
return null;
}

View File

@ -81,7 +81,7 @@
* A unit is used to measure an amount of time, such as years, days or minutes.
* All units implement {@link java.time.temporal.TemporalUnit}.
* The set of well known units is defined in {@link java.time.temporal.ChronoUnit}, such as {@code DAYS}.
* The unit interface is designed to allow applications defined units.
* The unit interface is designed to allow application defined units.
* </p>
* <p>
* A field is used to express part of a larger date-time, such as year, month-of-year or second-of-minute.
@ -89,7 +89,7 @@
* The set of well known fields are defined in {@link java.time.temporal.ChronoField}, such as {@code HOUR_OF_DAY}.
* Additional fields are defined by {@link java.time.temporal.JulianFields}, {@link java.time.temporal.WeekFields}
* and {@link java.time.temporal.IsoFields}.
* The field interface is designed to allow applications defined fields.
* The field interface is designed to allow application defined fields.
* </p>
* <p>
* This package provides tools that allow the units and fields of date and time to be accessed
@ -112,23 +112,23 @@
* such as the "last day of the month", or "next Wednesday".
* These are modeled as functions that adjust a base date-time.
* The functions implement {@link java.time.temporal.TemporalAdjuster} and operate on {@code Temporal}.
* A set of common functions are provided in {@code TemporalAdjuster}.
* A set of common functions are provided in {@link java.time.temporal.TemporalAdjusters}.
* For example, to find the first occurrence of a day-of-week after a given date, use
* {@link java.time.temporal.TemporalAdjuster#next(DayOfWeek)}, such as
* {@link java.time.temporal.TemporalAdjusters#next(DayOfWeek)}, such as
* {@code date.with(next(MONDAY))}.
* Applications can also define adjusters by implementing {@code TemporalAdjuster}.
* Applications can also define adjusters by implementing {@link java.time.temporal.TemporalAdjuster}.
* </p>
* <p>
* The {@link java.time.temporal.TemporalAmount} interface models amounts of relative time.
* </p>
* <p>
* In addition to adjusting a date-time, an interface is provided to enable querying -
* In addition to adjusting a date-time, an interface is provided to enable querying via
* {@link java.time.temporal.TemporalQuery}.
* The most common implementations of the query interface are method references.
* The {@code from(TemporalAccessor)} methods on major classes can all be used, such as
* {@code LocalDate::from} or {@code Month::from}.
* Further implementations are provided in {@code TemporalQuery} as static methods.
* Applications can also define queries by implementing {@code TemporalQuery}.
* Further implementations are provided in {@link java.time.temporal.TemporalQueries} as static methods.
* Applications can also define queries by implementing {@link java.time.temporal.TemporalQuery}.
* </p>
*
* <h3>Weeks</h3>

View File

@ -61,8 +61,8 @@
*/
package java.time.zone;
import static java.time.temporal.TemporalAdjuster.nextOrSame;
import static java.time.temporal.TemporalAdjuster.previousOrSame;
import static java.time.temporal.TemporalAdjusters.nextOrSame;
import static java.time.temporal.TemporalAdjusters.previousOrSame;
import java.io.DataInput;
import java.io.DataOutput;

View File

@ -56,7 +56,7 @@ import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalQueries;
import sun.misc.DoubleConsts;
import sun.misc.FormattedFloatingDecimal;
@ -4153,7 +4153,7 @@ public final class Formatter implements Closeable, Flushable {
break;
}
case DateTime.ZONE: { // 'Z' (symbol)
ZoneId zid = t.query(TemporalQuery.zone());
ZoneId zid = t.query(TemporalQueries.zone());
if (zid == null) {
throw new IllegalFormatConversionException(c, t.getClass());
}

View File

@ -77,6 +77,7 @@ import java.time.temporal.JulianFields;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.util.ArrayList;
import java.util.Arrays;
@ -215,13 +216,13 @@ public class TCKDayOfWeek extends AbstractDateTimeTest {
@DataProvider(name="query")
Object[][] data_query() {
return new Object[][] {
{DayOfWeek.FRIDAY, TemporalQuery.chronology(), null},
{DayOfWeek.FRIDAY, TemporalQuery.zoneId(), null},
{DayOfWeek.FRIDAY, TemporalQuery.precision(), ChronoUnit.DAYS},
{DayOfWeek.FRIDAY, TemporalQuery.zone(), null},
{DayOfWeek.FRIDAY, TemporalQuery.offset(), null},
{DayOfWeek.FRIDAY, TemporalQuery.localDate(), null},
{DayOfWeek.FRIDAY, TemporalQuery.localTime(), null},
{DayOfWeek.FRIDAY, TemporalQueries.chronology(), null},
{DayOfWeek.FRIDAY, TemporalQueries.zoneId(), null},
{DayOfWeek.FRIDAY, TemporalQueries.precision(), ChronoUnit.DAYS},
{DayOfWeek.FRIDAY, TemporalQueries.zone(), null},
{DayOfWeek.FRIDAY, TemporalQueries.offset(), null},
{DayOfWeek.FRIDAY, TemporalQueries.localDate(), null},
{DayOfWeek.FRIDAY, TemporalQueries.localTime(), null},
};
}

View File

@ -97,6 +97,7 @@ import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
@ -401,13 +402,13 @@ public class TCKInstant extends AbstractDateTimeTest {
@DataProvider(name="query")
Object[][] data_query() {
return new Object[][] {
{TEST_12345_123456789, TemporalQuery.chronology(), null},
{TEST_12345_123456789, TemporalQuery.zoneId(), null},
{TEST_12345_123456789, TemporalQuery.precision(), NANOS},
{TEST_12345_123456789, TemporalQuery.zone(), null},
{TEST_12345_123456789, TemporalQuery.offset(), null},
{TEST_12345_123456789, TemporalQuery.localDate(), null},
{TEST_12345_123456789, TemporalQuery.localTime(), null},
{TEST_12345_123456789, TemporalQueries.chronology(), null},
{TEST_12345_123456789, TemporalQueries.zoneId(), null},
{TEST_12345_123456789, TemporalQueries.precision(), NANOS},
{TEST_12345_123456789, TemporalQueries.zone(), null},
{TEST_12345_123456789, TemporalQueries.offset(), null},
{TEST_12345_123456789, TemporalQueries.localDate(), null},
{TEST_12345_123456789, TemporalQueries.localTime(), null},
};
}

View File

@ -113,6 +113,7 @@ import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
@ -693,13 +694,13 @@ public class TCKLocalDate extends AbstractDateTimeTest {
@DataProvider(name="query")
Object[][] data_query() {
return new Object[][] {
{TEST_2007_07_15, TemporalQuery.chronology(), IsoChronology.INSTANCE},
{TEST_2007_07_15, TemporalQuery.zoneId(), null},
{TEST_2007_07_15, TemporalQuery.precision(), ChronoUnit.DAYS},
{TEST_2007_07_15, TemporalQuery.zone(), null},
{TEST_2007_07_15, TemporalQuery.offset(), null},
{TEST_2007_07_15, TemporalQuery.localDate(), TEST_2007_07_15},
{TEST_2007_07_15, TemporalQuery.localTime(), null},
{TEST_2007_07_15, TemporalQueries.chronology(), IsoChronology.INSTANCE},
{TEST_2007_07_15, TemporalQueries.zoneId(), null},
{TEST_2007_07_15, TemporalQueries.precision(), ChronoUnit.DAYS},
{TEST_2007_07_15, TemporalQueries.zone(), null},
{TEST_2007_07_15, TemporalQueries.offset(), null},
{TEST_2007_07_15, TemporalQueries.localDate(), TEST_2007_07_15},
{TEST_2007_07_15, TemporalQueries.localTime(), null},
};
}

View File

@ -134,6 +134,7 @@ import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;
import java.util.ArrayList;
@ -1017,13 +1018,13 @@ public class TCKLocalDateTime extends AbstractDateTimeTest {
@DataProvider(name="query")
Object[][] data_query() {
return new Object[][] {
{TEST_2007_07_15_12_30_40_987654321, TemporalQuery.chronology(), IsoChronology.INSTANCE},
{TEST_2007_07_15_12_30_40_987654321, TemporalQuery.zoneId(), null},
{TEST_2007_07_15_12_30_40_987654321, TemporalQuery.precision(), ChronoUnit.NANOS},
{TEST_2007_07_15_12_30_40_987654321, TemporalQuery.zone(), null},
{TEST_2007_07_15_12_30_40_987654321, TemporalQuery.offset(), null},
{TEST_2007_07_15_12_30_40_987654321, TemporalQuery.localDate(), LocalDate.of(2007, 7, 15)},
{TEST_2007_07_15_12_30_40_987654321, TemporalQuery.localTime(), LocalTime.of(12, 30, 40, 987654321)},
{TEST_2007_07_15_12_30_40_987654321, TemporalQueries.chronology(), IsoChronology.INSTANCE},
{TEST_2007_07_15_12_30_40_987654321, TemporalQueries.zoneId(), null},
{TEST_2007_07_15_12_30_40_987654321, TemporalQueries.precision(), ChronoUnit.NANOS},
{TEST_2007_07_15_12_30_40_987654321, TemporalQueries.zone(), null},
{TEST_2007_07_15_12_30_40_987654321, TemporalQueries.offset(), null},
{TEST_2007_07_15_12_30_40_987654321, TemporalQueries.localDate(), LocalDate.of(2007, 7, 15)},
{TEST_2007_07_15_12_30_40_987654321, TemporalQueries.localTime(), LocalTime.of(12, 30, 40, 987654321)},
};
}

View File

@ -116,6 +116,7 @@ import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
@ -143,7 +144,7 @@ public class TCKLocalTime extends AbstractDateTimeTest {
private static final TemporalUnit[] INVALID_UNITS;
static {
EnumSet<ChronoUnit> set = EnumSet.range(DAYS, FOREVER);
INVALID_UNITS = (TemporalUnit[]) set.toArray(new TemporalUnit[set.size()]);
INVALID_UNITS = set.toArray(new TemporalUnit[set.size()]);
}
@BeforeMethod
@ -654,13 +655,13 @@ public class TCKLocalTime extends AbstractDateTimeTest {
@DataProvider(name="query")
Object[][] data_query() {
return new Object[][] {
{TEST_12_30_40_987654321, TemporalQuery.chronology(), null},
{TEST_12_30_40_987654321, TemporalQuery.zoneId(), null},
{TEST_12_30_40_987654321, TemporalQuery.precision(), ChronoUnit.NANOS},
{TEST_12_30_40_987654321, TemporalQuery.zone(), null},
{TEST_12_30_40_987654321, TemporalQuery.offset(), null},
{TEST_12_30_40_987654321, TemporalQuery.localDate(), null},
{TEST_12_30_40_987654321, TemporalQuery.localTime(), TEST_12_30_40_987654321},
{TEST_12_30_40_987654321, TemporalQueries.chronology(), null},
{TEST_12_30_40_987654321, TemporalQueries.zoneId(), null},
{TEST_12_30_40_987654321, TemporalQueries.precision(), ChronoUnit.NANOS},
{TEST_12_30_40_987654321, TemporalQueries.zone(), null},
{TEST_12_30_40_987654321, TemporalQueries.offset(), null},
{TEST_12_30_40_987654321, TemporalQueries.localDate(), null},
{TEST_12_30_40_987654321, TemporalQueries.localTime(), TEST_12_30_40_987654321},
};
}

View File

@ -73,6 +73,7 @@ import java.time.temporal.ChronoUnit;
import java.time.temporal.JulianFields;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.util.ArrayList;
import java.util.Arrays;
@ -207,13 +208,13 @@ public class TCKMonth extends AbstractDateTimeTest {
@DataProvider(name="query")
Object[][] data_query() {
return new Object[][] {
{Month.JUNE, TemporalQuery.chronology(), IsoChronology.INSTANCE},
{Month.JUNE, TemporalQuery.zoneId(), null},
{Month.JUNE, TemporalQuery.precision(), ChronoUnit.MONTHS},
{Month.JUNE, TemporalQuery.zone(), null},
{Month.JUNE, TemporalQuery.offset(), null},
{Month.JUNE, TemporalQuery.localDate(), null},
{Month.JUNE, TemporalQuery.localTime(), null},
{Month.JUNE, TemporalQueries.chronology(), IsoChronology.INSTANCE},
{Month.JUNE, TemporalQueries.zoneId(), null},
{Month.JUNE, TemporalQueries.precision(), ChronoUnit.MONTHS},
{Month.JUNE, TemporalQueries.zone(), null},
{Month.JUNE, TemporalQueries.offset(), null},
{Month.JUNE, TemporalQueries.localDate(), null},
{Month.JUNE, TemporalQueries.localTime(), null},
};
}

View File

@ -86,6 +86,7 @@ import java.time.temporal.ChronoField;
import java.time.temporal.JulianFields;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.util.ArrayList;
import java.util.Arrays;
@ -428,13 +429,13 @@ public class TCKMonthDay extends AbstractDateTimeTest {
@DataProvider(name="query")
Object[][] data_query() {
return new Object[][] {
{TEST_07_15, TemporalQuery.chronology(), IsoChronology.INSTANCE},
{TEST_07_15, TemporalQuery.zoneId(), null},
{TEST_07_15, TemporalQuery.precision(), null},
{TEST_07_15, TemporalQuery.zone(), null},
{TEST_07_15, TemporalQuery.offset(), null},
{TEST_07_15, TemporalQuery.localDate(), null},
{TEST_07_15, TemporalQuery.localTime(), null},
{TEST_07_15, TemporalQueries.chronology(), IsoChronology.INSTANCE},
{TEST_07_15, TemporalQueries.zoneId(), null},
{TEST_07_15, TemporalQueries.precision(), null},
{TEST_07_15, TemporalQueries.zone(), null},
{TEST_07_15, TemporalQueries.offset(), null},
{TEST_07_15, TemporalQueries.localDate(), null},
{TEST_07_15, TemporalQueries.localTime(), null},
};
}

View File

@ -132,6 +132,7 @@ import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;
import java.util.ArrayList;
@ -635,13 +636,13 @@ public class TCKOffsetDateTime extends AbstractDateTimeTest {
@DataProvider(name="query")
Object[][] data_query() {
return new Object[][] {
{TEST_2008_6_30_11_30_59_000000500, TemporalQuery.chronology(), IsoChronology.INSTANCE},
{TEST_2008_6_30_11_30_59_000000500, TemporalQuery.zoneId(), null},
{TEST_2008_6_30_11_30_59_000000500, TemporalQuery.precision(), ChronoUnit.NANOS},
{TEST_2008_6_30_11_30_59_000000500, TemporalQuery.zone(), OFFSET_PONE},
{TEST_2008_6_30_11_30_59_000000500, TemporalQuery.offset(), OFFSET_PONE},
{TEST_2008_6_30_11_30_59_000000500, TemporalQuery.localDate(), LocalDate.of(2008, 6, 30)},
{TEST_2008_6_30_11_30_59_000000500, TemporalQuery.localTime(), LocalTime.of(11, 30, 59, 500)},
{TEST_2008_6_30_11_30_59_000000500, TemporalQueries.chronology(), IsoChronology.INSTANCE},
{TEST_2008_6_30_11_30_59_000000500, TemporalQueries.zoneId(), null},
{TEST_2008_6_30_11_30_59_000000500, TemporalQueries.precision(), ChronoUnit.NANOS},
{TEST_2008_6_30_11_30_59_000000500, TemporalQueries.zone(), OFFSET_PONE},
{TEST_2008_6_30_11_30_59_000000500, TemporalQueries.offset(), OFFSET_PONE},
{TEST_2008_6_30_11_30_59_000000500, TemporalQueries.localDate(), LocalDate.of(2008, 6, 30)},
{TEST_2008_6_30_11_30_59_000000500, TemporalQueries.localTime(), LocalTime.of(11, 30, 59, 500)},
};
}

View File

@ -115,6 +115,7 @@ import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;
import java.util.ArrayList;
@ -605,13 +606,13 @@ public class TCKOffsetTime extends AbstractDateTimeTest {
@DataProvider(name="query")
Object[][] data_query() {
return new Object[][] {
{TEST_11_30_59_500_PONE, TemporalQuery.chronology(), null},
{TEST_11_30_59_500_PONE, TemporalQuery.zoneId(), null},
{TEST_11_30_59_500_PONE, TemporalQuery.precision(), ChronoUnit.NANOS},
{TEST_11_30_59_500_PONE, TemporalQuery.zone(), OFFSET_PONE},
{TEST_11_30_59_500_PONE, TemporalQuery.offset(), OFFSET_PONE},
{TEST_11_30_59_500_PONE, TemporalQuery.localDate(), null},
{TEST_11_30_59_500_PONE, TemporalQuery.localTime(), LocalTime.of(11, 30, 59, 500)},
{TEST_11_30_59_500_PONE, TemporalQueries.chronology(), null},
{TEST_11_30_59_500_PONE, TemporalQueries.zoneId(), null},
{TEST_11_30_59_500_PONE, TemporalQueries.precision(), ChronoUnit.NANOS},
{TEST_11_30_59_500_PONE, TemporalQueries.zone(), OFFSET_PONE},
{TEST_11_30_59_500_PONE, TemporalQueries.offset(), OFFSET_PONE},
{TEST_11_30_59_500_PONE, TemporalQueries.localDate(), null},
{TEST_11_30_59_500_PONE, TemporalQueries.localTime(), LocalTime.of(11, 30, 59, 500)},
};
}

View File

@ -99,6 +99,7 @@ import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
@ -411,13 +412,13 @@ public class TCKYear extends AbstractDateTimeTest {
@DataProvider(name="query")
Object[][] data_query() {
return new Object[][] {
{TEST_2008, TemporalQuery.chronology(), IsoChronology.INSTANCE},
{TEST_2008, TemporalQuery.zoneId(), null},
{TEST_2008, TemporalQuery.precision(), ChronoUnit.YEARS},
{TEST_2008, TemporalQuery.zone(), null},
{TEST_2008, TemporalQuery.offset(), null},
{TEST_2008, TemporalQuery.localDate(), null},
{TEST_2008, TemporalQuery.localTime(), null},
{TEST_2008, TemporalQueries.chronology(), IsoChronology.INSTANCE},
{TEST_2008, TemporalQueries.zoneId(), null},
{TEST_2008, TemporalQueries.precision(), ChronoUnit.YEARS},
{TEST_2008, TemporalQueries.zone(), null},
{TEST_2008, TemporalQueries.offset(), null},
{TEST_2008, TemporalQueries.localDate(), null},
{TEST_2008, TemporalQueries.localTime(), null},
};
}
@ -596,7 +597,7 @@ public class TCKYear extends AbstractDateTimeTest {
}
@Test(dataProvider="plus_long_TemporalUnit")
public void test_plus_long_TemporalUnit(Year base, long amount, TemporalUnit unit, Year expectedYear, Class expectedEx) {
public void test_plus_long_TemporalUnit(Year base, long amount, TemporalUnit unit, Year expectedYear, Class<?> expectedEx) {
if (expectedEx == null) {
assertEquals(base.plus(amount, unit), expectedYear);
} else {
@ -728,7 +729,7 @@ public class TCKYear extends AbstractDateTimeTest {
}
@Test(dataProvider="minus_long_TemporalUnit")
public void test_minus_long_TemporalUnit(Year base, long amount, TemporalUnit unit, Year expectedYear, Class expectedEx) {
public void test_minus_long_TemporalUnit(Year base, long amount, TemporalUnit unit, Year expectedYear, Class<?> expectedEx) {
if (expectedEx == null) {
assertEquals(base.minus(amount, unit), expectedYear);
} else {

View File

@ -100,6 +100,7 @@ import java.time.temporal.JulianFields;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
@ -476,13 +477,13 @@ public class TCKYearMonth extends AbstractDateTimeTest {
@DataProvider(name="query")
Object[][] data_query() {
return new Object[][] {
{TEST_2008_06, TemporalQuery.chronology(), IsoChronology.INSTANCE},
{TEST_2008_06, TemporalQuery.zoneId(), null},
{TEST_2008_06, TemporalQuery.precision(), ChronoUnit.MONTHS},
{TEST_2008_06, TemporalQuery.zone(), null},
{TEST_2008_06, TemporalQuery.offset(), null},
{TEST_2008_06, TemporalQuery.localDate(), null},
{TEST_2008_06, TemporalQuery.localTime(), null},
{TEST_2008_06, TemporalQueries.chronology(), IsoChronology.INSTANCE},
{TEST_2008_06, TemporalQueries.zoneId(), null},
{TEST_2008_06, TemporalQueries.precision(), ChronoUnit.MONTHS},
{TEST_2008_06, TemporalQueries.zone(), null},
{TEST_2008_06, TemporalQueries.offset(), null},
{TEST_2008_06, TemporalQueries.localDate(), null},
{TEST_2008_06, TemporalQueries.localTime(), null},
};
}
@ -768,7 +769,7 @@ public class TCKYearMonth extends AbstractDateTimeTest {
}
@Test(dataProvider="plus_long_TemporalUnit")
public void test_plus_long_TemporalUnit(YearMonth base, long amount, TemporalUnit unit, YearMonth expectedYearMonth, Class expectedEx) {
public void test_plus_long_TemporalUnit(YearMonth base, long amount, TemporalUnit unit, YearMonth expectedYearMonth, Class<?> expectedEx) {
if (expectedEx == null) {
assertEquals(base.plus(amount, unit), expectedYearMonth);
} else {
@ -820,7 +821,7 @@ public class TCKYearMonth extends AbstractDateTimeTest {
}
@Test(dataProvider="plus_TemporalAmount")
public void test_plus_TemporalAmount(YearMonth base, TemporalAmount temporalAmount, YearMonth expectedYearMonth, Class expectedEx) {
public void test_plus_TemporalAmount(YearMonth base, TemporalAmount temporalAmount, YearMonth expectedYearMonth, Class<?> expectedEx) {
if (expectedEx == null) {
assertEquals(base.plus(temporalAmount), expectedYearMonth);
} else {
@ -983,7 +984,7 @@ public class TCKYearMonth extends AbstractDateTimeTest {
}
@Test(dataProvider="minus_long_TemporalUnit")
public void test_minus_long_TemporalUnit(YearMonth base, long amount, TemporalUnit unit, YearMonth expectedYearMonth, Class expectedEx) {
public void test_minus_long_TemporalUnit(YearMonth base, long amount, TemporalUnit unit, YearMonth expectedYearMonth, Class<?> expectedEx) {
if (expectedEx == null) {
assertEquals(base.minus(amount, unit), expectedYearMonth);
} else {
@ -1035,7 +1036,7 @@ public class TCKYearMonth extends AbstractDateTimeTest {
}
@Test(dataProvider="minus_TemporalAmount")
public void test_minus_TemporalAmount(YearMonth base, TemporalAmount temporalAmount, YearMonth expectedYearMonth, Class expectedEx) {
public void test_minus_TemporalAmount(YearMonth base, TemporalAmount temporalAmount, YearMonth expectedYearMonth, Class<?> expectedEx) {
if (expectedEx == null) {
assertEquals(base.minus(temporalAmount), expectedYearMonth);
} else {

View File

@ -76,6 +76,7 @@ import java.time.ZoneOffset;
import java.time.format.TextStyle;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.zone.ZoneRulesException;
import java.util.HashMap;
@ -559,7 +560,7 @@ public class TCKZoneId extends AbstractTCKTest {
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.zoneId()) {
if (query == TemporalQueries.zoneId()) {
return (R) ZoneId.of("Europe/Paris");
}
return TemporalAccessor.super.query(query);

View File

@ -81,6 +81,7 @@ import java.time.temporal.ChronoField;
import java.time.temporal.JulianFields;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.util.ArrayList;
import java.util.Arrays;
@ -523,13 +524,13 @@ public class TCKZoneOffset extends AbstractDateTimeTest {
@DataProvider(name="query")
Object[][] data_query() {
return new Object[][] {
{ZoneOffset.UTC, TemporalQuery.chronology(), null},
{ZoneOffset.UTC, TemporalQuery.zoneId(), null},
{ZoneOffset.UTC, TemporalQuery.precision(), null},
{ZoneOffset.UTC, TemporalQuery.zone(), ZoneOffset.UTC},
{ZoneOffset.UTC, TemporalQuery.offset(), ZoneOffset.UTC},
{ZoneOffset.UTC, TemporalQuery.localDate(), null},
{ZoneOffset.UTC, TemporalQuery.localTime(), null},
{ZoneOffset.UTC, TemporalQueries.chronology(), null},
{ZoneOffset.UTC, TemporalQueries.zoneId(), null},
{ZoneOffset.UTC, TemporalQueries.precision(), null},
{ZoneOffset.UTC, TemporalQueries.zone(), ZoneOffset.UTC},
{ZoneOffset.UTC, TemporalQueries.offset(), ZoneOffset.UTC},
{ZoneOffset.UTC, TemporalQueries.localDate(), null},
{ZoneOffset.UTC, TemporalQueries.localTime(), null},
};
}

View File

@ -126,6 +126,7 @@ import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;
import java.util.ArrayList;
@ -685,7 +686,7 @@ public class TCKZonedDateTime extends AbstractDateTimeTest {
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.zoneId()) {
if (query == TemporalQueries.zoneId()) {
return (R) TEST_DATE_TIME_PARIS.getZone();
}
return TemporalAccessor.super.query(query);
@ -709,7 +710,7 @@ public class TCKZonedDateTime extends AbstractDateTimeTest {
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.zoneId()) {
if (query == TemporalQueries.zoneId()) {
return (R) TEST_DATE_TIME_PARIS.getZone();
}
return TemporalAccessor.super.query(query);
@ -964,32 +965,32 @@ public class TCKZonedDateTime extends AbstractDateTimeTest {
//-----------------------------------------------------------------------
@Test
public void test_query_chrono() {
assertEquals(TEST_DATE_TIME.query(TemporalQuery.chronology()), IsoChronology.INSTANCE);
assertEquals(TemporalQuery.chronology().queryFrom(TEST_DATE_TIME), IsoChronology.INSTANCE);
assertEquals(TEST_DATE_TIME.query(TemporalQueries.chronology()), IsoChronology.INSTANCE);
assertEquals(TemporalQueries.chronology().queryFrom(TEST_DATE_TIME), IsoChronology.INSTANCE);
}
@Test
public void test_query_zoneId() {
assertEquals(TEST_DATE_TIME.query(TemporalQuery.zoneId()), TEST_DATE_TIME.getZone());
assertEquals(TemporalQuery.zoneId().queryFrom(TEST_DATE_TIME), TEST_DATE_TIME.getZone());
assertEquals(TEST_DATE_TIME.query(TemporalQueries.zoneId()), TEST_DATE_TIME.getZone());
assertEquals(TemporalQueries.zoneId().queryFrom(TEST_DATE_TIME), TEST_DATE_TIME.getZone());
}
@Test
public void test_query_precision() {
assertEquals(TEST_DATE_TIME.query(TemporalQuery.precision()), NANOS);
assertEquals(TemporalQuery.precision().queryFrom(TEST_DATE_TIME), NANOS);
assertEquals(TEST_DATE_TIME.query(TemporalQueries.precision()), NANOS);
assertEquals(TemporalQueries.precision().queryFrom(TEST_DATE_TIME), NANOS);
}
@Test
public void test_query_offset() {
assertEquals(TEST_DATE_TIME.query(TemporalQuery.offset()), TEST_DATE_TIME.getOffset());
assertEquals(TemporalQuery.offset().queryFrom(TEST_DATE_TIME), TEST_DATE_TIME.getOffset());
assertEquals(TEST_DATE_TIME.query(TemporalQueries.offset()), TEST_DATE_TIME.getOffset());
assertEquals(TemporalQueries.offset().queryFrom(TEST_DATE_TIME), TEST_DATE_TIME.getOffset());
}
@Test
public void test_query_zone() {
assertEquals(TEST_DATE_TIME.query(TemporalQuery.zone()), TEST_DATE_TIME.getZone());
assertEquals(TemporalQuery.zone().queryFrom(TEST_DATE_TIME), TEST_DATE_TIME.getZone());
assertEquals(TEST_DATE_TIME.query(TemporalQueries.zone()), TEST_DATE_TIME.getZone());
assertEquals(TemporalQueries.zone().queryFrom(TEST_DATE_TIME), TEST_DATE_TIME.getZone());
}
@Test(expectedExceptions=NullPointerException.class)

View File

@ -80,7 +80,7 @@ import java.time.chrono.HijrahEra;
import java.time.chrono.IsoChronology;
import java.time.chrono.IsoEra;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
@ -208,14 +208,14 @@ public class TestIsoChronology {
@Test
public void test_adjust1() {
LocalDate base = IsoChronology.INSTANCE.date(1728, 10, 28);
LocalDate test = base.with(TemporalAdjuster.lastDayOfMonth());
LocalDate test = base.with(TemporalAdjusters.lastDayOfMonth());
assertEquals(test, IsoChronology.INSTANCE.date(1728, 10, 31));
}
@Test
public void test_adjust2() {
LocalDate base = IsoChronology.INSTANCE.date(1728, 12, 2);
LocalDate test = base.with(TemporalAdjuster.lastDayOfMonth());
LocalDate test = base.with(TemporalAdjusters.lastDayOfMonth());
assertEquals(test, IsoChronology.INSTANCE.date(1728, 12, 31));
}

View File

@ -59,13 +59,11 @@ package tck.java.time.chrono;
import static java.time.temporal.ChronoField.EPOCH_DAY;
import java.io.Serializable;
import java.time.chrono.AbstractChronology;
import java.time.chrono.Era;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.ValueRange;
import java.time.chrono.Chronology;
import java.time.chrono.Era;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
@ -95,7 +93,7 @@ import java.util.Locale;
* <h4>Implementation notes</h4>
* This class is immutable and thread-safe.
*/
public final class CopticChronology extends Chronology implements Serializable {
public final class CopticChronology extends AbstractChronology implements Serializable {
/**
* Singleton instance of the Coptic chronology.

View File

@ -308,7 +308,7 @@ public final class CopticDate
@Override
public Period until(ChronoLocalDate endDate) {
// TODO: untested
CopticDate end = (CopticDate) getChronology().date(endDate);
CopticDate end = getChronology().date(endDate);
long totalMonths = (end.prolepticYear - this.prolepticYear) * 13 + (end.month - this.month); // safe
int days = end.day - this.day;
if (totalMonths > 0 && days < 0) {

View File

@ -346,7 +346,7 @@ public class TCKChronoLocalDateTime {
//-----------------------------------------------------------------------
@Test(dataProvider="calendars")
public void test_getChronology(Chronology chrono) {
ChronoLocalDateTime test = chrono.localDateTime(LocalDateTime.of(2010, 6, 30, 11, 30));
ChronoLocalDateTime<?> test = chrono.localDateTime(LocalDateTime.of(2010, 6, 30, 11, 30));
assertEquals(test.getChronology(), chrono);
}

View File

@ -347,7 +347,7 @@ public class TCKChronoZonedDateTime {
//-----------------------------------------------------------------------
@Test(dataProvider="calendars")
public void test_getChronology(Chronology chrono) {
ChronoZonedDateTime test = chrono.zonedDateTime(ZonedDateTime.of(2010, 6, 30, 11, 30, 0, 0, ZoneOffset.UTC));
ChronoZonedDateTime<?> test = chrono.zonedDateTime(ZonedDateTime.of(2010, 6, 30, 11, 30, 0, 0, ZoneOffset.UTC));
assertEquals(test.getChronology(), chrono);
}

View File

@ -70,7 +70,9 @@ import java.time.chrono.IsoChronology;
import java.time.format.ResolverStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.util.HashMap;
import java.util.Map;
@ -107,7 +109,7 @@ public class TCKIsoChronology {
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.chronology()) {
if (query == TemporalQueries.chronology()) {
return (R) IsoChronology.INSTANCE;
}
throw new UnsupportedOperationException();
@ -130,7 +132,7 @@ public class TCKIsoChronology {
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.chronology()) {
if (query == TemporalQueries.chronology()) {
return null;
}
throw new UnsupportedOperationException();
@ -166,7 +168,7 @@ public class TCKIsoChronology {
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.localDate()) {
if (query == TemporalQueries.localDate()) {
return (R) LocalDate.of(2012, 6, 30);
}
throw new UnsupportedOperationException();
@ -205,10 +207,10 @@ public class TCKIsoChronology {
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.localDate()) {
if (query == TemporalQueries.localDate()) {
return (R) LocalDate.of(2012, 6, 30);
}
if (query == TemporalQuery.localTime()) {
if (query == TemporalQueries.localTime()) {
return (R) LocalTime.of(12, 30, 40);
}
throw new UnsupportedOperationException();
@ -254,13 +256,13 @@ public class TCKIsoChronology {
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.localDate()) {
if (query == TemporalQueries.localDate()) {
return (R) LocalDate.of(2012, 6, 30);
}
if (query == TemporalQuery.localTime()) {
if (query == TemporalQueries.localTime()) {
return (R) LocalTime.of(12, 30, 40);
}
if (query == TemporalQuery.zoneId() || query == TemporalQuery.zone()) {
if (query == TemporalQueries.zoneId() || query == TemporalQueries.zone()) {
return (R) ZoneId.of("Europe/London");
}
throw new UnsupportedOperationException();

View File

@ -92,10 +92,9 @@ import java.time.chrono.ThaiBuddhistChronology;
import java.time.format.ResolverStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalQueries;
import java.time.temporal.ValueRange;
import java.util.HashMap;
@ -229,7 +228,7 @@ public class TCKJapaneseChronology {
@Test(dataProvider="createByEra")
public void test_createByEra_query(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
JapaneseDate test = JapaneseDate.of(era, yoe, moy, dom);
assertEquals(test.query(TemporalQuery.localDate()), iso);
assertEquals(test.query(TemporalQueries.localDate()), iso);
}
@Test(dataProvider="createByEra")
@ -297,7 +296,7 @@ public class TCKJapaneseChronology {
@Test(dataProvider="createByProleptic")
public void test_createByProleptic_query(int y, int moy, int dom, int doy, LocalDate iso) {
JapaneseDate test = JapaneseDate.of(y, moy, dom);
assertEquals(test.query(TemporalQuery.localDate()), iso);
assertEquals(test.query(TemporalQueries.localDate()), iso);
}
@Test(dataProvider="createByProleptic")
@ -495,14 +494,14 @@ public class TCKJapaneseChronology {
@Test
public void test_adjust1() {
JapaneseDate base = JapaneseChronology.INSTANCE.date(1928, 10, 29);
JapaneseDate test = base.with(TemporalAdjuster.lastDayOfMonth());
JapaneseDate test = base.with(TemporalAdjusters.lastDayOfMonth());
assertEquals(test, JapaneseChronology.INSTANCE.date(1928, 10, 31));
}
@Test
public void test_adjust2() {
JapaneseDate base = JapaneseChronology.INSTANCE.date(1928, 12, 2);
JapaneseDate test = base.with(TemporalAdjuster.lastDayOfMonth());
JapaneseDate test = base.with(TemporalAdjusters.lastDayOfMonth());
assertEquals(test, JapaneseChronology.INSTANCE.date(1928, 12, 31));
}

View File

@ -82,15 +82,15 @@ import java.time.chrono.Era;
import java.time.chrono.IsoChronology;
import java.time.chrono.JapaneseDate;
import java.time.chrono.MinguoChronology;
import java.time.chrono.MinguoDate;
import java.time.chrono.MinguoEra;
import java.time.chrono.MinguoDate;
import java.time.chrono.ThaiBuddhistChronology;
import java.time.chrono.ThaiBuddhistDate;
import java.time.format.ResolverStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.TemporalField;
import java.util.HashMap;
import java.util.List;
@ -360,14 +360,14 @@ public class TCKMinguoChronology {
@Test
public void test_adjust1() {
MinguoDate base = MinguoChronology.INSTANCE.date(2012, 10, 29);
MinguoDate test = base.with(TemporalAdjuster.lastDayOfMonth());
MinguoDate test = base.with(TemporalAdjusters.lastDayOfMonth());
assertEquals(test, MinguoChronology.INSTANCE.date(2012, 10, 31));
}
@Test
public void test_adjust2() {
MinguoDate base = MinguoChronology.INSTANCE.date(1728, 12, 2);
MinguoDate test = base.with(TemporalAdjuster.lastDayOfMonth());
MinguoDate test = base.with(TemporalAdjusters.lastDayOfMonth());
assertEquals(test, MinguoChronology.INSTANCE.date(1728, 12, 31));
}

View File

@ -88,7 +88,7 @@ import java.time.chrono.ThaiBuddhistEra;
import java.time.format.ResolverStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.TemporalField;
import java.time.temporal.ValueRange;
import java.util.HashMap;
@ -366,14 +366,14 @@ public class TCKThaiBuddhistChronology {
@Test
public void test_adjust1() {
ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(1728, 10, 29);
ThaiBuddhistDate test = base.with(TemporalAdjuster.lastDayOfMonth());
ThaiBuddhistDate test = base.with(TemporalAdjusters.lastDayOfMonth());
assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(1728, 10, 31));
}
@Test
public void test_adjust2() {
ThaiBuddhistDate base = ThaiBuddhistChronology.INSTANCE.date(1728, 12, 2);
ThaiBuddhistDate test = base.with(TemporalAdjuster.lastDayOfMonth());
ThaiBuddhistDate test = base.with(TemporalAdjusters.lastDayOfMonth());
assertEquals(test, ThaiBuddhistChronology.INSTANCE.date(1728, 12, 31));
}

View File

@ -68,6 +68,7 @@ import java.time.chrono.JapaneseChronology;
import java.time.chrono.ThaiBuddhistChronology;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.util.Locale;
@ -122,7 +123,7 @@ public class TCKChronoPrinterParser {
TemporalAccessor parsed = builder.toFormatter().parseUnresolved(text, pos);
assertEquals(pos.getIndex(), expected.getId().length());
assertEquals(pos.getErrorIndex(), -1);
assertEquals(parsed.query(TemporalQuery.chronology()), expected);
assertEquals(parsed.query(TemporalQueries.chronology()), expected);
}
@Test(dataProvider="parseValid")
@ -140,7 +141,7 @@ public class TCKChronoPrinterParser {
TemporalAccessor parsed = builder.toFormatter().parseUnresolved(text.toLowerCase(Locale.ENGLISH), pos);
assertEquals(pos.getIndex(), expected.getId().length());
assertEquals(pos.getErrorIndex(), -1);
assertEquals(parsed.query(TemporalQuery.chronology()), expected);
assertEquals(parsed.query(TemporalQueries.chronology()), expected);
}
//-----------------------------------------------------------------------

View File

@ -94,6 +94,7 @@ import java.time.format.TextStyle;
import java.time.temporal.IsoFields;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.util.HashMap;
import java.util.Iterator;
@ -1405,8 +1406,8 @@ public class TCKDateTimeFormatters {
assertEquals(parsed.isSupported(field), true);
parsed.getLong(field);
}
assertEquals(parsed.query(TemporalQuery.chronology()), expected.chrono);
assertEquals(parsed.query(TemporalQuery.zoneId()), expected.zone);
assertEquals(parsed.query(TemporalQueries.chronology()), expected.chrono);
assertEquals(parsed.query(TemporalQueries.zoneId()), expected.zone);
}
//-------------------------------------------------------------------------
@ -1471,7 +1472,7 @@ public class TCKDateTimeFormatters {
@SuppressWarnings("unchecked")
@Override
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQuery.zoneId()) {
if (query == TemporalQueries.zoneId()) {
return (R) zoneId;
}
return TemporalAccessor.super.query(query);

View File

@ -113,7 +113,7 @@ import java.time.temporal.IsoFields;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalUnit;
import java.time.temporal.ValueRange;
import java.util.Map;
@ -147,8 +147,8 @@ public class TCKDateTimeParseResolver {
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field1).toFormatter();
TemporalAccessor accessor = f.parse(str);
assertEquals(accessor.query(TemporalQuery.localDate()), null);
assertEquals(accessor.query(TemporalQuery.localTime()), null);
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), null);
assertEquals(accessor.isSupported(field1), true);
assertEquals(accessor.getLong(field1), value1);
}
@ -186,8 +186,8 @@ public class TCKDateTimeParseResolver {
.appendValue(field2).toFormatter();
TemporalAccessor accessor = f.parse(str);
assertEquals(accessor.query(TemporalQuery.localDate()), null);
assertEquals(accessor.query(TemporalQuery.localTime()), null);
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), null);
assertEquals(accessor.isSupported(field1), true);
assertEquals(accessor.isSupported(field2), true);
assertEquals(accessor.getLong(field1), value1);
@ -218,8 +218,8 @@ public class TCKDateTimeParseResolver {
.appendValue(field3).toFormatter();
TemporalAccessor accessor = f.parse(str);
assertEquals(accessor.query(TemporalQuery.localDate()), null);
assertEquals(accessor.query(TemporalQuery.localTime()), null);
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), null);
assertEquals(accessor.isSupported(field1), true);
assertEquals(accessor.isSupported(field2), true);
assertEquals(accessor.isSupported(field3), true);
@ -252,8 +252,8 @@ public class TCKDateTimeParseResolver {
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field1).toFormatter();
TemporalAccessor accessor = f.parse(str);
assertEquals(accessor.query(TemporalQuery.localDate()), null);
assertEquals(accessor.query(TemporalQuery.localTime()), null);
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), null);
if (expectedField1 != null) {
assertEquals(accessor.isSupported(expectedField1), true);
assertEquals(accessor.getLong(expectedField1), expectedValue1.longValue());
@ -278,8 +278,8 @@ public class TCKDateTimeParseResolver {
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field1).toFormatter();
TemporalAccessor accessor = f.parse(str);
assertEquals(accessor.query(TemporalQuery.localDate()), expectedDate);
assertEquals(accessor.query(TemporalQuery.localTime()), null);
assertEquals(accessor.query(TemporalQueries.localDate()), expectedDate);
assertEquals(accessor.query(TemporalQueries.localTime()), null);
}
//-----------------------------------------------------------------------
@ -303,8 +303,8 @@ public class TCKDateTimeParseResolver {
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field1).toFormatter();
TemporalAccessor accessor = f.parse(str);
assertEquals(accessor.query(TemporalQuery.localDate()), null);
assertEquals(accessor.query(TemporalQuery.localTime()), expectedTime);
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime);
}
//-----------------------------------------------------------------------
@ -334,8 +334,8 @@ public class TCKDateTimeParseResolver {
.appendValue(field2).toFormatter();
TemporalAccessor accessor = f.parse(str);
assertEquals(accessor.query(TemporalQuery.localDate()), null);
assertEquals(accessor.query(TemporalQuery.localTime()), null);
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), null);
if (expectedField1 != null) {
assertEquals(accessor.isSupported(expectedField1), true);
assertEquals(accessor.getLong(expectedField1), expectedValue1.longValue());
@ -382,8 +382,8 @@ public class TCKDateTimeParseResolver {
.appendValue(field2).toFormatter();
TemporalAccessor accessor = f.parse(str);
assertEquals(accessor.query(TemporalQuery.localDate()), expectedDate);
assertEquals(accessor.query(TemporalQuery.localTime()), null);
assertEquals(accessor.query(TemporalQueries.localDate()), expectedDate);
assertEquals(accessor.query(TemporalQueries.localTime()), null);
}
//-----------------------------------------------------------------------
@ -469,8 +469,8 @@ public class TCKDateTimeParseResolver {
.appendValue(field2).toFormatter();
TemporalAccessor accessor = f.parse(str);
assertEquals(accessor.query(TemporalQuery.localDate()), null);
assertEquals(accessor.query(TemporalQuery.localTime()), expectedTime);
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime);
}
//-----------------------------------------------------------------------
@ -502,8 +502,8 @@ public class TCKDateTimeParseResolver {
.appendValue(field3).toFormatter();
TemporalAccessor accessor = f.parse(str);
assertEquals(accessor.query(TemporalQuery.localDate()), expectedDate);
assertEquals(accessor.query(TemporalQuery.localTime()), null);
assertEquals(accessor.query(TemporalQueries.localDate()), expectedDate);
assertEquals(accessor.query(TemporalQueries.localTime()), null);
}
//-----------------------------------------------------------------------
@ -535,8 +535,8 @@ public class TCKDateTimeParseResolver {
.appendValue(field4).toFormatter();
TemporalAccessor accessor = f.parse(str);
assertEquals(accessor.query(TemporalQuery.localDate()), expectedDate);
assertEquals(accessor.query(TemporalQuery.localTime()), null);
assertEquals(accessor.query(TemporalQueries.localDate()), expectedDate);
assertEquals(accessor.query(TemporalQueries.localTime()), null);
}
//-----------------------------------------------------------------------
@ -603,8 +603,8 @@ public class TCKDateTimeParseResolver {
for (ResolverStyle s : styles) {
if (expectedTime != null) {
TemporalAccessor accessor = f.withResolverStyle(s).parse("");
assertEquals(accessor.query(TemporalQuery.localDate()), null, "ResolverStyle: " + s);
assertEquals(accessor.query(TemporalQuery.localTime()), expectedTime, "ResolverStyle: " + s);
assertEquals(accessor.query(TemporalQueries.localDate()), null, "ResolverStyle: " + s);
assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime, "ResolverStyle: " + s);
assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), excessPeriod, "ResolverStyle: " + s);
} else {
try {
@ -629,8 +629,8 @@ public class TCKDateTimeParseResolver {
for (ResolverStyle s : styles) {
if (expectedTime != null) {
TemporalAccessor accessor = f.withResolverStyle(s).parse("");
assertEquals(accessor.query(TemporalQuery.localDate()), null, "ResolverStyle: " + s);
assertEquals(accessor.query(TemporalQuery.localTime()), expectedTime.minusNanos(nano), "ResolverStyle: " + s);
assertEquals(accessor.query(TemporalQueries.localDate()), null, "ResolverStyle: " + s);
assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime.minusNanos(nano), "ResolverStyle: " + s);
assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), excessPeriod, "ResolverStyle: " + s);
} else {
try {
@ -658,8 +658,8 @@ public class TCKDateTimeParseResolver {
LocalDate expectedDate = LocalDate.of(2012, 6, 30).plus(excessPeriod);
for (ResolverStyle s : styles) {
TemporalAccessor accessor = f.withResolverStyle(s).parse("");
assertEquals(accessor.query(TemporalQuery.localDate()), expectedDate, "ResolverStyle: " + s);
assertEquals(accessor.query(TemporalQuery.localTime()), expectedTime, "ResolverStyle: " + s);
assertEquals(accessor.query(TemporalQueries.localDate()), expectedDate, "ResolverStyle: " + s);
assertEquals(accessor.query(TemporalQueries.localTime()), expectedTime, "ResolverStyle: " + s);
assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ZERO, "ResolverStyle: " + s);
}
}
@ -696,8 +696,8 @@ public class TCKDateTimeParseResolver {
if (expectedSecond != null) {
TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
assertEquals(accessor.query(TemporalQuery.localDate()), null);
assertEquals(accessor.query(TemporalQuery.localTime()), LocalTime.ofSecondOfDay(expectedSecond));
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.ofSecondOfDay(expectedSecond));
assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ofDays(expectedDays));
} else {
try {
@ -740,8 +740,8 @@ public class TCKDateTimeParseResolver {
if (expectedMinute != null) {
TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
assertEquals(accessor.query(TemporalQuery.localDate()), null);
assertEquals(accessor.query(TemporalQuery.localTime()), LocalTime.ofSecondOfDay(expectedMinute * 60));
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.ofSecondOfDay(expectedMinute * 60));
assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ofDays(expectedDays));
} else {
try {
@ -784,8 +784,8 @@ public class TCKDateTimeParseResolver {
if (expectedHour != null) {
TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
assertEquals(accessor.query(TemporalQuery.localDate()), null);
assertEquals(accessor.query(TemporalQuery.localTime()), LocalTime.of(expectedHour, 0));
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.of(expectedHour, 0));
assertEquals(accessor.query(DateTimeFormatter.parsedExcessDays()), Period.ofDays(expectedDays));
} else {
try {
@ -828,8 +828,8 @@ public class TCKDateTimeParseResolver {
if (expectedValue != null) {
TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
assertEquals(accessor.query(TemporalQuery.localDate()), null);
assertEquals(accessor.query(TemporalQuery.localTime()), null);
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), null);
assertEquals(accessor.isSupported(CLOCK_HOUR_OF_AMPM), false);
assertEquals(accessor.isSupported(HOUR_OF_AMPM), true);
assertEquals(accessor.getLong(HOUR_OF_AMPM), expectedValue.longValue());
@ -871,8 +871,8 @@ public class TCKDateTimeParseResolver {
if (expectedValue != null) {
TemporalAccessor accessor = f.withResolverStyle(style).parse(str);
assertEquals(accessor.query(TemporalQuery.localDate()), null);
assertEquals(accessor.query(TemporalQuery.localTime()), null);
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), null);
assertEquals(accessor.isSupported(AMPM_OF_DAY), true);
assertEquals(accessor.getLong(AMPM_OF_DAY), expectedValue.longValue());
} else {
@ -927,15 +927,14 @@ public class TCKDateTimeParseResolver {
}
@Override
public TemporalAccessor resolve(
Map<TemporalField, Long> fieldValues, Chronology chronology,
ZoneId zone, ResolverStyle resolverStyle) {
Map<TemporalField, Long> fieldValues, TemporalAccessor partialTemporal, ResolverStyle resolverStyle) {
return LocalTime.MIDNIGHT.plusNanos(fieldValues.remove(this));
}
};
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field).toFormatter();
TemporalAccessor accessor = f.parse("1234567890");
assertEquals(accessor.query(TemporalQuery.localDate()), null);
assertEquals(accessor.query(TemporalQuery.localTime()), LocalTime.of(0, 0, 1, 234_567_890));
assertEquals(accessor.query(TemporalQueries.localDate()), null);
assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.of(0, 0, 1, 234_567_890));
}
@Test
@ -979,16 +978,15 @@ public class TCKDateTimeParseResolver {
}
@Override
public TemporalAccessor resolve(
Map<TemporalField, Long> fieldValues, Chronology chronology,
ZoneId zone, ResolverStyle resolverStyle) {
Map<TemporalField, Long> fieldValues, TemporalAccessor partialTemporal, ResolverStyle resolverStyle) {
fieldValues.remove(this);
return LocalDateTime.of(2010, 6, 30, 12, 30);
}
};
DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(field).toFormatter();
TemporalAccessor accessor = f.parse("1234567890");
assertEquals(accessor.query(TemporalQuery.localDate()), LocalDate.of(2010, 6, 30));
assertEquals(accessor.query(TemporalQuery.localTime()), LocalTime.of(12, 30));
assertEquals(accessor.query(TemporalQueries.localDate()), LocalDate.of(2010, 6, 30));
assertEquals(accessor.query(TemporalQueries.localTime()), LocalTime.of(12, 30));
}
@Test(expectedExceptions = DateTimeParseException.class)
@ -1032,8 +1030,7 @@ public class TCKDateTimeParseResolver {
}
@Override
public TemporalAccessor resolve(
Map<TemporalField, Long> fieldValues, Chronology chronology,
ZoneId zone, ResolverStyle resolverStyle) {
Map<TemporalField, Long> fieldValues, TemporalAccessor partialTemporal, ResolverStyle resolverStyle) {
return ThaiBuddhistChronology.INSTANCE.dateNow();
}
};
@ -1082,8 +1079,7 @@ public class TCKDateTimeParseResolver {
}
@Override
public TemporalAccessor resolve(
Map<TemporalField, Long> fieldValues, Chronology chronology,
ZoneId zone, ResolverStyle resolverStyle) {
Map<TemporalField, Long> fieldValues, TemporalAccessor partialTemporal, ResolverStyle resolverStyle) {
return ZonedDateTime.of(2010, 6, 30, 12, 30, 0, 0, ZoneId.of("Europe/Paris"));
}
};

View File

@ -123,7 +123,7 @@ public class TCKLocalizedPrinterParser {
};
}
@SuppressWarnings("deprecated")
@SuppressWarnings("deprecation")
@Test(dataProvider="date")
public void test_date_print(LocalDate date, FormatStyle dateStyle, int dateStyleOld, Locale locale) {
DateFormat old = DateFormat.getDateInstance(dateStyleOld, locale);
@ -135,7 +135,7 @@ public class TCKLocalizedPrinterParser {
assertEquals(formatted, text);
}
@SuppressWarnings("deprecated")
@SuppressWarnings("deprecation")
@Test(dataProvider="date")
public void test_date_parse(LocalDate date, FormatStyle dateStyle, int dateStyleOld, Locale locale) {
DateFormat old = DateFormat.getDateInstance(dateStyleOld, locale);
@ -176,7 +176,7 @@ public class TCKLocalizedPrinterParser {
};
}
@SuppressWarnings("deprecated")
@SuppressWarnings("deprecation")
@Test(dataProvider="time")
public void test_time_print(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);
@ -188,7 +188,7 @@ public class TCKLocalizedPrinterParser {
assertEquals(formatted, text);
}
@SuppressWarnings("deprecated")
@SuppressWarnings("deprecation")
@Test(dataProvider="time")
public void test_time_parse(LocalTime time, FormatStyle timeStyle, int timeStyleOld, Locale locale) {
DateFormat old = DateFormat.getTimeInstance(timeStyleOld, locale);

View File

@ -71,7 +71,7 @@ import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalQueries;
import java.util.Locale;
import java.util.Objects;
@ -214,9 +214,9 @@ public class TCKZoneIdPrinterParser {
assertEquals(pos.getErrorIndex(), expectedErrorIndex, "Incorrect error index parsing: " + text);
assertEquals(pos.getIndex(), expectedIndex, "Incorrect index parsing: " + text);
if (expected != null) {
assertEquals(parsed.query(TemporalQuery.zoneId()), expected, "Incorrect zoneId parsing: " + text);
assertEquals(parsed.query(TemporalQuery.offset()), null, "Incorrect offset parsing: " + text);
assertEquals(parsed.query(TemporalQuery.zone()), expected, "Incorrect zone parsing: " + text);
assertEquals(parsed.query(TemporalQueries.zoneId()), expected, "Incorrect zoneId parsing: " + text);
assertEquals(parsed.query(TemporalQueries.offset()), null, "Incorrect offset parsing: " + text);
assertEquals(parsed.query(TemporalQueries.zone()), expected, "Incorrect zone parsing: " + text);
} else {
assertEquals(parsed, null);
}
@ -231,9 +231,9 @@ public class TCKZoneIdPrinterParser {
assertEquals(pos.getErrorIndex(), expectedErrorIndex >= 0 ? expectedErrorIndex + 3 : expectedErrorIndex, "Incorrect error index parsing: " + prefixText);
assertEquals(pos.getIndex(), expectedIndex + 3, "Incorrect index parsing: " + prefixText);
if (expected != null) {
assertEquals(parsed.query(TemporalQuery.zoneId()), expected, "Incorrect zoneId parsing: " + prefixText);
assertEquals(parsed.query(TemporalQuery.offset()), null, "Incorrect offset parsing: " + prefixText);
assertEquals(parsed.query(TemporalQuery.zone()), expected, "Incorrect zone parsing: " + prefixText);
assertEquals(parsed.query(TemporalQueries.zoneId()), expected, "Incorrect zoneId parsing: " + prefixText);
assertEquals(parsed.query(TemporalQueries.offset()), null, "Incorrect offset parsing: " + prefixText);
assertEquals(parsed.query(TemporalQueries.zone()), expected, "Incorrect zone parsing: " + prefixText);
} else {
assertEquals(parsed, null);
}
@ -247,9 +247,9 @@ public class TCKZoneIdPrinterParser {
assertEquals(pos.getErrorIndex(), expectedErrorIndex, "Incorrect error index parsing: " + suffixText);
assertEquals(pos.getIndex(), expectedIndex, "Incorrect index parsing: " + suffixText);
if (expected != null) {
assertEquals(parsed.query(TemporalQuery.zoneId()), expected, "Incorrect zoneId parsing: " + suffixText);
assertEquals(parsed.query(TemporalQuery.offset()), null, "Incorrect offset parsing: " + suffixText);
assertEquals(parsed.query(TemporalQuery.zone()), expected, "Incorrect zone parsing: " + suffixText);
assertEquals(parsed.query(TemporalQueries.zoneId()), expected, "Incorrect zoneId parsing: " + suffixText);
assertEquals(parsed.query(TemporalQueries.offset()), null, "Incorrect offset parsing: " + suffixText);
assertEquals(parsed.query(TemporalQueries.zone()), expected, "Incorrect zone parsing: " + suffixText);
} else {
assertEquals(parsed, null);
}
@ -269,9 +269,9 @@ public class TCKZoneIdPrinterParser {
assertEquals(pos.getIndex(), expectedIndex, "Incorrect index parsing: " + lcText);
assertEquals(pos.getErrorIndex(), expectedErrorIndex, "Incorrect error index parsing: " + lcText);
if (expected != null) {
assertEquals(parsed.query(TemporalQuery.zoneId()), expected);
assertEquals(parsed.query(TemporalQuery.offset()), null);
assertEquals(parsed.query(TemporalQuery.zone()), expected);
assertEquals(parsed.query(TemporalQueries.zoneId()), expected);
assertEquals(parsed.query(TemporalQueries.offset()), null);
assertEquals(parsed.query(TemporalQueries.zone()), expected);
} else {
assertEquals(parsed, null);
}
@ -286,10 +286,10 @@ public class TCKZoneIdPrinterParser {
assertEquals(pos.getErrorIndex(), expectedErrorIndex, "Incorrect error index parsing: " + lcText);
assertEquals(pos.getIndex(), expectedIndex, "Incorrect index parsing: " + lcText);
if (expected != null) {
ZoneId zid = parsed.query(TemporalQuery.zoneId());
assertEquals(parsed.query(TemporalQuery.zoneId()), expected, "Incorrect zoneId parsing: " + lcText);
assertEquals(parsed.query(TemporalQuery.offset()), null, "Incorrect offset parsing: " + lcText);
assertEquals(parsed.query(TemporalQuery.zone()), expected, "Incorrect zone parsing: " + lcText);
ZoneId zid = parsed.query(TemporalQueries.zoneId());
assertEquals(parsed.query(TemporalQueries.zoneId()), expected, "Incorrect zoneId parsing: " + lcText);
assertEquals(parsed.query(TemporalQueries.offset()), null, "Incorrect offset parsing: " + lcText);
assertEquals(parsed.query(TemporalQueries.zone()), expected, "Incorrect zone parsing: " + lcText);
} else {
assertEquals(parsed, null);
}

View File

@ -73,12 +73,13 @@ import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/**
* Test TemporalAdjuster.
* Test TemporalAdjusters.
*/
@Test
public class TCKTemporalAdjusters {
@ -88,13 +89,13 @@ public class TCKTemporalAdjusters {
//-----------------------------------------------------------------------
@Test
public void factory_ofDateAdjuster() {
TemporalAdjuster test = TemporalAdjuster.ofDateAdjuster(date -> date.plusDays(2));
TemporalAdjuster test = TemporalAdjusters.ofDateAdjuster(date -> date.plusDays(2));
assertEquals(LocalDate.of(2012, 6, 30).with(test), LocalDate.of(2012, 7, 2));
}
@Test(expectedExceptions = NullPointerException.class)
public void factory_ofDateAdjuster_null() {
TemporalAdjuster.ofDateAdjuster(null);
TemporalAdjusters.ofDateAdjuster(null);
}
@ -103,7 +104,7 @@ public class TCKTemporalAdjusters {
//-----------------------------------------------------------------------
@Test
public void factory_firstDayOfMonth() {
assertNotNull(TemporalAdjuster.firstDayOfMonth());
assertNotNull(TemporalAdjusters.firstDayOfMonth());
}
@Test
@ -111,7 +112,7 @@ public class TCKTemporalAdjusters {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = date(2007, month, i);
LocalDate test = (LocalDate) TemporalAdjuster.firstDayOfMonth().adjustInto(date);
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfMonth().adjustInto(date);
assertEquals(test.getYear(), 2007);
assertEquals(test.getMonth(), month);
assertEquals(test.getDayOfMonth(), 1);
@ -124,7 +125,7 @@ public class TCKTemporalAdjusters {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(true); i++) {
LocalDate date = date(2008, month, i);
LocalDate test = (LocalDate) TemporalAdjuster.firstDayOfMonth().adjustInto(date);
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfMonth().adjustInto(date);
assertEquals(test.getYear(), 2008);
assertEquals(test.getMonth(), month);
assertEquals(test.getDayOfMonth(), 1);
@ -137,7 +138,7 @@ public class TCKTemporalAdjusters {
//-----------------------------------------------------------------------
@Test
public void factory_lastDayOfMonth() {
assertNotNull(TemporalAdjuster.lastDayOfMonth());
assertNotNull(TemporalAdjusters.lastDayOfMonth());
}
@Test
@ -145,7 +146,7 @@ public class TCKTemporalAdjusters {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = date(2007, month, i);
LocalDate test = (LocalDate) TemporalAdjuster.lastDayOfMonth().adjustInto(date);
LocalDate test = (LocalDate) TemporalAdjusters.lastDayOfMonth().adjustInto(date);
assertEquals(test.getYear(), 2007);
assertEquals(test.getMonth(), month);
assertEquals(test.getDayOfMonth(), month.length(false));
@ -158,7 +159,7 @@ public class TCKTemporalAdjusters {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(true); i++) {
LocalDate date = date(2008, month, i);
LocalDate test = (LocalDate) TemporalAdjuster.lastDayOfMonth().adjustInto(date);
LocalDate test = (LocalDate) TemporalAdjusters.lastDayOfMonth().adjustInto(date);
assertEquals(test.getYear(), 2008);
assertEquals(test.getMonth(), month);
assertEquals(test.getDayOfMonth(), month.length(true));
@ -171,7 +172,7 @@ public class TCKTemporalAdjusters {
//-----------------------------------------------------------------------
@Test
public void factory_firstDayOfNextMonth() {
assertNotNull(TemporalAdjuster.firstDayOfNextMonth());
assertNotNull(TemporalAdjusters.firstDayOfNextMonth());
}
@Test
@ -179,7 +180,7 @@ public class TCKTemporalAdjusters {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = date(2007, month, i);
LocalDate test = (LocalDate) TemporalAdjuster.firstDayOfNextMonth().adjustInto(date);
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfNextMonth().adjustInto(date);
assertEquals(test.getYear(), month == DECEMBER ? 2008 : 2007);
assertEquals(test.getMonth(), month.plus(1));
assertEquals(test.getDayOfMonth(), 1);
@ -192,7 +193,7 @@ public class TCKTemporalAdjusters {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(true); i++) {
LocalDate date = date(2008, month, i);
LocalDate test = (LocalDate) TemporalAdjuster.firstDayOfNextMonth().adjustInto(date);
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfNextMonth().adjustInto(date);
assertEquals(test.getYear(), month == DECEMBER ? 2009 : 2008);
assertEquals(test.getMonth(), month.plus(1));
assertEquals(test.getDayOfMonth(), 1);
@ -205,7 +206,7 @@ public class TCKTemporalAdjusters {
//-----------------------------------------------------------------------
@Test
public void factory_firstDayOfYear() {
assertNotNull(TemporalAdjuster.firstDayOfYear());
assertNotNull(TemporalAdjusters.firstDayOfYear());
}
@Test
@ -213,7 +214,7 @@ public class TCKTemporalAdjusters {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = date(2007, month, i);
LocalDate test = (LocalDate) TemporalAdjuster.firstDayOfYear().adjustInto(date);
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfYear().adjustInto(date);
assertEquals(test.getYear(), 2007);
assertEquals(test.getMonth(), Month.JANUARY);
assertEquals(test.getDayOfMonth(), 1);
@ -226,7 +227,7 @@ public class TCKTemporalAdjusters {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(true); i++) {
LocalDate date = date(2008, month, i);
LocalDate test = (LocalDate) TemporalAdjuster.firstDayOfYear().adjustInto(date);
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfYear().adjustInto(date);
assertEquals(test.getYear(), 2008);
assertEquals(test.getMonth(), Month.JANUARY);
assertEquals(test.getDayOfMonth(), 1);
@ -239,7 +240,7 @@ public class TCKTemporalAdjusters {
//-----------------------------------------------------------------------
@Test
public void factory_lastDayOfYear() {
assertNotNull(TemporalAdjuster.lastDayOfYear());
assertNotNull(TemporalAdjusters.lastDayOfYear());
}
@Test
@ -247,7 +248,7 @@ public class TCKTemporalAdjusters {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = date(2007, month, i);
LocalDate test = (LocalDate) TemporalAdjuster.lastDayOfYear().adjustInto(date);
LocalDate test = (LocalDate) TemporalAdjusters.lastDayOfYear().adjustInto(date);
assertEquals(test.getYear(), 2007);
assertEquals(test.getMonth(), Month.DECEMBER);
assertEquals(test.getDayOfMonth(), 31);
@ -260,7 +261,7 @@ public class TCKTemporalAdjusters {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(true); i++) {
LocalDate date = date(2008, month, i);
LocalDate test = (LocalDate) TemporalAdjuster.lastDayOfYear().adjustInto(date);
LocalDate test = (LocalDate) TemporalAdjusters.lastDayOfYear().adjustInto(date);
assertEquals(test.getYear(), 2008);
assertEquals(test.getMonth(), Month.DECEMBER);
assertEquals(test.getDayOfMonth(), 31);
@ -273,7 +274,7 @@ public class TCKTemporalAdjusters {
//-----------------------------------------------------------------------
@Test
public void factory_firstDayOfNextYear() {
assertNotNull(TemporalAdjuster.firstDayOfNextYear());
assertNotNull(TemporalAdjusters.firstDayOfNextYear());
}
@Test
@ -281,7 +282,7 @@ public class TCKTemporalAdjusters {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = date(2007, month, i);
LocalDate test = (LocalDate) TemporalAdjuster.firstDayOfNextYear().adjustInto(date);
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfNextYear().adjustInto(date);
assertEquals(test.getYear(), 2008);
assertEquals(test.getMonth(), JANUARY);
assertEquals(test.getDayOfMonth(), 1);
@ -294,7 +295,7 @@ public class TCKTemporalAdjusters {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(true); i++) {
LocalDate date = date(2008, month, i);
LocalDate test = (LocalDate) TemporalAdjuster.firstDayOfNextYear().adjustInto(date);
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfNextYear().adjustInto(date);
assertEquals(test.getYear(), 2009);
assertEquals(test.getMonth(), JANUARY);
assertEquals(test.getDayOfMonth(), 1);
@ -307,12 +308,12 @@ public class TCKTemporalAdjusters {
//-----------------------------------------------------------------------
@Test
public void factory_dayOfWeekInMonth() {
assertNotNull(TemporalAdjuster.dayOfWeekInMonth(1, MONDAY));
assertNotNull(TemporalAdjusters.dayOfWeekInMonth(1, MONDAY));
}
@Test(expectedExceptions=NullPointerException.class)
public void factory_dayOfWeekInMonth_nullDayOfWeek() {
TemporalAdjuster.dayOfWeekInMonth(1, null);
TemporalAdjusters.dayOfWeekInMonth(1, null);
}
@DataProvider(name = "dayOfWeekInMonth_positive")
@ -338,7 +339,7 @@ public class TCKTemporalAdjusters {
for (int ordinal = 1; ordinal <= 5; ordinal++) {
for (int day = 1; day <= Month.of(month).length(false); day++) {
LocalDate date = date(year, month, day);
LocalDate test = (LocalDate) TemporalAdjuster.dayOfWeekInMonth(ordinal, dow).adjustInto(date);
LocalDate test = (LocalDate) TemporalAdjusters.dayOfWeekInMonth(ordinal, dow).adjustInto(date);
assertEquals(test, expected.plusWeeks(ordinal - 1));
}
}
@ -366,7 +367,7 @@ public class TCKTemporalAdjusters {
public void test_dayOfWeekInMonth_zero(int year, int month, DayOfWeek dow, LocalDate expected) {
for (int day = 1; day <= Month.of(month).length(false); day++) {
LocalDate date = date(year, month, day);
LocalDate test = (LocalDate) TemporalAdjuster.dayOfWeekInMonth(0, dow).adjustInto(date);
LocalDate test = (LocalDate) TemporalAdjusters.dayOfWeekInMonth(0, dow).adjustInto(date);
assertEquals(test, expected);
}
}
@ -394,7 +395,7 @@ public class TCKTemporalAdjusters {
for (int ordinal = 0; ordinal < 5; ordinal++) {
for (int day = 1; day <= Month.of(month).length(false); day++) {
LocalDate date = date(year, month, day);
LocalDate test = (LocalDate) TemporalAdjuster.dayOfWeekInMonth(-1 - ordinal, dow).adjustInto(date);
LocalDate test = (LocalDate) TemporalAdjusters.dayOfWeekInMonth(-1 - ordinal, dow).adjustInto(date);
assertEquals(test, expected.minusWeeks(ordinal));
}
}
@ -405,19 +406,19 @@ public class TCKTemporalAdjusters {
//-----------------------------------------------------------------------
@Test
public void factory_firstInMonth() {
assertNotNull(TemporalAdjuster.firstInMonth(MONDAY));
assertNotNull(TemporalAdjusters.firstInMonth(MONDAY));
}
@Test(expectedExceptions=NullPointerException.class)
public void factory_firstInMonth_nullDayOfWeek() {
TemporalAdjuster.firstInMonth(null);
TemporalAdjusters.firstInMonth(null);
}
@Test(dataProvider = "dayOfWeekInMonth_positive")
public void test_firstInMonth(int year, int month, DayOfWeek dow, LocalDate expected) {
for (int day = 1; day <= Month.of(month).length(false); day++) {
LocalDate date = date(year, month, day);
LocalDate test = (LocalDate) TemporalAdjuster.firstInMonth(dow).adjustInto(date);
LocalDate test = (LocalDate) TemporalAdjusters.firstInMonth(dow).adjustInto(date);
assertEquals(test, expected, "day-of-month=" + day);
}
}
@ -427,19 +428,19 @@ public class TCKTemporalAdjusters {
//-----------------------------------------------------------------------
@Test
public void factory_lastInMonth() {
assertNotNull(TemporalAdjuster.lastInMonth(MONDAY));
assertNotNull(TemporalAdjusters.lastInMonth(MONDAY));
}
@Test(expectedExceptions=NullPointerException.class)
public void factory_lastInMonth_nullDayOfWeek() {
TemporalAdjuster.lastInMonth(null);
TemporalAdjusters.lastInMonth(null);
}
@Test(dataProvider = "dayOfWeekInMonth_negative")
public void test_lastInMonth(int year, int month, DayOfWeek dow, LocalDate expected) {
for (int day = 1; day <= Month.of(month).length(false); day++) {
LocalDate date = date(year, month, day);
LocalDate test = (LocalDate) TemporalAdjuster.lastInMonth(dow).adjustInto(date);
LocalDate test = (LocalDate) TemporalAdjusters.lastInMonth(dow).adjustInto(date);
assertEquals(test, expected, "day-of-month=" + day);
}
}
@ -449,12 +450,12 @@ public class TCKTemporalAdjusters {
//-----------------------------------------------------------------------
@Test
public void factory_next() {
assertNotNull(TemporalAdjuster.next(MONDAY));
assertNotNull(TemporalAdjusters.next(MONDAY));
}
@Test(expectedExceptions = NullPointerException.class)
public void factory_next_nullDayOfWeek() {
TemporalAdjuster.next(null);
TemporalAdjusters.next(null);
}
@Test
@ -464,7 +465,7 @@ public class TCKTemporalAdjusters {
LocalDate date = date(2007, month, i);
for (DayOfWeek dow : DayOfWeek.values()) {
LocalDate test = (LocalDate) TemporalAdjuster.next(dow).adjustInto(date);
LocalDate test = (LocalDate) TemporalAdjusters.next(dow).adjustInto(date);
assertSame(test.getDayOfWeek(), dow, date + " " + test);
@ -488,12 +489,12 @@ public class TCKTemporalAdjusters {
//-----------------------------------------------------------------------
@Test
public void factory_nextOrCurrent() {
assertNotNull(TemporalAdjuster.nextOrSame(MONDAY));
assertNotNull(TemporalAdjusters.nextOrSame(MONDAY));
}
@Test(expectedExceptions = NullPointerException.class)
public void factory_nextOrCurrent_nullDayOfWeek() {
TemporalAdjuster.nextOrSame(null);
TemporalAdjusters.nextOrSame(null);
}
@Test
@ -503,7 +504,7 @@ public class TCKTemporalAdjusters {
LocalDate date = date(2007, month, i);
for (DayOfWeek dow : DayOfWeek.values()) {
LocalDate test = (LocalDate) TemporalAdjuster.nextOrSame(dow).adjustInto(date);
LocalDate test = (LocalDate) TemporalAdjusters.nextOrSame(dow).adjustInto(date);
assertSame(test.getDayOfWeek(), dow);
@ -529,12 +530,12 @@ public class TCKTemporalAdjusters {
//-----------------------------------------------------------------------
@Test
public void factory_previous() {
assertNotNull(TemporalAdjuster.previous(MONDAY));
assertNotNull(TemporalAdjusters.previous(MONDAY));
}
@Test(expectedExceptions = NullPointerException.class)
public void factory_previous_nullDayOfWeek() {
TemporalAdjuster.previous(null);
TemporalAdjusters.previous(null);
}
@Test
@ -544,7 +545,7 @@ public class TCKTemporalAdjusters {
LocalDate date = date(2007, month, i);
for (DayOfWeek dow : DayOfWeek.values()) {
LocalDate test = (LocalDate) TemporalAdjuster.previous(dow).adjustInto(date);
LocalDate test = (LocalDate) TemporalAdjusters.previous(dow).adjustInto(date);
assertSame(test.getDayOfWeek(), dow, date + " " + test);
@ -568,12 +569,12 @@ public class TCKTemporalAdjusters {
//-----------------------------------------------------------------------
@Test
public void factory_previousOrCurrent() {
assertNotNull(TemporalAdjuster.previousOrSame(MONDAY));
assertNotNull(TemporalAdjusters.previousOrSame(MONDAY));
}
@Test(expectedExceptions = NullPointerException.class)
public void factory_previousOrCurrent_nullDayOfWeek() {
TemporalAdjuster.previousOrSame(null);
TemporalAdjusters.previousOrSame(null);
}
@Test
@ -583,7 +584,7 @@ public class TCKTemporalAdjusters {
LocalDate date = date(2007, month, i);
for (DayOfWeek dow : DayOfWeek.values()) {
LocalDate test = (LocalDate) TemporalAdjuster.previousOrSame(dow).adjustInto(date);
LocalDate test = (LocalDate) TemporalAdjusters.previousOrSame(dow).adjustInto(date);
assertSame(test.getDayOfWeek(), dow);

View File

@ -60,7 +60,7 @@ import java.time.format.FormatStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.ValueRange;
import java.time.temporal.WeekFields;
import java.util.Locale;
@ -357,12 +357,12 @@ public class TestUmmAlQuraChronology {
@Test
public void test_temporalDayAdjustments() {
HijrahDate date = HijrahDate.of(1554, 7, 21);
assertEquals(date.with(TemporalAdjuster.firstDayOfMonth()), HijrahDate.of(1554, 7, 1));
assertEquals(date.with(TemporalAdjuster.lastDayOfMonth()), HijrahDate.of(1554, 7, 29));
assertEquals(date.with(TemporalAdjuster.firstDayOfNextMonth()), HijrahDate.of(1554, 8, 1));
assertEquals(date.with(TemporalAdjuster.firstDayOfNextYear()), HijrahDate.of(1555, 1, 1));
assertEquals(date.with(TemporalAdjuster.firstDayOfYear()), HijrahDate.of(1554, 1, 1));
assertEquals(date.with(TemporalAdjuster.lastDayOfYear()), HijrahDate.of(1554, 12, 30));
assertEquals(date.with(TemporalAdjusters.firstDayOfMonth()), HijrahDate.of(1554, 7, 1));
assertEquals(date.with(TemporalAdjusters.lastDayOfMonth()), HijrahDate.of(1554, 7, 29));
assertEquals(date.with(TemporalAdjusters.firstDayOfNextMonth()), HijrahDate.of(1554, 8, 1));
assertEquals(date.with(TemporalAdjusters.firstDayOfNextYear()), HijrahDate.of(1555, 1, 1));
assertEquals(date.with(TemporalAdjusters.firstDayOfYear()), HijrahDate.of(1554, 1, 1));
assertEquals(date.with(TemporalAdjusters.lastDayOfYear()), HijrahDate.of(1554, 12, 30));
}
// Data provider for string representation of the date instances
@ -412,7 +412,7 @@ public class TestUmmAlQuraChronology {
@Test(dataProvider="monthDays")
public void test_lastDayOfMonth(int year, int month, int numDays) {
HijrahDate hDate = HijrahChronology.INSTANCE.date(year, month, 1);
hDate = hDate.with(TemporalAdjuster.lastDayOfMonth());
hDate = hDate.with(TemporalAdjusters.lastDayOfMonth());
assertEquals(hDate.get(ChronoField.DAY_OF_MONTH), numDays);
}

View File

@ -66,7 +66,7 @@ import static org.testng.Assert.fail;
import java.text.ParsePosition;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalQueries;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@ -111,8 +111,8 @@ public class TestCharLiteralParser extends AbstractTestPrinterParser {
} else {
assertEquals(ppos.getIndex(), expectedPos);
assertEquals(parsed.isSupported(YEAR), false);
assertEquals(parsed.query(TemporalQuery.chronology()), null);
assertEquals(parsed.query(TemporalQuery.zoneId()), null);
assertEquals(parsed.query(TemporalQueries.chronology()), null);
assertEquals(parsed.query(TemporalQueries.zoneId()), null);
}
}

View File

@ -39,7 +39,7 @@ import java.time.format.DateTimeParseException;
import java.time.format.FormatStyle;
import java.time.format.TextStyle;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalQueries;
import java.util.Locale;
import org.testng.annotations.BeforeMethod;
@ -163,7 +163,7 @@ public class TestNonIsoFormatter {
String text = dtf.format(chrono.dateNow());
assertEquals(text, expected);
TemporalAccessor ta = dtf.parse(text);
Chronology cal = ta.query(TemporalQuery.chronology());
Chronology cal = ta.query(TemporalQueries.chronology());
assertEquals(cal, chrono);
}
}

View File

@ -72,7 +72,7 @@ import java.time.format.DateTimeFormatter;
import java.time.format.SignStyle;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalQueries;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@ -178,8 +178,8 @@ public class TestNumberParser extends AbstractTestPrinterParser {
assertTrue(subsequentWidth >= 0);
assertEquals(ppos.getIndex(), expectedPos + subsequentWidth);
assertEquals(parsed.getLong(DAY_OF_MONTH), expectedValue);
assertEquals(parsed.query(TemporalQuery.chronology()), null);
assertEquals(parsed.query(TemporalQuery.zoneId()), null);
assertEquals(parsed.query(TemporalQueries.chronology()), null);
assertEquals(parsed.query(TemporalQueries.zoneId()), null);
}
}
@ -198,8 +198,8 @@ public class TestNumberParser extends AbstractTestPrinterParser {
assertTrue(subsequentWidth >= 0);
assertEquals(ppos.getIndex(), expectedPos + subsequentWidth);
assertEquals(parsed.getLong(DAY_OF_WEEK), expectedValue);
assertEquals(parsed.query(TemporalQuery.chronology()), null);
assertEquals(parsed.query(TemporalQuery.zoneId()), null);
assertEquals(parsed.query(TemporalQueries.chronology()), null);
assertEquals(parsed.query(TemporalQueries.zoneId()), null);
}
}
@ -313,8 +313,8 @@ public class TestNumberParser extends AbstractTestPrinterParser {
} else {
assertEquals(pos.getIndex(), parseLen);
assertEquals(parsed.getLong(DAY_OF_MONTH), (long)parseVal);
assertEquals(parsed.query(TemporalQuery.chronology()), null);
assertEquals(parsed.query(TemporalQuery.zoneId()), null);
assertEquals(parsed.query(TemporalQueries.chronology()), null);
assertEquals(parsed.query(TemporalQueries.zoneId()), null);
}
}
@ -423,8 +423,8 @@ public class TestNumberParser extends AbstractTestPrinterParser {
} else {
assertEquals(pos.getIndex(), parseLen);
assertEquals(parsed.getLong(DAY_OF_MONTH), (long)parseVal);
assertEquals(parsed.query(TemporalQuery.chronology()), null);
assertEquals(parsed.query(TemporalQuery.zoneId()), null);
assertEquals(parsed.query(TemporalQueries.chronology()), null);
assertEquals(parsed.query(TemporalQueries.zoneId()), null);
}
}
@ -514,8 +514,8 @@ public class TestNumberParser extends AbstractTestPrinterParser {
} else {
assertEquals(pos.getIndex(), parseLen);
assertEquals(parsed.getLong(DAY_OF_MONTH), (long)parseVal);
assertEquals(parsed.query(TemporalQuery.chronology()), null);
assertEquals(parsed.query(TemporalQuery.zoneId()), null);
assertEquals(parsed.query(TemporalQueries.chronology()), null);
assertEquals(parsed.query(TemporalQueries.zoneId()), null);
}
}
@ -552,8 +552,8 @@ public class TestNumberParser extends AbstractTestPrinterParser {
assertEquals(pos.getIndex(), parseLen);
assertEquals(parsed.getLong(MONTH_OF_YEAR), (long) parseMonth);
assertEquals(parsed.getLong(DAY_OF_MONTH), (long) parsedDay);
assertEquals(parsed.query(TemporalQuery.chronology()), null);
assertEquals(parsed.query(TemporalQuery.zoneId()), null);
assertEquals(parsed.query(TemporalQueries.chronology()), null);
assertEquals(parsed.query(TemporalQueries.zoneId()), null);
}
}

View File

@ -66,7 +66,7 @@ import static org.testng.Assert.fail;
import java.text.ParsePosition;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalQueries;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@ -114,8 +114,8 @@ public class TestStringLiteralParser extends AbstractTestPrinterParser {
} else {
assertEquals(ppos.getIndex(), expectedPos);
assertEquals(parsed.isSupported(YEAR), false);
assertEquals(parsed.query(TemporalQuery.chronology()), null);
assertEquals(parsed.query(TemporalQuery.zoneId()), null);
assertEquals(parsed.query(TemporalQueries.chronology()), null);
assertEquals(parsed.query(TemporalQueries.zoneId()), null);
}
}

View File

@ -33,7 +33,7 @@ import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.TextStyle;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalQueries;
import java.time.zone.ZoneRulesProvider;
import java.util.Arrays;
import java.util.Date;
@ -150,7 +150,7 @@ public class TestZoneTextPrinterParser extends AbstractTestPrinterParser {
.toFormatter(locale)
.withDecimalStyle(DecimalStyle.of(locale));
String ret = fmt.parse(text, TemporalQuery.zone()).getId();
String ret = fmt.parse(text, TemporalQueries.zone()).getId();
System.out.printf("[%-5s %s] %24s -> %s(%s)%n",
locale.toString(),
@ -186,7 +186,7 @@ public class TestZoneTextPrinterParser extends AbstractTestPrinterParser {
if (ci) {
text = text.toUpperCase();
}
String ret = fmt.parse(text, TemporalQuery.zone()).getId();
String ret = fmt.parse(text, TemporalQueries.zone()).getId();
// TBD: need an excluding list
// assertEquals(...);
if (ret.equals(expected) ||

View File

@ -36,7 +36,7 @@ import java.time.chrono.ChronoZonedDateTime;
import java.time.chrono.Chronology;
import java.time.temporal.ChronoField;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalAccessor;
import java.util.*;
@ -134,7 +134,7 @@ public class TestFormatter {
Class<?> c = o.getClass();
String clname = c.getName().substring(c.getPackage().getName().length() + 1);
if (o instanceof TemporalAccessor) {
Chronology chrono = ((TemporalAccessor)o).query(TemporalQuery.chronology());
Chronology chrono = ((TemporalAccessor)o).query(TemporalQueries.chronology());
if (chrono != null) {
clname = clname + "(" + chrono.getId() + ")";
}