public final class DateTimeFields extends Object implements Calendrical, CalendricalMatcher, Iterable<DateTimeFieldRule<?>>, Serializable
Instances of this class store a map of field-value pairs. Together these specify constraints on the dates and times that match. For example, if an instance stores 'DayOfMonth=13' and 'DayOfWeek=Friday' then it represents and matches only dates of Friday the Thirteenth.
All the values will be within the valid range for the field. However, there is no cross validation between fields. Thus, it is possible for the date-time represented to never exist. For example, if an instance stores 'DayOfMonth=31' and 'MonthOfYear=February' then there will never be a matching date.
Modifier and Type | Field and Description |
---|---|
static DateTimeFields |
EMPTY
A singleton empty
DateTimeFields , placing no restrictions on the date-time. |
Modifier and Type | Method and Description |
---|---|
boolean |
contains(DateTimeFieldRule<?> fieldRule)
Checks if this object contains a mapping for the specified field.
|
boolean |
equals(Object obj)
Is this object equal to the specified object.
|
<T> T |
get(CalendricalRule<T> rule)
Gets the value of the specified calendrical rule.
|
int |
getInt(DateTimeFieldRule<?> rule)
Gets the value for the specified field throwing an exception if the
field is not in the field-value map.
|
Integer |
getQuiet(DateTimeFieldRule<?> fieldRule)
Gets the value for the specified field quietly returning null
if the field is not in the field-value map.
|
int |
hashCode()
A hash code for these fields.
|
Iterator<DateTimeFieldRule<?>> |
iterator()
Iterates through all the field rules.
|
boolean |
matchesCalendrical(Calendrical calendrical)
Checks if the fields in this object match those in the specified calendrical.
|
static DateTimeFields |
of(DateTimeFieldRule<?> fieldRule,
int value)
Obtains an instance of
DateTimeFields from a field-value pair. |
static DateTimeFields |
of(DateTimeFieldRule<?> fieldRule1,
int value1,
DateTimeFieldRule<?> fieldRule2,
int value2)
Obtains an instance of
DateTimeFields from two field-value pairs. |
static DateTimeFields |
of(Map<DateTimeFieldRule<?>,Integer> fieldValueMap)
Obtains an instance of
DateTimeFields from a map of field-value pairs. |
int |
size()
Returns the size of the map of fields to values.
|
SortedMap<DateTimeFieldRule<?>,Integer> |
toFieldValueMap()
Converts this object to a map of fields to values.
|
String |
toString()
Outputs the fields as a
String . |
DateTimeFields |
with(DateTimeFieldRule<?> fieldRule,
int value)
Returns a copy of this DateTimeFields with the specified field value.
|
DateTimeFields |
with(DateTimeFields fields)
Returns a copy of this DateTimeFields with the specified fields added.
|
DateTimeFields |
withFieldRemoved(DateTimeFieldRule<?> fieldRule)
Returns a copy of this object with the specified field removed.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public static final DateTimeFields EMPTY
DateTimeFields
, placing no restrictions on the date-time.public static DateTimeFields of(DateTimeFieldRule<?> fieldRule, int value)
DateTimeFields
from a field-value pair.
This factory allows the creation of a fields object with a single field-value pair. The value must be within the valid range for the field.
fieldRule
- the rule, not nullvalue
- the field value, may be invalidNullPointerException
- if the field rule is nullIllegalCalendarFieldValueException
- if the value is invalidpublic static DateTimeFields of(DateTimeFieldRule<?> fieldRule1, int value1, DateTimeFieldRule<?> fieldRule2, int value2)
DateTimeFields
from two field-value pairs.
This factory allows the creation of a fields object with two field-value pairs. Each value must be within the valid range for that field.
The two fields are not cross-validated. Thus, you can specify MonthOfYear of June and DayOfMonth of 31, which is a date that can never occur.
fieldRule1
- the first rule, not nullvalue1
- the first field valuefieldRule2
- the second rule, not nullvalue2
- the second field valueNullPointerException
- if either field rule is nullIllegalCalendarFieldValueException
- if either value is invalidpublic static DateTimeFields of(Map<DateTimeFieldRule<?>,Integer> fieldValueMap)
DateTimeFields
from a map of field-value pairs.
This factory allows the creation of a fields object from a map of field-value pairs. Each value must be within the valid range for that field.
The fields are not cross-validated. Thus, you can specify MonthOfYear of June and DayOfMonth of 31, which is a date that can never occur.
fieldValueMap
- a map of fields that will be used to create a field set,
not updated by this factory, not null, contains no nullsNullPointerException
- if the map contains null keys or valuesIllegalCalendarFieldValueException
- if any value is invalidpublic int size()
This method returns the number of field-value pairs stored.
public Iterator<DateTimeFieldRule<?>> iterator()
This method fulfills the Iterable
interface and allows looping
around the fields using the for-each loop. The values can be obtained using
get(javax.time.calendar.CalendricalRule<T>)
or getInt(javax.time.calendar.DateTimeFieldRule<?>)
.
iterator
in interface Iterable<DateTimeFieldRule<?>>
public boolean contains(DateTimeFieldRule<?> fieldRule)
This method returns true if a value can be obtained for the specified field.
fieldRule
- the field to query, null returns falsepublic <T> T get(CalendricalRule<T> rule)
This method queries the value of the specified calendrical rule.
If the value cannot be returned for the rule from this instance then
an attempt is made to derive the value.
If that fails, null
will be returned.
get
in interface Calendrical
rule
- the rule to use, not nullpublic int getInt(DateTimeFieldRule<?> rule)
The value will be within the valid range for the field.
No attempt is made to derive values. The result is simply based on
the contents of the stored field-value map. If you want to derive a
value then use get(javax.time.calendar.CalendricalRule<T>)
or a CalendricalMerger
.
rule
- the rule to query from the map, not nullUnsupportedRuleException
- if the field is not in the mappublic Integer getQuiet(DateTimeFieldRule<?> fieldRule)
The value will be within the valid range for the field.
fieldRule
- the rule to query from the map, null returns nullpublic DateTimeFields with(DateTimeFieldRule<?> fieldRule, int value)
If this instance already has a value for the field then the value is replaced. Otherwise the value is added to the map.
This instance is immutable and unaffected by this method call.
fieldRule
- the field to set in the returned object, not nullvalue
- the value to set in the returned set of fieldsNullPointerException
- if DateTimeFieldRule is nullIllegalCalendarFieldValueException
- if the value is invalidpublic DateTimeFields with(DateTimeFields fields)
If this instance already has a value for the field then the value is replaced. Otherwise the value is added.
This instance is immutable and unaffected by this method call.
fields
- the fields to add to the returned object, not nullpublic DateTimeFields withFieldRemoved(DateTimeFieldRule<?> fieldRule)
If this instance does not contain the field then the returned instance is the same as this one.
This instance is immutable and unaffected by this method call.
fieldRule
- the field to remove from the returned object, not nullpublic boolean matchesCalendrical(Calendrical calendrical)
This implementation checks that all calendrical fields in this object match.
matchesCalendrical
in interface CalendricalMatcher
calendrical
- the calendrical to match, not nullpublic SortedMap<DateTimeFieldRule<?>,Integer> toFieldValueMap()
The returned map will never be null, however it may be empty. It is independent of this object - changes will not be reflected back.
public boolean equals(Object obj)
This compares the map of field-value pairs.
public int hashCode()
Copyright © 2014. All rights reserved.