org.joda.time

Class PeriodType

Implemented Interfaces:
Serializable

public class PeriodType
extends java.lang.Object
implements Serializable

Controls a period implementation by specifying which duration fields are to be used.

The following implementations are provided:

PeriodType is thread-safe and immutable, and all subclasses must be as well.

Authors:
Brian S O'Neill
Stephen Colebourne
Since:
1.0

Constructor Summary

PeriodType(String name, DurationFieldType[] types, int[] indices)
Constructor.

Method Summary

static PeriodType
dayTime()
Gets a type that defines all standard fields from days downwards.
static PeriodType
days()
Gets a type that defines just the days field.
boolean
equals(Object obj)
Compares this type to another object.
static PeriodType
forFields(DurationFieldType[] types)
Gets a period type that contains the duration types of the array.
DurationFieldType
getFieldType(int index)
Gets the field type by index.
String
getName()
Gets the name of the period type.
int
hashCode()
Returns a hashcode based on the field types.
static PeriodType
hours()
Gets a type that defines just the hours field.
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.
static PeriodType
millis()
Gets a type that defines just the millis field.
static PeriodType
minutes()
Gets a type that defines just the minutes field.
static PeriodType
months()
Gets a type that defines just the months field.
static PeriodType
seconds()
Gets a type that defines just the seconds field.
int
size()
Gets the number of fields in the period type.
static PeriodType
standard()
Gets a type that defines all standard fields.
static PeriodType
time()
Gets a type that defines all standard time fields.
String
toString()
Gets a debugging to string.
static PeriodType
weeks()
Gets a type that defines just the weeks field.
PeriodType
withDaysRemoved()
Returns a version of this PeriodType instance that does not support days.
PeriodType
withHoursRemoved()
Returns a version of this PeriodType instance that does not support hours.
PeriodType
withMillisRemoved()
Returns a version of this PeriodType instance that does not support milliseconds.
PeriodType
withMinutesRemoved()
Returns a version of this PeriodType instance that does not support minutes.
PeriodType
withMonthsRemoved()
Returns a version of this PeriodType instance that does not support months.
PeriodType
withSecondsRemoved()
Returns a version of this PeriodType instance that does not support seconds.
PeriodType
withWeeksRemoved()
Returns a version of this PeriodType instance that does not support weeks.
PeriodType
withYearsRemoved()
Returns a version of this PeriodType instance that does not support years.
static PeriodType
yearDay()
Gets a type that defines the year and day fields.
static PeriodType
yearDayTime()
Gets a type that defines all standard fields except months and weeks.
static PeriodType
yearMonthDay()
Gets a type that defines the year, month and day fields.
static PeriodType
yearMonthDayTime()
Gets a type that defines all standard fields except weeks.
static PeriodType
yearWeekDay()
Gets a type that defines year, week and day fields.
static PeriodType
yearWeekDayTime()
Gets a type that defines all standard fields except months.
static PeriodType
years()
Gets a type that defines just the years field.

Constructor Details

PeriodType

protected PeriodType(String name,
                     DurationFieldType[] types,
                     int[] indices)
Constructor.
Parameters:
name - the name
types - the types
indices - the indices

Method Details

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

days

public static PeriodType days()
Gets a type that defines just the days field.
Returns:
the period type

equals

public boolean equals(Object obj)
Compares this type to another object. To be equal, the object must be a PeriodType with the same set of fields.
Parameters:
obj - the object to compare to
Returns:
true if equal

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

getFieldType

public DurationFieldType getFieldType(int index)
Gets the field type by index.
Parameters:
index - the index to retrieve
Returns:
the field type

getName

public String getName()
Gets the name of the period type.
Returns:
the name

hashCode

public int hashCode()
Returns a hashcode based on the field types.
Returns:
a suitable hashcode

hours

public static PeriodType hours()
Gets a type that defines just the hours field.
Returns:
the period type

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

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

millis

public static PeriodType millis()
Gets a type that defines just the millis field.
Returns:
the period type

minutes

public static PeriodType minutes()
Gets a type that defines just the minutes field.
Returns:
the period type

months

public static PeriodType months()
Gets a type that defines just the months field.
Returns:
the period type

seconds

public static PeriodType seconds()
Gets a type that defines just the seconds field.
Returns:
the period type

size

public int size()
Gets the number of fields in the period type.
Returns:
the number of fields

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

time

public static PeriodType time()
Gets a type that defines all standard time fields.
  • hours
  • minutes
  • seconds
  • milliseconds
Returns:
the period type

toString

public String toString()
Gets a debugging to string.
Returns:
a string

weeks

public static PeriodType weeks()
Gets a type that defines just the weeks field.
Returns:
the period type

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

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

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

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

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

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

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

yearDay

public static PeriodType yearDay()
Gets a type that defines the year and day fields.
  • years
  • 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

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

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

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

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

years

public static PeriodType years()
Gets a type that defines just the years field.
Returns:
the period type

Copyright (c) 2001-2006 - Joda.org