-
- All Known Subinterfaces:
MutableRange<N>
- All Known Implementing Classes:
AbstractRange
public interface Range<N>
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description boolean
contains(N value)
Check if a given value is contained within this rangeN
getMax()
N
getMin()
boolean
intersects(Range<N> other)
Check if the given range intersects the current range.boolean
isMaxInclusive()
boolean
isMinInclusive()
static <N extends Comparable<N>>
Range<N>of(N min, N max)
static <N> Range<N>
of(N min, N max, Comparator<? super N> comparator)
static <N extends Comparable<N>>
Range<N>ofClosed(N min, N max)
static <N> Range<N>
ofClosed(N min, N max, Comparator<? super N> comparator)
static Range<Double>
ofDouble(double min, double max)
static Range<Double>
ofDoubleClosed(double min, double max)
static Range<Integer>
ofInteger(int min, int max)
static Range<Integer>
ofIntegerClosed(int min, int max)
static Range<Long>
ofLong(long min, long max)
static Range<Long>
ofLongClosed(long min, long max)
default Stream<N>
stream(UnaryOperator<N> incrementer)
Return aStream
containing all values contained by the range, with a given incrementer.Range<N>
withMax(N max)
Create a copy of the current range with the given max value.Range<N>
withMaxInclusive(boolean maxInclusive)
Create a copy of the current range where the max value will be either inclusive or exclusive.Range<N>
withMin(N min)
Create a copy of the current range with the given min value.Range<N>
withMinInclusive(boolean minInclusive)
Create a copy of the current range where the min value will be either inclusive or exclusive.
-
-
-
Method Detail
-
getMin
N getMin()
-
getMax
N getMax()
-
isMinInclusive
boolean isMinInclusive()
-
isMaxInclusive
boolean isMaxInclusive()
-
intersects
boolean intersects(Range<N> other)
Check if the given range intersects the current range.- Parameters:
other
- the range to check against the current range- Returns:
true
if both ranges intersect andfalse
otherwise
-
contains
boolean contains(N value)
Check if a given value is contained within this range- Parameters:
value
- the value to check- Returns:
true
if the value is contained by this range andfalse
otherwise
-
withMin
Range<N> withMin(N min)
Create a copy of the current range with the given min value.- Parameters:
min
- the new min value for the copy- Returns:
- a copy of the current range
-
withMax
Range<N> withMax(N max)
Create a copy of the current range with the given max value.- Parameters:
max
- the new max value for the copy- Returns:
- a copy of the current range
-
withMinInclusive
Range<N> withMinInclusive(boolean minInclusive)
Create a copy of the current range where the min value will be either inclusive or exclusive.- Parameters:
minInclusive
- boolean indicating if the min value should be inclusive or exclusive- Returns:
- a copy of the current range
-
withMaxInclusive
Range<N> withMaxInclusive(boolean maxInclusive)
Create a copy of the current range where the max value will be either inclusive or exclusive.- Parameters:
maxInclusive
- boolean indicating if the max value should be inclusive or exclusive- Returns:
- a copy of the current range
-
stream
default Stream<N> stream(UnaryOperator<N> incrementer)
Return aStream
containing all values contained by the range, with a given incrementer.This method should not return the min or max value if they are exclusive.
The default implementation will apply the incrementer repeatedly on the current value, starting with the min value and will continue as long as
contains(Object)
returns true.- Parameters:
incrementer
- the incrementer to use to determine the next value- Returns:
- a stream containing all values within the range
-
of
static <N extends Comparable<N>> Range<N> of(N min, N max)
-
of
static <N> Range<N> of(N min, N max, Comparator<? super N> comparator)
-
ofClosed
static <N extends Comparable<N>> Range<N> ofClosed(N min, N max)
-
ofClosed
static <N> Range<N> ofClosed(N min, N max, Comparator<? super N> comparator)
-
-