public final class ArgumentAssertion extends Object
double
, int
, long
, short
, float
and byte
can be
used as input arguments. If input arguments violate the assertion, an
IllegalArgumentException
with appropriate error message will be thrown.
For example:
ArgumentAssertion.assertRangeLeftOpen(1.5, 1.0, 2.0); // double
ArgumentAssertion.assertRangeLeftOpen(2, 1, 3); // int
ArgumentAssertion.assertRangeLeftOpen(1.5f, 1.0f, 2.0f); // float
Modifier and Type | Method and Description |
---|---|
static <T extends Number & Comparable<? super T>> |
assertEqual(T x,
T bound,
String variableName)
|
static <T extends Number & Comparable<? super T>> |
assertEqual(T x1,
T x2,
String variableName1,
String variableName2)
|
static void |
assertFalse(boolean condition,
String errorMessage,
Object... args)
Check if an argument
condition is false. |
static <T extends Number & Comparable<? super T>> |
assertGreaterThan(T x,
T bound,
String variableName)
|
static <T extends Number & Comparable<? super T>> |
assertLessThan(T x,
T bound,
String variableName)
|
static <T extends Number & Comparable<? super T>> |
assertNegative(T x,
String variableName)
Test if
Number x is negative. |
static <T extends Number & Comparable<? super T>> |
assertNonNegative(T x,
String variableName)
Test if
Number x is non-negative. |
static <T extends Number & Comparable<? super T>> |
assertNonPositive(T x,
String variableName)
Test if
Number x is non-positive. |
static void |
assertNormalDouble(double d,
String variableName)
Check if an argument is a normal
double value (that is, NOT
Double.NaN nor infinity). |
static void |
assertNormalFloat(float f,
String variableName)
Check if an argument is a normal
float value (that is, NOT
Float.NaN nor infinity). |
static <T extends Number & Comparable<? super T>> |
assertNotGreaterThan(T x,
T bound,
String variableName)
|
static void |
assertNotInfinity(double d,
String variableName)
Check if an argument is NOT a
Double.POSITIVE_INFINITY nor
Double.NEGATIVE_INFINITY . |
static void |
assertNotInfinity(float f,
String variableName)
Check if an argument is NOT a
Float.POSITIVE_INFINITY nor
Float.NEGATIVE_INFINITY . |
static <T extends Number & Comparable<? super T>> |
assertNotLessThan(T x,
T bound,
String variableName)
|
static void |
assertNotNaN(double d,
String variableName)
Check if an argument is NOT a
Double.NaN . |
static void |
assertNotNaN(float f,
String variableName)
Check if an argument is NOT a
Float.NaN . |
static void |
assertNotNull(Object obj,
String variableName)
Check if
obj is not null . |
static void |
assertNull(Object obj,
String variableName)
Check if
obj is null . |
static <T extends Number & Comparable<? super T>> |
assertPositive(T x,
String variableName)
Test if
Number x is positive. |
static <T extends Number & Comparable<? super T>> |
assertRange(T x,
T low,
T high,
String variableName)
|
static <T extends Number & Comparable<? super T>> |
assertRangeLeftOpen(T x,
T low,
T high,
String variableName)
Test whether the specified
Number occurs within the range (low , high ]
(left exclusive, right inclusive). |
static <T extends Number & Comparable<? super T>> |
assertRangeOpen(T x,
T low,
T high,
String variableName)
|
static <T extends Number & Comparable<? super T>> |
assertRangeRightOpen(T x,
T low,
T high,
String variableName)
Test whether the specified
Number occurs within the range [low , high )
(left inclusive, right exclusive). |
static void |
assertTrue(boolean condition,
String errorMessage,
Object... args)
Check if an argument
condition is true. |
public static <T extends Number & Comparable<? super T>> void assertRange(T x, T low, T high, String variableName)
Number
occurs within the range [low
, high
]
(both inclusive). Throw IllegalArgumentException
if not.T
- subclass of Number
which implements Comparable
x
- the number to testlow
- lower bound of the range, inclusivehigh
- upper bound of the range, inclusivevariableName
- the display name of variable x
public static <T extends Number & Comparable<? super T>> void assertRangeOpen(T x, T low, T high, String variableName)
Number
occurs within the range (low
, high
)
(both exclusive). Throw IllegalArgumentException
if not.T
- subclass of Number
which implements Comparable
x
- the number to testlow
- lower bound of the range, exclusivehigh
- upper bound of the range, exclusivevariableName
- the display name of variable x
public static <T extends Number & Comparable<? super T>> void assertRangeLeftOpen(T x, T low, T high, String variableName)
Number
occurs within the range (low
, high
]
(left exclusive, right inclusive). Throw IllegalArgumentException
if not.T
- subclass of Number
which implements Comparable
x
- the number to testlow
- lower bound of the range, exclusivehigh
- upper bound of the range, inclusivevariableName
- the display name of variable x
public static <T extends Number & Comparable<? super T>> void assertRangeRightOpen(T x, T low, T high, String variableName)
Number
occurs within the range [low
, high
)
(left inclusive, right exclusive). Throw IllegalArgumentException
if not.T
- subclass of Number
which implements Comparable
x
- the number to testlow
- lower bound of the range, inclusivehigh
- upper bound of the range, exclusivevariableName
- the display name of variable x
public static <T extends Number & Comparable<? super T>> void assertGreaterThan(T x, T bound, String variableName)
T
- subclass of Number
which implements Comparable
x
- the number to testbound
- the number to see if x
is greater thanvariableName
- the display name of variable x
public static <T extends Number & Comparable<? super T>> void assertNotLessThan(T x, T bound, String variableName)
T
- subclass of Number
which implements Comparable
x
- the number to testbound
- the number to see if x
is not less thanvariableName
- the display name of variable x
public static <T extends Number & Comparable<? super T>> void assertLessThan(T x, T bound, String variableName)
T
- subclass of Number
which implements Comparable
x
- the number to testbound
- the number to see if x
is less thanvariableName
- the display name of variable x
public static <T extends Number & Comparable<? super T>> void assertNotGreaterThan(T x, T bound, String variableName)
T
- subclass of Number
which implements Comparable
x
- the number to testbound
- the number to see if x
is not greater thanvariableName
- the display name of variable x
public static <T extends Number & Comparable<? super T>> void assertPositive(T x, String variableName)
T
- subclass of Number
which implements Comparable
x
- the number to testvariableName
- the display name of variable x
public static <T extends Number & Comparable<? super T>> void assertNonNegative(T x, String variableName)
T
- subclass of Number
which implements Comparable
x
- the number to testvariableName
- the display name of variable x
public static <T extends Number & Comparable<? super T>> void assertNegative(T x, String variableName)
T
- subclass of Number
which implements Comparable
x
- the number to testvariableName
- the display name of variable x
public static <T extends Number & Comparable<? super T>> void assertNonPositive(T x, String variableName)
T
- subclass of Number
which implements Comparable
x
- the number to testvariableName
- the display name of variable x
public static <T extends Number & Comparable<? super T>> void assertEqual(T x, T bound, String variableName)
T
- subclass of Number
which implements Comparable
x
- the number to testbound
- the number to see if x
is equal tovariableName
- the display name of variable x
public static <T extends Number & Comparable<? super T>> void assertEqual(T x1, T x2, String variableName1, String variableName2)
T
- subclass of Number
which implements Comparable
x1
- the number x1
x2
- the number x2
variableName1
- the display name of variable x1
variableName2
- the display name of variable x2
public static void assertTrue(boolean condition, String errorMessage, Object... args)
condition
is true. Throw IllegalArgumentException
if
it is false.condition
- the argument condition to be checkederrorMessage
- the error message if the condition is not true (format string can be used
with args
, see
String.format(java.lang.String, java.lang.Object[])
)args
- the arguments for the error messagepublic static void assertFalse(boolean condition, String errorMessage, Object... args)
condition
is false. Throw IllegalArgumentException
if
it is true.condition
- the argument condition to be checkederrorMessage
- the error message if the condition is not false (format string can be
used with args
, see
String.format(java.lang.String, java.lang.Object[])
)args
- the arguments for the error messagepublic static void assertNotNull(Object obj, String variableName)
obj
- variable to be checkedvariableName
- the display name of variable obj
public static void assertNull(Object obj, String variableName)
obj
- variable to be checkedvariableName
- the display name of variable obj
public static void assertNotNaN(double d, String variableName)
d
- the double
variablevariableName
- the display name of the variablepublic static void assertNotInfinity(double d, String variableName)
Double.POSITIVE_INFINITY
nor
Double.NEGATIVE_INFINITY
. Throw IllegalArgumentException
if it holds an
infinite value.d
- the double
variablevariableName
- the display name of the variablepublic static void assertNormalDouble(double d, String variableName)
double
value (that is, NOT
Double.NaN
nor infinity). Throw IllegalArgumentException
if it is not a
normal double
value.d
- the double
variablevariableName
- the display name of the variablepublic static void assertNotNaN(float f, String variableName)
f
- the float
variablevariableName
- the display name of the variablepublic static void assertNotInfinity(float f, String variableName)
Float.POSITIVE_INFINITY
nor
Float.NEGATIVE_INFINITY
. Throw IllegalArgumentException
if it holds an
infinite value.f
- the float
variablevariableName
- the display name of the variablepublic static void assertNormalFloat(float f, String variableName)
float
value (that is, NOT
Float.NaN
nor infinity). Throw IllegalArgumentException
if it is not a
normal float
value.f
- the float
variablevariableName
- the display name of the variableCopyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.