org.joda.time.field
Class DecoratedDateTimeField

java.lang.Object
  extended by org.joda.time.DateTimeField
      extended by org.joda.time.field.BaseDateTimeField
          extended by org.joda.time.field.DecoratedDateTimeField
Direct Known Subclasses:
DividedDateTimeField, OffsetDateTimeField, RemainderDateTimeField, ZeroIsMaxDateTimeField

public abstract class DecoratedDateTimeField
extends BaseDateTimeField

DecoratedDateTimeField extends BaseDateTimeField, implementing only the minimum required set of methods. These implemented methods delegate to a wrapped field.

This design allows new DateTimeField types to be defined that piggyback on top of another, inheriting all the safe method implementations from BaseDateTimeField. Should any method require pure delegation to the wrapped field, simply override and use the provided getWrappedField method.

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

Since:
1.0
See Also:
DelegatedDateTimeField

Constructor Summary
protected DecoratedDateTimeField(DateTimeField field, DateTimeFieldType type)
          Constructor.
 
Method Summary
 int get(long instant)
          Get the value of this field from the milliseconds.
 DurationField getDurationField()
          Returns the duration per unit value of this field.
 int getMaximumValue()
          Get the maximum allowable value for this field.
 int getMinimumValue()
          Get the minimum allowable value for this field.
 DurationField getRangeDurationField()
          Returns the range duration of this field.
 DateTimeField getWrappedField()
          Gets the wrapped date time field.
 boolean isLenient()
          Returns true if the set method is lenient.
 long roundFloor(long instant)
          Round to the lowest whole unit of this field.
 long set(long instant, int value)
          Sets a value in the milliseconds supplied.
 
Methods inherited from class org.joda.time.field.BaseDateTimeField
add, add, add, addWrapField, addWrapField, addWrapPartial, convertText, getAsShortText, getAsShortText, getAsShortText, getAsShortText, getAsShortText, getAsText, getAsText, getAsText, getAsText, getAsText, getDifference, getDifferenceAsLong, getLeapAmount, getLeapDurationField, getMaximumShortTextLength, getMaximumTextLength, getMaximumValue, getMaximumValue, getMaximumValue, getMinimumValue, getMinimumValue, getMinimumValue, getName, getType, isLeap, isSupported, remainder, roundCeiling, roundHalfCeiling, roundHalfEven, roundHalfFloor, set, set, set, set, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DecoratedDateTimeField

protected DecoratedDateTimeField(DateTimeField field,
                                 DateTimeFieldType type)
Constructor.

Parameters:
field - the field being decorated
type - allow type to be overridden
Method Detail

getWrappedField

public final DateTimeField getWrappedField()
Gets the wrapped date time field.

Returns:
the wrapped DateTimeField

isLenient

public boolean isLenient()
Description copied from class: DateTimeField
Returns true if the set method is lenient. If so, it accepts values that are out of bounds. For example, a lenient day of month field accepts 32 for January, converting it to February 1.

Specified by:
isLenient in class DateTimeField
Returns:
true if this field is lenient

get

public int get(long instant)
Description copied from class: BaseDateTimeField
Get the value of this field from the milliseconds.

Specified by:
get in class BaseDateTimeField
Parameters:
instant - the milliseconds from 1970-01-01T00:00:00Z to query
Returns:
the value of the field, in the units of the field

set

public long set(long instant,
                int value)
Description copied from class: BaseDateTimeField
Sets a value in the milliseconds supplied.

The value of this field will be set. If the value is invalid, an exception if thrown.

If setting this field would make other fields invalid, then those fields may be changed. For example if the current date is the 31st January, and the month is set to February, the day would be invalid. Instead, the day would be changed to the closest value - the 28th/29th February as appropriate.

Specified by:
set in class BaseDateTimeField
Parameters:
instant - the milliseconds from 1970-01-01T00:00:00Z to set in
value - the value to set, in the units of the field
Returns:
the updated milliseconds

getDurationField

public DurationField getDurationField()
Description copied from class: BaseDateTimeField
Returns the duration per unit value of this field. For example, if this field represents "hour of day", then the unit duration is an hour.

Specified by:
getDurationField in class BaseDateTimeField
Returns:
the duration of this field, or UnsupportedDurationField if field has no duration

getRangeDurationField

public DurationField getRangeDurationField()
Description copied from class: BaseDateTimeField
Returns the range duration of this field. For example, if this field represents "hour of day", then the range duration is a day.

Specified by:
getRangeDurationField in class BaseDateTimeField
Returns:
the range duration of this field, or null if field has no range

getMinimumValue

public int getMinimumValue()
Description copied from class: BaseDateTimeField
Get the minimum allowable value for this field.

Specified by:
getMinimumValue in class BaseDateTimeField
Returns:
the minimum valid value for this field, in the units of the field

getMaximumValue

public int getMaximumValue()
Description copied from class: BaseDateTimeField
Get the maximum allowable value for this field.

Specified by:
getMaximumValue in class BaseDateTimeField
Returns:
the maximum valid value for this field, in the units of the field

roundFloor

public long roundFloor(long instant)
Description copied from class: BaseDateTimeField
Round to the lowest whole unit of this field. After rounding, the value of this field and all fields of a higher magnitude are retained. The fractional millis that cannot be expressed in whole increments of this field are set to minimum.

For example, a datetime of 2002-11-02T23:34:56.789, rounded to the lowest whole hour is 2002-11-02T23:00:00.000.

Specified by:
roundFloor in class BaseDateTimeField
Parameters:
instant - the milliseconds from 1970-01-01T00:00:00Z to round
Returns:
rounded milliseconds


Copyright © 2002–2015 Joda.org. All rights reserved.