-
- 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 fromminimumtomaximum. Implementations shall validate at construction so a givenRangeshould always be valid.
ATTENTION:
Theminimumandmaximummay benullforunbounded ranges. It is still recommended to use fixed bounds such asLong.MAX_VALUE. However, for types such asBigDecimalthis is not possible.- Since:
- 1.0.0
-
-
Field Summary
Fields Modifier and Type Field Description static charBOUND_END_EXCLUSIVEChar indicating end with exclusive maximum.static charBOUND_END_INCLUSIVEChar indicating end with inclusive maximum.static charBOUND_SEPARATORChar to separate minimum and maximum.static charBOUND_START_EXCLUSIVEChar indicating start with exclusive minimum.static charBOUND_START_INCLUSIVEChar indicating start with inclusive minimum.static StringMAX_UNBOUNDThe unbound maximum.static StringMIN_UNBOUNDThe unbound minimum.static StringPROPERTY_MAXProperty name ofgetMax().static StringPROPERTY_MINProperty name ofgetMin().
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Vclip(V value)default booleancontains(V value)default Comparator<? super V>getComparator()VgetMax()VgetMin()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 representationsas 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
nullif no lower bound is defined. Has to be less thanmaxif both boundaries are notnull.
-
getMax
V getMax()
- Returns:
- the upper bound of this range or
nullif no upper bound is defined. Has to be greater thanminif both boundaries are notnull.
-
getComparator
default Comparator<? super V> getComparator()
- Returns:
- the
Comparatorused tocomparevalues 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
Rangeinstance (withgetMin()andgetMax()beingnull).
-
-