Package org.joda.time
Class PeriodType
- java.lang.Object
-
- org.joda.time.PeriodType
-
- All Implemented Interfaces:
java.io.Serializable
public class PeriodType extends java.lang.Object implements java.io.SerializableControls a period implementation by specifying which duration fields are to be used.The following implementations are provided:
- Standard - years, months, weeks, days, hours, minutes, seconds, millis
- YearMonthDayTime - years, months, days, hours, minutes, seconds, millis
- YearMonthDay - years, months, days
- YearWeekDayTime - years, weeks, days, hours, minutes, seconds, millis
- YearWeekDay - years, weeks, days
- YearDayTime - years, days, hours, minutes, seconds, millis
- YearDay - years, days, hours
- DayTime - days, hours, minutes, seconds, millis
- Time - hours, minutes, seconds, millis
- plus one for each single type
PeriodType is thread-safe and immutable, and all subclasses must be as well.
- Since:
- 1.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static PeriodTypecDaysprivate static PeriodTypecDTimeprivate static PeriodTypecHoursprivate static PeriodTypecMillisprivate static PeriodTypecMinutesprivate static PeriodTypecMonthsprivate static PeriodTypecSecondsprivate static PeriodTypecStandardprivate static PeriodTypecTimeprivate static java.util.Map<PeriodType,java.lang.Object>cTypesCache of all the known types.private static PeriodTypecWeeksprivate static PeriodTypecYDprivate static PeriodTypecYDTimeprivate static PeriodTypecYearsprivate static PeriodTypecYMDprivate static PeriodTypecYMDTimeprivate static PeriodTypecYWDprivate static PeriodTypecYWDTime(package private) static intDAY_INDEX(package private) static intHOUR_INDEXprivate int[]iIndicesThe array of indicesprivate java.lang.StringiNameThe name of the typeprivate DurationFieldType[]iTypesThe array of types(package private) static intMILLI_INDEX(package private) static intMINUTE_INDEX(package private) static intMONTH_INDEX(package private) static intSECOND_INDEXprivate static longserialVersionUIDSerialization version(package private) static intWEEK_INDEX(package private) static intYEAR_INDEX
-
Constructor Summary
Constructors Modifier Constructor Description protectedPeriodType(java.lang.String name, DurationFieldType[] types, int[] indices)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) booleanaddIndexedField(ReadablePeriod period, int index, int[] values, int valueToAdd)Adds to the indexed field part of the period.static PeriodTypedays()Gets a type that defines just the days field.static PeriodTypedayTime()Gets a type that defines all standard fields from days downwards.booleanequals(java.lang.Object obj)Compares this type to another object.static PeriodTypeforFields(DurationFieldType[] types)Gets a period type that contains the duration types of the array.DurationFieldTypegetFieldType(int index)Gets the field type by index.(package private) intgetIndexedField(ReadablePeriod period, int index)Gets the indexed field part of the period.java.lang.StringgetName()Gets the name of the period type.inthashCode()Returns a hashcode based on the field types.static PeriodTypehours()Gets a type that defines just the hours field.intindexOf(DurationFieldType type)Gets the index of the field in this period.booleanisSupported(DurationFieldType type)Checks whether the field specified is supported by this period.static PeriodTypemillis()Gets a type that defines just the millis field.static PeriodTypeminutes()Gets a type that defines just the minutes field.static PeriodTypemonths()Gets a type that defines just the months field.static PeriodTypeseconds()Gets a type that defines just the seconds field.(package private) booleansetIndexedField(ReadablePeriod period, int index, int[] values, int newValue)Sets the indexed field part of the period.intsize()Gets the number of fields in the period type.static PeriodTypestandard()Gets a type that defines all standard fields.static PeriodTypetime()Gets a type that defines all standard time fields.java.lang.StringtoString()Gets a debugging to string.static PeriodTypeweeks()Gets a type that defines just the weeks field.PeriodTypewithDaysRemoved()Returns a version of this PeriodType instance that does not support days.private PeriodTypewithFieldRemoved(int indicesIndex, java.lang.String name)Removes the field specified by indices index.PeriodTypewithHoursRemoved()Returns a version of this PeriodType instance that does not support hours.PeriodTypewithMillisRemoved()Returns a version of this PeriodType instance that does not support milliseconds.PeriodTypewithMinutesRemoved()Returns a version of this PeriodType instance that does not support minutes.PeriodTypewithMonthsRemoved()Returns a version of this PeriodType instance that does not support months.PeriodTypewithSecondsRemoved()Returns a version of this PeriodType instance that does not support seconds.PeriodTypewithWeeksRemoved()Returns a version of this PeriodType instance that does not support weeks.PeriodTypewithYearsRemoved()Returns a version of this PeriodType instance that does not support years.static PeriodTypeyearDay()Gets a type that defines the year and day fields.static PeriodTypeyearDayTime()Gets a type that defines all standard fields except months and weeks.static PeriodTypeyearMonthDay()Gets a type that defines the year, month and day fields.static PeriodTypeyearMonthDayTime()Gets a type that defines all standard fields except weeks.static PeriodTypeyears()Gets a type that defines just the years field.static PeriodTypeyearWeekDay()Gets a type that defines year, week and day fields.static PeriodTypeyearWeekDayTime()Gets a type that defines all standard fields except months.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Serialization version- See Also:
- Constant Field Values
-
cTypes
private static final java.util.Map<PeriodType,java.lang.Object> cTypes
Cache of all the known types.
-
YEAR_INDEX
static int YEAR_INDEX
-
MONTH_INDEX
static int MONTH_INDEX
-
WEEK_INDEX
static int WEEK_INDEX
-
DAY_INDEX
static int DAY_INDEX
-
HOUR_INDEX
static int HOUR_INDEX
-
MINUTE_INDEX
static int MINUTE_INDEX
-
SECOND_INDEX
static int SECOND_INDEX
-
MILLI_INDEX
static int MILLI_INDEX
-
cStandard
private static PeriodType cStandard
-
cYMDTime
private static PeriodType cYMDTime
-
cYMD
private static PeriodType cYMD
-
cYWDTime
private static PeriodType cYWDTime
-
cYWD
private static PeriodType cYWD
-
cYDTime
private static PeriodType cYDTime
-
cYD
private static PeriodType cYD
-
cDTime
private static PeriodType cDTime
-
cTime
private static PeriodType cTime
-
cYears
private static PeriodType cYears
-
cMonths
private static PeriodType cMonths
-
cWeeks
private static PeriodType cWeeks
-
cDays
private static PeriodType cDays
-
cHours
private static PeriodType cHours
-
cMinutes
private static PeriodType cMinutes
-
cSeconds
private static PeriodType cSeconds
-
cMillis
private static PeriodType cMillis
-
iName
private final java.lang.String iName
The name of the type
-
iTypes
private final DurationFieldType[] iTypes
The array of types
-
iIndices
private final int[] iIndices
The array of indices
-
-
Constructor Detail
-
PeriodType
protected PeriodType(java.lang.String name, DurationFieldType[] types, int[] indices)Constructor.- Parameters:
name- the nametypes- the typesindices- the indices
-
-
Method Detail
-
standard
public static PeriodType standard()
Gets a type that defines all standard fields.- years
- months
- weeks
- days
- hours
- minutes
- seconds
- milliseconds
- Returns:
- the period type
-
yearMonthDayTime
public static PeriodType yearMonthDayTime()
Gets a type that defines all standard fields except weeks.- years
- months
- days
- hours
- minutes
- seconds
- milliseconds
- Returns:
- the period type
-
yearMonthDay
public static PeriodType yearMonthDay()
Gets a type that defines the year, month and day fields.- years
- months
- days
- Returns:
- the period type
- Since:
- 1.1
-
yearWeekDayTime
public static PeriodType yearWeekDayTime()
Gets a type that defines all standard fields except months.- years
- weeks
- days
- hours
- minutes
- seconds
- milliseconds
- Returns:
- the period type
-
yearWeekDay
public static PeriodType yearWeekDay()
Gets a type that defines year, week and day fields.- years
- weeks
- days
- Returns:
- the period type
- Since:
- 1.1
-
yearDayTime
public static PeriodType yearDayTime()
Gets a type that defines all standard fields except months and weeks.- years
- days
- hours
- minutes
- seconds
- milliseconds
- Returns:
- the period type
-
yearDay
public static PeriodType yearDay()
Gets a type that defines the year and day fields.- years
- days
- Returns:
- the period type
- Since:
- 1.1
-
dayTime
public static PeriodType dayTime()
Gets a type that defines all standard fields from days downwards.- days
- hours
- minutes
- seconds
- milliseconds
- Returns:
- the period type
-
time
public static PeriodType time()
Gets a type that defines all standard time fields.- hours
- minutes
- seconds
- milliseconds
- Returns:
- the period type
-
years
public static PeriodType years()
Gets a type that defines just the years field.- Returns:
- the period type
-
months
public static PeriodType months()
Gets a type that defines just the months field.- Returns:
- the period type
-
weeks
public static PeriodType weeks()
Gets a type that defines just the weeks field.- Returns:
- the period type
-
days
public static PeriodType days()
Gets a type that defines just the days field.- Returns:
- the period type
-
hours
public static PeriodType hours()
Gets a type that defines just the hours field.- Returns:
- the period type
-
minutes
public static PeriodType minutes()
Gets a type that defines just the minutes field.- Returns:
- the period type
-
seconds
public static PeriodType seconds()
Gets a type that defines just the seconds field.- Returns:
- the period type
-
millis
public static PeriodType millis()
Gets a type that defines just the millis field.- Returns:
- the period type
-
forFields
public static PeriodType forFields(DurationFieldType[] types)
Gets a period type that contains the duration types of the array.Only the 8 standard duration field types are supported.
- Parameters:
types- the types to include in the array.- Returns:
- the period type
- Since:
- 1.1
-
getName
public java.lang.String getName()
Gets the name of the period type.- Returns:
- the name
-
size
public int size()
Gets the number of fields in the period type.- Returns:
- the number of fields
-
getFieldType
public DurationFieldType getFieldType(int index)
Gets the field type by index.- Parameters:
index- the index to retrieve- Returns:
- the field type
- Throws:
java.lang.IndexOutOfBoundsException- if the index is invalid
-
isSupported
public boolean isSupported(DurationFieldType type)
Checks whether the field specified is supported by this period.- Parameters:
type- the type to check, may be null which returns false- Returns:
- true if the field is supported
-
indexOf
public int indexOf(DurationFieldType type)
Gets the index of the field in this period.- Parameters:
type- the type to check, may be null which returns -1- Returns:
- the index of -1 if not supported
-
toString
public java.lang.String toString()
Gets a debugging to string.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string
-
getIndexedField
int getIndexedField(ReadablePeriod period, int index)
Gets the indexed field part of the period.- Parameters:
period- the period to queryindex- the index to use- Returns:
- the value of the field, zero if unsupported
-
setIndexedField
boolean setIndexedField(ReadablePeriod period, int index, int[] values, int newValue)
Sets the indexed field part of the period.- Parameters:
period- the period to queryindex- the index to usevalues- the array to populatenewValue- the value to set- Throws:
java.lang.UnsupportedOperationException- if not supported
-
addIndexedField
boolean addIndexedField(ReadablePeriod period, int index, int[] values, int valueToAdd)
Adds to the indexed field part of the period.- Parameters:
period- the period to queryindex- the index to usevalues- the array to populatevalueToAdd- the value to add- Returns:
- true if the array is updated
- Throws:
java.lang.UnsupportedOperationException- if not supported
-
withYearsRemoved
public PeriodType withYearsRemoved()
Returns a version of this PeriodType instance that does not support years.- Returns:
- a new period type that supports the original set of fields except years
-
withMonthsRemoved
public PeriodType withMonthsRemoved()
Returns a version of this PeriodType instance that does not support months.- Returns:
- a new period type that supports the original set of fields except months
-
withWeeksRemoved
public PeriodType withWeeksRemoved()
Returns a version of this PeriodType instance that does not support weeks.- Returns:
- a new period type that supports the original set of fields except weeks
-
withDaysRemoved
public PeriodType withDaysRemoved()
Returns a version of this PeriodType instance that does not support days.- Returns:
- a new period type that supports the original set of fields except days
-
withHoursRemoved
public PeriodType withHoursRemoved()
Returns a version of this PeriodType instance that does not support hours.- Returns:
- a new period type that supports the original set of fields except hours
-
withMinutesRemoved
public PeriodType withMinutesRemoved()
Returns a version of this PeriodType instance that does not support minutes.- Returns:
- a new period type that supports the original set of fields except minutes
-
withSecondsRemoved
public PeriodType withSecondsRemoved()
Returns a version of this PeriodType instance that does not support seconds.- Returns:
- a new period type that supports the original set of fields except seconds
-
withMillisRemoved
public PeriodType withMillisRemoved()
Returns a version of this PeriodType instance that does not support milliseconds.- Returns:
- a new period type that supports the original set of fields except milliseconds
-
withFieldRemoved
private PeriodType withFieldRemoved(int indicesIndex, java.lang.String name)
Removes the field specified by indices index.- Parameters:
indicesIndex- the index to removename- the name addition- Returns:
- the new type
-
equals
public boolean equals(java.lang.Object obj)
Compares this type to another object. To be equal, the object must be a PeriodType with the same set of fields.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the object to compare to- Returns:
- true if equal
-
hashCode
public int hashCode()
Returns a hashcode based on the field types.- Overrides:
hashCodein classjava.lang.Object- Returns:
- a suitable hashcode
-
-