Creates a new instance of the builder with a single field-value.
Creates a new instance of the builder with a single field-value.
This is equivalent to using #addFieldValue(TemporalField, long)
on an empty builder.
the field to add, not null
the value to add, not null
Builds the specified type from the values in this builder.
Builds the specified type from the values in this builder.
This attempts to build the specified type from this builder. If the builder cannot return the type, an exception is thrown.
the type to return
the type to invoke { @code from} on, not null
the extracted value, not null
if an error occurs
Gets the value of the specified field as an int
.
Gets the value of the specified field as an int
.
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.
Implementations must check and handle all fields defined in ChronoField
.
If the field is supported and has an int
range, then the value of
the field must be returned.
If unsupported, then a DateTimeException
must be thrown.
If the field is not a ChronoField
, then the result of this method
is obtained by invoking TemporalField.getFrom(TemporalAccessor)
passing this
as the argument.
Implementations must not alter either this object.
the field to get, not null
the value for the field, within the valid range of values
if numeric overflow occurs
DateTimeExceptionif the value is outside the range of valid values for the field
Gets the value of the specified field as a long
.
Gets the value of the specified field as a long
.
This queries the date-time for the value for the specified field. The returned value may be outside 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.
Implementations must check and handle all fields defined in ChronoField
.
If the field is supported, then the value of the field must be returned.
If unsupported, then a DateTimeException
must be thrown.
If the field is not a ChronoField
, then the result of this method
is obtained by invoking TemporalField.getFrom(TemporalAccessor)
passing this
as the argument.
Implementations must not alter either this object.
the field to get, not null
the value for the field
if numeric overflow occurs
DateTimeExceptionif a value for the field cannot be obtained
Checks if the specified field is supported.
Checks if the specified field is supported.
This checks if the date-time can be queried for the specified field.
If false, then calling the #range(TemporalField) range
and #get(TemporalField) get
methods will throw an exception.
Implementations must check and handle all fields defined in ChronoField
.
If the field is supported, then true is returned, otherwise false
If the field is not a ChronoField
, then the result of this method
is obtained by invoking TemporalField.isSupportedBy(TemporalAccessor)
passing this
as the argument.
Implementations must not alter this object.
the field to check, null returns false
true if this date-time can be queried for the field, false if not
Queries this date-time.
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
and ZoneId::from
.
Further implementations are on TemporalQueries
.
Queries may also be defined by applications.
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); }
the type of the result
the query to invoke, not null
the query result, null may be returned (defined by the query)
if numeric overflow occurs
DateTimeExceptionif unable to query
Gets the range of valid values for the specified field.
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.
Implementations must check and handle all fields defined in ChronoField
.
If the field is supported, then the range of the field must be returned.
If unsupported, then a DateTimeException
must be thrown.
If the field is not a ChronoField
, then the result of this method
is obtained by invoking TemporalField.rangeRefinedBy(TemporalAccessorl)
passing this
as the argument.
Implementations must not alter either this object.
the field to query the range for, not null
the range of valid values for the field, not null
if the range for the field cannot be obtained
Resolves the builder, evaluating the date and time.
Resolves the builder, evaluating the date and time.
This examines the contents of the builder and resolves it to produce the best available date and time, throwing an exception if a problem occurs. Calling this method changes the state of the builder.
how to resolve
{ @code this}, for method chaining
Builder that can holds date and time fields and related date and time objects.
The builder is used to hold onto different elements of date and time. It is designed as two separate maps:
TemporalField
tolong
value, where the value may be outside the valid range for the fieldClass
toTemporalAccessor
, holding larger scale objects likeLocalDateTime
.Specification for implementors
This class is mutable and not thread-safe. It should only be used from a single thread.
Creates an empty instance of the builder.