public final class InvariantChecks
extends java.lang.Object
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 <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 void |
checkNotNull(java.lang.Object o)
Checks the invariant "Object reference is not null" and
throws an exception if it is violated.
|
static void |
checkNotNull(java.lang.Object o,
java.lang.String name)
Checks the invariant "Object reference is not
null " and
throws an exception if it is violated. |
public static void checkNotNull(java.lang.Object o)
o
- Object reference to be checked.java.lang.NullPointerException
- 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.NullPointerException
- if the invariant is violated (o
is null
).java.lang.IllegalArgumentException
- if the invariant is violated (o.isEmpty
).public static <T> void checkNotEmpty(T[] o)
o
- Array to be checked.java.lang.NullPointerException
- if the invariant is violated (o
is null
).java.lang.IllegalArgumentException
- if the invariant is violated (o.length
is 0).public static void checkNotNull(java.lang.Object o, java.lang.String name)
null
" and
throws an exception if it is violated.o
- Object reference to be checked.name
- Name of the variable that stores the object reference.java.lang.NullPointerException
- if the invariant is violated (o
is null
).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
).