# ValueRange

public final class **ValueRange** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  
implements [Serializable](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Serializable.html) The range of valid values for a date-time field.


All `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalField.html` 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.


It is important to be aware of the limitations of this class.
Only the minimum and maximum values are provided.
It is possible for there to be invalid values within the outer range.
For example, a weird field may have valid values of 1, 2, 4, 6, 7, thus
have a range of '1 - 7', despite that fact that values 3 and 5 are invalid.


Instances of this class are not tied to a specific field.

### Public Method Summary

|---|---|
| int | [checkValidIntValue](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html#checkValidIntValue(long,%20java.time.temporal.TemporalField))(long value, [TemporalField](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalField.html) field) Checks that the specified value is valid and fits in an `int`. |
| long | [checkValidValue](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html#checkValidValue(long,%20java.time.temporal.TemporalField))(long value, [TemporalField](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalField.html) field) Checks that the specified value is valid. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Checks if this range is equal to another range. |
| long | [getLargestMinimum](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html#getLargestMinimum())() Gets the largest possible minimum value that the field can take. |
| long | [getMaximum](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html#getMaximum())() Gets the maximum value that the field can take. |
| long | [getMinimum](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html#getMinimum())() Gets the minimum value that the field can take. |
| long | [getSmallestMaximum](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html#getSmallestMaximum())() Gets the smallest possible maximum value that the field can take. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html#hashCode())() A hash code for this range. |
| boolean | [isFixed](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html#isFixed())() Is the value range fixed and fully known. |
| boolean | [isIntValue](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html#isIntValue())() Checks if all values in the range fit in an `int`. |
| boolean | [isValidIntValue](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html#isValidIntValue(long))(long value) Checks if the value is within the valid range and that all values in the range fit in an `int`. |
| boolean | [isValidValue](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html#isValidValue(long))(long value) Checks if the value is within the valid range. |
| static [ValueRange](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html) | [of](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html#of(long,%20long))(long min, long max) Obtains a fixed value range. |
| static [ValueRange](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html) | [of](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html#of(long,%20long,%20long,%20long))(long minSmallest, long minLargest, long maxSmallest, long maxLargest) Obtains a fully variable value range. |
| static [ValueRange](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html) | [of](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html#of(long,%20long,%20long))(long min, long maxSmallest, long maxLargest) Obtains a variable value range. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html#toString())() Outputs this range as a `String`. |

### Inherited Method Summary

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

## Public Methods

#### public int
**checkValidIntValue**
(long value, [TemporalField](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalField.html) field)

Checks that the specified value is valid and fits in an `int`.


This validates that the value is within the valid range of values and that
all valid values are within the bounds of an `int`.
The field is only used to improve the error message.

##### Parameters

| value | the value to check |
| field | the field being checked, may be null |
|---|---|

##### Returns

- the value that was passed in

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html#isValidIntValue(long)`

#### public long
**checkValidValue**
(long value, [TemporalField](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/TemporalField.html) field)

Checks that the specified value is valid.


This validates that the value is within the valid range of values.
The field is only used to improve the error message.

##### Parameters

| value | the value to check |
| field | the field being checked, may be null |
|---|---|

##### Returns

- the value that was passed in

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html#isValidValue(long)`

#### public boolean
**equals**
([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj)

Checks if this range is equal to another range.


The comparison is based on the four values, minimum, largest minimum,
smallest maximum and maximum.
Only objects of type `ValueRange` are compared, other types return false.

##### Parameters

| obj | the object to check, null returns false |
|---|---|

##### Returns

- true if this is equal to the other range

#### 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

#### 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

#### 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

#### 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

#### public int
**hashCode**
()

A hash code for this range.

##### Returns

- a suitable hash code

#### 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

#### 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 `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html#getMinimum()` and `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html#getMaximum()`.

##### Returns

- true if a valid value always fits in an `int`

#### 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 `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html#isIntValue()` and `https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html#isValidValue(long)`.

##### Parameters

| value | the value to check |
|---|---|

##### Returns

- true if the value is valid and fits in an `int`

#### 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

#### public static [ValueRange](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html)
**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 |
|---|---|

##### Returns

- the ValueRange for min, max, not null

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the minimum is greater than the maximum |
|---|---|

#### public static [ValueRange](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html)
**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 |
|---|---|

##### Returns

- the ValueRange for smallest min, largest min, smallest max, largest max, not null

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the smallest minimum is greater than the smallest maximum, or the smallest maximum is greater than the largest maximum or the largest minimum is greater than the largest maximum |
|---|---|

#### public static [ValueRange](https://developers.google.com/j2objc/javadoc/jre/reference/java/time/temporal/ValueRange.html)
**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 |
|---|---|

##### Returns

- the ValueRange for min, smallest max, largest max, not null

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the minimum is greater than the smallest maximum, or the smallest maximum is greater than the largest maximum |
|---|---|

#### public [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**toString**
()

Outputs this range as a `String`.


The format will be '{min}/{largestMin} - {smallestMax}/{max}',
where the largestMin or smallestMax sections may be omitted, together
with associated slash, if they are the same as the min or max.

##### Returns

- a string representation of this range, not null