Class AbstractPartial
- java.lang.Object
-
- org.joda.time.base.AbstractPartial
-
- All Implemented Interfaces:
java.lang.Comparable<ReadablePartial>
,ReadablePartial
- Direct Known Subclasses:
BaseLocal
,BasePartial
,Partial
public abstract class AbstractPartial extends java.lang.Object implements ReadablePartial, java.lang.Comparable<ReadablePartial>
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)
andReadablePartial.getValue(int)
to calculate their results. Subclasses may have a better implementation.AbstractPartial allows subclasses may be mutable and not thread-safe.
- Since:
- 1.0
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(ReadablePartial other)
Compares this partial with another returning an integer indicating the order.boolean
equals(java.lang.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 specified index.DateTimeField[]
getFields()
Gets an array of the fields that this partial supports.DateTimeFieldType
getFieldType(int index)
Gets the field type at the specified index.DateTimeFieldType[]
getFieldTypes()
Gets an array of the field types 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.java.lang.String
toString(DateTimeFormatter formatter)
Uses the specified formatter to convert this partial to a String.-
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.joda.time.ReadablePartial
getChronology, getValue, size, toString
-
-
-
-
Method Detail
-
getFieldType
public DateTimeFieldType getFieldType(int index)
Gets the field type at the specified index.- Specified by:
getFieldType
in interfaceReadablePartial
- Parameters:
index
- the index- Returns:
- the field type
- Throws:
java.lang.IndexOutOfBoundsException
- if the index is invalid
-
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.
- Returns:
- the fields supported in an array that may be altered, largest to smallest
-
getField
public DateTimeField getField(int index)
Gets the field at the specified index.- Specified by:
getField
in interfaceReadablePartial
- Parameters:
index
- the index- Returns:
- the field
- Throws:
java.lang.IndexOutOfBoundsException
- if the index is invalid
-
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.
- 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 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
-
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.
- Specified by:
get
in interfaceReadablePartial
- Parameters:
type
- a DateTimeFieldType instance that is supported by this partial- Returns:
- the value of that field
- Throws:
java.lang.IllegalArgumentException
- if the field is null or not supported
-
isSupported
public boolean isSupported(DateTimeFieldType type)
Checks whether the field specified is supported by this partial.- Specified by:
isSupported
in interfaceReadablePartial
- Parameters:
type
- the type to check, may be null which returns false- Returns:
- true if the field is supported
-
indexOf
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
-
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.
- Specified by:
toDateTime
in interfaceReadablePartial
- Parameters:
baseInstant
- the instant that provides the missing fields, null means now- Returns:
- the combined datetime
-
equals
public boolean equals(java.lang.Object partial)
Compares this ReadablePartial with another returning true if the chronology, field types and values are equal.- Specified by:
equals
in interfaceReadablePartial
- Overrides:
equals
in classjava.lang.Object
- Parameters:
partial
- an object to check against- Returns:
- true if fields and values are equal
-
hashCode
public int hashCode()
Gets a hash code for the ReadablePartial that is compatible with the equals method.- Specified by:
hashCode
in interfaceReadablePartial
- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- a suitable hash code
-
compareTo
public int compareTo(ReadablePartial other)
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: Prior to v2.0, the
Comparable
interface was only implemented in this class and not in theReadablePartial
interface.- Specified by:
compareTo
in interfacejava.lang.Comparable<ReadablePartial>
- Parameters:
other
- an object to check against- Returns:
- negative if this is less, zero if equal, positive if greater
- Throws:
java.lang.ClassCastException
- if the partial is the wrong class or if it has field types that don't matchjava.lang.NullPointerException
- if the partial is null- Since:
- 1.1
-
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.
- Parameters:
partial
- a partial to check against, must not be null- Returns:
- true if this date is strictly after the date passed in
- Throws:
java.lang.IllegalArgumentException
- if the specified partial is nulljava.lang.ClassCastException
- if the partial has field types that don't match- Since:
- 1.1
-
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.
- Parameters:
partial
- a partial to check against, must not be null- Returns:
- true if this date is strictly before the date passed in
- Throws:
java.lang.IllegalArgumentException
- if the specified partial is nulljava.lang.ClassCastException
- if the partial has field types that don't match- Since:
- 1.1
-
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.
- 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:
java.lang.IllegalArgumentException
- if the specified partial is nulljava.lang.ClassCastException
- if the partial has field types that don't match- Since:
- 1.1
-
toString
public java.lang.String toString(DateTimeFormatter formatter)
Uses the specified formatter to convert this partial to a String.- Parameters:
formatter
- the formatter to use, null means usetoString()
.- Returns:
- the formatted string
- Since:
- 1.1
-
-