public class RangeValidator extends Object implements AttributeValidator
Is capable of validating Number
s.
Constructor and Description |
---|
RangeValidator(BigDecimal min,
BigDecimal max)
Creates a
RangeValidator with an inclusive range. |
RangeValidator(BigDecimal min,
BigDecimal max,
BigDecimal epsilon)
Creates a
RangeValidator with an inclusive range and the provided
epsilon. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
int |
hashCode() |
Optional<AttributeValidationReport> |
validate(Attribute attribute)
Validates a single
Attribute . |
public RangeValidator(BigDecimal min, BigDecimal max)
RangeValidator
with an inclusive range.
Uses an epsilon of 1e-6 on both sides of the range to account for floating point representation inaccuracies, so the range is really [min - epsilon, max + epsilon].
min
- the minimum allowable value (inclusive), cannot be nullmax
- the maximum allowable value (inclusive), cannot be null and must be greater than
min
IllegalArgumentException
- if max
is not greater than min
or either is
nullpublic RangeValidator(BigDecimal min, BigDecimal max, BigDecimal epsilon)
RangeValidator
with an inclusive range and the provided
epsilon.
Uses the provided epsilon on both sides of the range to account for floating point representation inaccuracies, so the range is really [min - epsilon, max + epsilon].
min
- the minimum allowable value (inclusive), cannot be nullmax
- the maximum allowable value (inclusive), cannot be null and must be greater than
min
epsilon
- the epsilon value, cannot be null and must be positiveIllegalArgumentException
- if max
is not greater than min
, epsilon
is not positive, or if any argument is nullpublic Optional<AttributeValidationReport> validate(Attribute attribute)
AttributeValidator
Attribute
.validate
in interface AttributeValidator
attribute
- the Attribute
to validate, cannot be nullOptional
containing an AttributeValidationReport
if there are
violations, or an empty Optional
if there are no violationsThis work is licensed under a Creative Commons Attribution 4.0 International License.