Class Range<T>
- java.lang.Object
-
- org.hibernate.search.util.common.data.Range<T>
-
- Type Parameters:
T
- The type of values in this range.
public final class Range<T> extends Object
A representation of a range that can be used with any type.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 thelowerBoundValue()
andupperBoundValue()
methods.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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)
static <T> Range<T>
greaterThan(T lowerBoundValue)
int
hashCode()
static <T> Range<T>
lessThan(T upperBoundValue)
RangeBoundInclusion
lowerBoundInclusion()
Optional<T>
lowerBoundValue()
<R> Range<R>
map(Function<? super T,? extends R> function)
String
toString()
RangeBoundInclusion
upperBoundInclusion()
Optional<T>
upperBoundValue()
-
-
-
Method Detail
-
canonical
public static <T> Range<T> canonical(T lowerBoundValue, T upperBoundValue)
Create a canonical range, i.e. a range in the form[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.
- Type Parameters:
T
- The type of range bounds.- Parameters:
lowerBoundValue
- The lower bound of the range. May benull
to represent-Infinity
(no lower bound),upperBoundValue
- The upper bound of the range. May benull
to represent+Infinity
(no upper bound).- Returns:
- The range
[lowerBoundValue, upperBoundValue)
(lower bound included, upper bound excluded), or[lowerBoundValue, +Infinity]
(both bounds included) if the upper bound is+Infinity
.
-
all
public static <T> Range<T> all()
- Type Parameters:
T
- The type of range bounds.- Returns:
- The range
[-Infinity, +Infinity]
(both bounds included).
-
between
public static <T> Range<T> between(T lowerBoundValue, T upperBoundValue)
- Type Parameters:
T
- The type of range bounds.- Parameters:
lowerBoundValue
- The lower bound of the range. May benull
to represent-Infinity
(no lower bound),upperBoundValue
- The upper bound of the range. May benull
to represent+Infinity
(no upper bound).- Returns:
- The range
[lowerBoundValue, upperBoundValue]
(both bounds included).
-
between
public static <T> Range<T> between(T lowerBoundValue, RangeBoundInclusion lowerBoundInclusion, T upperBoundValue, RangeBoundInclusion upperBoundInclusion)
- Type Parameters:
T
- The type of range bounds.- Parameters:
lowerBoundValue
- The value of the lower bound of the range. May benull
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 benull
to represent+Infinity
(no upper bound).upperBoundInclusion
- Whether the upper bound is included in the range or excluded.- Returns:
- A
Range
.
-
atLeast
public static <T> Range<T> atLeast(T lowerBoundValue)
- Type Parameters:
T
- The type of range bounds.- Parameters:
lowerBoundValue
- The value of the lower bound of the range. Must not benull
.- Returns:
- The range
[lowerBoundValue, +Infinity]
(both bounds included).
-
greaterThan
public static <T> Range<T> greaterThan(T lowerBoundValue)
- Type Parameters:
T
- The type of range bounds.- Parameters:
lowerBoundValue
- The value of the lower bound of the range. Must not benull
.- Returns:
- The range
(lowerBoundValue, +Infinity]
(lower bound excluded, upper bound included).
-
atMost
public static <T> Range<T> atMost(T upperBoundValue)
- Type Parameters:
T
- The type of range bounds.- Parameters:
upperBoundValue
- The value of the upper bound of the range. Must not benull
.- Returns:
- The range
[-Infinity, upperBoundValue]
(both bounds included).
-
lessThan
public static <T> Range<T> lessThan(T upperBoundValue)
- Type Parameters:
T
- The type of range bounds.- Parameters:
upperBoundValue
- The value of the upper bound of the range. Must not benull
.- Returns:
- The range
[-Infinity, upperBoundValue)
(lower bound included, upper bound excluded).
-
lowerBoundValue
public Optional<T> lowerBoundValue()
- Returns:
- The value of the lower bound, or an empty optional to represent {-Infinity} (no lower bound).
-
lowerBoundInclusion
public RangeBoundInclusion lowerBoundInclusion()
- Returns:
- Whether the lower bound is included in the range or excluded.
Always
RangeBoundInclusion.EXCLUDED
if there is no lower bound.
-
upperBoundValue
public Optional<T> upperBoundValue()
- Returns:
- The value of the lower bound, or an empty optional to represent {+Infinity} (no upper bound).
-
upperBoundInclusion
public RangeBoundInclusion upperBoundInclusion()
- Returns:
- Whether the upper bound is included in the range or excluded.
Always
RangeBoundInclusion.EXCLUDED
if there is no upper bound.
-
-