TemporalQuery.
This class provides common implementations of TemporalQuery.
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.
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.
The TemporalField interface provides another mechanism for querying
temporal objects. That interface is limited to returning a long.
By contrast, queries can return any type.
There are two equivalent ways of using a TemporalQuery.
The first is to invoke the method on this interface directly.
The second is to use TemporalAccessor#query(TemporalQuery):
// these two lines are equivalent, but the second approach is recommended result = thisQuery.queryFrom(temporal); result = temporal.query(thisQuery);It is recommended to use the second approach,
query(thisQuery),
as it is a lot clearer to read in code.
The most common implementations are method references, such as
LocalDate::from and ZoneId::from.
Additional common queries are provided to return:
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final TemporalQuery | CHRONO
A query for the |
| pack-priv static final TemporalQuery | LOCAL_DATE
A query for |
| pack-priv static final TemporalQuery | LOCAL_TIME
A query for |
| pack-priv static final TemporalQuery | OFFSET
A query for |
| pack-priv static final TemporalQuery | PRECISION
A query for the smallest supported unit. |
| pack-priv static final TemporalQuery | ZONE
A lenient query for the |
| pack-priv static final TemporalQuery | ZONE_ID
A strict query for the |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static TemporalQuery | Returns: a query that can obtain the chronology of a temporal, not nullA query for the |
| public static TemporalQuery | Returns: a query that can obtain the date of a temporal, not nullA query for |
| public static TemporalQuery | Returns: a query that can obtain the time of a temporal, not nullA query for |
| public static TemporalQuery | Returns: a query that can obtain the offset of a temporal, not nullA query for |
| public static TemporalQuery | Returns: a query that can obtain the precision of a temporal, not nullA query for the smallest supported unit. |
| public static TemporalQuery | Returns: a query that can obtain the zone ID or offset of a temporal, not nullA lenient query for the |
| public static TemporalQuery | Returns: a query that can obtain the zone ID of a temporal, not nullA strict query for the |
| CHRONO | back to summary |
|---|---|
| pack-priv static final TemporalQuery<Chronology> CHRONO A query for the | |
| LOCAL_DATE | back to summary |
|---|---|
| pack-priv static final TemporalQuery<LocalDate> LOCAL_DATE A query for | |
| LOCAL_TIME | back to summary |
|---|---|
| pack-priv static final TemporalQuery<LocalTime> LOCAL_TIME A query for | |
| OFFSET | back to summary |
|---|---|
| pack-priv static final TemporalQuery<ZoneOffset> OFFSET A query for | |
| PRECISION | back to summary |
|---|---|
| pack-priv static final TemporalQuery<TemporalUnit> PRECISION A query for the smallest supported unit. | |
| ZONE | back to summary |
|---|---|
| pack-priv static final TemporalQuery<ZoneId> ZONE A lenient query for the | |
| ZONE_ID | back to summary |
|---|---|
| pack-priv static final TemporalQuery<ZoneId> ZONE_ID A strict query for the | |
| TemporalQueries | back to summary |
|---|---|
| private TemporalQueries() Private constructor since this is a utility class. | |
| chronology | back to summary |
|---|---|
| public static TemporalQuery A query for the
This queries a
The result from JDK classes implementing
The method
| |
| localDate | back to summary |
|---|---|
| public static TemporalQuery A query for
This returns a
The query implementation examines the
The method
| |
| localTime | back to summary |
|---|---|
| public static TemporalQuery A query for
This returns a
The query implementation examines the
The method
| |
| offset | back to summary |
|---|---|
| public static TemporalQuery A query for
This returns a
The query implementation examines the
The method
| |
| precision | back to summary |
|---|---|
| public static TemporalQuery A query for the smallest supported unit.
This queries a
The result from JDK classes implementing
| |
| zone | back to summary |
|---|---|
| public static TemporalQuery A lenient query for the
This queries a
In most cases, applications should use this query rather than
The method
| |
| zoneId | back to summary |
|---|---|
| public static TemporalQuery A strict query for the
This queries a
In most cases, applications should use
The result from JDK classes implementing
| |