public abstract class

AbstractPartial

extends Object
implements Comparable<T> ReadablePartial
java.lang.Object
   ↳ org.joda.time.base.AbstractPartial
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

AbstractPartial provides a standard base implementation of most methods in the ReadablePartial interface.

Calculations on are performed using a Chronology. This chronology is set to be in the UTC time zone for all calculations.

The methods on this class use size(), getField(int, Chronology) and getValue(int) to calculate their results. Subclasses may have a better implementation.

AbstractPartial allows subclasses may be mutable and not thread-safe.

Summary

Protected Constructors
AbstractPartial()
Constructor.
Public Methods
int compareTo(Object partial)
Compares this partial with another returning an integer indicating the order.
boolean equals(Object partial)
Compares this ReadablePartial with another returning true if the chronology, field types and values are equal.
int get(DateTimeFieldType type)
Get the value of one of the fields of a datetime.
DateTimeField getField(int index)
Gets the field at the specifed index.
DateTimeFieldType getFieldType(int index)
Gets the field type at the specifed index.
DateTimeFieldType[] getFieldTypes()
Gets an array of the field types that this partial supports.
DateTimeField[] getFields()
Gets an array of the fields that this partial supports.
int[] getValues()
Gets an array of the value of each of the fields that this partial supports.
int hashCode()
Gets a hash code for the ReadablePartial that is compatible with the equals method.
int indexOf(DateTimeFieldType type)
Gets the index of the specified field, or -1 if the field is unsupported.
boolean isAfter(ReadablePartial partial)
Is this partial later than the specified partial.
boolean isBefore(ReadablePartial partial)
Is this partial earlier than the specified partial.
boolean isEqual(ReadablePartial partial)
Is this partial the same as the specified partial.
boolean isSupported(DateTimeFieldType type)
Checks whether the field specified is supported by this partial.
DateTime toDateTime(ReadableInstant baseInstant)
Resolves this partial against another complete instant to create a new full instant.
String toString(DateTimeFormatter formatter)
Uses the specified formatter to convert this partial to a String.
Protected Methods
abstract DateTimeField getField(int index, Chronology chrono)
Gets the field for a specific index in the chronology specified.
int indexOf(DurationFieldType type)
Gets the index of the first fields to have the specified duration, or -1 if the field is unsupported.
int indexOfSupported(DurationFieldType type)
Gets the index of the first fields to have the specified duration, throwing an exception if the field is unsupported.
int indexOfSupported(DateTimeFieldType type)
Gets the index of the specified field, throwing an exception if the field is unsupported.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.lang.Comparable
From interface org.joda.time.ReadablePartial

Protected Constructors

protected AbstractPartial ()

Constructor.

Public Methods

public int compareTo (Object partial)

Compares this partial with another returning an integer indicating the order.

The fields are compared in order, from largest to smallest. The first field that is non-equal is used to determine the result.

The specified object must be a partial instance whose field types match those of this partial.

NOTE: This implementation violates the Comparable contract. This method will accept any instance of ReadablePartial as input. However, it is possible that some implementations of ReadablePartial exist that do not extend AbstractPartial, and thus will throw a ClassCastException if compared in the opposite direction. The cause of this problem is that ReadablePartial doesn't define the compareTo() method, however we can't change that until v2.0.

Parameters
partial an object to check against
Returns
  • negative if this is less, zero if equal, positive if greater
Throws
ClassCastException if the partial is the wrong class or if it has field types that don't match
NullPointerException if the partial is null

public boolean equals (Object partial)

Compares this ReadablePartial with another returning true if the chronology, field types and values are equal.

Parameters
partial an object to check against
Returns
  • true if fields and values are equal

public int get (DateTimeFieldType type)

Get the value of one of the fields of a datetime.

The field specified must be one of those that is supported by the partial.

Parameters
type a DateTimeFieldType instance that is supported by this partial
Returns
  • the value of that field
Throws
IllegalArgumentException if the field is null or not supported

public DateTimeField getField (int index)

Gets the field at the specifed index.

Parameters
index the index
Returns
  • the field
Throws
IndexOutOfBoundsException if the index is invalid

public DateTimeFieldType getFieldType (int index)

Gets the field type at the specifed index.

Parameters
index the index
Returns
  • the field type
Throws
IndexOutOfBoundsException if the index is invalid

public DateTimeFieldType[] getFieldTypes ()

Gets an array of the field types that this partial supports.

The fields are returned largest to smallest, for example Hour, Minute, Second.

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

public DateTimeField[] getFields ()

Gets an array of the fields that this partial supports.

The fields are returned largest to smallest, for example Hour, Minute, Second.

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

public int[] getValues ()

Gets an array of the value of each of the fields that this partial supports.

The fields are returned largest to smallest, for example Hour, Minute, Second. 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

public int hashCode ()

Gets a hash code for the ReadablePartial that is compatible with the equals method.

Returns
  • a suitable hash code

public int indexOf (DateTimeFieldType type)

Gets the index of the specified field, or -1 if the field is unsupported.

Parameters
type the type to check, may be null which returns -1
Returns
  • the index of the field, -1 if unsupported

public boolean isAfter (ReadablePartial partial)

Is this partial later than the specified partial.

The fields are compared in order, from largest to smallest. The first field that is non-equal is used to determine the result.

You may not pass null into this method. This is because you need a time zone to accurately determine the current date.

Parameters
partial a partial to check against, must not be null
Returns
  • true if this date is after the date passed in
Throws
IllegalArgumentException if the specified partial is null
ClassCastException if the partial has field types that don't match

public boolean isBefore (ReadablePartial partial)

Is this partial earlier than the specified partial.

The fields are compared in order, from largest to smallest. The first field that is non-equal is used to determine the result.

You may not pass null into this method. This is because you need a time zone to accurately determine the current date.

Parameters
partial a partial to check against, must not be null
Returns
  • true if this date is before the date passed in
Throws
IllegalArgumentException if the specified partial is null
ClassCastException if the partial has field types that don't match

public boolean isEqual (ReadablePartial partial)

Is this partial the same as the specified partial.

The fields are compared in order, from largest to smallest. If all fields are equal, the result is true.

You may not pass null into this method. This is because you need a time zone to accurately determine the current date.

Parameters
partial a partial to check against, must not be null
Returns
  • true if this date is the same as the date passed in
Throws
IllegalArgumentException if the specified partial is null
ClassCastException if the partial has field types that don't match

public boolean isSupported (DateTimeFieldType type)

Checks whether the field specified is supported by this partial.

Parameters
type the type to check, may be null which returns false
Returns
  • true if the field is supported

public DateTime toDateTime (ReadableInstant baseInstant)

Resolves this partial against another complete instant to create a new full instant. The combination is performed using the chronology of the specified instant.

For example, if this partial represents a time, then the result of this method will be the datetime from the specified base instant plus the time from this partial.

Parameters
baseInstant the instant that provides the missing fields, null means now
Returns
  • the combined datetime

public String toString (DateTimeFormatter formatter)

Uses the specified formatter to convert this partial to a String.

Parameters
formatter the formatter to use, null means use toString().
Returns
  • the formatted string

Protected Methods

protected abstract DateTimeField getField (int index, Chronology chrono)

Gets the field for a specific index in the chronology specified.

This method must not use any instance variables.

Parameters
index the index to retrieve
chrono the chronology to use
Returns
  • the field
Throws
IndexOutOfBoundsException if the index is invalid

protected int indexOf (DurationFieldType type)

Gets the index of the first fields to have the specified duration, or -1 if the field is unsupported.

Parameters
type the type to check, may be null which returns -1
Returns
  • the index of the field, -1 if unsupported

protected int indexOfSupported (DurationFieldType type)

Gets the index of the first fields to have the specified duration, throwing an exception if the field is unsupported.

Parameters
type the type to check, not null
Returns
  • the index of the field
Throws
IllegalArgumentException if the field is null or not supported

protected int indexOfSupported (DateTimeFieldType type)

Gets the index of the specified field, throwing an exception if the field is unsupported.

Parameters
type the type to check, not null
Returns
  • the index of the field
Throws
IllegalArgumentException if the field is null or not supported