public final class InvariantChecks
extends java.lang.Object
InvariantChecks class provides static methods for checking different
kinds of invariants. If a check fails a corresponding exception is thrown.| Modifier and Type | Method and Description |
|---|---|
static void |
checkBounds(int index,
int length)
Checks the invariant "
0 <= index < length" and
throws an exception if it is violated. |
static void |
checkBoundsInclusive(int index,
int length)
Checks the invariant "
0 <= index <= length" and
throws an exception if it is violated. |
static void |
checkFalse(boolean condition)
Checks the invariant "Condition is false" and throws an exception
if it is violated.
|
static void |
checkFalse(boolean condition,
java.lang.String message)
Checks the invariant "Condition is false" and throws an exception
if it is violated.
|
static <T extends java.lang.Number & java.lang.Comparable<T>> |
checkGreaterOrEq(T a,
T b)
Checks the invariant "Numeric value
a is greater than or equal to b" and
throws an exception if it is violated. |
static void |
checkGreaterOrEqZero(int n)
Checks the invariant "Integer value is greater or equal
0" and
throws an exception if it is violated. |
static <T extends java.lang.Number & java.lang.Comparable<T>> |
checkGreaterThan(T a,
T b)
Checks the invariant "Numeric value
a is greater than b" and
throws an exception if it is violated. |
static void |
checkGreaterThanZero(int n)
Checks the invariant "Integer value is greater than
0" and
throws an exception if it is violated. |
static <T> void |
checkNotEmpty(java.util.Collection<T> o)
Checks the invariants "Object reference is not null" and "Collection is not empty"
throws an exception if they are violated.
|
static <T> void |
checkNotEmpty(T[] o)
Checks the invariants "Object reference is not null" and "Array is not empty"
throws an exception if they are violated.
|
static <T> void |
checkNotNull(T o)
Checks the invariant "Object reference is not null" and
throws an exception if it is violated.
|
static <T> void |
checkNotNull(T o,
java.lang.String message)
Checks the invariant "Object reference is not null" and
throws an exception if it is violated.
|
static void |
checkTrue(boolean condition)
Checks the invariant "Condition is true" and throws an exception
if it is violated.
|
static void |
checkTrue(boolean condition,
java.lang.String message)
Checks the invariant "Condition is true" and throws an exception
if it is violated.
|
public static void checkTrue(boolean condition)
condition - Condition to be checked.java.lang.IllegalArgumentException - if the invariant is violated
(condition is false).public static void checkTrue(boolean condition,
java.lang.String message)
condition - Condition to be checked.message - Exception message.java.lang.IllegalArgumentException - if the invariant is violated
(condition is false).public static void checkFalse(boolean condition)
condition - Condition to be checked.java.lang.IllegalArgumentException - if the invariant is violated
(condition is true).public static void checkFalse(boolean condition,
java.lang.String message)
condition - Condition to be checked.message - Exception message.java.lang.IllegalArgumentException - if the invariant is violated
(condition is true).public static <T> void checkNotNull(T o)
o - Object reference to be checked.java.lang.IllegalArgumentException - if the invariant is violated (o is null).public static <T> void checkNotNull(T o,
java.lang.String message)
o - Object reference to be checked.message - Exception message.java.lang.IllegalArgumentException - if the invariant is violated (o is null).public static <T> void checkNotEmpty(java.util.Collection<T> o)
o - Collection to be checked.java.lang.IllegalArgumentException - if the invariant is violated (o is null);
if the invariant is violated (o.isEmpty).public static <T> void checkNotEmpty(T[] o)
o - Array to be checked.java.lang.IllegalArgumentException - if the invariant is violated (o is null);
if the invariant is violated (o.length is 0).public static void checkGreaterThanZero(int n)
0" and
throws an exception if it is violated.n - Integer value to be checked.java.lang.IllegalArgumentException - if the invariant is violated (n <= 0).public static void checkGreaterOrEqZero(int n)
0" and
throws an exception if it is violated.n - Integer value to be checked.java.lang.IllegalArgumentException - if the invariant is violated (n < 0).public static void checkBounds(int index,
int length)
0 <= index < length" and
throws an exception if it is violated.index - Index to be checked.length - Length of the allowed range.java.lang.IndexOutOfBoundsException - if the invariant is violated
(index is not within range [0..length)).public static void checkBoundsInclusive(int index,
int length)
0 <= index <= length" and
throws an exception if it is violated.index - Index to be checked.length - Length of the allowed range.java.lang.IndexOutOfBoundsException - if the invariant is violated
(index is not within range [0..length]).public static <T extends java.lang.Number & java.lang.Comparable<T>> void checkGreaterThan(T a,
T b)
a is greater than b" and
throws an exception if it is violated.a - Numeric value to be checked.b - Numeric value to be checked.java.lang.IllegalArgumentException - if the invariant is violated (a <= b).public static <T extends java.lang.Number & java.lang.Comparable<T>> void checkGreaterOrEq(T a,
T b)
a is greater than or equal to b" and
throws an exception if it is violated.a - Numeric value to be checked.b - Numeric value to be checked.java.lang.IllegalArgumentException - if the invariant is violated (a < b).