diff --git a/src/main/java/org/threeten/extra/AmPm.java b/src/main/java/org/threeten/extra/AmPm.java index 5437c18b..8132950f 100644 --- a/src/main/java/org/threeten/extra/AmPm.java +++ b/src/main/java/org/threeten/extra/AmPm.java @@ -310,14 +310,9 @@ public long getLong(TemporalField field) { /** * Queries this am-pm using the specified query. *

- * This queries this am-pm using the specified query strategy object. - * The {@code TemporalQuery} object defines the logic to be used to - * obtain the result. Read the documentation of the query to understand - * what the result of this method will be. - *

- * The result of this method is obtained by invoking the - * {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the - * specified query passing {@code this} as the argument. + * {@link TemporalQueries#precision()} is directly supported. + * Otherwise, the result of this method is obtained by invoking + * {@link TemporalAccessor#query(TemporalQuery)} on the parent interface. * * @param the type of the result * @param query the query to invoke, not null diff --git a/src/main/java/org/threeten/extra/DayOfMonth.java b/src/main/java/org/threeten/extra/DayOfMonth.java index 277f8f04..c84c3bc2 100644 --- a/src/main/java/org/threeten/extra/DayOfMonth.java +++ b/src/main/java/org/threeten/extra/DayOfMonth.java @@ -44,6 +44,7 @@ import java.time.chrono.Chronology; import java.time.chrono.IsoChronology; import java.time.temporal.ChronoField; +import java.time.temporal.ChronoUnit; import java.time.temporal.Temporal; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAdjuster; @@ -366,14 +367,9 @@ public boolean isValidYearMonth(YearMonth yearMonth) { /** * Queries this day-of-month using the specified query. *

- * This queries this day-of-month using the specified query strategy object. - * The {@code TemporalQuery} object defines the logic to be used to - * obtain the result. Read the documentation of the query to understand - * what the result of this method will be. - *

- * The result of this method is obtained by invoking the - * {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the - * specified query passing {@code this} as the argument. + * {@link TemporalQueries#chronology()} and {@link TemporalQueries#precision()} are directly supported. + * Otherwise, the result of this method is obtained by invoking + * {@link TemporalAccessor#query(TemporalQuery)} on the parent interface. * * @param the type of the result * @param query the query to invoke, not null @@ -386,6 +382,8 @@ public boolean isValidYearMonth(YearMonth yearMonth) { public R query(TemporalQuery query) { if (query == TemporalQueries.chronology()) { return (R) IsoChronology.INSTANCE; + } else if (query == TemporalQueries.precision()) { + return (R) ChronoUnit.DAYS; } return TemporalAccessor.super.query(query); } diff --git a/src/main/java/org/threeten/extra/DayOfYear.java b/src/main/java/org/threeten/extra/DayOfYear.java index 942008cc..c2603b5c 100644 --- a/src/main/java/org/threeten/extra/DayOfYear.java +++ b/src/main/java/org/threeten/extra/DayOfYear.java @@ -42,6 +42,7 @@ import java.time.chrono.Chronology; import java.time.chrono.IsoChronology; import java.time.temporal.ChronoField; +import java.time.temporal.ChronoUnit; import java.time.temporal.Temporal; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAdjuster; @@ -350,7 +351,7 @@ public long getLong(TemporalField field) { /** * Checks if the year is valid for this day-of-year. *

- * This method checks whether this day-of-yearand the input year form + * This method checks whether this day-of-year and the input year form * a valid date. This can only return false for day-of-year 366. * * @param year the year to validate @@ -364,14 +365,9 @@ public boolean isValidYear(int year) { /** * Queries this day-of-year using the specified query. *

- * This queries this day-of-year using the specified query strategy object. - * The {@code TemporalQuery} object defines the logic to be used to - * obtain the result. Read the documentation of the query to understand - * what the result of this method will be. - *

- * The result of this method is obtained by invoking the - * {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the - * specified query passing {@code this} as the argument. + * {@link TemporalQueries#chronology()} and {@link TemporalQueries#precision()} are directly supported. + * Otherwise, the result of this method is obtained by invoking + * {@link TemporalAccessor#query(TemporalQuery)} on the parent interface. * * @param the type of the result * @param query the query to invoke, not null @@ -384,6 +380,8 @@ public boolean isValidYear(int year) { public R query(TemporalQuery query) { if (query == TemporalQueries.chronology()) { return (R) IsoChronology.INSTANCE; + } else if (query == TemporalQueries.precision()) { + return (R) ChronoUnit.DAYS; } return TemporalAccessor.super.query(query); } diff --git a/src/main/java/org/threeten/extra/Half.java b/src/main/java/org/threeten/extra/Half.java index 99d63561..1bdb5017 100644 --- a/src/main/java/org/threeten/extra/Half.java +++ b/src/main/java/org/threeten/extra/Half.java @@ -175,7 +175,7 @@ public int getValue() { //----------------------------------------------------------------------- /** - * Gets the textual representation, such as 'H1' or '4th half'. + * Gets the textual representation, such as 'H1' or '2nd half'. *

* This returns the textual name used to identify the half-of-year, * suitable for presentation to the user. @@ -362,7 +362,7 @@ public Half minus(long halves) { * H2 has 184 days. * * @param leapYear true if the length is required for a leap year - * @return the length of this month in days, 181, 182 or 184 + * @return the length of this half in days, 181, 182 or 184 */ public int length(boolean leapYear) { return this == H1 ? (leapYear ? 182 : 181) : 184; @@ -385,14 +385,9 @@ public Month firstMonth() { /** * Queries this half-of-year using the specified query. *

- * This queries this half-of-year using the specified query strategy object. - * The {@code TemporalQuery} object defines the logic to be used to - * obtain the result. Read the documentation of the query to understand - * what the result of this method will be. - *

- * The result of this method is obtained by invoking the - * {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the - * specified query passing {@code this} as the argument. + * {@link TemporalQueries#chronology()} and {@link TemporalQueries#precision()} are directly supported. + * Otherwise, the result of this method is obtained by invoking + * {@link TemporalAccessor#query(TemporalQuery)} on the parent interface. * * @param the type of the result * @param query the query to invoke, not null diff --git a/src/main/java/org/threeten/extra/HourMinute.java b/src/main/java/org/threeten/extra/HourMinute.java index d91de31b..77204490 100644 --- a/src/main/java/org/threeten/extra/HourMinute.java +++ b/src/main/java/org/threeten/extra/HourMinute.java @@ -404,7 +404,7 @@ public ValueRange range(TemporalField field) { *

* If the field is a {@link ChronoField} then the query is implemented here. * The {@link #isSupported(TemporalField) supported fields} will return valid - * values based on this hour-minute,. + * values based on this hour-minute. * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. *

* If the field is not a {@code ChronoField}, then the result of this method @@ -674,13 +674,13 @@ public HourMinute plus(TemporalAmount amountToAdd) { * The supported fields behave as follows: *

@@ -842,14 +842,9 @@ public HourMinute minusMinutes(long minutesToSubtract) { /** * Queries this hour-minute using the specified query. *

- * This queries this hour-minute using the specified query strategy object. - * The {@code TemporalQuery} object defines the logic to be used to - * obtain the result. Read the documentation of the query to understand - * what the result of this method will be. - *

- * The result of this method is obtained by invoking the - * {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the - * specified query passing {@code this} as the argument. + * {@link TemporalQueries#localTime()} and {@link TemporalQueries#precision()} are directly supported. + * Otherwise, the result of this method is obtained by invoking + * {@link TemporalAccessor#query(TemporalQuery)} on the parent interface. * * @param the type of the result * @param query the query to invoke, not null diff --git a/src/main/java/org/threeten/extra/OffsetDate.java b/src/main/java/org/threeten/extra/OffsetDate.java index 1f3731d7..22f1130a 100644 --- a/src/main/java/org/threeten/extra/OffsetDate.java +++ b/src/main/java/org/threeten/extra/OffsetDate.java @@ -1050,14 +1050,10 @@ public OffsetDate minusDays(long days) { /** * Queries this date using the specified query. *

- * This queries this date using the specified query strategy object. - * The {@code TemporalQuery} object defines the logic to be used to - * obtain the result. Read the documentation of the query to understand - * what the result of this method will be. - *

- * The result of this method is obtained by invoking the - * {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the - * specified query passing {@code this} as the argument. + * {@link TemporalQueries#localDate()}, {@link TemporalQueries#chronology()}, {@link TemporalQueries#offset()}, + * {@link TemporalQueries#zone()} and {@link TemporalQueries#precision()} are directly supported. + * Otherwise, the result of this method is obtained by invoking + * {@link TemporalAccessor#query(TemporalQuery)} on the parent interface. * * @param the type of the result * @param query the query to invoke, not null @@ -1068,7 +1064,9 @@ public OffsetDate minusDays(long days) { @SuppressWarnings("unchecked") @Override public R query(TemporalQuery query) { - if (query == TemporalQueries.chronology()) { + if (query == TemporalQueries.localDate()) { + return (R) date; + } else if (query == TemporalQueries.chronology()) { return (R) IsoChronology.INSTANCE; } else if (query == TemporalQueries.precision()) { return (R) DAYS; diff --git a/src/main/java/org/threeten/extra/Quarter.java b/src/main/java/org/threeten/extra/Quarter.java index 04265ce8..a1f44c56 100644 --- a/src/main/java/org/threeten/extra/Quarter.java +++ b/src/main/java/org/threeten/extra/Quarter.java @@ -383,7 +383,7 @@ public Quarter minus(long quarters) { * Q3 and Q4 have 92 days. * * @param leapYear true if the length is required for a leap year - * @return the length of this month in days, from 90 to 92 + * @return the length of this quarter in days, from 90 to 92 */ public int length(boolean leapYear) { switch (this) { @@ -429,14 +429,9 @@ public Month firstMonth() { /** * Queries this quarter-of-year using the specified query. *

- * This queries this quarter-of-year using the specified query strategy object. - * The {@code TemporalQuery} object defines the logic to be used to - * obtain the result. Read the documentation of the query to understand - * what the result of this method will be. - *

- * The result of this method is obtained by invoking the - * {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the - * specified query passing {@code this} as the argument. + * {@link TemporalQueries#chronology()} and {@link TemporalQueries#precision()} are directly supported. + * Otherwise, the result of this method is obtained by invoking + * {@link TemporalAccessor#query(TemporalQuery)} on the parent interface. * * @param the type of the result * @param query the query to invoke, not null diff --git a/src/main/java/org/threeten/extra/YearHalf.java b/src/main/java/org/threeten/extra/YearHalf.java index 49436413..37a96e4c 100644 --- a/src/main/java/org/threeten/extra/YearHalf.java +++ b/src/main/java/org/threeten/extra/YearHalf.java @@ -270,7 +270,7 @@ public static YearHalf from(TemporalAccessor temporal) { * Obtains an instance of {@code YearHalf} from a text string such as {@code 2007-H2}. *

* The string must represent a valid year-half. - * The format must be {@code uuuu-'Q'Q} where the 'Q' is case insensitive. + * The format must be {@code uuuu-'H'H} where the 'H' is case insensitive. * Years outside the range 0000 to 9999 must be prefixed by the plus or minus symbol. * * @param text the text to parse such as "2007-H2", not null @@ -452,7 +452,7 @@ public ValueRange range(TemporalField field) { *

* If the field is a {@link ChronoField} then the query is implemented here. * The {@link #isSupported(TemporalField) supported fields} will return valid - * values based on this year-half,. + * values based on this year-half. * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. *

* If the field is not a {@code ChronoField}, then the result of this method @@ -974,14 +974,9 @@ public YearHalf minusHalves(long halvesToSubtract) { /** * Queries this year-half using the specified query. *

- * This queries this year-half using the specified query strategy object. - * The {@code TemporalQuery} object defines the logic to be used to - * obtain the result. Read the documentation of the query to understand - * what the result of this method will be. - *

- * The result of this method is obtained by invoking the - * {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the - * specified query passing {@code this} as the argument. + * {@link TemporalQueries#chronology()} and {@link TemporalQueries#precision()} are directly supported. + * Otherwise, the result of this method is obtained by invoking + * {@link TemporalAccessor#query(TemporalQuery)} on the parent interface. * * @param the type of the result * @param query the query to invoke, not null diff --git a/src/main/java/org/threeten/extra/YearQuarter.java b/src/main/java/org/threeten/extra/YearQuarter.java index 5d455abc..2cb250a5 100644 --- a/src/main/java/org/threeten/extra/YearQuarter.java +++ b/src/main/java/org/threeten/extra/YearQuarter.java @@ -453,7 +453,7 @@ public ValueRange range(TemporalField field) { *

* If the field is a {@link ChronoField} then the query is implemented here. * The {@link #isSupported(TemporalField) supported fields} will return valid - * values based on this year-quarter,. + * values based on this year-quarter. * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. *

* If the field is not a {@code ChronoField}, then the result of this method @@ -975,14 +975,9 @@ public YearQuarter minusQuarters(long quartersToSubtract) { /** * Queries this year-quarter using the specified query. *

- * This queries this year-quarter using the specified query strategy object. - * The {@code TemporalQuery} object defines the logic to be used to - * obtain the result. Read the documentation of the query to understand - * what the result of this method will be. - *

- * The result of this method is obtained by invoking the - * {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the - * specified query passing {@code this} as the argument. + * {@link TemporalQueries#chronology()} and {@link TemporalQueries#precision()} are directly supported. + * Otherwise, the result of this method is obtained by invoking + * {@link TemporalAccessor#query(TemporalQuery)} on the parent interface. * * @param the type of the result * @param query the query to invoke, not null diff --git a/src/main/java/org/threeten/extra/YearWeek.java b/src/main/java/org/threeten/extra/YearWeek.java index 148212ae..4ae583ad 100644 --- a/src/main/java/org/threeten/extra/YearWeek.java +++ b/src/main/java/org/threeten/extra/YearWeek.java @@ -842,14 +842,9 @@ public YearWeek minusWeeks(long weeksToSubtract) { /** * Queries this year-week using the specified query. *

- * This queries this year-week using the specified query strategy object. - * The {@code TemporalQuery} object defines the logic to be used to - * obtain the result. Read the documentation of the query to understand - * what the result of this method will be. - *

- * The result of this method is obtained by invoking the - * {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the - * specified query passing {@code this} as the argument. + * {@link TemporalQueries#chronology()} and {@link TemporalQueries#precision()} are directly supported. + * Otherwise, the result of this method is obtained by invoking + * {@link TemporalAccessor#query(TemporalQuery)} on the parent interface. * * @param the type of the result * @param query the query to invoke, not null @@ -862,6 +857,8 @@ public YearWeek minusWeeks(long weeksToSubtract) { public R query(TemporalQuery query) { if (query == TemporalQueries.chronology()) { return (R) IsoChronology.INSTANCE; + } else if (query == TemporalQueries.precision()) { + return (R) WEEKS; } return Temporal.super.query(query); } diff --git a/src/test/java/org/threeten/extra/TestDayOfMonth.java b/src/test/java/org/threeten/extra/TestDayOfMonth.java index fa1f7e24..ff3147b4 100644 --- a/src/test/java/org/threeten/extra/TestDayOfMonth.java +++ b/src/test/java/org/threeten/extra/TestDayOfMonth.java @@ -524,7 +524,7 @@ public void test_query() { assertEquals(null, TEST.query(TemporalQueries.localDate())); assertEquals(null, TEST.query(TemporalQueries.localTime())); assertEquals(null, TEST.query(TemporalQueries.offset())); - assertEquals(null, TEST.query(TemporalQueries.precision())); + assertEquals(ChronoUnit.DAYS, TEST.query(TemporalQueries.precision())); assertEquals(null, TEST.query(TemporalQueries.zone())); assertEquals(null, TEST.query(TemporalQueries.zoneId())); } diff --git a/src/test/java/org/threeten/extra/TestDayOfYear.java b/src/test/java/org/threeten/extra/TestDayOfYear.java index 24952ae0..2e9e605e 100644 --- a/src/test/java/org/threeten/extra/TestDayOfYear.java +++ b/src/test/java/org/threeten/extra/TestDayOfYear.java @@ -405,7 +405,7 @@ public void test_query() { assertEquals(null, TEST.query(TemporalQueries.localDate())); assertEquals(null, TEST.query(TemporalQueries.localTime())); assertEquals(null, TEST.query(TemporalQueries.offset())); - assertEquals(null, TEST.query(TemporalQueries.precision())); + assertEquals(ChronoUnit.DAYS, TEST.query(TemporalQueries.precision())); assertEquals(null, TEST.query(TemporalQueries.zone())); assertEquals(null, TEST.query(TemporalQueries.zoneId())); } diff --git a/src/test/java/org/threeten/extra/TestOffsetDate.java b/src/test/java/org/threeten/extra/TestOffsetDate.java index 7095e3f5..5bc46478 100644 --- a/src/test/java/org/threeten/extra/TestOffsetDate.java +++ b/src/test/java/org/threeten/extra/TestOffsetDate.java @@ -518,6 +518,18 @@ public void test_query_zone() { assertEquals(OFFSET_PONE, TemporalQueries.zone().queryFrom(TEST_2007_07_15_PONE)); } + @Test + public void test_query_localDate() { + assertEquals(TEST_2007_07_15_PONE.toLocalDate(), TEST_2007_07_15_PONE.query(TemporalQueries.localDate())); + assertEquals(TEST_2007_07_15_PONE.toLocalDate(), TemporalQueries.localDate().queryFrom(TEST_2007_07_15_PONE)); + } + + @Test + public void test_query_localTime() { + assertNull(TEST_2007_07_15_PONE.query(TemporalQueries.localTime())); + assertNull(TemporalQueries.localTime().queryFrom(TEST_2007_07_15_PONE)); + } + @Test public void test_query_null() { assertThrows(NullPointerException.class, () -> TEST_2007_07_15_PONE.query(null)); diff --git a/src/test/java/org/threeten/extra/TestYearWeek.java b/src/test/java/org/threeten/extra/TestYearWeek.java index 77a21d39..9a91c129 100644 --- a/src/test/java/org/threeten/extra/TestYearWeek.java +++ b/src/test/java/org/threeten/extra/TestYearWeek.java @@ -1059,7 +1059,7 @@ public void test_query() { assertEquals(null, TEST.query(TemporalQueries.localDate())); assertEquals(null, TEST.query(TemporalQueries.localTime())); assertEquals(null, TEST.query(TemporalQueries.offset())); - assertEquals(null, TEST.query(TemporalQueries.precision())); + assertEquals(ChronoUnit.WEEKS, TEST.query(TemporalQueries.precision())); assertEquals(null, TEST.query(TemporalQueries.zone())); assertEquals(null, TEST.query(TemporalQueries.zoneId())); }