Class DefaultInterfaceTemporalAccessor
- java.lang.Object
-
- org.threeten.bp.jdk8.DefaultInterfaceTemporalAccessor
-
- All Implemented Interfaces:
TemporalAccessor
- Direct Known Subclasses:
DefaultInterfaceEra
,DefaultInterfaceTemporal
,Instant
,LocalTime
,MonthDay
,OffsetTime
,Year
,YearMonth
public abstract class DefaultInterfaceTemporalAccessor extends Object implements TemporalAccessor
A temporary class providing implementations that will become default interface methods once integrated into JDK 8.
-
-
Constructor Summary
Constructors Constructor Description DefaultInterfaceTemporalAccessor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
get(TemporalField field)
Gets the value of the specified field as anint
.<R> R
query(TemporalQuery<R> query)
Queries this date-time.ValueRange
range(TemporalField field)
Gets the range of valid values for the specified field.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.threeten.bp.temporal.TemporalAccessor
getLong, isSupported
-
-
-
-
Method Detail
-
range
public ValueRange range(TemporalField field)
Description copied from interface:TemporalAccessor
Gets the range of valid values for the specified field.All fields can be expressed as a
long
integer. This method returns an object that describes the valid range for that value. The value of this temporal object is used to enhance the accuracy of the returned range. If the date-time cannot return the range, because the field is unsupported or for some other reason, an exception will be thrown.Note that the result only describes the minimum and maximum valid values and it is important not to read too much into them. For example, there could be values within the range that are invalid for the field.
Specification for implementors
Implementations must check and handle all fields defined inChronoField
. If the field is supported, then the range of the field must be returned. If unsupported, then aDateTimeException
must be thrown.If the field is not a
ChronoField
, then the result of this method is obtained by invokingTemporalField.rangeRefinedBy(TemporalAccessorl)
passingthis
as the argument.Implementations must not alter either this object.
- Specified by:
range
in interfaceTemporalAccessor
- Parameters:
field
- the field to query the range for, not null- Returns:
- the range of valid values for the field, not null
-
get
public int get(TemporalField field)
Description copied from interface:TemporalAccessor
Gets the value of the specified field as anint
.This queries the date-time for the value for the specified field. The returned value will always be within the valid range of values for the field. If the date-time cannot return the value, because the field is unsupported or for some other reason, an exception will be thrown.
Specification for implementors
Implementations must check and handle all fields defined inChronoField
. If the field is supported and has anint
range, then the value of the field must be returned. If unsupported, then aDateTimeException
must be thrown.If the field is not a
ChronoField
, then the result of this method is obtained by invokingTemporalField.getFrom(TemporalAccessor)
passingthis
as the argument.Implementations must not alter either this object.
- Specified by:
get
in interfaceTemporalAccessor
- Parameters:
field
- the field to get, not null- Returns:
- the value for the field, within the valid range of values
-
query
public <R> R query(TemporalQuery<R> query)
Description copied from interface:TemporalAccessor
Queries this date-time.This queries this date-time using the specified query strategy object.
Queries are a key tool for extracting information from date-times. They exists 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 most common query implementations are method references, such as
LocalDate::from
andZoneId::from
. Further implementations are onTemporalQueries
. Queries may also be defined by applications.Specification for implementors
Implementations of this method must behave as follows:public <R> R query(TemporalQuery<R> type) { // only include an if statement if the implementation can return it if (query == TemporalQueries.zoneId()) return // the ZoneId if (query == TemporalQueries.chronology()) return // the Chrono if (query == TemporalQueries.precision()) return // the precision // call default method return super.query(query); }
- Specified by:
query
in interfaceTemporalAccessor
- Type Parameters:
R
- the type of the result- Parameters:
query
- the query to invoke, not null- Returns:
- the query result, null may be returned (defined by the query)
-
-