T - The type of values in this range.public final class Range<T> extends Object
Because there are no restrictions on type of values that can be used with this Range class,
it is not able to "understand" values that are passed to its various factory methods.
As a result, only minimal consistency checks are performed: null-checks, mostly.
In particular, this class does not check that the lower bound is actually lower than the upper bound,
because it has no idea what ordering to use.
Checking the relative order of bounds is the responsibility of callers of the getLowerBoundValue()
and getUpperBoundValue() methods.
| Modifier and Type | Method and Description |
|---|---|
static <T> Range<T> |
all() |
static <T> Range<T> |
atLeast(T lowerBoundValue) |
static <T> Range<T> |
atMost(T upperBoundValue) |
static <T> Range<T> |
between(T lowerBoundValue,
RangeBoundInclusion lowerBoundInclusion,
T upperBoundValue,
RangeBoundInclusion upperBoundInclusion) |
static <T> Range<T> |
between(T lowerBoundValue,
T upperBoundValue) |
static <T> Range<T> |
canonical(T lowerBoundValue,
T upperBoundValue)
Create a canonical range, i.e.
|
boolean |
equals(Object obj) |
RangeBoundInclusion |
getLowerBoundInclusion() |
Optional<T> |
getLowerBoundValue() |
RangeBoundInclusion |
getUpperBoundInclusion() |
Optional<T> |
getUpperBoundValue() |
static <T> Range<T> |
greaterThan(T lowerBoundValue) |
int |
hashCode() |
static <T> Range<T> |
lessThan(T upperBoundValue) |
<R> Range<R> |
map(Function<? super T,? extends R> function) |
String |
toString() |
public static <T> Range<T> canonical(T lowerBoundValue, T upperBoundValue)
[lowerBoundValue, upperBoundValue) (lower bound included, upper bound excluded),
or [lowerBoundValue, +Infinity] (both bounds included) if the upper bound is +Infinity.
This is mostly useful when creating multiple, contiguous ranges, like for example in range aggregations.
T - The type of range bounds.lowerBoundValue - The lower bound of the range.
May be null to represent -Infinity (no lower bound),upperBoundValue - The upper bound of the range.
May be null to represent +Infinity (no upper bound).[lowerBoundValue, upperBoundValue) (lower bound included, upper bound excluded),
or [lowerBoundValue, +Infinity] (both bounds included) if the upper bound is +Infinity.public static <T> Range<T> all()
T - The type of range bounds.[-Infinity, +Infinity] (both bounds included).public static <T> Range<T> between(T lowerBoundValue, T upperBoundValue)
T - The type of range bounds.lowerBoundValue - The lower bound of the range.
May be null to represent -Infinity (no lower bound),upperBoundValue - The upper bound of the range.
May be null to represent +Infinity (no upper bound).[lowerBoundValue, upperBoundValue] (both bounds included).public static <T> Range<T> between(T lowerBoundValue, RangeBoundInclusion lowerBoundInclusion, T upperBoundValue, RangeBoundInclusion upperBoundInclusion)
T - The type of range bounds.lowerBoundValue - The value of the lower bound of the range.
May be null to represent -Infinity (no lower bound).lowerBoundInclusion - Whether the lower bound is included in the range or excluded.upperBoundValue - The value of the upper bound of the range.
May be null to represent +Infinity (no upper bound).upperBoundInclusion - Whether the upper bound is included in the range or excluded.Range.public static <T> Range<T> atLeast(T lowerBoundValue)
T - The type of range bounds.lowerBoundValue - The value of the lower bound of the range. Must not be null.[lowerBoundValue, +Infinity] (both bounds included).public static <T> Range<T> greaterThan(T lowerBoundValue)
T - The type of range bounds.lowerBoundValue - The value of the lower bound of the range. Must not be null.(lowerBoundValue, +Infinity] (lower bound excluded, upper bound included).public static <T> Range<T> atMost(T upperBoundValue)
T - The type of range bounds.upperBoundValue - The value of the upper bound of the range. Must not be null.[-Infinity, upperBoundValue] (both bounds included).public static <T> Range<T> lessThan(T upperBoundValue)
T - The type of range bounds.upperBoundValue - The value of the upper bound of the range. Must not be null.[-Infinity, upperBoundValue) (lower bound included, upper bound excluded).public Optional<T> getLowerBoundValue()
public RangeBoundInclusion getLowerBoundInclusion()
RangeBoundInclusion.EXCLUDED if there is no lower bound.public Optional<T> getUpperBoundValue()
public RangeBoundInclusion getUpperBoundInclusion()
RangeBoundInclusion.EXCLUDED if there is no upper bound.Copyright © 2006-2019 Red Hat, Inc. and others. Licensed under the GNU Lesser General Public License (LGPL), version 2.1 or later.