Class Range<T extends Comparable<? super T>>
java.lang.Object
rgu.transport.algorithms.util.Range<T>
- Type Parameters:
T- the type
- All Implemented Interfaces:
Predicate<T>
A non-empty range in between two values. This also implements the
Predicate functional
interface and tests true if the tested value is contained in the range.- Author:
- Lee A. Christie
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Comparable<? super T>>
Range<T> any()Creates a range of all values (contains everything of type T).static <T extends Comparable<? super T>>
Range<T> closed(T lower, T upper) Creates a closed range.static <T extends Comparable<? super T>>
Range<T> halfOpen(T lower, T bound) Creates a half-open range.booleanintersects(Range<T> other) Checks if this range intersects another range or not.booleanisAny()Returns true if this range is an instance of any.booleanChecks if a given object is contained with the range.toString()Returns a string representation of the range,[lower, upper]is closed,[lower, bound)if half-open.
-
Method Details
-
closed
Creates a closed range.- Type Parameters:
T- the type- Parameters:
lower- the minimum value in the range, not nullupper- the maximum value (inclusive), not null- Returns:
- a range
- Throws:
IllegalArgumentException- if lower > bound
-
halfOpen
Creates a half-open range.- Type Parameters:
T- the type- Parameters:
lower- the minimum value in the range, not nullbound- the upper bound (exclusive), not null- Returns:
- a range
- Throws:
IllegalArgumentException- if lower >= bound
-
any
Creates a range of all values (contains everything of type T).- Type Parameters:
T- the type- Returns:
- a range
-
isAny
public boolean isAny()Returns true if this range is an instance of any. Note that there may be other instances for a given typeTfor whichtest(Comparable)always returnstrue, but for whichisAny()returns false.- Returns:
- true if any, false otherwise
-
toString
-
intersects
-
test
-