-
- Type Parameters:
V
- type of the contained values.
- All Known Subinterfaces:
WritableRange<V>
- All Known Implementing Classes:
AbstractRange
,NumberRangeType
,NumericRange
,RangeType
public interface Range<V>
This class represents a range fromminimum
tomaximum
. Implementations shall validate at construction so a givenRange
should always be valid.
ATTENTION:
Theminimum
andmaximum
may benull
forunbounded ranges
. It is still recommended to use fixed bounds such asLong.MAX_VALUE
. However, for types such asBigDecimal
this is not possible.- Since:
- 1.0.0
-
-
Field Summary
Fields Modifier and Type Field Description static char
BOUND_END_EXCLUSIVE
Char indicating end with exclusive maximum.static char
BOUND_END_INCLUSIVE
Char indicating end with inclusive maximum.static char
BOUND_SEPARATOR
Char to separate minimum and maximum.static char
BOUND_START_EXCLUSIVE
Char indicating start with exclusive minimum.static char
BOUND_START_INCLUSIVE
Char indicating start with inclusive minimum.static String
MAX_UNBOUND
The unbound maximum.static String
MIN_UNBOUND
The unbound minimum.static String
PROPERTY_MAX
Property name ofgetMax()
.static String
PROPERTY_MIN
Property name ofgetMin()
.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default V
clip(V value)
default boolean
contains(V value)
default Comparator<? super V>
getComparator()
V
getMax()
V
getMin()
static <T> Range<T>
unbounded()
-
-
-
Field Detail
-
BOUND_START_INCLUSIVE
static final char BOUND_START_INCLUSIVE
Char indicating start with inclusive minimum.- See Also:
- Constant Field Values
-
BOUND_START_EXCLUSIVE
static final char BOUND_START_EXCLUSIVE
Char indicating start with exclusive minimum.- See Also:
- Constant Field Values
-
BOUND_END_INCLUSIVE
static final char BOUND_END_INCLUSIVE
Char indicating end with inclusive maximum.- See Also:
- Constant Field Values
-
BOUND_END_EXCLUSIVE
static final char BOUND_END_EXCLUSIVE
Char indicating end with exclusive maximum.- See Also:
- Constant Field Values
-
BOUND_SEPARATOR
static final char BOUND_SEPARATOR
Char to separate minimum and maximum. Mathematical convention would be to use a comma (','), but this causes problems when parsingstring representations
as a comma may also occur in the minimum or maximum value.- See Also:
- Constant Field Values
-
MIN_UNBOUND
static final String MIN_UNBOUND
The unbound minimum.- See Also:
- Constant Field Values
-
MAX_UNBOUND
static final String MAX_UNBOUND
The unbound maximum.- See Also:
- Constant Field Values
-
PROPERTY_MIN
static final String PROPERTY_MIN
Property name ofgetMin()
.- See Also:
- Constant Field Values
-
PROPERTY_MAX
static final String PROPERTY_MAX
Property name ofgetMax()
.- See Also:
- Constant Field Values
-
-
Method Detail
-
getMin
V getMin()
- Returns:
- the lower bound of this range or
null
if no lower bound is defined. Has to be less thanmax
if both boundaries are notnull
.
-
getMax
V getMax()
- Returns:
- the upper bound of this range or
null
if no upper bound is defined. Has to be greater thanmin
if both boundaries are notnull
.
-
getComparator
default Comparator<? super V> getComparator()
- Returns:
- the
Comparator
used tocompare
values of thisRange
. The default implementation assumes that the value type implementsComparable
. If you want to use other value types you need to override this method.
-
contains
default boolean contains(V value)
-
unbounded
static <T> Range<T> unbounded()
- Type Parameters:
T
- type of thecontained value
.- Returns:
- the unbounded
Range
instance (withgetMin()
andgetMax()
beingnull
).
-
-