public final class Partial extends AbstractPartial implements ReadablePartial, java.io.Serializable
A Partial instance can be used to hold any combination of fields. The instance does not contain a time zone, so any datetime is local.
A Partial can be matched against an instant using isMatch(ReadableInstant)
.
This method compares each field on this partial with those of the instant
and determines if the partial matches the instant.
Given this definition, an empty Partial instance represents any datetime
and always matches.
Calculations on Partial are performed using a Chronology
.
This chronology is set to be in the UTC time zone for all calculations.
Each individual field can be queried in two ways:
get(DateTimeFieldType.monthOfYear())
property(DateTimeFieldType.monthOfYear()).get()
monthOfYear().get()
monthOfYear().getAsText()
monthOfYear().getAsShortText()
monthOfYear().getMaximumValue()
monthOfYear().addToCopy()
monthOfYear().setCopy()
Partial is thread-safe and immutable, provided that the Chronology is as well. All standard Chronology classes supplied are thread-safe and immutable.
Modifier and Type | Class and Description |
---|---|
static class |
Partial.Property
The property class for
Partial . |
Constructor and Description |
---|
Partial()
Constructs a Partial with no fields or values, which can be considered
to represent any date.
|
Partial(Chronology chrono)
Constructs a Partial with no fields or values, which can be considered
to represent any date.
|
Partial(DateTimeFieldType[] types,
int[] values)
Constructs a Partial with the specified fields and values.
|
Partial(DateTimeFieldType[] types,
int[] values,
Chronology chronology)
Constructs a Partial with the specified fields and values.
|
Partial(DateTimeFieldType type,
int value)
Constructs a Partial with the specified field and value.
|
Partial(DateTimeFieldType type,
int value,
Chronology chronology)
Constructs a Partial with the specified field and value.
|
Partial(ReadablePartial partial)
Constructs a Partial by copying all the fields and types from
another partial.
|
Modifier and Type | Method and Description |
---|---|
Chronology |
getChronology()
Gets the chronology of the partial which is never null.
|
DateTimeFieldType |
getFieldType(int index)
Gets the field type at the specified index.
|
DateTimeFieldType[] |
getFieldTypes()
Gets an array of the field type of each of the fields that
this partial supports.
|
DateTimeFormatter |
getFormatter()
Gets a formatter suitable for the fields in this partial.
|
int |
getValue(int index)
Gets the value of the field at the specified index.
|
int[] |
getValues()
Gets an array of the value of each of the fields that
this partial supports.
|
boolean |
isMatch(ReadableInstant instant)
Does this partial match the specified instant.
|
boolean |
isMatch(ReadablePartial partial)
Does this partial match the specified partial.
|
Partial |
minus(ReadablePeriod period)
Gets a copy of this instance with the specified period take away.
|
Partial |
plus(ReadablePeriod period)
Gets a copy of this instance with the specified period added.
|
Partial.Property |
property(DateTimeFieldType type)
Gets the property object for the specified type, which contains
many useful methods for getting and manipulating the partial.
|
int |
size()
Gets the number of fields in this partial.
|
java.lang.String |
toString()
Output the date in an appropriate ISO8601 format.
|
java.lang.String |
toString(java.lang.String pattern)
Output the date using the specified format pattern.
|
java.lang.String |
toString(java.lang.String pattern,
java.util.Locale locale)
Output the date using the specified format pattern.
|
java.lang.String |
toStringList()
Gets a string version of the partial that lists all the fields.
|
Partial |
with(DateTimeFieldType fieldType,
int value)
Gets a copy of this date with the specified field set to a new value.
|
Partial |
withChronologyRetainFields(Chronology newChronology)
Creates a new Partial instance with the specified chronology.
|
Partial |
withField(DateTimeFieldType fieldType,
int value)
Gets a copy of this Partial with the specified field set to a new value.
|
Partial |
withFieldAdded(DurationFieldType fieldType,
int amount)
Gets a copy of this Partial with the value of the specified field increased.
|
Partial |
withFieldAddWrapped(DurationFieldType fieldType,
int amount)
Gets a copy of this Partial with the value of the specified field increased.
|
Partial |
without(DateTimeFieldType fieldType)
Gets a copy of this date with the specified field removed.
|
Partial |
withPeriodAdded(ReadablePeriod period,
int scalar)
Gets a copy of this Partial with the specified period added.
|
compareTo, equals, get, getField, getFields, hashCode, indexOf, isAfter, isBefore, isEqual, isSupported, toDateTime, toString
equals, get, getField, hashCode, isSupported, toDateTime
public Partial()
This is most useful when constructing partials, for example:
Partial p = new Partial() .with(DateTimeFieldType.dayOfWeek(), 5) .with(DateTimeFieldType.hourOfDay(), 12) .with(DateTimeFieldType.minuteOfHour(), 20);Note that, although this is a clean way to write code, it is fairly inefficient internally.
The constructor uses the default ISO chronology.
public Partial(Chronology chrono)
This is most useful when constructing partials, for example:
Partial p = new Partial(chrono) .with(DateTimeFieldType.dayOfWeek(), 5) .with(DateTimeFieldType.hourOfDay(), 12) .with(DateTimeFieldType.minuteOfHour(), 20);Note that, although this is a clean way to write code, it is fairly inefficient internally.
chrono
- the chronology, null means ISOpublic Partial(DateTimeFieldType type, int value)
The constructor uses the default ISO chronology.
type
- the single type to create the partial from, not nullvalue
- the value to storejava.lang.IllegalArgumentException
- if the type or value is invalidpublic Partial(DateTimeFieldType type, int value, Chronology chronology)
The constructor uses the specified chronology.
type
- the single type to create the partial from, not nullvalue
- the value to storechronology
- the chronology, null means ISOjava.lang.IllegalArgumentException
- if the type or value is invalidpublic Partial(DateTimeFieldType[] types, int[] values)
The constructor uses the specified chronology.
types
- the types to create the partial from, not nullvalues
- the values to store, not nulljava.lang.IllegalArgumentException
- if the types or values are invalidpublic Partial(DateTimeFieldType[] types, int[] values, Chronology chronology)
The constructor uses the specified chronology.
types
- the types to create the partial from, not nullvalues
- the values to store, not nullchronology
- the chronology, null means ISOjava.lang.IllegalArgumentException
- if the types or values are invalidpublic Partial(ReadablePartial partial)
This is most useful when copying from a YearMonthDay or TimeOfDay.
public int size()
size
in interface ReadablePartial
public Chronology getChronology()
The Chronology
is the calculation engine behind the partial and
provides conversion and validation of the fields in a particular calendar system.
getChronology
in interface ReadablePartial
public DateTimeFieldType getFieldType(int index)
getFieldType
in interface ReadablePartial
getFieldType
in class AbstractPartial
index
- the index to retrievejava.lang.IndexOutOfBoundsException
- if the index is invalidpublic DateTimeFieldType[] getFieldTypes()
The fields are returned largest to smallest.
getFieldTypes
in class AbstractPartial
public int getValue(int index)
getValue
in interface ReadablePartial
index
- the indexjava.lang.IndexOutOfBoundsException
- if the index is invalidpublic int[] getValues()
The fields are returned largest to smallest.
Each value corresponds to the same array index as getFieldTypes()
getValues
in class AbstractPartial
public Partial withChronologyRetainFields(Chronology newChronology)
This method retains the values of the fields, thus the result will typically refer to a different instant.
The time zone of the specified chronology is ignored, as Partial operates without a time zone.
newChronology
- the new chronology, null means ISOjava.lang.IllegalArgumentException
- if the values are invalid for the new chronologypublic Partial with(DateTimeFieldType fieldType, int value)
If this partial did not previously support the field, the new one will.
Contrast this behaviour with withField(DateTimeFieldType, int)
.
For example, if the field type is dayOfMonth
then the day
would be changed/added in the returned instance.
fieldType
- the field type to set, not nullvalue
- the value to setjava.lang.IllegalArgumentException
- if the value is null or invalidpublic Partial without(DateTimeFieldType fieldType)
If this partial did not previously support the field, no error occurs.
fieldType
- the field type to remove, may be nullpublic Partial withField(DateTimeFieldType fieldType, int value)
If this partial does not support the field, an exception is thrown.
Contrast this behaviour with with(DateTimeFieldType, int)
.
For example, if the field type is dayOfMonth
then the day
would be changed in the returned instance if supported.
fieldType
- the field type to set, not nullvalue
- the value to setjava.lang.IllegalArgumentException
- if the value is null or invalidpublic Partial withFieldAdded(DurationFieldType fieldType, int amount)
If the addition is zero, then this
is returned.
The addition will overflow into larger fields (eg. minute to hour).
However, it will not wrap around if the top maximum is reached.
fieldType
- the field type to add to, not nullamount
- the amount to addjava.lang.IllegalArgumentException
- if the value is null or invalidjava.lang.ArithmeticException
- if the new datetime exceeds the capacitypublic Partial withFieldAddWrapped(DurationFieldType fieldType, int amount)
If the addition is zero, then this
is returned.
The addition will overflow into larger fields (eg. minute to hour).
If the maximum is reached, the addition will wra.
fieldType
- the field type to add to, not nullamount
- the amount to addjava.lang.IllegalArgumentException
- if the value is null or invalidjava.lang.ArithmeticException
- if the new datetime exceeds the capacitypublic Partial withPeriodAdded(ReadablePeriod period, int scalar)
If the addition is zero, then this
is returned.
Fields in the period that aren't present in the partial are ignored.
This method is typically used to add multiple copies of complex
period instances. Adding one field is best achieved using the method
withFieldAdded(DurationFieldType, int)
.
period
- the period to add to this one, null means zeroscalar
- the amount of times to add, such as -1 to subtract oncejava.lang.ArithmeticException
- if the new datetime exceeds the capacitypublic Partial plus(ReadablePeriod period)
If the amount is zero or null, then this
is returned.
period
- the duration to add to this one, null means zerojava.lang.ArithmeticException
- if the new datetime exceeds the capacity of a longpublic Partial minus(ReadablePeriod period)
If the amount is zero or null, then this
is returned.
period
- the period to reduce this instant byjava.lang.ArithmeticException
- if the new datetime exceeds the capacity of a longpublic Partial.Property property(DateTimeFieldType type)
See also ReadablePartial.get(DateTimeFieldType)
.
type
- the field type to get the property for, not nulljava.lang.IllegalArgumentException
- if the field is null or unsupportedpublic boolean isMatch(ReadableInstant instant)
A match occurs when all the fields of this partial are the same as the corresponding fields on the specified instant.
instant
- an instant to check against, null means now in default zonepublic boolean isMatch(ReadablePartial partial)
A match occurs when all the fields of this partial are the same as the corresponding fields on the specified partial.
partial
- a partial to check against, must not be nulljava.lang.IllegalArgumentException
- if the partial is nulljava.lang.IllegalArgumentException
- if the fields of the two partials do not matchpublic DateTimeFormatter getFormatter()
If there is no appropriate ISO format, null is returned. This method may return a formatter that does not display all the fields of the partial. This might occur when you have overlapping fields, such as dayOfWeek and dayOfMonth.
public java.lang.String toString()
This method will output the partial in one of two ways.
If getFormatter()
If there is no appropriate ISO format a dump of the fields is output
via toStringList()
.
toString
in interface ReadablePartial
toString
in class java.lang.Object
public java.lang.String toStringList()
This method exists to provide a better debugging toString than the standard toString. This method lists all the fields and their values in a style similar to the collections framework.
public java.lang.String toString(java.lang.String pattern)
pattern
- the pattern specification, null means use toString
DateTimeFormat
public java.lang.String toString(java.lang.String pattern, java.util.Locale locale)
pattern
- the pattern specification, null means use toString
locale
- Locale to use, null means defaultDateTimeFormat
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"