|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.qualitycheck.Check
public final class Check
This class offers simple static methods to test your arguments to be valid. Checks should be added to all arguments of all public methods in your class to assure that only valid values can be encountered within your class. This is major step to avoid technical errors like NullPointerExceptions or IndexOutOfBoundsException in your code.
Nested Class Summary | |
---|---|
protected static class |
Check.NumericRegularExpressionHolder
Holder for the regular expression to determine numeric values. |
Method Summary | ||
---|---|---|
static
|
contains(Collection<T> haystack,
T needle)
Ensures that an element needle is contained in a collection haystack . |
|
static
|
contains(Collection<T> haystack,
T needle,
String name)
Ensures that an element needle is contained in a collection haystack . |
|
static boolean |
equals(boolean expected,
boolean check)
Ensures that a passed boolean is equal to another boolean. |
|
static boolean |
equals(boolean expected,
boolean check,
String message)
Ensures that a passed boolean is equal to another boolean. |
|
static byte |
equals(byte expected,
byte check)
Ensures that a passed byte is equal to another byte. |
|
static byte |
equals(byte expected,
byte check,
String message)
Ensures that a passed byte is equal to another byte. |
|
static char |
equals(char expected,
char check)
Ensures that a passed char is equal to another char. |
|
static char |
equals(char expected,
char check,
String message)
Ensures that a passed char is equal to another char. |
|
static int |
equals(int expected,
int check)
Ensures that a passed intH is equal to another int. |
|
static int |
equals(int expected,
int check,
String message)
Ensures that a passed int is equal to another int. |
|
static long |
equals(long expected,
long check)
Ensures that a passed long is equal to another long. |
|
static long |
equals(long expected,
long check,
String message)
Ensures that a passed long is equal to another long. |
|
static short |
equals(short expected,
short check)
Ensures that a passed short is equal to another short. |
|
static short |
equals(short expected,
short check,
String message)
Ensures that a passed short is equal to another short. |
|
static
|
equals(T expected,
T check)
Ensures that a passed object is equal to another object. |
|
static
|
equals(T expected,
T check)
Ensures that a passed Comparable is equal to another Comparable . |
|
static
|
equals(T expected,
T check,
String message)
Ensures that a passed object is equal to another object. |
|
static
|
equals(T expected,
T check,
String message)
Ensures that a passed Comparable is equal to another Comparable . |
|
static
|
greaterOrEqualThan(T expected,
T check)
Ensures that a passed Comparable is greater or equal compared to another Comparable . |
|
static
|
greaterOrEqualThan(T expected,
T check,
String message)
Ensures that a passed Comparable is greater or equal compared to another Comparable . |
|
static byte |
greaterThan(byte expected,
byte check)
Ensures that a passed byte is greater to another byte . |
|
static byte |
greaterThan(byte expected,
byte check,
String message)
Ensures that a passed byte is greater than another byte . |
|
static char |
greaterThan(char expected,
char check)
Ensures that a passed char is greater to another char . |
|
static char |
greaterThan(char expected,
char check,
String message)
Ensures that a passed char is greater than another char . |
|
static double |
greaterThan(double expected,
double check)
Ensures that a passed double is greater to another double . |
|
static double |
greaterThan(double expected,
double check,
String message)
Ensures that a passed double is greater than another double . |
|
static float |
greaterThan(float expected,
float check)
Ensures that a passed float is greater to another float . |
|
static float |
greaterThan(float expected,
float check,
String message)
Ensures that a passed float is greater than another float . |
|
static int |
greaterThan(int expected,
int check)
Ensures that a passed int is greater to another int . |
|
static int |
greaterThan(int expected,
int check,
String message)
Ensures that a passed int is greater than another int . |
|
static long |
greaterThan(long expected,
long check)
Ensures that a passed long is greater to another long . |
|
static long |
greaterThan(long expected,
long check,
String message)
Ensures that a passed long is greater than another long . |
|
static short |
greaterThan(short expected,
short check)
Ensures that a passed short is greater to another short . |
|
static short |
greaterThan(short expected,
short check,
String message)
Ensures that a passed short is greater than another short . |
|
static
|
greaterThan(T expected,
T check)
Ensures that a passed Comparable is greater to another Comparable . |
|
static
|
greaterThan(T expected,
T check,
String message)
Ensures that a passed Comparable is greater than another Comparable . |
|
static Annotation |
hasAnnotation(Class<?> clazz,
Class<? extends Annotation> annotation)
Ensures that a passed class has an annotation of a specific type |
|
static
|
instanceOf(Class<?> type,
Object obj)
Ensures that a passed argument is a member of a specific type. |
|
static
|
instanceOf(Class<?> type,
Object obj,
String name)
Ensures that a passed argument is a member of a specific type. |
|
static void |
isNull(Object reference)
Ensures that a given argument is null . |
|
static void |
isNull(Object reference,
String name)
Ensures that a given argument is null . |
|
static int |
isNumber(String value)
Ensures that a String argument is a number. |
|
static
|
isNumber(String value,
Class<T> type)
Ensures that a String argument is a number. |
|
static int |
isNumber(String value,
String name)
Ensures that a string argument is a number according to Integer.parseInt |
|
static
|
isNumber(String value,
String name,
Class<T> type)
Ensures that a String argument is a number. |
|
static
|
isNumeric(T value)
Ensures that a readable sequence of char values is numeric. |
|
static
|
isNumeric(T value,
String name)
Ensures that a readable sequence of char values is numeric. |
|
static byte |
lesserThan(byte expected,
byte check)
Ensures that a passed byte is less than another byte . |
|
static byte |
lesserThan(byte expected,
byte check,
String message)
Ensures that a passed byte is less than another byte . |
|
static char |
lesserThan(char expected,
char check)
Ensures that a passed char is less than another char . |
|
static char |
lesserThan(char expected,
char check,
String message)
Ensures that a passed char is less than another char . |
|
static double |
lesserThan(double expected,
double check)
Ensures that a passed double is less than another double . |
|
static double |
lesserThan(double expected,
double check,
String message)
Ensures that a passed double is less than another double . |
|
static float |
lesserThan(float expected,
float check)
Ensures that a passed float is less than another float . |
|
static float |
lesserThan(float expected,
float check,
String message)
Ensures that a passed float is less than another float . |
|
static int |
lesserThan(int expected,
int check)
Ensures that a passed int is less than another int . |
|
static int |
lesserThan(int expected,
int check,
String message)
Ensures that a passed int is less than another int . |
|
static long |
lesserThan(long expected,
long check)
Ensures that a passed long is less than another long . |
|
static long |
lesserThan(long expected,
long check,
String message)
Ensures that a passed long is less than another long . |
|
static short |
lesserThan(short expected,
short check)
Ensures that a passed short is less than another short . |
|
static short |
lesserThan(short expected,
short check,
String message)
Ensures that a passed short is less than another short . |
|
static
|
lesserThan(T expected,
T check)
Ensures that a passed Comparable is less than another Comparable . |
|
static
|
lesserThan(T expected,
T check,
String message)
Ensures that a passed Comparable is less than another Comparable . |
|
static
|
matchesPattern(Pattern pattern,
T chars)
Ensures that a readable sequence of char values matches a specified pattern. |
|
static
|
matchesPattern(Pattern pattern,
T chars,
String name)
Ensures that a readable sequence of char values matches a specified pattern. |
|
static
|
noNullElements(T iterable)
Ensures that an iterable reference is neither null nor contains any elements that are null . |
|
static
|
noNullElements(T[] array)
Ensures that an array does not contain null . |
|
static
|
noNullElements(T[] array,
String name)
Ensures that an array does not contain null . |
|
static
|
noNullElements(T iterable,
String name)
Ensures that an iterable reference is neither null nor contains any elements that are null . |
|
static void |
notEmpty(boolean expression)
Ensures that a passed parameter of the calling method is not empty, using the passed expression to evaluate the emptiness. |
|
static void |
notEmpty(boolean expression,
String name)
Ensures that a passed parameter of the calling method is not empty, using the passed expression to evaluate the emptiness. |
|
static
|
notEmpty(T chars)
Ensures that a passed string as a parameter of the calling method is not empty. |
|
static
|
notEmpty(T collection)
Ensures that a passed collection as a parameter of the calling method is not empty. |
|
static
|
notEmpty(T map)
Ensures that a passed map as a parameter of the calling method is not empty. |
|
static
|
notEmpty(T[] array)
Ensures that a passed map as a parameter of the calling method is not empty. |
|
static
|
notEmpty(T[] array,
String name)
Ensures that a passed map as a parameter of the calling method is not empty. |
|
static
|
notEmpty(T reference,
boolean expression,
String name)
Ensures that an object reference passed as a parameter to the calling method is not empty. |
|
static
|
notEmpty(T chars,
String name)
Ensures that a passed string as a parameter of the calling method is not empty. |
|
static
|
notEmpty(T collection,
String name)
Ensures that a passed collection as a parameter of the calling method is not empty. |
|
static
|
notEmpty(T map,
String name)
Ensures that a passed map as a parameter of the calling method is not empty. |
|
static
|
nothing(T t)
Do not perform any check and just return t . |
|
static double |
notNaN(double value)
Ensures that a double argument is not NaN (not a number). |
|
static double |
notNaN(double value,
String name)
Ensures that a double argument is not NaN (not a number). |
|
static float |
notNaN(float value)
Ensures that a double argument is not NaN (not a number). |
|
static float |
notNaN(float value,
String name)
Ensures that a double argument is not NaN (not a number). |
|
static double |
notNegative(double value)
Ensures that an double reference passed as a parameter to the calling method is not smaller than 0 . |
|
static double |
notNegative(double value,
String name)
Ensures that an double reference passed as a parameter to the calling method is not smaller than 0 . |
|
static float |
notNegative(float value)
Ensures that an float reference passed as a parameter to the calling method is not smaller than 0 . |
|
static float |
notNegative(float value,
String name)
Ensures that an float reference passed as a parameter to the calling method is not smaller than 0 . |
|
static int |
notNegative(int value)
Ensures that an integer reference passed as a parameter to the calling method is not smaller than 0 . |
|
static int |
notNegative(int value,
String name)
Ensures that an integer reference passed as a parameter to the calling method is not smaller than 0 . |
|
static long |
notNegative(long value)
Ensures that an long reference passed as a parameter to the calling method is not smaller than 0 . |
|
static long |
notNegative(long value,
String name)
Ensures that an long reference passed as a parameter to the calling method is not smaller than 0 . |
|
static short |
notNegative(short value)
Ensures that an short reference passed as a parameter to the calling method is not smaller than 0 . |
|
static short |
notNegative(short value,
String name)
Ensures that an short reference passed as a parameter to the calling method is not smaller than 0 . |
|
static
|
notNull(T reference)
Ensures that an object reference passed as a parameter to the calling method is not null . |
|
static
|
notNull(T reference,
String name)
Ensures that an object reference passed as a parameter to the calling method is not null . |
|
static double |
notPositive(double value)
Ensures that an double reference passed as a parameter to the calling method is not greater than 0 . |
|
static double |
notPositive(double value,
String name)
Ensures that an double reference passed as a parameter to the calling method is not greater than 0 . |
|
static float |
notPositive(float value)
Ensures that an float reference passed as a parameter to the calling method is not greater than 0 . |
|
static float |
notPositive(float value,
String name)
Ensures that an float reference passed as a parameter to the calling method is not greater than 0 . |
|
static int |
notPositive(int value)
Ensures that an integer reference passed as a parameter to the calling method is not greater than 0 . |
|
static int |
notPositive(int value,
String name)
Ensures that an integer reference passed as a parameter to the calling method is not greater than 0 . |
|
static long |
notPositive(long value)
Ensures that an long reference passed as a parameter to the calling method is not greater than 0 . |
|
static long |
notPositive(long value,
String name)
Ensures that an long reference passed as a parameter to the calling method is not greater than 0 . |
|
static short |
notPositive(short value)
Ensures that an short reference passed as a parameter to the calling method is not greater than 0 . |
|
static short |
notPositive(short value,
String name)
Ensures that an short reference passed as a parameter to the calling method is not greater than 0 . |
|
static int |
positionIndex(int index,
int size)
Ensures that a given position index is valid within the size of an array, list or string ... |
|
static void |
range(int start,
int end,
int size)
Ensures that the given arguments are a valid range. |
|
static void |
stateIsTrue(boolean expression)
Ensures that a given state is true . |
|
static void |
stateIsTrue(boolean expression,
Class<? extends RuntimeException> clazz)
Ensures that a given state is true and allows to specify the class of exception which is thrown in case
the state is not true . |
|
static void |
stateIsTrue(boolean expression,
String description)
Ensures that a given state is true . |
|
static void |
stateIsTrue(boolean expression,
String descriptionTemplate,
Object... descriptionTemplateArgs)
Ensures that a given state is true |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static <T> T contains(@Nonnull Collection<T> haystack, @Nonnull T needle)
needle
is contained in a collection haystack
.
This is in particular useful if you want to check whether an enum value is contained in an EnumSet
. The
check is implemented using Collection.contains(Object)
.
We recommend to use the overloaded method contains(Collection, Object, String)
and pass as second
argument the name of the parameter to enhance the exception message.
haystack
- A collection which must contain needle
needle
- An object that must be contained into a collection.
needle
IllegalArgumentNotContainedException
- if the passed needle
can not be found in haystack
public static <T> T contains(@Nonnull Collection<T> haystack, @Nonnull T needle, @Nonnull String name)
needle
is contained in a collection haystack
.
This is in particular useful if you want to check whether an enum value is contained in an EnumSet
. The
check is implemented using Collection.contains(Object)
.
haystack
- A collection which must contain needle
needle
- An object that must be contained into a collection.name
- name of argument of needle
needle
IllegalArgumentNotContainedException
- if the passed needle
can not be found in haystack
public static boolean equals(@Nonnull boolean expected, @Nonnull boolean check)
expected != check
.
We recommend to use the overloaded method equals(boolean, boolean, String)
and pass as second
argument the name of the parameter to enhance the exception message.
expected
- Expected valuecheck
- boolean to be checked
check
IllegalNotEqualException
- if both argument values are not equalpublic static boolean equals(@Nonnull boolean expected, @Nonnull boolean check, String message)
expected != check
.
expected
- Expected valuecheck
- boolean to be checkedmessage
- an error message describing why the booleans must equal (will be passed to
IllegalNotEqualException
)
check
IllegalNotEqualException
- if both argument values are not equalpublic static byte equals(@Nonnull byte expected, @Nonnull byte check)
expected != check
.
We recommend to use the overloaded method equals(byte, byte, String)
and pass as second argument
the name of the parameter to enhance the exception message.
expected
- Expected valuecheck
- byte to be checked
check
IllegalNotEqualException
- if both argument values are not equalpublic static byte equals(@Nonnull byte expected, @Nonnull byte check, String message)
expected != check
.
expected
- Expected valuecheck
- byte to be checkedmessage
- an error message describing why the bytes must equal (will be passed to
IllegalNotEqualException
)
check
IllegalNotEqualException
- if both argument values are not equalpublic static char equals(@Nonnull char expected, @Nonnull char check)
expected != check
.
We recommend to use the overloaded method equals(char, char, String)
and pass as second argument
the name of the parameter to enhance the exception message.
expected
- Expected valuecheck
- char to be checked
check
IllegalNotEqualException
- if both argument values are not equalpublic static char equals(@Nonnull char expected, @Nonnull char check, String message)
expected != check
.
expected
- Expected valuecheck
- char to be checkedmessage
- an error message describing why the chars must equal (will be passed to
IllegalNotEqualException
)
check
IllegalNotEqualException
- if both argument values are not equalpublic static int equals(@Nonnull int expected, @Nonnull int check)
expected != check
.
We recommend to use the overloaded method equals(int, int, String)
and pass as second argument the
name of the parameter to enhance the exception message.
expected
- Expected valuecheck
- int to be checked
check
IllegalNotEqualException
- if both argument values are not equalpublic static int equals(@Nonnull int expected, @Nonnull int check, String message)
expected != check
.
expected
- Expected valuecheck
- int to be checkedmessage
- an error message describing why the ints must equal (will be passed to
IllegalNotEqualException
)
check
IllegalNotEqualException
- if both argument values are not equalpublic static long equals(@Nonnull long expected, @Nonnull long check)
expected != check
.
We recommend to use the overloaded method equals(long, long, String)
and pass as second argument
the name of the parameter to enhance the exception message.
expected
- Expected valuecheck
- long to be checked
check
IllegalNotEqualException
- if both argument values are not equalpublic static long equals(@Nonnull long expected, @Nonnull long check, String message)
expected != check
.
expected
- Expected valuecheck
- long to be checkedmessage
- an error message describing why the longs must equal (will be passed to
IllegalNotEqualException
)
check
IllegalNotEqualException
- if both argument values are not equalpublic static short equals(@Nonnull short expected, @Nonnull short check)
expected != check
.
We recommend to use the overloaded method equals(short, short, String)
and pass as second argument
the name of the parameter to enhance the exception message.
expected
- Expected valuecheck
- short to be checked
check
IllegalNotEqualException
- if both argument values are not equalpublic static short equals(@Nonnull short expected, @Nonnull short check, String message)
expected != check
.
expected
- Expected valuecheck
- short to be checkedmessage
- an error message describing why the shorts must equal (will be passed to
IllegalNotEqualException
)
check
IllegalNotEqualException
- if both argument values are not equalpublic static <T extends Comparable<T>> T equals(@Nonnull T expected, @Nonnull T check)
Comparable
is equal to another Comparable
. The comparison is made using
expected.compareTo(check) != 0
.
We recommend to use the overloaded method equals(Comparable, Comparable, String)
and pass as second
argument the name of the parameter to enhance the exception message.
expected
- Expected valuecheck
- Comparable to be checked
Comparable
argument check
IllegalNotEqualException
- if both argument values are not equalpublic static <T> T equals(@Nonnull T expected, @Nonnull T check)
expected.equals(check)
.
We recommend to use the overloaded method equals(Object, Object, String)
and pass as second
argument the name of the parameter to enhance the exception message.
expected
- Expected valuecheck
- Object to be checked
check
IllegalNotEqualException
- if both argument values are not equalpublic static <T extends Comparable<T>> T equals(@Nonnull T expected, @Nonnull T check, String message)
Comparable
is equal to another Comparable
. The comparison is made using
expected.compareTo(check) != 0
.
expected
- Expected valuecheck
- Comparable to be checkedmessage
- an error message describing why the s must equal (will be passed to
IllegalNotEqualException
)
Comparable
argument check
IllegalNotEqualException
- if both argument values are not equalpublic static <T> T equals(@Nonnull T expected, @Nonnull T check, String message)
expected.equals(check)
.
expected
- Expected valuecheck
- Object to be checkedmessage
- an error message describing why the objects must equal (will be passed to
IllegalNotEqualException
)
check
IllegalNotEqualException
- if both argument values are not equalpublic static <T extends Comparable<T>> T greaterOrEqualThan(@Nonnull T expected, @Nonnull T check)
Comparable
is greater or equal compared to another Comparable
. The
comparison is made using expected.compareTo(check) > 0
.
expected
- Expected valuecheck
- Comparable to be checked
Comparable
argument check
IllegalNotGreaterOrEqualThanException
- if the argument value check
is not greater or equal than the value expected
when
using method compareTo
public static <T extends Comparable<T>> T greaterOrEqualThan(@Nonnull T expected, @Nonnull T check, String message)
Comparable
is greater or equal compared to another Comparable
. The
comparison is made using expected.compareTo(check) > 0
.
expected
- Expected valuecheck
- Comparable to be checkedmessage
- an error message describing why the comparable must be greater than a value (will be passed to
IllegalNotGreaterOrEqualThanException
)
Comparable
argument check
IllegalNotGreaterOrEqualThanException
- if the argument value check
is not greater or equal than the value expected
when
using method compareTo
public static byte greaterThan(@Nonnull byte expected, @Nonnull byte check)
byte
is greater to another byte
.
expected
- Expected valuecheck
- Comparable to be checked
Comparable
argument check
IllegalNotGreaterThanException
- if the argument value check
is not greater than value expected
public static byte greaterThan(@Nonnull byte expected, @Nonnull byte check, String message)
byte
is greater than another byte
.
expected
- Expected valuecheck
- Comparable to be checkedmessage
- an error message describing why the comparable must be greater than a value (will be passed to
IllegalNotGreaterThanException
)
Comparable
argument check
IllegalNotGreaterThanException
- if the argument value check
is not greater than value expected
public static char greaterThan(@Nonnull char expected, @Nonnull char check)
char
is greater to another char
.
expected
- Expected valuecheck
- Comparable to be checked
Comparable
argument check
IllegalNotGreaterThanException
- if the argument value check
is not greater than value expected
public static char greaterThan(@Nonnull char expected, @Nonnull char check, String message)
char
is greater than another char
.
expected
- Expected valuecheck
- Comparable to be checkedmessage
- an error message describing why the comparable must be greater than a value (will be passed to
IllegalNotGreaterThanException
)
Comparable
argument check
IllegalNotGreaterThanException
- if the argument value check
is not greater than value expected
public static double greaterThan(@Nonnull double expected, @Nonnull double check)
double
is greater to another double
.
expected
- Expected valuecheck
- Comparable to be checked
Comparable
argument check
IllegalNotGreaterThanException
- if the argument value check
is not greater than value expected
public static double greaterThan(@Nonnull double expected, @Nonnull double check, String message)
double
is greater than another double
.
expected
- Expected valuecheck
- Comparable to be checkedmessage
- an error message describing why the comparable must be greater than a value (will be passed to
IllegalNotGreaterThanException
)
Comparable
argument check
IllegalNotGreaterThanException
- if the argument value check
is not greater than value expected
public static float greaterThan(@Nonnull float expected, @Nonnull float check)
float
is greater to another float
.
expected
- Expected valuecheck
- Comparable to be checked
Comparable
argument check
IllegalNotGreaterThanException
- if the argument value check
is not greater than value expected
public static float greaterThan(@Nonnull float expected, @Nonnull float check, String message)
float
is greater than another float
.
expected
- Expected valuecheck
- Comparable to be checkedmessage
- an error message describing why the comparable must be greater than a value (will be passed to
IllegalNotGreaterThanException
)
Comparable
argument check
IllegalNotGreaterThanException
- if the argument value check
is not greater than value expected
public static int greaterThan(@Nonnull int expected, @Nonnull int check)
int
is greater to another int
.
expected
- Expected valuecheck
- Comparable to be checked
Comparable
argument check
IllegalNotGreaterThanException
- if the argument value check
is not greater than value expected
public static int greaterThan(@Nonnull int expected, @Nonnull int check, String message)
int
is greater than another int
.
expected
- Expected valuecheck
- Comparable to be checkedmessage
- an error message describing why the comparable must be greater than a value (will be passed to
IllegalNotGreaterThanException
)
Comparable
argument check
IllegalNotGreaterThanException
- if the argument value check
is not greater than value expected
public static long greaterThan(@Nonnull long expected, @Nonnull long check)
long
is greater to another long
.
expected
- Expected valuecheck
- Comparable to be checked
Comparable
argument check
IllegalNotGreaterThanException
- if the argument value check
is not greater than value expected
public static long greaterThan(@Nonnull long expected, @Nonnull long check, String message)
long
is greater than another long
.
expected
- Expected valuecheck
- Comparable to be checkedmessage
- an error message describing why the comparable must be greater than a value (will be passed to
IllegalNotGreaterThanException
)
Comparable
argument check
IllegalNotGreaterThanException
- if the argument value check
is not greater than value expected
public static short greaterThan(@Nonnull short expected, @Nonnull short check)
short
is greater to another short
.
expected
- Expected valuecheck
- Comparable to be checked
Comparable
argument check
IllegalNotGreaterThanException
- if the argument value check
is not greater than value expected
public static short greaterThan(@Nonnull short expected, @Nonnull short check, String message)
short
is greater than another short
.
expected
- Expected valuecheck
- Comparable to be checkedmessage
- an error message describing why the comparable must be greater than a value (will be passed to
IllegalNotGreaterThanException
)
Comparable
argument check
IllegalNotGreaterThanException
- if the argument value check
is not greater than value expected
public static <T extends Comparable<T>> T greaterThan(@Nonnull T expected, @Nonnull T check)
Comparable
is greater to another Comparable
. The comparison is made using
expected.compareTo(check) >= 0
.
expected
- Expected valuecheck
- Comparable to be checked
Comparable
argument check
IllegalNotGreaterThanException
- if the argument value check
is not greater than value expected
when using method
compareTo
public static <T extends Comparable<T>> T greaterThan(@Nonnull T expected, @Nonnull T check, String message)
Comparable
is greater than another Comparable
. The comparison is made using
expected.compareTo(check) >= 0
.
expected
- Expected valuecheck
- Comparable to be checkedmessage
- an error message describing why the comparable must be greater than a value (will be passed to
IllegalNotGreaterThanException
)
Comparable
argument check
IllegalNotGreaterThanException
- if the argument value check
is not greater than value expected
when using method
compareTo
public static Annotation hasAnnotation(@Nonnull Class<?> clazz, @Nonnull Class<? extends Annotation> annotation)
clazz
- the class that must have a required annotationannotation
- the type of annotation that is required on the class
IllegalMissingAnnotationException
- if the passed annotation is not annotated at the given classpublic static <T> T instanceOf(@Nonnull Class<?> type, @Nonnull Object obj)
type
- class that the given object is a member ofobj
- the object reference that should be a member of a specific type
IllegalInstanceOfArgumentException
- if the given argument obj
is not a member of type
public static <T> T instanceOf(@Nonnull Class<?> type, @Nonnull Object obj, @Nullable String name)
type
- class that the given object is a member ofobj
- the object reference that should be a member of a specific type
name
- name of object reference (in source code)
IllegalInstanceOfArgumentException
- if the given argument obj
is not a member of type
public static void isNull(@Nullable Object reference)
null
.
Normally, the usage of null
arguments is disregarded by the authors of quality-check. Still, there are
certain circumstances where null is required, e.g. the primary key of an entity before it is written to the
database for the first time. In such cases it is ok to use null values and there should also be checks for them.
For example, to avoid overwriting an existing primary key with a new one.
reference
- reference which must be null
IllegalNotNullArgumentException
- if the given argument reference
is not nullpublic static void isNull(@Nullable Object reference, @Nullable String name)
null
.
Normally, the usage of null
arguments is disregarded by the authors of quality-check. Still, there are
certain circumstances where null is required, e.g. the primary key of an entity before it is written to the
database for the first time. In such cases it is ok to use null values and there should also be checks for them.
For example, to avoid overwriting an existing primary key with a new one.
reference
- reference which must be null.name
- name of object reference (in source code)
IllegalNotNullArgumentException
- if the given argument reference
is not nullpublic static int isNumber(@Nonnull String value)
value
- value which must be a number
IllegalNumberArgumentException
- if the given argument value
is not a numberpublic static <T extends Number> T isNumber(@Nonnull String value, @Nonnull Class<T> type)
Number
. The number
is first converted to a BigInteger
value
- value which must be a numbertype
- requested return value type, must be a subclass of Number
, i.e. one of BigDecimal,
BigInteger, Byte, Double, Float, Integer, Long, Short
IllegalNumberArgumentException
- if the given argument value
is no numberpublic static int isNumber(@Nonnull String value, @Nullable String name)
Integer.parseInt
value
- value which must be a numbername
- name of object reference (in source code)
IllegalNumberArgumentException
- if the given argument value
is no numberpublic static <T extends Number> T isNumber(@Nonnull String value, @Nullable String name, @Nonnull Class<T> type)
Number
. The number
is first converted to a BigDecimal
or BigInteger
. Floating point types are only supported if the
type
is one of Float, Double, BigDecimal
.
This method does also check against the ranges of the given datatypes.
value
- value which must be a number and in the range of the given datatype.name
- (optional) name of object reference (in source code).type
- requested return value type, must be a subclass of Number
, i.e. one of BigDecimal,
BigInteger, Byte, Double, Float, Integer, Long, Short
IllegalNumberArgumentException
- if the given argument value
is no numberpublic static <T extends CharSequence> T isNumeric(@Nonnull T value)
char
values is numeric. Numeric arguments consist only of the
characters 0-9 and may start with 0 (compared to number arguments, which must be valid numbers - think of a bank
account number).
We recommend to use the overloaded method isNumeric(CharSequence, String)
and pass as second
argument the name of the parameter to enhance the exception message.
value
- a readable sequence of char
values which must be a number
IllegalNumberArgumentException
- if the given argument value
is no numberpublic static <T extends CharSequence> T isNumeric(@Nonnull T value, @Nullable String name)
char
values is numeric. Numeric arguments consist only of the
characters 0-9 and may start with 0 (compared to number arguments, which must be valid numbers - think of a bank
account number).
value
- a readable sequence of char
values which must be a numbername
- name of object reference (in source code)
IllegalNumberArgumentException
- if the given argument value
is no numberpublic static byte lesserThan(@Nonnull byte expected, @Nonnull byte check)
byte
is less than another byte
.
expected
- Expected valuecheck
- Comparable to be checked
byte
argument check
IllegalNotLesserThanException
- if the argument value check
is not lesser than value expected
public static byte lesserThan(@Nonnull byte expected, @Nonnull byte check, String message)
byte
is less than another byte
.
expected
- Expected valuecheck
- Comparable to be checkedmessage
- an error message describing why the comparables must be less than a value (will be passed to
IllegalNotLessThanException
)
Comparable
argument check
IllegalNotLesserThanException
- if the argument value check
is not lesser than value expected
public static char lesserThan(@Nonnull char expected, @Nonnull char check)
char
is less than another char
.
expected
- Expected valuecheck
- Comparable to be checked
char
argument check
IllegalNotLesserThanException
- if the argument value check
is not lesser than value expected
public static char lesserThan(@Nonnull char expected, @Nonnull char check, String message)
char
is less than another char
.
expected
- Expected valuecheck
- Comparable to be checkedmessage
- an error message describing why the comparables must be less than a value (will be passed to
IllegalNotLessThanException
)
Comparable
argument check
IllegalNotLesserThanException
- if the argument value check
is not lesser than value expected
public static double lesserThan(@Nonnull double expected, @Nonnull double check)
double
is less than another double
.
expected
- Expected valuecheck
- Comparable to be checked
double
argument check
IllegalNotLesserThanException
- if the argument value check
is not lesser than value expected
public static double lesserThan(@Nonnull double expected, @Nonnull double check, String message)
double
is less than another double
.
expected
- Expected valuecheck
- Comparable to be checkedmessage
- an error message describing why the comparables must be less than a value (will be passed to
IllegalNotLessThanException
)
Comparable
argument check
IllegalNotLesserThanException
- if the argument value check
is not lesser than value expected
public static float lesserThan(@Nonnull float expected, @Nonnull float check)
float
is less than another float
.
expected
- Expected valuecheck
- Comparable to be checked
float
argument check
IllegalNotLesserThanException
- if the argument value check
is not lesser than value expected
public static float lesserThan(@Nonnull float expected, @Nonnull float check, String message)
float
is less than another float
.
expected
- Expected valuecheck
- Comparable to be checkedmessage
- an error message describing why the comparables must be less than a value (will be passed to
IllegalNotLessThanException
)
Comparable
argument check
IllegalNotLesserThanException
- if the argument value check
is not lesser than value expected
public static int lesserThan(@Nonnull int expected, @Nonnull int check)
int
is less than another int
.
expected
- Expected valuecheck
- Comparable to be checked
int
argument check
IllegalNotLesserThanException
- if the argument value check
is not lesser than value expected
public static int lesserThan(@Nonnull int expected, @Nonnull int check, String message)
int
is less than another int
.
expected
- Expected valuecheck
- Comparable to be checkedmessage
- an error message describing why the comparables must be less than a value (will be passed to
IllegalNotLessThanException
)
Comparable
argument check
IllegalNotLesserThanException
- if the argument value check
is not lesser than value expected
public static long lesserThan(@Nonnull long expected, @Nonnull long check)
long
is less than another long
.
expected
- Expected valuecheck
- Comparable to be checked
long
argument check
IllegalNotLesserThanException
- if the argument value check
is not lesser than value expected
public static long lesserThan(@Nonnull long expected, @Nonnull long check, String message)
long
is less than another long
.
expected
- Expected valuecheck
- Comparable to be checkedmessage
- an error message describing why the comparables must be less than a value (will be passed to
IllegalNotLessThanException
)
Comparable
argument check
IllegalNotLesserThanException
- if the argument value check
is not lesser than value expected
public static short lesserThan(@Nonnull short expected, @Nonnull short check)
short
is less than another short
.
expected
- Expected valuecheck
- Comparable to be checked
short
argument check
IllegalNotLesserThanException
- if the argument value check
is not lesser than value expected
public static short lesserThan(@Nonnull short expected, @Nonnull short check, String message)
short
is less than another short
.
expected
- Expected valuecheck
- Comparable to be checkedmessage
- an error message describing why the comparables must be less than a value (will be passed to
IllegalNotLessThanException
)
Comparable
argument check
IllegalNotLesserThanException
- if the argument value check
is not lesser than value expected
public static <T extends Comparable<T>> T lesserThan(@Nonnull T expected, @Nonnull T check)
Comparable
is less than another Comparable
. The comparison is made using
expected.compareTo(check) <= 0
.
expected
- Expected valuecheck
- Comparable to be checked
Comparable
argument check
IllegalNotLesserThanException
- if the argument value check
is not lesser than value expected
when using method
compareTo
public static <T extends Comparable<T>> T lesserThan(@Nonnull T expected, @Nonnull T check, String message)
Comparable
is less than another Comparable
. The comparison is made using
expected.compareTo(check) <= 0
.
expected
- Expected valuecheck
- Comparable to be checkedmessage
- an error message describing why the comparables must be less than a value (will be passed to
IllegalNotLessThanException
)
Comparable
argument check
IllegalNotLesserThanException
- if the argument value check
is not lesser than value expected
when using method
compareTo
public static <T extends CharSequence> T matchesPattern(@Nonnull Pattern pattern, @Nonnull T chars)
char
values matches a specified pattern. If the given character
sequence does not match against the passed pattern, an IllegalPatternArgumentException
will be thrown.
We recommend to use the overloaded method matchesPattern(Pattern, CharSequence, String)
and pass as
second argument the name of the parameter to enhance the exception message.
pattern
- pattern, that the chars
must correspond tochars
- a readable sequence of char
values which should match the given pattern
chars
that matches the given pattern
IllegalNullArgumentException
- if the given argument chars
is null
IllegalPatternArgumentException
- if the given chars
that does not match the pattern
public static <T extends CharSequence> T matchesPattern(@Nonnull Pattern pattern, @Nonnull T chars, @Nullable String name)
char
values matches a specified pattern. If the given character
sequence does not match against the passed pattern, an IllegalPatternArgumentException
will be thrown.
pattern
- pattern, that the chars
must correspond tochars
- a readable sequence of char
values which should match the given patternname
- name of object reference (in source code)
chars
that matches the given pattern
IllegalNullArgumentException
- if the given argument chars
is null
IllegalPatternArgumentException
- if the given chars
that does not match the pattern
public static <T extends Iterable<?>> T noNullElements(@Nonnull T iterable)
null
nor contains any elements that are null
.
We recommend to use the overloaded method noNullElements(Iterable, String)
and pass as second
argument the name of the parameter to enhance the exception message.
iterable
- the iterable reference which should not contain null
null
IllegalNullElementsException
- if the given argument iterable
contains elements that are null
public static <T extends Iterable<?>> T noNullElements(@Nonnull T iterable, String name)
null
nor contains any elements that are null
.
iterable
- the iterable reference which should not contain null
name
- name of object reference (in source code)
null
IllegalNullElementsException
- if the given argument iterable
contains elements that are null
public static <T> T[] noNullElements(@Nonnull T[] array)
null
.
We recommend to use the overloaded method noNullElements(Object[], String)
and pass as second
argument the name of the parameter to enhance the exception message.
array
- reference to an array
null
IllegalNullElementsException
- if the given argument array
contains null
public static <T> T[] noNullElements(@Nonnull T[] array, @Nullable String name)
null
.
array
- reference to an arrayname
- name of object reference (in source code)
null
IllegalNullElementsException
- if the given argument array
contains null
public static void notEmpty(boolean expression)
We recommend to use the overloaded method notEmpty(boolean, String)
and pass as second argument the
name of the parameter to enhance the exception message.
expression
- the result of the expression to verify the emptiness of a reference (true
means empty,
false
means not empty)
IllegalNullArgumentException
- if the given argument reference
is null
IllegalEmptyArgumentException
- if the given argument reference
is emptypublic static void notEmpty(boolean expression, @Nullable String name)
expression
- the result of the expression to verify the emptiness of a reference (true
means empty,
false
means not empty)name
- name of object reference (in source code)
IllegalEmptyArgumentException
- if the given argument reference
is emptypublic static <T extends CharSequence> T notEmpty(@Nonnull T chars)
We recommend to use the overloaded method notEmpty(CharSequence, String)
and pass as second
argument the name of the parameter to enhance the exception message.
chars
- a readable sequence of char
values which should not be empty
IllegalNullArgumentException
- if the given argument reference
is null
IllegalEmptyArgumentException
- if the given argument reference
is emptypublic static <T extends Collection<?>> T notEmpty(@Nonnull T collection)
We recommend to use the overloaded method notEmpty(Collection, String)
and pass as second argument
the name of the parameter to enhance the exception message.
collection
- a collection which should not be empty
IllegalNullArgumentException
- if the given argument collection
is null
IllegalEmptyArgumentException
- if the given argument collection
is emptypublic static <T extends Map<?,?>> T notEmpty(@Nonnull T map)
We recommend to use the overloaded method notEmpty(Collection, String)
and pass as second argument
the name of the parameter to enhance the exception message.
map
- a map which should not be empty
IllegalNullArgumentException
- if the given argument map
is null
IllegalEmptyArgumentException
- if the given argument map
is emptypublic static <T> T notEmpty(@Nonnull T reference, boolean expression, @Nullable String name)
The following example describes how to use it.
@ArgumentsChecked public setText(String text) { Check.notEmpty(text, text.isEmpty(), "text"); this.text = text; }
reference
- an object reference which should not be emptyexpression
- the result of the expression to verify the emptiness of a reference (true
means empty,
false
means not empty)name
- name of object reference (in source code)
IllegalNullArgumentException
- if the given argument reference
is null
IllegalEmptyArgumentException
- if the given argument reference
is emptypublic static <T extends CharSequence> T notEmpty(@Nonnull T chars, @Nullable String name)
The following example describes how to use it.
@ArgumentsChecked public setText(String text) { this.text = Check.notEmpty(text, "text"); }
chars
- a readable sequence of char
values which should not be emptyname
- name of object reference (in source code)
IllegalNullArgumentException
- if the given argument string
is null
IllegalEmptyArgumentException
- if the given argument string
is emptypublic static <T extends Map<?,?>> T notEmpty(@Nonnull T map, @Nullable String name)
We recommend to use the overloaded method notEmpty(Collection, String)
and pass as second argument
the name of the parameter to enhance the exception message.
map
- a map which should not be emptyname
- name of object reference (in source code)
IllegalNullArgumentException
- if the given argument map
is null
IllegalEmptyArgumentException
- if the given argument map
is emptypublic static <T extends Collection<?>> T notEmpty(@Nonnull T collection, @Nullable String name)
The following example describes how to use it.
@ArgumentsChecked public setCollection(Collection<String> collection) { this.collection = Check.notEmpty(collection, "collection"); }
collection
- a collection which should not be emptyname
- name of object reference (in source code)
IllegalNullArgumentException
- if the given argument collection
is null
IllegalEmptyArgumentException
- if the given argument collection
is emptypublic static <T> T[] notEmpty(@Nonnull T[] array)
We recommend to use the overloaded method notEmpty(Object[], String)
and pass as second argument
the name of the parameter to enhance the exception message.
array
- a map which should not be empty
IllegalNullArgumentException
- if the given argument array
is null
IllegalEmptyArgumentException
- if the given argument array
is emptypublic static <T> T[] notEmpty(@Nonnull T[] array, @Nullable String name)
array
- a map which should not be emptyname
- name of object reference (in source code)
IllegalNullArgumentException
- if the given argument array
is null
IllegalEmptyArgumentException
- if the given argument array
is emptypublic static <T> T nothing(T t)
t
.
This is useful if you have several checks on some arguments, but do not check other arguments on purpose. This
checks helps to document that a check was omitted on purpose instead of forgotten.
t
- any object
public static double notNaN(double value)
We recommend to use the overloaded method notNaN(double, String)
and pass as second argument the
name of the parameter to enhance the exception message.
value
- value which should not be NaN
IllegalNaNArgumentException
- if the given argument value
is NaNDouble.NaN
public static double notNaN(double value, @Nullable String name)
value
- value which should not be NaNname
- name of object reference (in source code)
IllegalNaNArgumentException
- if the given argument value
is NaNDouble.NaN
public static float notNaN(float value)
We recommend to use the overloaded method notNaN(float, String)
and pass as second argument the
name of the parameter to enhance the exception message.
value
- value which should not be NaN
IllegalNaNArgumentException
- if the given argument value
is NaNFloat.NaN
public static float notNaN(float value, @Nullable String name)
value
- value which should not be NaNname
- name of object reference (in source code)
IllegalNaNArgumentException
- if the given argument value
is NaNFloat.NaN
public static double notNegative(@Nonnull double value)
0
.
We recommend to use the overloaded method notNegative(double, String)
and pass as second argument
the name of the parameter to enhance the exception message.
value
- a number
IllegalNegativeArgumentException
- if the given argument reference
is smaller than 0
public static double notNegative(@Nonnull double value, @Nullable String name)
0
.
value
- a numbername
- name of the number reference (in source code)
IllegalNullArgumentException
- if the given argument reference
is smaller than 0
public static float notNegative(@Nonnull float value)
0
.
We recommend to use the overloaded method notNegative(float, String)
and pass as second argument
the name of the parameter to enhance the exception message.
value
- a number
IllegalNegativeArgumentException
- if the given argument reference
is smaller than 0
public static float notNegative(@Nonnull float value, @Nullable String name)
0
.
value
- a numbername
- name of the number reference (in source code)
IllegalNullArgumentException
- if the given argument reference
is smaller than 0
public static int notNegative(@Nonnull int value)
0
.
We recommend to use the overloaded method notNegative(int, String)
and pass as second argument the
name of the parameter to enhance the exception message.
value
- a number
IllegalNegativeArgumentException
- if the given argument reference
is smaller than 0
public static int notNegative(@Nonnull int value, @Nullable String name)
0
.
value
- a numbername
- name of the number reference (in source code)
IllegalNullArgumentException
- if the given argument reference
is smaller than 0
public static long notNegative(@Nonnull long value)
0
.
We recommend to use the overloaded method notNegative(long, String)
and pass as second argument the
name of the parameter to enhance the exception message.
value
- a number
IllegalNegativeArgumentException
- if the given argument reference
is smaller than 0
public static long notNegative(@Nonnull long value, @Nullable String name)
0
.
value
- a numbername
- name of the number reference (in source code)
IllegalNullArgumentException
- if the given argument reference
is smaller than 0
public static short notNegative(@Nonnull short value)
0
.
We recommend to use the overloaded method notNegative(short, String)
and pass as second argument
the name of the parameter to enhance the exception message.
value
- a number
IllegalNegativeArgumentException
- if the given argument reference
is smaller than 0
public static short notNegative(@Nonnull short value, @Nullable String name)
0
.
value
- a numbername
- name of the number reference (in source code)
IllegalNullArgumentException
- if the given argument reference
is smaller than 0
public static <T> T notNull(@Nonnull T reference)
null
.
We recommend to use the overloaded method notNull(Object, String)
and pass as second argument the
name of the parameter to enhance the exception message.
reference
- an object reference
IllegalNullArgumentException
- if the given argument reference
is null
public static <T> T notNull(@Nonnull T reference, @Nullable String name)
null
.
reference
- an object referencename
- name of object reference (in source code)
IllegalNullArgumentException
- if the given argument reference
is null
public static double notPositive(@Nonnull double value)
0
.
We recommend to use the overloaded method notPositive(double, String)
and pass as second argument
the name of the parameter to enhance the exception message.
value
- a number
IllegalPositiveArgumentException
- if the given argument reference
is smaller than 0
public static double notPositive(@Nonnull double value, @Nullable String name)
0
.
value
- a numbername
- name of the number reference (in source code)
IllegalNullArgumentException
- if the given argument reference
is smaller than 0
public static float notPositive(@Nonnull float value)
0
.
We recommend to use the overloaded method notPositive(float, String)
and pass as second argument
the name of the parameter to enhance the exception message.
value
- a number
IllegalPositiveArgumentException
- if the given argument reference
is smaller than 0
public static float notPositive(@Nonnull float value, @Nullable String name)
0
.
value
- a numbername
- name of the number reference (in source code)
IllegalNullArgumentException
- if the given argument reference
is smaller than 0
public static int notPositive(@Nonnull int value)
0
.
We recommend to use the overloaded method notPositive(int, String)
and pass as second argument the
name of the parameter to enhance the exception message.
value
- a number
IllegalPositiveArgumentException
- if the given argument reference
is smaller than 0
public static int notPositive(@Nonnull int value, @Nullable String name)
0
.
value
- a numbername
- name of the number reference (in source code)
IllegalNullArgumentException
- if the given argument reference
is smaller than 0
public static long notPositive(@Nonnull long value)
0
.
We recommend to use the overloaded method notPositive(long, String)
and pass as second argument the
name of the parameter to enhance the exception message.
value
- a number
IllegalPositiveArgumentException
- if the given argument reference
is smaller than 0
public static long notPositive(@Nonnull long value, @Nullable String name)
0
.
value
- a numbername
- name of the number reference (in source code)
IllegalNullArgumentException
- if the given argument reference
is smaller than 0
public static short notPositive(@Nonnull short value)
0
.
We recommend to use the overloaded method notPositive(short, String)
and pass as second argument
the name of the parameter to enhance the exception message.
value
- a number
IllegalPositiveArgumentException
- if the given argument reference
is smaller than 0
public static short notPositive(@Nonnull short value, @Nullable String name)
0
.
value
- a numbername
- name of the number reference (in source code)
IllegalNullArgumentException
- if the given argument reference
is smaller than 0
public static int positionIndex(int index, int size)
index
- index of an array, list or stringsize
- size of an array list or string
IllegalPositionIndexException
- if the index is not a valid position index within an array, list or string of size sizepublic static void range(@Nonnegative int start, @Nonnegative int end, @Nonnegative int size)
true
:
start
- the start value of the range (must be a positive integer or 0)end
- the end value of the range (must be a positive integer or 0)size
- the size value of the range (must be a positive integer or 0)
IllegalRangeException
- if the given arguments do not form a valid rangepublic static void stateIsTrue(boolean expression)
true
.
We recommend to use the overloaded method stateIsTrue(boolean, String)
and pass as second argument
the name of the parameter to enhance the exception message. A better way is to create specific exceptions (with a
good wording) for your case and to use the overloaded method stateIsTrue(boolean, Class)
and pass
as second argument your exception.
expression
- an expression that must be true to indicate a valid state
IllegalStateOfArgumentException
- if the given arguments caused an invalid statepublic static void stateIsTrue(boolean expression, Class<? extends RuntimeException> clazz)
true
and allows to specify the class of exception which is thrown in case
the state is not true
.
expression
- an expression that must be true
to indicate a valid stateclazz
- an subclass of RuntimeException
which will be thrown if the given state is not valid
clazz
- a new instance of clazz
if the given arguments caused an invalid state
RuntimeInstantiationException
- Attention: Be aware, that a RuntimeInstantiationException
can be thrown when
the given clazz
cannot be instantiatedpublic static void stateIsTrue(boolean expression, @Nonnull String description)
true
.
expression
- an expression that must be true
to indicate a valid statedescription
- will be used in the error message to describe why the arguments caused an invalid state
IllegalStateOfArgumentException
- if the given arguments caused an invalid statepublic static void stateIsTrue(boolean expression, @Nonnull String descriptionTemplate, Object... descriptionTemplateArgs)
true
expression
- an expression that must be true
to indicate a valid statedescriptionTemplate
- format string template that explains why the state is invaliddescriptionTemplateArgs
- format string template arguments to explain why the state is invalid
IllegalStateOfArgumentException
- if the given arguments caused an invalid state
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |