org.joda.time.base

Class AbstractPeriod

Implemented Interfaces:
ReadablePeriod
Known Direct Subclasses:
BasePeriod

public abstract class AbstractPeriod
extends java.lang.Object
implements ReadablePeriod

AbstractPeriod provides the common behaviour for period classes.

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.

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

Constructor Summary

AbstractPeriod()
Constructor.

Method Summary

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[]
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.
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.

Constructor Details

AbstractPeriod

protected AbstractPeriod()
Constructor.

Method Details

equals

public boolean equals(Object period)
Specified by:
equals in interface ReadablePeriod
Parameters:
period - a readable period to check against
Returns:
true if all the field values are equal, false if not or the period is null or of an incorrect type

get

public int get(DurationFieldType type)
Gets the value of one of the fields.

If the field type specified is not supported by the period then zero is returned.

Specified by:
get in interface ReadablePeriod
Parameters:
type - the field type to query, null returns zero
Returns:
the value of that field, zero if field not supported

getFieldTypes

public DurationFieldType[] getFieldTypes()
Gets an array of the field types that this period supports.

The fields are returned largest to smallest, for example Hours, Minutes, Seconds.

Returns:
the fields supported in an array that may be altered, largest to smallest

getValues

public int[] getValues()
Gets an array of the value of each of the fields that this period supports.

The fields are returned largest to smallest, for example Hours, Minutes, Seconds. Each value corresponds to the same array index as getFields()

Returns:
the current values of each field in an array that may be altered, largest to smallest

hashCode

public int hashCode()
Gets a hash code for the period as defined by ReadablePeriod.
Specified by:
hashCode in interface ReadablePeriod
Returns:
a hash code

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.
Specified by:
isSupported in interface ReadablePeriod
Parameters:
type - the type to check, may be null which returns false
Returns:
true if the field is supported

toMutablePeriod

public MutablePeriod toMutablePeriod()
Get this object as a MutablePeriod.

This will always return a new MutablePeriod with the same fields.

Specified by:
toMutablePeriod in interface ReadablePeriod
Returns:
a MutablePeriod using the same field set and values

toPeriod

public Period toPeriod()
Get this period as an immutable Period object.
Specified by:
toPeriod in interface ReadablePeriod
Returns:
a Period using the same field set and values

toString

public String toString()
Specified by:
toString in interface ReadablePeriod
Returns:
the value as an ISO8601 string

toString

public String toString(PeriodFormatter formatter)
Uses the specified formatter to convert this period to a String.
Parameters:
formatter - the formatter to use, null means use toString().
Returns:
the formatted string
Since:
1.5

Copyright (c) 2001-2006 - Joda.org