public class Assert
extends java.lang.Object
| Constructor and Description |
|---|
Assert() |
| Modifier and Type | Method and Description |
|---|---|
static <T,E extends java.lang.RuntimeException> |
cast(java.lang.Object obj,
java.lang.Class<T> clazz,
java.lang.String info,
java.lang.Class<E> throwable)
Tests to see if the object can be cast to the specified type.
|
static <E extends java.lang.RuntimeException> |
inRange(int n,
int from,
int to,
java.lang.String info,
java.lang.Class<E> clazz)
Note: asserts n is in the range from->to, inclusive.
|
static <E extends java.lang.RuntimeException> |
inRange(long n,
long from,
long to,
java.lang.String info,
java.lang.Class<E> clazz) |
static <E extends java.lang.RuntimeException> |
isEquivalent(byte[] a,
byte[] b)
assert identical based on content.
|
static <E extends java.lang.RuntimeException> |
isEquivalent(byte[] a,
byte[] b,
java.lang.Class<E> clazz)
assert identical based on content.
|
static <E extends java.lang.RuntimeException> |
isTrue(boolean fact,
java.lang.Class<E> clazz)
Usage:
|
static <E extends java.lang.RuntimeException> |
isTrue(boolean fact,
java.lang.String claim,
java.lang.Class<E> clazz)
Usage:
|
static <T,E extends java.lang.RuntimeException> |
notNull(T obj,
java.lang.Class<E> clazz)
Usage:
|
static <T,E extends java.lang.RuntimeException> |
notNull(T obj,
int idx,
java.lang.Class<E> clazz) |
static <T,E extends java.lang.RuntimeException> |
notNull(T obj,
java.lang.String info,
java.lang.Class<E> clazz)
Usage:
|
private static <E extends java.lang.RuntimeException> |
throwIt(java.lang.String msg,
java.lang.Class<E> clazz)
Not really intended for external use since you could simply throw new E (msg).
|
public static final <E extends java.lang.RuntimeException> void isEquivalent(byte[] a,
byte[] b)
E - a - b - clazz - public static final <E extends java.lang.RuntimeException> void isEquivalent(byte[] a,
byte[] b,
java.lang.Class<E> clazz)
E - a - b - clazz - public static final <T,E extends java.lang.RuntimeException> T notNull(T obj,
java.lang.Class<E> clazz)
throws E extends java.lang.RuntimeException
// ... somewhere within the bowels of your code ..
//
Assert.notNull (aReference, YourRuntimeException.class);
T - E - obj - clazz - EE extends java.lang.RuntimeExceptionpublic static final <T,E extends java.lang.RuntimeException> T notNull(T obj,
java.lang.String info,
java.lang.Class<E> clazz)
throws E extends java.lang.RuntimeException
// ... somewhere within the bowels of your code ..
//
Assert.notNull (inputRecord, "inputRecord", YourRuntimeException.class);
T - E - obj - info - clazz - EE extends java.lang.RuntimeExceptionpublic static final <T,E extends java.lang.RuntimeException> T notNull(T obj,
int idx,
java.lang.Class<E> clazz)
throws E extends java.lang.RuntimeException
E extends java.lang.RuntimeExceptionpublic static final <E extends java.lang.RuntimeException> void isTrue(boolean fact,
java.lang.String claim,
java.lang.Class<E> clazz)
throws E extends java.lang.RuntimeException
// ... somewhere within the bowels of your code ..
//
Assert.isTrue (conn.isReady(), "connection is ready", YourRuntimeException.class);
E - fact - claim - clazz - EE extends java.lang.RuntimeExceptionpublic static final <E extends java.lang.RuntimeException> void isTrue(boolean fact,
java.lang.Class<E> clazz)
throws E extends java.lang.RuntimeException
// ... somewhere within the bowels of your code ..
//
Assert.isTrue (conn.isReady(), YourRuntimeException.class);
E - is what you wish thrown - must be related to RuntimeExceptionfact - clazz - EE extends java.lang.RuntimeExceptionpublic static final <E extends java.lang.RuntimeException> long inRange(long n,
long from,
long to,
java.lang.String info,
java.lang.Class<E> clazz)
throws E extends java.lang.RuntimeException
E - n - from - to - info - clazz - EE extends java.lang.RuntimeExceptionpublic static final <E extends java.lang.RuntimeException> int inRange(int n,
int from,
int to,
java.lang.String info,
java.lang.Class<E> clazz)
throws E extends java.lang.RuntimeException
E - n - from - to - info - clazz - EE extends java.lang.RuntimeExceptionpublic static final <T,E extends java.lang.RuntimeException> T cast(java.lang.Object obj,
java.lang.Class<T> clazz,
java.lang.String info,
java.lang.Class<E> throwable)
throws E extends java.lang.RuntimeException
T - the typeE - the thrown exception typeobj - the object to be castclazz - of the the target typeinfo - the message for the exception thrownthrowable - specified if notEE extends java.lang.RuntimeExceptionprivate static final <E extends java.lang.RuntimeException> void throwIt(java.lang.String msg,
java.lang.Class<E> clazz)
throws E extends java.lang.RuntimeException
Usage (if you must):
// ... somewhere within the bowels of your code ..
//
Assert.throwIt ("why am i calling Assert.throwIt() when I could be throwing myself?", YourRuntimeException.class);
E - RuntimeException subclass to to throwmsg - message to set in the exceptionclazz - the Class of EE - your requested exception (unless reflection instantiate failed,
in which case it will be a plain old RuntimeException)E extends java.lang.RuntimeException