org.joda.time.base
Class BasePeriod

java.lang.Object
  extended byorg.joda.time.base.AbstractPeriod
      extended byorg.joda.time.base.BasePeriod
All Implemented Interfaces:
ReadablePeriod, Serializable
Direct Known Subclasses:
MutablePeriod, Period

public abstract class BasePeriod
extends AbstractPeriod
implements ReadablePeriod, Serializable

BasePeriod is an abstract implementation of ReadablePeriod that stores data in a PeriodType and an int[].

This class should generally not be used directly by API users. The ReadablePeriod interface should be used when different kinds of period objects are to be referenced.

BasePeriod subclasses may be mutable and not thread-safe.

Since:
1.0
Author:
Brian S O'Neill, Stephen Colebourne
See Also:
Serialized Form

Method Summary
 DurationFieldType getFieldType(int index)
          Gets the field type at the specified index.
 PeriodType getPeriodType()
          Gets the period type.
 int getValue(int index)
          Gets the value at the specified index.
 int size()
          Gets the number of fields that this period supports.
 Duration toDurationFrom(ReadableInstant startInstant)
          Gets the total millisecond duration of this period relative to a start instant.
 Duration toDurationTo(ReadableInstant endInstant)
          Gets the total millisecond duration of this period relative to an end instant.
 
Methods inherited from class org.joda.time.base.AbstractPeriod
equals, get, getFieldTypes, getValues, hashCode, indexOf, isSupported, toMutablePeriod, toPeriod, toString, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.joda.time.ReadablePeriod
equals, get, hashCode, isSupported, toMutablePeriod, toPeriod, toString
 

Method Detail

getPeriodType

public PeriodType getPeriodType()
Gets the period type.

Specified by:
getPeriodType in interface ReadablePeriod
Returns:
the period type

size

public int size()
Gets the number of fields that this period supports.

Specified by:
size in interface ReadablePeriod
Returns:
the number of fields supported

getFieldType

public DurationFieldType getFieldType(int index)
Gets the field type at the specified index.

Specified by:
getFieldType in interface ReadablePeriod
Parameters:
index - the index to retrieve
Returns:
the field at the specified index
Throws:
IndexOutOfBoundsException - if the index is invalid

getValue

public int getValue(int index)
Gets the value at the specified index.

Specified by:
getValue in interface ReadablePeriod
Parameters:
index - the index to retrieve
Returns:
the value of the field at the specified index
Throws:
IndexOutOfBoundsException - if the index is invalid

toDurationFrom

public Duration toDurationFrom(ReadableInstant startInstant)
Gets the total millisecond duration of this period relative to a start instant.

This method adds the period to the specified instant in order to calculate the duration.

An instant must be supplied as the duration of a period varies. For example, a period of 1 month could vary between the equivalent of 28 and 31 days in milliseconds due to different length months. Similarly, a day can vary at Daylight Savings cutover, typically between 23 and 25 hours.

Parameters:
startInstant - the instant to add the period to, thus obtaining the duration
Returns:
the total length of the period as a duration relative to the start instant
Throws:
ArithmeticException - if the millis exceeds the capacity of the duration

toDurationTo

public Duration toDurationTo(ReadableInstant endInstant)
Gets the total millisecond duration of this period relative to an end instant.

This method subtracts the period from the specified instant in order to calculate the duration.

An instant must be supplied as the duration of a period varies. For example, a period of 1 month could vary between the equivalent of 28 and 31 days in milliseconds due to different length months. Similarly, a day can vary at Daylight Savings cutover, typically between 23 and 25 hours.

Parameters:
endInstant - the instant to subtract the period from, thus obtaining the duration
Returns:
the total length of the period as a duration relative to the end instant
Throws:
ArithmeticException - if the millis exceeds the capacity of the duration


Copyright © 2002-2008 Joda.org. All Rights Reserved.