org.joda.time.field

Class BaseDurationField

Implemented Interfaces:
Comparable, Serializable
Known Direct Subclasses:
DecoratedDurationField, PreciseDurationField

public abstract class BaseDurationField
extends DurationField
implements Serializable

BaseDurationField provides the common behaviour for DurationField implementations.

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

BaseDurationField is thread-safe and immutable, and its subclasses must be as well.

Author:
Brian S O'Neill
Since:
1.0
See Also:
DecoratedDurationField

Constructor Summary

BaseDurationField(DurationFieldType type)

Method Summary

int
compareTo(Object durationField)
int
getDifference(long minuendInstant, long subtrahendInstant)
long
getMillis(int value)
Get the millisecond duration of this field from its value, which is approximate if this field is imprecise.
long
getMillis(long value)
Get the millisecond duration of this field from its value, which is approximate if this field is imprecise.
String
getName()
DurationFieldType
getType()
int
getValue(long duration)
Get the value of this field from the milliseconds, which is approximate if this field is imprecise.
int
getValue(long duration, long instant)
Get the value of this field from the milliseconds relative to an instant.
long
getValueAsLong(long duration)
Get the value of this field from the milliseconds, which is approximate if this field is imprecise.
boolean
isSupported()
String
toString()
Get a suitable debug string.

Methods inherited from class org.joda.time.DurationField

add, add, compareTo, getDifference, getDifferenceAsLong, getMillis, getMillis, getMillis, getMillis, getName, getType, getUnitMillis, getValue, getValue, getValueAsLong, getValueAsLong, isPrecise, isSupported, subtract, subtract, toString

Constructor Details

BaseDurationField

protected BaseDurationField(DurationFieldType type)

Method Details

compareTo

public int compareTo(Object durationField)
Overrides:
compareTo in interface DurationField

getDifference

public int getDifference(long minuendInstant,
                         long subtrahendInstant)
Overrides:
getDifference in interface DurationField

getMillis

public long getMillis(int value)
Get the millisecond duration of this field from its value, which is approximate if this field is imprecise.
Overrides:
getMillis in interface DurationField
Parameters:
value - the value of the field, which may be negative
Returns:
the milliseconds that the field represents, which may be negative

getMillis

public long getMillis(long value)
Get the millisecond duration of this field from its value, which is approximate if this field is imprecise.
Overrides:
getMillis in interface DurationField
Parameters:
value - the value of the field, which may be negative
Returns:
the milliseconds that the field represents, which may be negative

getName

public final String getName()
Overrides:
getName in interface DurationField

getType

public final DurationFieldType getType()
Overrides:
getType in interface DurationField

getValue

public int getValue(long duration)
Get the value of this field from the milliseconds, which is approximate if this field is imprecise.
Overrides:
getValue in interface DurationField
Parameters:
duration - the milliseconds to query, which may be negative
Returns:
the value of the field, in the units of the field, which may be negative

getValue

public int getValue(long duration,
                    long instant)
Get the value of this field from the milliseconds relative to an instant.

If the milliseconds is positive, then the instant is treated as a "start instant". If negative, the instant is treated as an "end instant".

The default implementation returns Utils.safeToInt(getAsLong(millisDuration, instant)).

Overrides:
getValue in interface DurationField
Parameters:
duration - the milliseconds to query, which may be negative
instant - the start instant to calculate relative to
Returns:
the value of the field, in the units of the field, which may be negative

getValueAsLong

public long getValueAsLong(long duration)
Get the value of this field from the milliseconds, which is approximate if this field is imprecise.
Overrides:
getValueAsLong in interface DurationField
Parameters:
duration - the milliseconds to query, which may be negative
Returns:
the value of the field, in the units of the field, which may be negative

isSupported

public final boolean isSupported()
Overrides:
isSupported in interface DurationField
Returns:
true always

toString

public String toString()
Get a suitable debug string.
Overrides:
toString in interface DurationField
Returns:
debug string

Copyright (c) 2001-2006 - Joda.org