| java.lang.Object org.joda.time.base.BaseSingleFieldPeriod
All known Subclasses: org.joda.time.Days, org.joda.time.Seconds, org.joda.time.Minutes, org.joda.time.Years, org.joda.time.Months, org.joda.time.Weeks, org.joda.time.Hours,
BaseSingleFieldPeriod | abstract public class BaseSingleFieldPeriod implements ReadablePeriod,Comparable,Serializable(Code) | | BaseSingleFieldPeriod is an abstract implementation of ReadablePeriod that
manages a single duration field, such as days or minutes.
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.
BaseSingleFieldPeriod subclasses may be mutable and not thread-safe.
author: Stephen Colebourne since: 1.4 |
Constructor Summary | |
protected | BaseSingleFieldPeriod(int period) Creates a new instance representing the specified period. |
Method Summary | |
protected static int | between(ReadableInstant start, ReadableInstant end, DurationFieldType field) Calculates the number of whole units between the two specified datetimes. | protected static int | between(ReadablePartial start, ReadablePartial end, ReadablePeriod zeroInstance) Calculates the number of whole units between the two specified partial datetimes. | public int | compareTo(Object other) Compares this period to another object of the same class. | public boolean | equals(Object period) Compares this object with the specified object for equality based on the
value of each field. | public int | get(DurationFieldType type) Gets the value of a duration field represented by this period. | abstract public DurationFieldType | getFieldType() Gets the single duration field type. | public DurationFieldType | getFieldType(int index) Gets the field type at the specified index. | abstract public PeriodType | getPeriodType() Gets the period type which matches the duration field type. | protected int | getValue() Gets the amount of this period. | public int | getValue(int index) Gets the value at the specified index. | public int | hashCode() Gets a hash code for the period as defined by ReadablePeriod. | public boolean | isSupported(DurationFieldType type) Checks whether the duration field specified is supported by this period. | protected void | setValue(int value) Sets the amount of this period. | public int | size() Gets the number of fields that this period supports, which is one. | protected static int | standardPeriodIn(ReadablePeriod period, long millisPerUnit) Creates a new instance representing the number of complete standard length units
in the specified period.
This factory method converts all fields from the period to hours using standardised
durations for each field. | public MutablePeriod | toMutablePeriod() Get this object as a MutablePeriod . | public Period | toPeriod() Get this period as an immutable Period object. |
BaseSingleFieldPeriod | protected BaseSingleFieldPeriod(int period)(Code) | | Creates a new instance representing the specified period.
Parameters: period - the period to represent |
between | protected static int between(ReadableInstant start, ReadableInstant end, DurationFieldType field)(Code) | | Calculates the number of whole units between the two specified datetimes.
Parameters: start - the start instant, validated to not be null Parameters: end - the end instant, validated to not be null Parameters: field - the field type to use, must not be null the period throws: IllegalArgumentException - if the instants are null or invalid |
between | protected static int between(ReadablePartial start, ReadablePartial end, ReadablePeriod zeroInstance)(Code) | | Calculates the number of whole units between the two specified partial datetimes.
The two partials must contain the same fields, for example you can specify
two LocalDate objects.
Parameters: start - the start partial date, validated to not be null Parameters: end - the end partial date, validated to not be null Parameters: zeroInstance - the zero instance constant, must not be null the period throws: IllegalArgumentException - if the partials are null or invalid |
compareTo | public int compareTo(Object other)(Code) | | Compares this period to another object of the same class.
Parameters: other - the other period, must not be null zero if equal, positive if greater, negative if less throws: NullPointerException - if the other period is null throws: ClassCastException - if the other period is of a different type |
equals | public boolean equals(Object period)(Code) | | Compares this object with the specified object for equality based on the
value of each field. All ReadablePeriod instances are accepted, but only
those with a matching PeriodType can return true.
Parameters: period - a readable period to check against true if all the field values are equal, false ifnot or the period is null or of an incorrect type |
get | public int get(DurationFieldType type)(Code) | | Gets the value of a duration field represented by this period.
If the field type specified does not match the type used by this class
then zero is returned.
Parameters: type - the field type to query, null returns zero the value of that field, zero if field not supported |
getFieldType | abstract public DurationFieldType getFieldType()(Code) | | Gets the single duration field type.
the duration field type, not null |
getFieldType | public DurationFieldType getFieldType(int index)(Code) | | Gets the field type at the specified index.
The only index supported by this period is zero which returns the
field type of this class.
Parameters: index - the index to retrieve, which must be zero the field at the specified index throws: IndexOutOfBoundsException - if the index is invalid |
getPeriodType | abstract public PeriodType getPeriodType()(Code) | | Gets the period type which matches the duration field type.
the period type, not null |
getValue | protected int getValue()(Code) | | Gets the amount of this period.
the period value |
getValue | public int getValue(int index)(Code) | | Gets the value at the specified index.
The only index supported by this period is zero.
Parameters: index - the index to retrieve, which must be zero the value of the field at the specified index throws: IndexOutOfBoundsException - if the index is invalid |
hashCode | public int hashCode()(Code) | | Gets a hash code for the period as defined by ReadablePeriod.
a hash code |
isSupported | public boolean isSupported(DurationFieldType type)(Code) | | Checks whether the duration field specified is supported by this period.
Parameters: type - the type to check, may be null which returns false true if the field is supported |
setValue | protected void setValue(int value)(Code) | | Sets the amount of this period.
To make a subclass immutable you must declare it final, or block this method.
Parameters: value - the period value |
size | public int size()(Code) | | Gets the number of fields that this period supports, which is one.
the number of fields supported, which is one |
standardPeriodIn | protected static int standardPeriodIn(ReadablePeriod period, long millisPerUnit)(Code) | | Creates a new instance representing the number of complete standard length units
in the specified period.
This factory method converts all fields from the period to hours using standardised
durations for each field. Only those fields which have a precise duration in
the ISO UTC chronology can be converted.
- One week consists of 7 days.
- One day consists of 24 hours.
- One hour consists of 60 minutes.
- One minute consists of 60 seconds.
- One second consists of 1000 milliseconds.
Months and Years are imprecise and periods containing these values cannot be converted.
Parameters: period - the period to get the number of hours from, must not be null Parameters: millisPerUnit - the number of milliseconds in one standard unit of this period throws: IllegalArgumentException - if the period contains imprecise duration values |
toMutablePeriod | public MutablePeriod toMutablePeriod()(Code) | | Get this object as a MutablePeriod .
This will always return a new MutablePeriod with the same fields.
The period will use PeriodType.standard() .
a MutablePeriod using the same field set and values |
toPeriod | public Period toPeriod()(Code) | | Get this period as an immutable Period object.
The period will use PeriodType.standard() .
a Period representing the same number of days |
|
|