javax.time.calendar
Class DateTimeRuleRange

java.lang.Object
  extended by javax.time.calendar.DateTimeRuleRange
All Implemented Interfaces:
java.io.Serializable

public final class DateTimeRuleRange
extends java.lang.Object
implements java.io.Serializable

The range of valid values for a date-time field.

All DateTimeField instances have a valid range of values. For example, the ISO day-of-month runs from 1 to somewhere between 28 and 31. This class captures that valid range.

Instances of this class are not tied to a specific rule

This class is immutable and thread-safe.

Author:
Stephen Colebourne
See Also:
Serialized Form

Method Summary
 boolean equals(java.lang.Object obj)
           
 long getLargestMinimum()
          Gets the largest possible minimum value that the field can take.
 long getMaximum()
          Gets the maximum value that the field can take.
 long getMinimum()
          Gets the minimum value that the field can take.
 long getSmallestMaximum()
          Gets the smallest possible maximum value that the field can take.
 int hashCode()
           
 boolean isFixed()
          Is the value range fixed and fully known.
 boolean isIntValue()
          Checks if all values in the range fit in an int.
 boolean isValidIntValue(long value)
          Checks if the value is within the valid range and that all values in the range fit in an int.
 boolean isValidValue(long value)
          Checks if the value is within the valid range.
static DateTimeRuleRange of(long min, long max)
          Obtains a fixed value range.
static DateTimeRuleRange of(long min, long maxSmallest, long maxLargest)
          Obtains a variable value range.
static DateTimeRuleRange of(long minSmallest, long minLargest, long maxSmallest, long maxLargest)
          Obtains a fully variable value range.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

of

public static DateTimeRuleRange of(long min,
                                   long max)
Obtains a fixed value range.

This factory obtains a range where the minimum and maximum values are fixed. For example, the ISO month-of-year always runs from 1 to 12.

Parameters:
min - the minimum value
max - the maximum value

of

public static DateTimeRuleRange of(long min,
                                   long maxSmallest,
                                   long maxLargest)
Obtains a variable value range.

This factory obtains a range where the minimum value is fixed and the maximum value may vary. For example, the ISO day-of-month always starts at 1, but ends between 28 and 31.

Parameters:
min - the minimum value
maxSmallest - the smallest maximum value
maxLargest - the largest maximum value

of

public static DateTimeRuleRange of(long minSmallest,
                                   long minLargest,
                                   long maxSmallest,
                                   long maxLargest)
Obtains a fully variable value range.

This factory obtains a range where both the minimum and maximum value may vary.

Parameters:
minSmallest - the smallest minimum value
minLargest - the largest minimum value
maxSmallest - the smallest maximum value
maxLargest - the largest maximum value

isFixed

public boolean isFixed()
Is the value range fixed and fully known.

For example, the ISO day-of-month runs from 1 to between 28 and 31. Since there is uncertainty about the maximum value, the range is not fixed. However, for the month of January, the range is always 1 to 31, thus it is fixed.

Returns:
true if the set of values is fixed

getMinimum

public long getMinimum()
Gets the minimum value that the field can take.

For example, the ISO day-of-month always starts at 1. The minimum is therefore 1.

Returns:
the minimum value for this field

getLargestMinimum

public long getLargestMinimum()
Gets the largest possible minimum value that the field can take.

For example, the ISO day-of-month always starts at 1. The largest minimum is therefore 1.

Returns:
the largest possible minimum value for this field

getSmallestMaximum

public long getSmallestMaximum()
Gets the smallest possible maximum value that the field can take.

For example, the ISO day-of-month runs to between 28 and 31 days. The smallest maximum is therefore 28.

Returns:
the smallest possible maximum value for this field

getMaximum

public long getMaximum()
Gets the maximum value that the field can take.

For example, the ISO day-of-month runs to between 28 and 31 days. The maximum is therefore 31.

Returns:
the maximum value for this field

isIntValue

public boolean isIntValue()
Checks if all values in the range fit in an int.

This checks that all valid values are within the bounds of an int.

For example, the ISO month-of-year has values from 1 to 12, which fits in an int. By comparison, ISO nano-of-day runs from 1 to 86,400,000,000,000 which does not fit in an int.

This implementation uses getMinimum() and getMaximum().

Returns:
true if a valid value always fits in an int

isValidValue

public boolean isValidValue(long value)
Checks if the value is within the valid range.

This checks that the value is within the stored range of values.

Parameters:
value - the value to check
Returns:
true if the value is valid

isValidIntValue

public boolean isValidIntValue(long value)
Checks if the value is within the valid range and that all values in the range fit in an int.

This method combines isIntValue() and isValidValue(long).

Parameters:
value - the value to check
Returns:
true if the value is valid and fits in an int

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object