Class DoubleRange
- All Implemented Interfaces:
Serializable
Specializes
NumberRange for Doubles.
This class is not designed to interoperate with other NumberRanges
- Since:
- 3.13.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondoublefit(double element) Fits the given value into this range by returning the given value or, if out of bounds, the range minimum if below, or the range maximum if above.static DoubleRangeof(double fromInclusive, double toInclusive) Creates a range with the specified minimum and maximum values (both inclusive).static DoubleRangeCreates a range with the specified minimum and maximum values (both inclusive).Methods inherited from class Range
between, between, contains, containsRange, elementCompareTo, equals, fit, getComparator, getMaximum, getMinimum, hashCode, intersectionWith, is, is, isAfter, isAfterRange, isBefore, isBeforeRange, isEndedBy, isNaturalOrdering, isOverlappedBy, isStartedBy, of, of, toString, toStringModifier and TypeMethodDescriptionstatic <T extends Comparable<? super T>>
Range<T> between(T fromInclusive, T toInclusive) Deprecated.static <T> Range<T> between(T fromInclusive, T toInclusive, Comparator<T> comparator) Deprecated.booleanChecks whether the specified element occurs within this range.booleancontainsRange(Range<Double> otherRange) Checks whether this range contains all the elements of the specified range.intelementCompareTo(Double element) Checks where the specified element occurs relative to this range.booleanCompares this range to another object to test if they are equal.Fits the given element into this range by returning the given element or, if out of bounds, the range minimum if below, or the range maximum if above.Gets the comparator being used to determine if objects are within the range.Gets the maximum value in this range.Gets the minimum value in this range.inthashCode()Gets a suitable hash code for the range.intersectionWith(Range<Double> other) Calculate the intersection ofthisand an overlapping Range.static <T extends Comparable<? super T>>
Range<T> is(T element) Creates a range using the specified element as both the minimum and maximum in this range.static <T> Range<T> is(T element, Comparator<T> comparator) Creates a range using the specified element as both the minimum and maximum in this range.booleanTests whether this range is after the specified element.booleanisAfterRange(Range<Double> otherRange) Tests whether this range is completely after the specified range.booleanTests whether this range is before the specified element.booleanisBeforeRange(Range<Double> otherRange) Tests whether this range is completely before the specified range.booleanTests whether this range ends with the specified element.booleanTests whether or not the Range is using the natural ordering of the elements.booleanisOverlappedBy(Range<Double> otherRange) Tests whether this range is overlapped by the specified range.booleanisStartedBy(Double element) Tests whether this range starts with the specified element.static <T extends Comparable<? super T>>
Range<T> of(T fromInclusive, T toInclusive) Creates a range with the specified minimum and maximum values (both inclusive).static <T> Range<T> of(T fromInclusive, T toInclusive, Comparator<T> comparator) Creates a range with the specified minimum and maximum values (both inclusive).toString()Gets the range as aString.Formats the receiver using the given format.
-
Method Details
-
of
Creates a range with the specified minimum and maximum values (both inclusive).The range uses the natural ordering of the elements to determine where values lie in the range.
The arguments may be passed in the order (min, max) or (max,min). The getMinimum and getMaximum methods will return the correct values.
- Parameters:
fromInclusive- The first value that defines the edge of the range, inclusive.toInclusive- The second value that defines the edge of the range, inclusive.- Returns:
- The range object, not null.
- Throws:
IllegalArgumentException- Thrown if either value is NaN.
-
of
Creates a range with the specified minimum and maximum values (both inclusive).The range uses the natural ordering of the elements to determine where values lie in the range.
The arguments may be passed in the order (min, max) or (max,min). The getMinimum and getMaximum methods will return the correct values.
- Parameters:
fromInclusive- The first value that defines the edge of the range, inclusive.toInclusive- The second value that defines the edge of the range, inclusive.- Returns:
- The range object, not null.
- Throws:
NullPointerException- Thrown if either element is null.IllegalArgumentException- Thrown if either element is NaN.
-
fit
Fits the given value into this range by returning the given value or, if out of bounds, the range minimum if below, or the range maximum if above.LongRange range = LongRange.of(16, 64); range.fit(-9) --> 16 range.fit(0) --> 16 range.fit(15) --> 16 range.fit(16) --> 16 range.fit(17) --> 17 ... range.fit(63) --> 63 range.fit(64) --> 64 range.fit(99) --> 64- Parameters:
element- The element to test.- Returns:
- The minimum, the element, or the maximum depending on the element's location relative to the range.
- Since:
- 3.19.0
-
Range.of(Comparable, Comparable).