@GwtCompatible public final class DoubleCheck extends PrimitiveBaseCheck<DoubleCheck>
double
arguments. It can also be (and
is - if you use the Check
methods correctly) used for
float
arguments.
It provides methods like isPositive()
or
isBetween(double, double)
but also methods specific to floating
numbers like isNotInfinite()
and isNotNaN()
.
Constructor and Description |
---|
DoubleCheck(double arg)
For internal use only.
|
Modifier and Type | Method and Description |
---|---|
DoubleCheck |
is(double number)
Checks that the
double argument is equal to the given
number, throwing an exception otherwise. |
DoubleCheck |
isBetween(double min,
double max)
Checks that the
double argument is greater than or equal to
min and less than or equal to max , throwing an
exception otherwise. |
DoubleCheck |
isGreaterThan(double number)
Checks that the
double argument is (strictly) greater than
the given number, throwing an exception otherwise. |
DoubleCheck |
isLessThan(double number)
Checks that the
double argument is (strictly) less than the
given number, throwing an exception otherwise. |
DoubleCheck |
isNegative()
Checks that the
double argument is negative, throwing an
exception otherwise. |
DoubleCheck |
isNotInfinite()
Checks that the
double argument is not infinite (positive or
negative), throwing an exception otherwise. |
DoubleCheck |
isNotNaN()
Checks that the
double argument is not NaN (not a number,
see Double.NaN ), throwing an exception otherwise. |
DoubleCheck |
isPositive()
Checks that the
double argument is positive, throwing an
exception otherwise. |
check, disable
checkConversion, me, named, not
public DoubleCheck isPositive()
double
argument is positive, throwing an
exception otherwise. Note that zero is not a valid number. Often, you
want to check that a number is non-negative. Use the inverted
isNegative()
check for that:
Check.that(number).not().isNegative();
The message type used for exceptions thrown by this method is
MessageType.ARG_POSITIVE
.
IllegalArgumentException
- if argument is not positiveisNegative()
public DoubleCheck isNegative()
double
argument is negative, throwing an
exception otherwise.
The message type used for exceptions thrown by this method is
MessageType.ARG_NEGATIVE
.
IllegalArgumentException
- if argument is not negativeisPositive()
public DoubleCheck is(double number)
double
argument is equal to the given
number, throwing an exception otherwise. This check exists merely for
reasons of symmetry to the IntCheck
class which can be used as a
property check. See StringCheck.hasLengthWhich()
for example.
However, in conjunction with inversion (see BaseCheck.not()
), this method
can also be used to exclude a single value.
The message type used for exceptions thrown by this method is
MessageType.ARG_IS
.
number
- The number this argument must be equal toIllegalArgumentException
- if argument is not equal to the given numberpublic DoubleCheck isGreaterThan(double number)
double
argument is (strictly) greater than
the given number, throwing an exception otherwise. To create a
greater-than-or-equals check, you may use an inverted
isLessThan(double)
check:
Check.that(number).not().isLessThan(1.0);
The message type used for exceptions thrown by this method is
MessageType.ARG_GREATER
.
number
- The number this argument must be greater thanIllegalArgumentException
- if argument is not greater than the given numberpublic DoubleCheck isLessThan(double number)
double
argument is (strictly) less than the
given number, throwing an exception otherwise. To create a
less-than-or-equals check, you may use an inverted
isGreaterThan(double)
check:
Check.that(number).not().isGreaterThan(1.0);
The message type used for exceptions thrown by this method is
MessageType.ARG_LESS
.
number
- The number this argument must be less thanIllegalArgumentException
- if argument is not less than the given numberpublic DoubleCheck isBetween(double min, double max)
double
argument is greater than or equal to
min
and less than or equal to max
, throwing an
exception otherwise.
To create a strict or one-sided-strict between test, you may use the
isGreaterThan(double)
and isLessThan(double)
checks,
possibly in conjunction with BaseCheck.not()
.
The message type used for exceptions thrown by this method is
MessageType.ARG_BETWEEN
.
min
- The minimum numbermax
- The maximum numberIllegalArgumentException
- if argument is not between the two given numbers as defined
abovepublic DoubleCheck isNotNaN()
double
argument is not NaN (not a number,
see Double.NaN
), throwing an exception otherwise.
The message type used for exceptions thrown by this method is
MessageType.ARG_NAN
.
IllegalArgumentException
- if argument is NaNpublic DoubleCheck isNotInfinite()
double
argument is not infinite (positive or
negative), throwing an exception otherwise.
The message type used for exceptions thrown by this method is
MessageType.ARG_INFINITE
.
IllegalArgumentException
- if argument is infiniteCopyright © 2012–2017 Michael Faes. All rights reserved.