ValueRange
class ValueRange : Serializable
kotlin.Any | |
↳ | java.time.temporal.ValueRange |
The range of valid values for a date-time field.
All TemporalField
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.
Summary
Public methods | |
---|---|
Int |
checkValidIntValue(value: Long, field: TemporalField!) Checks that the specified value is valid and fits in an |
Long |
checkValidValue(value: Long, field: TemporalField!) Checks that the specified value is valid. |
Boolean |
Checks if this range is equal to another range. |
Long |
Gets the largest possible minimum value that the field can take. |
Long |
Gets the maximum value that the field can take. |
Long |
Gets the minimum value that the field can take. |
Long |
Gets the smallest possible maximum value that the field can take. |
Int |
hashCode() A hash code for this range. |
Boolean |
isFixed() Is the value range fixed and fully known. |
Boolean |
Checks if all values in the range fit in an |
Boolean |
isValidIntValue(value: Long) Checks if the value is within the valid range and that all values in the range fit in an |
Boolean |
isValidValue(value: Long) Checks if the value is within the valid range. |
static ValueRange! |
Obtains a fixed value range. |
static ValueRange! |
Obtains a variable value range. |
static ValueRange! |
Obtains a fully variable value range. |
String |
toString() Outputs this range as a |
Public methods
checkValidIntValue
fun checkValidIntValue(
value: Long,
field: TemporalField!
): Int
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 |
Long: the value to check |
field |
TemporalField!: the field being checked, may be null |
Return | |
---|---|
Int |
the value that was passed in |
See Also
checkValidValue
fun checkValidValue(
value: Long,
field: TemporalField!
): Long
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 |
Long: the value to check |
field |
TemporalField!: the field being checked, may be null |
Return | |
---|---|
Long |
the value that was passed in |
See Also
equals
fun equals(other: Any?): Boolean
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 |
Return | |
---|---|
Boolean |
true if this is equal to the other range |
getLargestMinimum
fun getLargestMinimum(): Long
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.
Return | |
---|---|
Long |
the largest possible minimum value for this field |
getMaximum
fun getMaximum(): Long
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.
Return | |
---|---|
Long |
the maximum value for this field |
getMinimum
fun getMinimum(): Long
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.
Return | |
---|---|
Long |
the minimum value for this field |
getSmallestMaximum
fun getSmallestMaximum(): Long
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.
Return | |
---|---|
Long |
the smallest possible maximum value for this field |
hashCode
fun hashCode(): Int
A hash code for this range.
Return | |
---|---|
Int |
a suitable hash code |
isFixed
fun isFixed(): Boolean
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.
Return | |
---|---|
Boolean |
true if the set of values is fixed |
isIntValue
fun isIntValue(): Boolean
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()
.
Return | |
---|---|
Boolean |
true if a valid value always fits in an int |
isValidIntValue
fun isValidIntValue(value: Long): Boolean
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 |
Long: the value to check |
Return | |
---|---|
Boolean |
true if the value is valid and fits in an int |
isValidValue
fun isValidValue(value: Long): Boolean
Checks if the value is within the valid range.
This checks that the value is within the stored range of values.
Parameters | |
---|---|
value |
Long: the value to check |
Return | |
---|---|
Boolean |
true if the value is valid |
of
static fun of(
min: Long,
max: Long
): ValueRange!
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 |
Long: the minimum value |
max |
Long: the maximum value |
Return | |
---|---|
ValueRange! |
the ValueRange for min, max, not null |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the minimum is greater than the maximum |
of
static fun of(
min: Long,
maxSmallest: Long,
maxLargest: Long
): ValueRange!
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 |
Long: the minimum value |
maxSmallest |
Long: the smallest maximum value |
maxLargest |
Long: the largest maximum value |
Return | |
---|---|
ValueRange! |
the ValueRange for min, smallest max, largest max, not null |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the minimum is greater than the smallest maximum, or the smallest maximum is greater than the largest maximum |
of
static fun of(
minSmallest: Long,
minLargest: Long,
maxSmallest: Long,
maxLargest: Long
): ValueRange!
Obtains a fully variable value range.
This factory obtains a range where both the minimum and maximum value may vary.
Parameters | |
---|---|
minSmallest |
Long: the smallest minimum value |
minLargest |
Long: the largest minimum value |
maxSmallest |
Long: the smallest maximum value |
maxLargest |
Long: the largest maximum value |
Return | |
---|---|
ValueRange! |
the ValueRange for smallest min, largest min, smallest max, largest max, not null |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
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, or the smallest minimum is greater than the largest minimum |
toString
fun toString(): String
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.
Return | |
---|---|
String |
a string representation of this range, not null |