public abstract class AbstractPeriod extends Object implements ReadablePeriod
This class should generally not be used directly by API users. The
ReadablePeriod interface should be used when different
kinds of periods are to be referenced.
AbstractPeriod subclasses may be mutable and not thread-safe.
| 限定符 | 构造器和说明 |
|---|---|
protected |
AbstractPeriod()
Constructor.
|
| 限定符和类型 | 方法和说明 |
|---|---|
boolean |
equals(Object period)
Compares this object with the specified object for equality based
on the value of each field.
|
int |
get(DurationFieldType type)
Gets the value of one of the fields.
|
DurationFieldType |
getFieldType(int index)
Gets the field type at the specified index.
|
DurationFieldType[] |
getFieldTypes()
Gets an array of the field types that this period supports.
|
int[] |
getValues()
Gets an array of the value of each of the fields that this period supports.
|
int |
hashCode()
Gets a hash code for the period as defined by ReadablePeriod.
|
int |
indexOf(DurationFieldType type)
Gets the index of the field in this period.
|
boolean |
isSupported(DurationFieldType type)
Checks whether the field specified is supported by this period.
|
int |
size()
Gets the number of fields that this period supports.
|
MutablePeriod |
toMutablePeriod()
Get this object as a
MutablePeriod. |
Period |
toPeriod()
Get this period as an immutable
Period object. |
String |
toString()
Gets the value as a String in the ISO8601 duration format.
|
String |
toString(PeriodFormatter formatter)
Uses the specified formatter to convert this period to a String.
|
getPeriodType, getValuepublic int size()
size 在接口中 ReadablePeriodpublic DurationFieldType getFieldType(int index)
getFieldType 在接口中 ReadablePeriodindex - the index to retrieveIndexOutOfBoundsException - if the index is invalidpublic DurationFieldType[] getFieldTypes()
The fields are returned largest to smallest, for example Hours, Minutes, Seconds.
public int[] getValues()
The fields are returned largest to smallest, for example Hours, Minutes, Seconds.
Each value corresponds to the same array index as getFields()
public int get(DurationFieldType type)
If the field type specified is not supported by the period then zero is returned.
get 在接口中 ReadablePeriodtype - the field type to query, null returns zeropublic boolean isSupported(DurationFieldType type)
isSupported 在接口中 ReadablePeriodtype - the type to check, may be null which returns falsepublic int indexOf(DurationFieldType type)
type - the type to check, may be null which returns -1public Period toPeriod()
Period object.toPeriod 在接口中 ReadablePeriodpublic MutablePeriod toMutablePeriod()
MutablePeriod.
This will always return a new MutablePeriod with the same fields.
toMutablePeriod 在接口中 ReadablePeriodpublic boolean equals(Object period)
Note that a period of 1 day is not equal to a period of 24 hours, nor is 1 hour equal to 60 minutes. Only periods with the same amount in each field are equal.
This is because periods represent an abstracted definition of a time period (eg. a day may not actually be 24 hours, it might be 23 or 25 at daylight savings boundary).
To compare the actual duration of two periods, convert both to
Durations, an operation that emphasises
that the result may differ according to the date you choose.
equals 在接口中 ReadablePeriodequals 在类中 Objectperiod - a readable period to check againstpublic int hashCode()
hashCode 在接口中 ReadablePeriodhashCode 在类中 Objectpublic String toString()
For example, "PT6H3M7S" represents 6 hours, 3 minutes, 7 seconds.
For more control over the output, see
PeriodFormatterBuilder.
toString 在接口中 ReadablePeriodtoString 在类中 Objectpublic String toString(PeriodFormatter formatter)
formatter - the formatter to use, null means use toString().Copyright © 2019. All rights reserved.