The ValueRange Class captures the valid range of the values of TemporalField instances. Given class provides the minimum and maximum values of the range.
Note: It’s possible that there might be invalid values within the outer range. For example, a field may have valid values of 1, 2, 3, 6, 7, thus have a range of ‘1-7’, despite the fact that values 4 and 5 are not valid.
Class declaration:
public final class ValueRange
extends Object
implements Serializable
ValueRange Class inherits following methods from class java.lang.Object:
- clone()
- finalize()
- getClass()
- notify()
- notifyAll()
- wait()
Methods of ValueRange Class:
| Method | Description |
|---|---|
| checkValidIntValue(long value, TemporalField field) | This method checks that the specified value is valid and fits in an int. |
| checkValidValue(long value, TemporalField field) | This method checks that the specified value is valid. |
| equals(Object obj) | This method checks if this range is equal to another range. |
| getLargestMinimum() | This method gets the largest possible minimum value that the field can take. |
| getMaximum() | This method gets the maximum value that the field can take. |
| getMinimum() | This method gets the minimum value that the field can take. |
| getSmallestMaximum() | This method gets the smallest possible maximum value that the field can take. |
| hashCode() | This method returns a suitable hash code for this range. |
| isFixed() | This method returns true if the set of values is fixed. |
| isIntValue() | This method checks if all values in the range fit in an int. |
| isValidIntValue(long value) | This method checks if the value is within the valid range and that all values in the range fit in an int. |
| isValidValue(long value) | This method checks if the value is within the valid range. |
| of(long min, long max) | This method obtains a fixed value range. |
| of(long min, long maxSmallest, long maxLargest) | This method obtains a variable value range. |
| of(long minSmallest, long minLargest, long maxSmallest, long maxLargest) | This method obtains a fully variable value range. |
| toString() | This method a string representation of this range, not null. |
Example 1:
Java
// Java program to demonstrate// ValueRange Class and its methods import java.time.temporal.ValueRange; public class GFG { public static void main(String[] args) { // create ValueRange object ValueRange vRange = ValueRange.of(5555, 1000000); // store the minimum value that the field can take long minVal = vRange.getMinimum(); // store the maximum value that the field can take long maxVal = vRange.getMaximum(); // print System.out.println("Minimum value is: " + minVal); System.out.println("Maximum value is: " + maxVal); }} |
Minimum value is: 5555 Maximum value is: 1000000
Example 2:
Java
// Java program to demonstrate// ValueRange Class and its methods import java.time.temporal.ValueRange; public class GFG { public static void main(String[] args) { // create ValueRange object ValueRange vRange = ValueRange.of(1, 10000); // check value 6001 in range or not long value1 = vRange.checkValidValue(6001, null); // print System.out.println("Value passed: " + value1); }} |
Value passed: 6001
