org.joda.time.base
Class AbstractPartial
java.lang.Object
org.joda.time.base.AbstractPartial
- Comparable, ReadablePartial
public abstract class AbstractPartial
extends java.lang.Object
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
ReadablePartial.size()
,
getField(int,Chronology)
and
ReadablePartial.getValue(int)
to calculate their results.
Subclasses may have a better implementation.
AbstractPartial allows subclasses may be mutable and not thread-safe.
AbstractPartial
protected AbstractPartial()
Constructor.
compareTo
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.
partial
- an object to check against
- negative if this is less, zero if equal, positive if greater
equals
public boolean equals(Object partial)
Compares this ReadablePartial with another returning true if the chronology,
field types and values are equal.
- equals in interface ReadablePartial
partial
- an object to check against
- true if fields and values are equal
get
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.
- get in interface ReadablePartial
type
- a DateTimeFieldType instance that is supported by this partial
getField
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.
index
- the index to retrievechrono
- the chronology to use
getFieldTypes
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.
- the fields supported in an array that may be altered, largest to smallest
getFields
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.
- 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 partial supports.
The fields are returned largest to smallest, for example Hour, Minute, Second.
Each value corresponds to the same array index as
getFields()
- 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 ReadablePartial that is compatible with the
equals method.
- hashCode in interface ReadablePartial
indexOf
public int indexOf(DateTimeFieldType type)
Gets the index of the specified field, or -1 if the field is unsupported.
type
- the type to check, may be null which returns -1
- the index of the field, -1 if unsupported
indexOf
protected int indexOf(DurationFieldType type)
Gets the index of the first fields to have the specified duration,
or -1 if the field is unsupported.
type
- the type to check, may be null which returns -1
- the index of the field, -1 if unsupported
indexOfSupported
protected int indexOfSupported(DateTimeFieldType type)
Gets the index of the specified field, throwing an exception if the
field is unsupported.
type
- the type to check, not null
indexOfSupported
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.
type
- the type to check, not null
isAfter
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.
partial
- a partial to check against, must not be null
- true if this date is after the date passed in
isBefore
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.
partial
- a partial to check against, must not be null
- true if this date is before the date passed in
isEqual
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.
partial
- a partial to check against, must not be null
- true if this date is the same as the date passed in
isSupported
public boolean isSupported(DateTimeFieldType type)
Checks whether the field specified is supported by this partial.
- isSupported in interface ReadablePartial
type
- the type to check, may be null which returns false
- true if the field is supported
toDateTime
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.
- toDateTime in interface ReadablePartial
baseInstant
- the instant that provides the missing fields, null means now
toString
public String toString(DateTimeFormatter formatter)
Uses the specified formatter to convert this partial to a String.
formatter
- the formatter to use, null means use toString()
.
Copyright (c) 2001-2006 - Joda.org