Class AbstractReadableInstantFieldProperty
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
DateMidnight.Property
,DateTime.Property
,LocalDate.Property
,LocalDateTime.Property
,LocalTime.Property
,MutableDateTime.Property
It allows the date and time manipulation code to be field based yet still easy to use.
AbstractReadableInstantFieldProperty itself is thread-safe and immutable, but the ReadableInstant being operated on may be mutable and not thread-safe.
- Since:
- 1.0
- Author:
- Stephen Colebourne, Brian S O'Neill, Mike Schrag
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
compareTo
(ReadableInstant instant) Compare this field to the same field on another instant.int
compareTo
(ReadablePartial partial) Compare this field to the same field on another partial instant.boolean
Compares this property to another.int
get()
Gets the value of this property from the instant.Gets the short textual value of this property from the instant as a string in the default locale.getAsShortText
(Locale locale) Gets the short textual value of this property from the instant as a string in the specified locale.Gets the value of this property from the instant as a string.Gets the textual value of this property from the instant as a string in the default locale.Gets the textual value of this property from the instant as a string in the specified locale.protected Chronology
Gets the chronology of the datetime that this property is linked to.int
getDifference
(ReadableInstant instant) Returns the difference between this field property instant and the one passed in, in the units of this field.long
getDifferenceAsLong
(ReadableInstant instant) Returns the difference between this field property instant and the one passed in, in the units of this field.Returns the duration per unit value of this field.abstract DateTimeField
getField()
Gets the field being used.Gets the field type being used.int
Gets the amount by which this field is leap.If this field were to leap, then it would be in units described by the returned duration.int
getMaximumShortTextLength
(Locale locale) Gets the maximum short text length for the field.int
getMaximumTextLength
(Locale locale) Gets the maximum text length for the field.int
Gets the maximum value for the field.int
Gets the maximum value for the field ignoring the current time.protected abstract long
Gets the milliseconds of the datetime that this property is linked to.int
Gets the minimum value for the field.int
Gets the minimum value for the field ignoring the current time.getName()
Gets the name of the field.Returns the range duration of this field.int
hashCode()
Returns a hashcode compatible with the equals method.boolean
isLeap()
Gets whether this field is leap.long
Returns the fractional duration milliseconds of this field.Returns the interval that represents the range of the minimum and maximum values of this field.toString()
Output a debugging string.
-
Constructor Details
-
AbstractReadableInstantFieldProperty
public AbstractReadableInstantFieldProperty()Constructor.
-
-
Method Details
-
getField
Gets the field being used.- Returns:
- the field
-
getFieldType
Gets the field type being used.- Returns:
- the field type
-
getName
Gets the name of the field.- Returns:
- the field name
-
getMillis
protected abstract long getMillis()Gets the milliseconds of the datetime that this property is linked to.- Returns:
- the milliseconds
-
getChronology
Gets the chronology of the datetime that this property is linked to.This implementation throws UnsupportedOperationException, and must be implemented by subclasses to enable the equals() and hashCode() methods.
- Returns:
- the chronology
- Since:
- 1.4
-
get
public int get()Gets the value of this property from the instant.For example, the following two lines of code are equivalent:
datetime.getDayOfMonth(); datetime.dayOfMonth().get();
- Returns:
- the current value
- See Also:
-
getAsString
Gets the value of this property from the instant as a string.This method returns the value converted to a
String
usingInteger.toString
. This method does NOT return textual descriptions such as 'Monday' or 'January'. SeegetAsText()
andgetAsShortText()
for those.- Returns:
- the current value
- Since:
- 1.1
- See Also:
-
getAsText
Gets the textual value of this property from the instant as a string in the default locale.This method returns the value converted to a
String
returning the appropriate textual description wherever possible. Thus, a day of week of 1 would return 'Monday' in English.- Returns:
- the current text value
- See Also:
-
getAsText
Gets the textual value of this property from the instant as a string in the specified locale.This method returns the value converted to a
String
returning the appropriate textual description wherever possible. Thus, a day of week of 1 would return 'Monday' in English.- Parameters:
locale
- locale to use for selecting a text symbol, null means default- Returns:
- the current text value
- See Also:
-
getAsShortText
Gets the short textual value of this property from the instant as a string in the default locale.This method returns the value converted to a
String
returning the appropriate textual description wherever possible. Thus, a day of week of 1 would return 'Mon' in English.- Returns:
- the current text value
- See Also:
-
getAsShortText
Gets the short textual value of this property from the instant as a string in the specified locale.This method returns the value converted to a
String
returning the appropriate textual description wherever possible. Thus, a day of week of 1 would return 'Mon' in English.- Parameters:
locale
- locale to use for selecting a text symbol, null means default- Returns:
- the current text value
- See Also:
-
getDifference
Returns the difference between this field property instant and the one passed in, in the units of this field. The sign of the difference matches that of compareTo. In other words, this field property's instant is the minuend.- Parameters:
instant
- the subtrahend, null means now- Returns:
- the difference in the units of this field
- See Also:
-
getDifferenceAsLong
Returns the difference between this field property instant and the one passed in, in the units of this field. The sign of the difference matches that of compareTo. In other words, this field property's instant is the minuend.- Parameters:
instant
- the subtrahend, null means now- Returns:
- the difference in the units of this field
- See Also:
-
getDurationField
Returns the duration per unit value of this field. For example, if this field represents "hour of day", then the duration is an hour.- Returns:
- the duration of this field, or UnsupportedDurationField
-
getRangeDurationField
Returns the range duration of this field. For example, if this field represents "hour of day", then the range duration is a day.- Returns:
- the range duration of this field, or null if field has no range
-
isLeap
public boolean isLeap()Gets whether this field is leap.- Returns:
- true if a leap field
- See Also:
-
getLeapAmount
public int getLeapAmount()Gets the amount by which this field is leap.- Returns:
- the amount by which the field is leap
- See Also:
-
getLeapDurationField
If this field were to leap, then it would be in units described by the returned duration. If this field doesn't ever leap, null is returned.- Returns:
- the duration field
-
getMinimumValueOverall
public int getMinimumValueOverall()Gets the minimum value for the field ignoring the current time.- Returns:
- the minimum value
- See Also:
-
getMinimumValue
public int getMinimumValue()Gets the minimum value for the field.- Returns:
- the minimum value
- See Also:
-
getMaximumValueOverall
public int getMaximumValueOverall()Gets the maximum value for the field ignoring the current time.- Returns:
- the maximum value
- See Also:
-
getMaximumValue
public int getMaximumValue()Gets the maximum value for the field.- Returns:
- the maximum value
- See Also:
-
getMaximumTextLength
Gets the maximum text length for the field.- Parameters:
locale
- optional locale to use for selecting a text symbol- Returns:
- the maximum length
- See Also:
-
getMaximumShortTextLength
Gets the maximum short text length for the field.- Parameters:
locale
- optional locale to use for selecting a text symbol- Returns:
- the maximum length
- See Also:
-
remainder
public long remainder()Returns the fractional duration milliseconds of this field.- Returns:
- remainder duration, in milliseconds
- See Also:
-
toInterval
Returns the interval that represents the range of the minimum and maximum values of this field.For example,
datetime.monthOfYear().toInterval()
will return an interval over the whole month.- Returns:
- the interval of this field
- Since:
- 1.2
-
compareTo
Compare this field to the same field on another instant.The comparison is based on the value of the same field type, irrespective of any difference in chronology. Thus, if this property represents the hourOfDay field, then the hourOfDay field of the other instant will be queried whether in the same chronology or not.
- Parameters:
instant
- the instant to compare to- Returns:
- negative value if this is less, 0 if equal, or positive value if greater
- Throws:
IllegalArgumentException
- if the instant is null
-
compareTo
Compare this field to the same field on another partial instant.The comparison is based on the value of the same field type, irrespective of any difference in chronology. Thus, if this property represents the hourOfDay field, then the hourOfDay field of the other partial will be queried whether in the same chronology or not.
- Parameters:
partial
- the partial to compare to- Returns:
- negative value if this is less, 0 if equal, or positive value if greater
- Throws:
IllegalArgumentException
- if the partial is nullIllegalArgumentException
- if the partial doesn't support this field
-
equals
Compares this property to another. -
hashCode
public int hashCode()Returns a hashcode compatible with the equals method. -
toString
Output a debugging string.
-