Class DoubleRange
- java.lang.Object
-
- software.kes.kraftwerk.constraints.DoubleRange
-
- All Implemented Interfaces:
Constraint<java.lang.Double>
public final class DoubleRange extends java.lang.Object implements Constraint<java.lang.Double>
A range ofdouble
s. Like all ranges, it is immutable and its span always includes a minimum of one value.Construct using one of the static methods (
inclusive(double, double)
,exclusive(double, double)
),or by using
from(double)
:DoubleRange.from(0.0).to(10.0) // inclusive upper bound DoubleRange.from(0.0).until(10.0) // exclusive upper bound
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
DoubleRange.DoubleRangeFrom
A partially constructedDoubleRange
, with the lower bound already provided.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DoubleRange
doubleRange(double min, boolean minIncluded, double max, boolean maxIncluded)
Creates aDoubleRange
.boolean
equals(java.lang.Object o)
static DoubleRange
exclusive(double maxExclusive)
Creates aDoubleRange
from0
..maxExclusive
.static DoubleRange
exclusive(double minInclusive, double maxExclusive)
Creates aDoubleRange
fromminInclusive
..maxExclusive
.static DoubleRange.DoubleRangeFrom
from(double minInclusive)
Partially constructs aDoubleRange
with its lower bound.static DoubleRange.DoubleRangeFrom
fromExclusive(double minExclusive)
Partially constructs aDoubleRange
with its lower bound.int
hashCode()
boolean
includes(java.lang.Double value)
Tests if a value is included by thisConstraint
.static DoubleRange
inclusive(double minInclusive, double maxInclusive)
Creates aDoubleRange
fromminInclusive
..maxInclusive
.double
max()
double
maxExclusive()
boolean
maxIncluded()
double
maxInclusive()
double
min()
double
minExclusive()
boolean
minIncluded()
double
minInclusive()
DoubleRange
negate()
java.lang.String
toString()
DoubleRange
withMaxExclusive(double maxExclusive)
Creates a newDoubleRange
that is the same as this one, with a new upper bound.DoubleRange
withMaxInclusive(double maxInclusive)
Creates a newDoubleRange
that is the same as this one, with a new upper bound.DoubleRange
withMinExclusive(double minExclusive)
Creates a newDoubleRange
that is the same as this one, with a new lower bound.DoubleRange
withMinInclusive(double minInclusive)
Creates a newDoubleRange
that is the same as this one, with a new lower bound.
-
-
-
Method Detail
-
from
public static DoubleRange.DoubleRangeFrom from(double minInclusive)
Partially constructs aDoubleRange
with its lower bound.With the result, you can call
to
oruntil
with the upper bound to create theDoubleRange
.- Parameters:
minInclusive
- the lower bound (inclusive) of the range- Returns:
- a
DoubleRange.DoubleRangeFrom
-
fromExclusive
public static DoubleRange.DoubleRangeFrom fromExclusive(double minExclusive)
Partially constructs aDoubleRange
with its lower bound.With the result, you can call
to
oruntil
with the upper bound to create theDoubleRange
.- Parameters:
minExclusive
- the lower bound (exclusive) of the range- Returns:
- a
DoubleRange.DoubleRangeFrom
-
inclusive
public static DoubleRange inclusive(double minInclusive, double maxInclusive)
Creates aDoubleRange
fromminInclusive
..maxInclusive
.
-
exclusive
public static DoubleRange exclusive(double minInclusive, double maxExclusive)
Creates aDoubleRange
fromminInclusive
..maxExclusive
.
-
exclusive
public static DoubleRange exclusive(double maxExclusive)
Creates aDoubleRange
from0
..maxExclusive
.
-
doubleRange
public static DoubleRange doubleRange(double min, boolean minIncluded, double max, boolean maxIncluded)
Creates aDoubleRange
.
-
min
public double min()
-
max
public double max()
-
minIncluded
public boolean minIncluded()
-
maxIncluded
public boolean maxIncluded()
-
includes
public boolean includes(java.lang.Double value)
Description copied from interface:Constraint
Tests if a value is included by thisConstraint
.- Specified by:
includes
in interfaceConstraint<java.lang.Double>
- Parameters:
value
- the value- Returns:
- a
boolean
-
minInclusive
public double minInclusive()
-
minExclusive
public double minExclusive()
-
maxInclusive
public double maxInclusive()
-
maxExclusive
public double maxExclusive()
-
withMinInclusive
public DoubleRange withMinInclusive(double minInclusive)
Creates a newDoubleRange
that is the same as this one, with a new lower bound.- Parameters:
minInclusive
- the new lower bound (inclusive) for the range; must not exceed this range's upper bound- Returns:
- a
DoubleRange
-
withMaxInclusive
public DoubleRange withMaxInclusive(double maxInclusive)
Creates a newDoubleRange
that is the same as this one, with a new upper bound.- Parameters:
maxInclusive
- the new upper bound (inclusive) for the range; must not be less than this range's lower bound- Returns:
- a
DoubleRange
-
withMinExclusive
public DoubleRange withMinExclusive(double minExclusive)
Creates a newDoubleRange
that is the same as this one, with a new lower bound.- Parameters:
minExclusive
- the new lower bound (exclusive) for the range; must be less than this range's upper bound- Returns:
- a
DoubleRange
-
withMaxExclusive
public DoubleRange withMaxExclusive(double maxExclusive)
Creates a newDoubleRange
that is the same as this one, with a new upper bound.- Parameters:
maxExclusive
- the new upper bound (exclusive) for the range; must be greater than this range's lower bound- Returns:
- a
DoubleRange
-
negate
public DoubleRange negate()
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-