Class ISOChronology.Rule
- java.lang.Object
-
- javax.time.calendar.CalendricalRule<T>
-
- javax.time.calendar.DateTimeFieldRule<java.lang.Integer>
-
- javax.time.calendar.ISOChronology.Rule
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<CalendricalRule<?>>
,java.util.Comparator<Calendrical>
- Enclosing class:
- ISOChronology
static final class ISOChronology.Rule extends DateTimeFieldRule<java.lang.Integer> implements java.io.Serializable
Single rule subclass, which means fewer classes to load at startup.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javax.time.calendar.DateTimeFieldRule
DateTimeFieldRule.TextStore
-
-
Field Summary
Fields Modifier and Type Field Description private int
ordinal
private static long
serialVersionUID
private int
smallestMaximum
-
Constructor Summary
Constructors Modifier Constructor Description private
Rule(int ordinal, java.lang.String name, PeriodUnit periodUnit, PeriodUnit periodRange, int minimumValue, int maximumValue, int smallestMaximum)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(CalendricalRule<?> other)
Compares thisCalendricalRule
to another.protected java.lang.Integer
derive(Calendrical calendrical)
Derives the value of this rule from a calendrical.boolean
equals(java.lang.Object obj)
Compares two rules based on their ID.int
getMaximumValue(Calendrical calendrical)
Gets the minimum value that the field can take using the specified calendrical information to refine the accuracy of the response.int
getSmallestMaximumValue()
Gets the smallest possible maximum value that the field can take.int
hashCode()
Returns a hash code based on the ID.private java.lang.Object
readResolve()
-
Methods inherited from class javax.time.calendar.DateTimeFieldRule
checkValue, checkValue, convertFractionToInt, convertIntToFraction, convertIntToValue, convertValueToInt, createTextStores, getInt, getInteger, getLargestMinimumValue, getMaximumValue, getMinimumValue, getMinimumValue, getText, getTextStore, isFixedValueSet, isValidValue, isValidValue
-
Methods inherited from class javax.time.calendar.CalendricalRule
compare, deriveValueFor, deriveValueFrom, getChronology, getID, getName, getPeriodRange, getPeriodUnit, getReifiedType, getValue, getValueChecked, interpret, interpretValue, merge, reify, toString
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
ordinal
private final int ordinal
-
smallestMaximum
private final transient int smallestMaximum
-
-
Constructor Detail
-
Rule
private Rule(int ordinal, java.lang.String name, PeriodUnit periodUnit, PeriodUnit periodRange, int minimumValue, int maximumValue, int smallestMaximum)
-
-
Method Detail
-
readResolve
private java.lang.Object readResolve()
-
derive
protected java.lang.Integer derive(Calendrical calendrical)
Description copied from class:CalendricalRule
Derives the value of this rule from a calendrical.This method derives the value for this field from other fields in the calendrical without directly querying the calendrical for the value.
For example, if this field is quarter-of-year, then the value can be derived from month-of-year.
The implementation only needs to derive the value based on its immediate parents. The use of
Calendrical.get(javax.time.calendar.CalendricalRule<T>)
will extract any further parents on demand.A typical implementation of this method obtains the parent value and performs a calculation. For example, here is a simple implementation for the quarter-of-year field:
Integer moyVal = calendrical.get(ISOChronology.monthOfYearRule()); return (moyVal != null ? ((moyVal - 1) % 4) + 1) : null;
This method is designed to be overridden in subclasses. The subclass implementation must be thread-safe. The subclass implementation must not request the value of this rule from the specified calendrical, otherwise a stack overflow error will occur.
- Overrides:
derive
in classCalendricalRule<java.lang.Integer>
- Parameters:
calendrical
- the calendrical to derive from, not null- Returns:
- the derived value, null if unable to derive
-
getSmallestMaximumValue
public int getSmallestMaximumValue()
Description copied from class:DateTimeFieldRule
Gets the smallest possible maximum value that the field can take.The default implementation returns
DateTimeFieldRule.getMaximumValue()
. Subclasses must override this as necessary.- Overrides:
getSmallestMaximumValue
in classDateTimeFieldRule<java.lang.Integer>
- Returns:
- the smallest possible maximum value for this field
-
getMaximumValue
public int getMaximumValue(Calendrical calendrical)
Description copied from class:DateTimeFieldRule
Gets the minimum value that the field can take using the specified calendrical information to refine the accuracy of the response.The result of this method will still be inaccurate if there is insufficient information in the calendrical.
For example, if this field is the ISO day-of-month field, then the number of days in the month varies depending on the month and year. If both the month and year can be derived from the calendrical, then the maximum value returned will be accurate. Otherwise the 'best guess' value from
DateTimeFieldRule.getMaximumValue()
will be returned.The default implementation returns
DateTimeFieldRule.getMaximumValue()
. Subclasses must override this as necessary.- Overrides:
getMaximumValue
in classDateTimeFieldRule<java.lang.Integer>
- Parameters:
calendrical
- context calendrical, not null- Returns:
- the minimum value of the field given the context
-
compareTo
public int compareTo(CalendricalRule<?> other)
Description copied from class:CalendricalRule
Compares thisCalendricalRule
to another.The comparison is based on the period unit followed by the period range followed by the rule ID. The period unit is compared first, so MinuteOfHour will be less than HourOfDay, which will be less than DayOfWeek. When the period unit is the same, the period range is compared, so DayOfWeek is less than DayOfMonth, which is less than DayOfYear. Finally, the rule ID is compared.
- Specified by:
compareTo
in interfacejava.lang.Comparable<CalendricalRule<?>>
- Overrides:
compareTo
in classCalendricalRule<java.lang.Integer>
- Parameters:
other
- the other type to compare to, not null- Returns:
- the comparator result, negative if less, positive if greater, zero if equal
-
equals
public boolean equals(java.lang.Object obj)
Description copied from class:CalendricalRule
Compares two rules based on their ID.- Specified by:
equals
in interfacejava.util.Comparator<Calendrical>
- Overrides:
equals
in classCalendricalRule<java.lang.Integer>
- Returns:
- true if the rules are the same
-
hashCode
public int hashCode()
Description copied from class:CalendricalRule
Returns a hash code based on the ID.- Overrides:
hashCode
in classCalendricalRule<java.lang.Integer>
- Returns:
- a description of the rule
-
-