net.sf.qualitycheck
Class Check

java.lang.Object
  extended by net.sf.qualitycheck.Check

public final class Check
extends Object

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.

Author:
André Rouél, Dominik Seichter

Nested Class Summary
protected static class Check.NumericRegularExpressionHolder
          Holder for the regular expression to determine numeric values.
 
Method Summary
static
<T> T
contains(Collection<T> haystack, T needle)
          Ensures that an element needle is contained in a collection haystack.
static
<T> T
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
<T> T
equals(T expected, T check)
          Ensures that a passed object is equal to another object.
static
<T extends Comparable<T>>
T
equals(T expected, T check)
          Ensures that a passed Comparable is equal to another Comparable.
static
<T> T
equals(T expected, T check, String message)
          Ensures that a passed object is equal to another object.
static
<T extends Comparable<T>>
T
equals(T expected, T check, String message)
          Ensures that a passed Comparable is equal to another Comparable.
static
<T extends Comparable<T>>
T
greaterOrEqualThan(T expected, T check)
          Ensures that a passed Comparable is greater or equal compared to another Comparable.
static
<T extends Comparable<T>>
T
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
<T extends Comparable<T>>
T
greaterThan(T expected, T check)
          Ensures that a passed Comparable is greater to another Comparable.
static
<T extends Comparable<T>>
T
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
<T> T
instanceOf(Class<?> type, Object obj)
          Ensures that a passed argument is a member of a specific type.
static
<T> T
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
<T extends Number>
T
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
<T extends Number>
T
isNumber(String value, String name, Class<T> type)
          Ensures that a String argument is a number.
static
<T extends CharSequence>
T
isNumeric(T value)
          Ensures that a readable sequence of char values is numeric.
static
<T extends CharSequence>
T
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
<T extends Comparable<T>>
T
lesserThan(T expected, T check)
          Ensures that a passed Comparable is less than another Comparable.
static
<T extends Comparable<T>>
T
lesserThan(T expected, T check, String message)
          Ensures that a passed Comparable is less than another Comparable.
static
<T extends CharSequence>
T
matchesPattern(Pattern pattern, T chars)
          Ensures that a readable sequence of char values matches a specified pattern.
static
<T extends CharSequence>
T
matchesPattern(Pattern pattern, T chars, String name)
          Ensures that a readable sequence of char values matches a specified pattern.
static
<T extends Iterable<?>>
T
noNullElements(T iterable)
          Ensures that an iterable reference is neither null nor contains any elements that are null.
static
<T> T[]
noNullElements(T[] array)
          Ensures that an array does not contain null.
static
<T> T[]
noNullElements(T[] array, String name)
          Ensures that an array does not contain null.
static
<T extends Iterable<?>>
T
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
<T extends CharSequence>
T
notEmpty(T chars)
          Ensures that a passed string as a parameter of the calling method is not empty.
static
<T extends Collection<?>>
T
notEmpty(T collection)
          Ensures that a passed collection as a parameter of the calling method is not empty.
static
<T extends Map<?,?>>
T
notEmpty(T map)
          Ensures that a passed map as a parameter of the calling method is not empty.
static
<T> T[]
notEmpty(T[] array)
          Ensures that a passed map as a parameter of the calling method is not empty.
static
<T> T[]
notEmpty(T[] array, String name)
          Ensures that a passed map as a parameter of the calling method is not empty.
static
<T> T
notEmpty(T reference, boolean expression, String name)
          Ensures that an object reference passed as a parameter to the calling method is not empty.
static
<T extends CharSequence>
T
notEmpty(T chars, String name)
          Ensures that a passed string as a parameter of the calling method is not empty.
static
<T extends Collection<?>>
T
notEmpty(T collection, String name)
          Ensures that a passed collection as a parameter of the calling method is not empty.
static
<T extends Map<?,?>>
T
notEmpty(T map, String name)
          Ensures that a passed map as a parameter of the calling method is not empty.
static
<T> T
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
<T> T
notNull(T reference)
          Ensures that an object reference passed as a parameter to the calling method is not null.
static
<T> T
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

contains

public static <T> T contains(@Nonnull
                             Collection<T> haystack,
                             @Nonnull
                             T needle)
Ensures that an element 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.

Parameters:
haystack - A collection which must contain needle
needle - An object that must be contained into a collection.
Returns:
the passed argument needle
Throws:
IllegalArgumentNotContainedException - if the passed needle can not be found in haystack

contains

public static <T> T contains(@Nonnull
                             Collection<T> haystack,
                             @Nonnull
                             T needle,
                             @Nonnull
                             String name)
Ensures that an element 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).

Parameters:
haystack - A collection which must contain needle
needle - An object that must be contained into a collection.
name - name of argument of needle
Returns:
the passed argument needle
Throws:
IllegalArgumentNotContainedException - if the passed needle can not be found in haystack

equals

public static boolean equals(@Nonnull
                             boolean expected,
                             @Nonnull
                             boolean check)
Ensures that a passed boolean is equal to another boolean. The comparison is made using 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.

Parameters:
expected - Expected value
check - boolean to be checked
Returns:
the passed boolean argument check
Throws:
IllegalNotEqualException - if both argument values are not equal

equals

public static boolean equals(@Nonnull
                             boolean expected,
                             @Nonnull
                             boolean check,
                             String message)
Ensures that a passed boolean is equal to another boolean. The comparison is made using expected != check.

Parameters:
expected - Expected value
check - boolean to be checked
message - an error message describing why the booleans must equal (will be passed to IllegalNotEqualException)
Returns:
the passed boolean argument check
Throws:
IllegalNotEqualException - if both argument values are not equal

equals

public static byte equals(@Nonnull
                          byte expected,
                          @Nonnull
                          byte check)
Ensures that a passed byte is equal to another byte. The comparison is made using 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.

Parameters:
expected - Expected value
check - byte to be checked
Returns:
the passed byte argument check
Throws:
IllegalNotEqualException - if both argument values are not equal

equals

public static byte equals(@Nonnull
                          byte expected,
                          @Nonnull
                          byte check,
                          String message)
Ensures that a passed byte is equal to another byte. The comparison is made using expected != check.

Parameters:
expected - Expected value
check - byte to be checked
message - an error message describing why the bytes must equal (will be passed to IllegalNotEqualException)
Returns:
the byte boolean argument check
Throws:
IllegalNotEqualException - if both argument values are not equal

equals

public static char equals(@Nonnull
                          char expected,
                          @Nonnull
                          char check)
Ensures that a passed char is equal to another char. The comparison is made using 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.

Parameters:
expected - Expected value
check - char to be checked
Returns:
the passed char argument check
Throws:
IllegalNotEqualException - if both argument values are not equal

equals

public static char equals(@Nonnull
                          char expected,
                          @Nonnull
                          char check,
                          String message)
Ensures that a passed char is equal to another char. The comparison is made using expected != check.

Parameters:
expected - Expected value
check - char to be checked
message - an error message describing why the chars must equal (will be passed to IllegalNotEqualException)
Returns:
the passed char argument check
Throws:
IllegalNotEqualException - if both argument values are not equal

equals

public static int equals(@Nonnull
                         int expected,
                         @Nonnull
                         int check)
Ensures that a passed intH is equal to another int. The comparison is made using 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.

Parameters:
expected - Expected value
check - int to be checked
Returns:
the passed int argument check
Throws:
IllegalNotEqualException - if both argument values are not equal

equals

public static int equals(@Nonnull
                         int expected,
                         @Nonnull
                         int check,
                         String message)
Ensures that a passed int is equal to another int. The comparison is made using expected != check.

Parameters:
expected - Expected value
check - int to be checked
message - an error message describing why the ints must equal (will be passed to IllegalNotEqualException)
Returns:
the passed int argument check
Throws:
IllegalNotEqualException - if both argument values are not equal

equals

public static long equals(@Nonnull
                          long expected,
                          @Nonnull
                          long check)
Ensures that a passed long is equal to another long. The comparison is made using 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.

Parameters:
expected - Expected value
check - long to be checked
Returns:
the passed long argument check
Throws:
IllegalNotEqualException - if both argument values are not equal

equals

public static long equals(@Nonnull
                          long expected,
                          @Nonnull
                          long check,
                          String message)
Ensures that a passed long is equal to another long. The comparison is made using expected != check.

Parameters:
expected - Expected value
check - long to be checked
message - an error message describing why the longs must equal (will be passed to IllegalNotEqualException)
Returns:
the passed long argument check
Throws:
IllegalNotEqualException - if both argument values are not equal

equals

public static short equals(@Nonnull
                           short expected,
                           @Nonnull
                           short check)
Ensures that a passed short is equal to another short. The comparison is made using 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.

Parameters:
expected - Expected value
check - short to be checked
Returns:
the passed short argument check
Throws:
IllegalNotEqualException - if both argument values are not equal

equals

public static short equals(@Nonnull
                           short expected,
                           @Nonnull
                           short check,
                           String message)
Ensures that a passed short is equal to another short. The comparison is made using expected != check.

Parameters:
expected - Expected value
check - short to be checked
message - an error message describing why the shorts must equal (will be passed to IllegalNotEqualException)
Returns:
the passed short check
Throws:
IllegalNotEqualException - if both argument values are not equal

equals

public static <T extends Comparable<T>> T equals(@Nonnull
                                                 T expected,
                                                 @Nonnull
                                                 T check)
Ensures that a passed 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.

Parameters:
expected - Expected value
check - Comparable to be checked
Returns:
the passed Comparable argument check
Throws:
IllegalNotEqualException - if both argument values are not equal

equals

public static <T> T equals(@Nonnull
                           T expected,
                           @Nonnull
                           T check)
Ensures that a passed object is equal to another object. The comparison is made using a call to 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.

Parameters:
expected - Expected value
check - Object to be checked
Returns:
the passed argument check
Throws:
IllegalNotEqualException - if both argument values are not equal

equals

public static <T extends Comparable<T>> T equals(@Nonnull
                                                 T expected,
                                                 @Nonnull
                                                 T check,
                                                 String message)
Ensures that a passed Comparable is equal to another Comparable. The comparison is made using expected.compareTo(check) != 0.

Parameters:
expected - Expected value
check - Comparable to be checked
message - an error message describing why the s must equal (will be passed to IllegalNotEqualException)
Returns:
the passed Comparable argument check
Throws:
IllegalNotEqualException - if both argument values are not equal

equals

public static <T> T equals(@Nonnull
                           T expected,
                           @Nonnull
                           T check,
                           String message)
Ensures that a passed object is equal to another object. The comparison is made using a call to expected.equals(check) .

Parameters:
expected - Expected value
check - Object to be checked
message - an error message describing why the objects must equal (will be passed to IllegalNotEqualException)
Returns:
the passed argument check
Throws:
IllegalNotEqualException - if both argument values are not equal

greaterOrEqualThan

public static <T extends Comparable<T>> T greaterOrEqualThan(@Nonnull
                                                             T expected,
                                                             @Nonnull
                                                             T check)
Ensures that a passed Comparable is greater or equal compared to another Comparable. The comparison is made using expected.compareTo(check) > 0.

Parameters:
expected - Expected value
check - Comparable to be checked
Returns:
the passed Comparable argument check
Throws:
IllegalNotGreaterOrEqualThanException - if the argument value check is not greater or equal than the value expected when using method compareTo

greaterOrEqualThan

public static <T extends Comparable<T>> T greaterOrEqualThan(@Nonnull
                                                             T expected,
                                                             @Nonnull
                                                             T check,
                                                             String message)
Ensures that a passed Comparable is greater or equal compared to another Comparable. The comparison is made using expected.compareTo(check) > 0.

Parameters:
expected - Expected value
check - Comparable to be checked
message - an error message describing why the comparable must be greater than a value (will be passed to IllegalNotGreaterOrEqualThanException)
Returns:
the passed Comparable argument check
Throws:
IllegalNotGreaterOrEqualThanException - if the argument value check is not greater or equal than the value expected when using method compareTo

greaterThan

public static byte greaterThan(@Nonnull
                               byte expected,
                               @Nonnull
                               byte check)
Ensures that a passed byte is greater to another byte.

Parameters:
expected - Expected value
check - Comparable to be checked
Returns:
the passed Comparable argument check
Throws:
IllegalNotGreaterThanException - if the argument value check is not greater than value expected

greaterThan

public static byte greaterThan(@Nonnull
                               byte expected,
                               @Nonnull
                               byte check,
                               String message)
Ensures that a passed byte is greater than another byte.

Parameters:
expected - Expected value
check - Comparable to be checked
message - an error message describing why the comparable must be greater than a value (will be passed to IllegalNotGreaterThanException)
Returns:
the passed Comparable argument check
Throws:
IllegalNotGreaterThanException - if the argument value check is not greater than value expected

greaterThan

public static char greaterThan(@Nonnull
                               char expected,
                               @Nonnull
                               char check)
Ensures that a passed char is greater to another char.

Parameters:
expected - Expected value
check - Comparable to be checked
Returns:
the passed Comparable argument check
Throws:
IllegalNotGreaterThanException - if the argument value check is not greater than value expected

greaterThan

public static char greaterThan(@Nonnull
                               char expected,
                               @Nonnull
                               char check,
                               String message)
Ensures that a passed char is greater than another char.

Parameters:
expected - Expected value
check - Comparable to be checked
message - an error message describing why the comparable must be greater than a value (will be passed to IllegalNotGreaterThanException)
Returns:
the passed Comparable argument check
Throws:
IllegalNotGreaterThanException - if the argument value check is not greater than value expected

greaterThan

public static double greaterThan(@Nonnull
                                 double expected,
                                 @Nonnull
                                 double check)
Ensures that a passed double is greater to another double.

Parameters:
expected - Expected value
check - Comparable to be checked
Returns:
the passed Comparable argument check
Throws:
IllegalNotGreaterThanException - if the argument value check is not greater than value expected

greaterThan

public static double greaterThan(@Nonnull
                                 double expected,
                                 @Nonnull
                                 double check,
                                 String message)
Ensures that a passed double is greater than another double.

Parameters:
expected - Expected value
check - Comparable to be checked
message - an error message describing why the comparable must be greater than a value (will be passed to IllegalNotGreaterThanException)
Returns:
the passed Comparable argument check
Throws:
IllegalNotGreaterThanException - if the argument value check is not greater than value expected

greaterThan

public static float greaterThan(@Nonnull
                                float expected,
                                @Nonnull
                                float check)
Ensures that a passed float is greater to another float.

Parameters:
expected - Expected value
check - Comparable to be checked
Returns:
the passed Comparable argument check
Throws:
IllegalNotGreaterThanException - if the argument value check is not greater than value expected

greaterThan

public static float greaterThan(@Nonnull
                                float expected,
                                @Nonnull
                                float check,
                                String message)
Ensures that a passed float is greater than another float.

Parameters:
expected - Expected value
check - Comparable to be checked
message - an error message describing why the comparable must be greater than a value (will be passed to IllegalNotGreaterThanException)
Returns:
the passed Comparable argument check
Throws:
IllegalNotGreaterThanException - if the argument value check is not greater than value expected

greaterThan

public static int greaterThan(@Nonnull
                              int expected,
                              @Nonnull
                              int check)
Ensures that a passed int is greater to another int.

Parameters:
expected - Expected value
check - Comparable to be checked
Returns:
the passed Comparable argument check
Throws:
IllegalNotGreaterThanException - if the argument value check is not greater than value expected

greaterThan

public static int greaterThan(@Nonnull
                              int expected,
                              @Nonnull
                              int check,
                              String message)
Ensures that a passed int is greater than another int.

Parameters:
expected - Expected value
check - Comparable to be checked
message - an error message describing why the comparable must be greater than a value (will be passed to IllegalNotGreaterThanException)
Returns:
the passed Comparable argument check
Throws:
IllegalNotGreaterThanException - if the argument value check is not greater than value expected

greaterThan

public static long greaterThan(@Nonnull
                               long expected,
                               @Nonnull
                               long check)
Ensures that a passed long is greater to another long.

Parameters:
expected - Expected value
check - Comparable to be checked
Returns:
the passed Comparable argument check
Throws:
IllegalNotGreaterThanException - if the argument value check is not greater than value expected

greaterThan

public static long greaterThan(@Nonnull
                               long expected,
                               @Nonnull
                               long check,
                               String message)
Ensures that a passed long is greater than another long.

Parameters:
expected - Expected value
check - Comparable to be checked
message - an error message describing why the comparable must be greater than a value (will be passed to IllegalNotGreaterThanException)
Returns:
the passed Comparable argument check
Throws:
IllegalNotGreaterThanException - if the argument value check is not greater than value expected

greaterThan

public static short greaterThan(@Nonnull
                                short expected,
                                @Nonnull
                                short check)
Ensures that a passed short is greater to another short.

Parameters:
expected - Expected value
check - Comparable to be checked
Returns:
the passed Comparable argument check
Throws:
IllegalNotGreaterThanException - if the argument value check is not greater than value expected

greaterThan

public static short greaterThan(@Nonnull
                                short expected,
                                @Nonnull
                                short check,
                                String message)
Ensures that a passed short is greater than another short.

Parameters:
expected - Expected value
check - Comparable to be checked
message - an error message describing why the comparable must be greater than a value (will be passed to IllegalNotGreaterThanException)
Returns:
the passed Comparable argument check
Throws:
IllegalNotGreaterThanException - if the argument value check is not greater than value expected

greaterThan

public static <T extends Comparable<T>> T greaterThan(@Nonnull
                                                      T expected,
                                                      @Nonnull
                                                      T check)
Ensures that a passed Comparable is greater to another Comparable. The comparison is made using expected.compareTo(check) >= 0.

Parameters:
expected - Expected value
check - Comparable to be checked
Returns:
the passed Comparable argument check
Throws:
IllegalNotGreaterThanException - if the argument value check is not greater than value expected when using method compareTo

greaterThan

public static <T extends Comparable<T>> T greaterThan(@Nonnull
                                                      T expected,
                                                      @Nonnull
                                                      T check,
                                                      String message)
Ensures that a passed Comparable is greater than another Comparable. The comparison is made using expected.compareTo(check) >= 0.

Parameters:
expected - Expected value
check - Comparable to be checked
message - an error message describing why the comparable must be greater than a value (will be passed to IllegalNotGreaterThanException)
Returns:
the passed Comparable argument check
Throws:
IllegalNotGreaterThanException - if the argument value check is not greater than value expected when using method compareTo

hasAnnotation

public static Annotation hasAnnotation(@Nonnull
                                       Class<?> clazz,
                                       @Nonnull
                                       Class<? extends Annotation> annotation)
Ensures that a passed class has an annotation of a specific type

Parameters:
clazz - the class that must have a required annotation
annotation - the type of annotation that is required on the class
Returns:
the given annotation which is present on the checked class
Throws:
IllegalMissingAnnotationException - if the passed annotation is not annotated at the given class

instanceOf

public static <T> T instanceOf(@Nonnull
                               Class<?> type,
                               @Nonnull
                               Object obj)
Ensures that a passed argument is a member of a specific type.

Parameters:
type - class that the given object is a member of
obj - the object reference that should be a member of a specific type
Returns:
the given object cast to type
Throws:
IllegalInstanceOfArgumentException - if the given argument obj is not a member of type

instanceOf

public static <T> T instanceOf(@Nonnull
                               Class<?> type,
                               @Nonnull
                               Object obj,
                               @Nullable
                               String name)
Ensures that a passed argument is a member of a specific type.

Parameters:
type - class that the given object is a member of
obj - the object reference that should be a member of a specific type
name - name of object reference (in source code)
Returns:
the given object cast to type
Throws:
IllegalInstanceOfArgumentException - if the given argument obj is not a member of type

isNull

public static void isNull(@Nullable
                          Object reference)
Ensures that a given argument is 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.

Parameters:
reference - reference which must be null
Throws:
IllegalNotNullArgumentException - if the given argument reference is not null

isNull

public static void isNull(@Nullable
                          Object reference,
                          @Nullable
                          String name)
Ensures that a given argument is 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.

Parameters:
reference - reference which must be null.
name - name of object reference (in source code)
Throws:
IllegalNotNullArgumentException - if the given argument reference is not null

isNumber

public static int isNumber(@Nonnull
                           String value)
Ensures that a String argument is a number.

Parameters:
value - value which must be a number
Returns:
the given string argument converted to an int
Throws:
IllegalNumberArgumentException - if the given argument value is not a number

isNumber

public static <T extends Number> T isNumber(@Nonnull
                                            String value,
                                            @Nonnull
                                            Class<T> type)
Ensures that a String argument is a number. This overload supports all subclasses of Number. The number is first converted to a BigInteger

Parameters:
value - value which must be a number
type - requested return value type, must be a subclass of Number, i.e. one of BigDecimal, BigInteger, Byte, Double, Float, Integer, Long, Short
Returns:
the given string argument converted to a number of the requested type
Throws:
IllegalNumberArgumentException - if the given argument value is no number

isNumber

public static int isNumber(@Nonnull
                           String value,
                           @Nullable
                           String name)
Ensures that a string argument is a number according to Integer.parseInt

Parameters:
value - value which must be a number
name - name of object reference (in source code)
Returns:
the given string argument converted to an int
Throws:
IllegalNumberArgumentException - if the given argument value is no number

isNumber

public static <T extends Number> T isNumber(@Nonnull
                                            String value,
                                            @Nullable
                                            String name,
                                            @Nonnull
                                            Class<T> type)
Ensures that a String argument is a number. This overload supports all subclasses of 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.

Parameters:
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
Returns:
the given string argument converted to a number of the requested type
Throws:
IllegalNumberArgumentException - if the given argument value is no number

isNumeric

public static <T extends CharSequence> T isNumeric(@Nonnull
                                                   T value)
Ensures that a readable sequence of 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.

Parameters:
value - a readable sequence of char values which must be a number
Returns:
the given string argument
Throws:
IllegalNumberArgumentException - if the given argument value is no number

isNumeric

public static <T extends CharSequence> T isNumeric(@Nonnull
                                                   T value,
                                                   @Nullable
                                                   String name)
Ensures that a readable sequence of 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).

Parameters:
value - a readable sequence of char values which must be a number
name - name of object reference (in source code)
Returns:
the given string argument
Throws:
IllegalNumberArgumentException - if the given argument value is no number

lesserThan

public static byte lesserThan(@Nonnull
                              byte expected,
                              @Nonnull
                              byte check)
Ensures that a passed byte is less than another byte.

Parameters:
expected - Expected value
check - Comparable to be checked
Returns:
the passed byte argument check
Throws:
IllegalNotLesserThanException - if the argument value check is not lesser than value expected

lesserThan

public static byte lesserThan(@Nonnull
                              byte expected,
                              @Nonnull
                              byte check,
                              String message)
Ensures that a passed byte is less than another byte.

Parameters:
expected - Expected value
check - Comparable to be checked
message - an error message describing why the comparables must be less than a value (will be passed to IllegalNotLessThanException)
Returns:
the passed Comparable argument check
Throws:
IllegalNotLesserThanException - if the argument value check is not lesser than value expected

lesserThan

public static char lesserThan(@Nonnull
                              char expected,
                              @Nonnull
                              char check)
Ensures that a passed char is less than another char.

Parameters:
expected - Expected value
check - Comparable to be checked
Returns:
the passed char argument check
Throws:
IllegalNotLesserThanException - if the argument value check is not lesser than value expected

lesserThan

public static char lesserThan(@Nonnull
                              char expected,
                              @Nonnull
                              char check,
                              String message)
Ensures that a passed char is less than another char.

Parameters:
expected - Expected value
check - Comparable to be checked
message - an error message describing why the comparables must be less than a value (will be passed to IllegalNotLessThanException)
Returns:
the passed Comparable argument check
Throws:
IllegalNotLesserThanException - if the argument value check is not lesser than value expected

lesserThan

public static double lesserThan(@Nonnull
                                double expected,
                                @Nonnull
                                double check)
Ensures that a passed double is less than another double.

Parameters:
expected - Expected value
check - Comparable to be checked
Returns:
the passed double argument check
Throws:
IllegalNotLesserThanException - if the argument value check is not lesser than value expected

lesserThan

public static double lesserThan(@Nonnull
                                double expected,
                                @Nonnull
                                double check,
                                String message)
Ensures that a passed double is less than another double.

Parameters:
expected - Expected value
check - Comparable to be checked
message - an error message describing why the comparables must be less than a value (will be passed to IllegalNotLessThanException)
Returns:
the passed Comparable argument check
Throws:
IllegalNotLesserThanException - if the argument value check is not lesser than value expected

lesserThan

public static float lesserThan(@Nonnull
                               float expected,
                               @Nonnull
                               float check)
Ensures that a passed float is less than another float.

Parameters:
expected - Expected value
check - Comparable to be checked
Returns:
the passed float argument check
Throws:
IllegalNotLesserThanException - if the argument value check is not lesser than value expected

lesserThan

public static float lesserThan(@Nonnull
                               float expected,
                               @Nonnull
                               float check,
                               String message)
Ensures that a passed float is less than another float.

Parameters:
expected - Expected value
check - Comparable to be checked
message - an error message describing why the comparables must be less than a value (will be passed to IllegalNotLessThanException)
Returns:
the passed Comparable argument check
Throws:
IllegalNotLesserThanException - if the argument value check is not lesser than value expected

lesserThan

public static int lesserThan(@Nonnull
                             int expected,
                             @Nonnull
                             int check)
Ensures that a passed int is less than another int.

Parameters:
expected - Expected value
check - Comparable to be checked
Returns:
the passed int argument check
Throws:
IllegalNotLesserThanException - if the argument value check is not lesser than value expected

lesserThan

public static int lesserThan(@Nonnull
                             int expected,
                             @Nonnull
                             int check,
                             String message)
Ensures that a passed int is less than another int.

Parameters:
expected - Expected value
check - Comparable to be checked
message - an error message describing why the comparables must be less than a value (will be passed to IllegalNotLessThanException)
Returns:
the passed Comparable argument check
Throws:
IllegalNotLesserThanException - if the argument value check is not lesser than value expected

lesserThan

public static long lesserThan(@Nonnull
                              long expected,
                              @Nonnull
                              long check)
Ensures that a passed long is less than another long.

Parameters:
expected - Expected value
check - Comparable to be checked
Returns:
the passed long argument check
Throws:
IllegalNotLesserThanException - if the argument value check is not lesser than value expected

lesserThan

public static long lesserThan(@Nonnull
                              long expected,
                              @Nonnull
                              long check,
                              String message)
Ensures that a passed long is less than another long.

Parameters:
expected - Expected value
check - Comparable to be checked
message - an error message describing why the comparables must be less than a value (will be passed to IllegalNotLessThanException)
Returns:
the passed Comparable argument check
Throws:
IllegalNotLesserThanException - if the argument value check is not lesser than value expected

lesserThan

public static short lesserThan(@Nonnull
                               short expected,
                               @Nonnull
                               short check)
Ensures that a passed short is less than another short.

Parameters:
expected - Expected value
check - Comparable to be checked
Returns:
the passed short argument check
Throws:
IllegalNotLesserThanException - if the argument value check is not lesser than value expected

lesserThan

public static short lesserThan(@Nonnull
                               short expected,
                               @Nonnull
                               short check,
                               String message)
Ensures that a passed short is less than another short.

Parameters:
expected - Expected value
check - Comparable to be checked
message - an error message describing why the comparables must be less than a value (will be passed to IllegalNotLessThanException)
Returns:
the passed Comparable argument check
Throws:
IllegalNotLesserThanException - if the argument value check is not lesser than value expected

lesserThan

public static <T extends Comparable<T>> T lesserThan(@Nonnull
                                                     T expected,
                                                     @Nonnull
                                                     T check)
Ensures that a passed Comparable is less than another Comparable. The comparison is made using expected.compareTo(check) <= 0.

Parameters:
expected - Expected value
check - Comparable to be checked
Returns:
the passed Comparable argument check
Throws:
IllegalNotLesserThanException - if the argument value check is not lesser than value expected when using method compareTo

lesserThan

public static <T extends Comparable<T>> T lesserThan(@Nonnull
                                                     T expected,
                                                     @Nonnull
                                                     T check,
                                                     String message)
Ensures that a passed Comparable is less than another Comparable. The comparison is made using expected.compareTo(check) <= 0.

Parameters:
expected - Expected value
check - Comparable to be checked
message - an error message describing why the comparables must be less than a value (will be passed to IllegalNotLessThanException)
Returns:
the passed Comparable argument check
Throws:
IllegalNotLesserThanException - if the argument value check is not lesser than value expected when using method compareTo

matchesPattern

public static <T extends CharSequence> T matchesPattern(@Nonnull
                                                        Pattern pattern,
                                                        @Nonnull
                                                        T chars)
Ensures that a readable sequence of 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.

Parameters:
pattern - pattern, that the chars must correspond to
chars - a readable sequence of char values which should match the given pattern
Returns:
the passed chars that matches the given pattern
Throws:
IllegalNullArgumentException - if the given argument chars is null
IllegalPatternArgumentException - if the given chars that does not match the pattern

matchesPattern

public static <T extends CharSequence> T matchesPattern(@Nonnull
                                                        Pattern pattern,
                                                        @Nonnull
                                                        T chars,
                                                        @Nullable
                                                        String name)
Ensures that a readable sequence of char values matches a specified pattern. If the given character sequence does not match against the passed pattern, an IllegalPatternArgumentException will be thrown.

Parameters:
pattern - pattern, that the chars must correspond to
chars - a readable sequence of char values which should match the given pattern
name - name of object reference (in source code)
Returns:
the passed chars that matches the given pattern
Throws:
IllegalNullArgumentException - if the given argument chars is null
IllegalPatternArgumentException - if the given chars that does not match the pattern

noNullElements

public static <T extends Iterable<?>> T noNullElements(@Nonnull
                                                       T iterable)
Ensures that an iterable reference is neither 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.

Parameters:
iterable - the iterable reference which should not contain null
Returns:
the passed reference which contains no elements that are null
Throws:
IllegalNullElementsException - if the given argument iterable contains elements that are null

noNullElements

public static <T extends Iterable<?>> T noNullElements(@Nonnull
                                                       T iterable,
                                                       String name)
Ensures that an iterable reference is neither null nor contains any elements that are null.

Parameters:
iterable - the iterable reference which should not contain null
name - name of object reference (in source code)
Returns:
the passed reference which contains no elements that are null
Throws:
IllegalNullElementsException - if the given argument iterable contains elements that are null

noNullElements

public static <T> T[] noNullElements(@Nonnull
                                     T[] array)
Ensures that an array does not contain 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.

Parameters:
array - reference to an array
Returns:
the passed reference which contains no elements that are null
Throws:
IllegalNullElementsException - if the given argument array contains null

noNullElements

public static <T> T[] noNullElements(@Nonnull
                                     T[] array,
                                     @Nullable
                                     String name)
Ensures that an array does not contain null.

Parameters:
array - reference to an array
name - name of object reference (in source code)
Returns:
the passed reference which contains no elements that are null
Throws:
IllegalNullElementsException - if the given argument array contains null

notEmpty

public 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.

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.

Parameters:
expression - the result of the expression to verify the emptiness of a reference (true means empty, false means not empty)
Throws:
IllegalNullArgumentException - if the given argument reference is null
IllegalEmptyArgumentException - if the given argument reference is empty

notEmpty

public static void notEmpty(boolean expression,
                            @Nullable
                            String name)
Ensures that a passed parameter of the calling method is not empty, using the passed expression to evaluate the emptiness.

Parameters:
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)
Throws:
IllegalEmptyArgumentException - if the given argument reference is empty

notEmpty

public static <T extends CharSequence> T notEmpty(@Nonnull
                                                  T chars)
Ensures that a passed string as a parameter of the calling method is not empty.

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.

Parameters:
chars - a readable sequence of char values which should not be empty
Returns:
the passed reference that is not empty
Throws:
IllegalNullArgumentException - if the given argument reference is null
IllegalEmptyArgumentException - if the given argument reference is empty

notEmpty

public static <T extends Collection<?>> T notEmpty(@Nonnull
                                                   T collection)
Ensures that a passed collection as a parameter of the calling method is not empty.

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.

Parameters:
collection - a collection which should not be empty
Returns:
the passed reference that is not empty
Throws:
IllegalNullArgumentException - if the given argument collection is null
IllegalEmptyArgumentException - if the given argument collection is empty

notEmpty

public static <T extends Map<?,?>> T notEmpty(@Nonnull
                                              T map)
Ensures that a passed map as a parameter of the calling method is not empty.

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.

Parameters:
map - a map which should not be empty
Returns:
the passed reference that is not empty
Throws:
IllegalNullArgumentException - if the given argument map is null
IllegalEmptyArgumentException - if the given argument map is empty

notEmpty

public static <T> T notEmpty(@Nonnull
                             T reference,
                             boolean expression,
                             @Nullable
                             String name)
Ensures that an object reference passed as a parameter to the calling method is not empty. The passed boolean value is the result of checking whether the reference is empty or not.

The following example describes how to use it.

 @ArgumentsChecked
 public setText(String text) {
        Check.notEmpty(text, text.isEmpty(), "text");
        this.text = text;
 }
 

Parameters:
reference - an object reference which should not be empty
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)
Returns:
the passed reference that is not empty
Throws:
IllegalNullArgumentException - if the given argument reference is null
IllegalEmptyArgumentException - if the given argument reference is empty

notEmpty

public static <T extends CharSequence> T notEmpty(@Nonnull
                                                  T chars,
                                                  @Nullable
                                                  String name)
Ensures that a passed string as a parameter of the calling method is not empty.

The following example describes how to use it.

 @ArgumentsChecked
 public setText(String text) {
        this.text = Check.notEmpty(text, "text");
 }
 

Parameters:
chars - a readable sequence of char values which should not be empty
name - name of object reference (in source code)
Returns:
the passed reference that is not empty
Throws:
IllegalNullArgumentException - if the given argument string is null
IllegalEmptyArgumentException - if the given argument string is empty

notEmpty

public static <T extends Map<?,?>> T notEmpty(@Nonnull
                                              T map,
                                              @Nullable
                                              String name)
Ensures that a passed map as a parameter of the calling method is not empty.

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.

Parameters:
map - a map which should not be empty
name - name of object reference (in source code)
Returns:
the passed reference that is not empty
Throws:
IllegalNullArgumentException - if the given argument map is null
IllegalEmptyArgumentException - if the given argument map is empty

notEmpty

public static <T extends Collection<?>> T notEmpty(@Nonnull
                                                   T collection,
                                                   @Nullable
                                                   String name)
Ensures that a passed collection as a parameter of the calling method is not empty.

The following example describes how to use it.

 @ArgumentsChecked
 public setCollection(Collection<String> collection) {
        this.collection = Check.notEmpty(collection, "collection");
 }
 

Parameters:
collection - a collection which should not be empty
name - name of object reference (in source code)
Returns:
the passed reference that is not empty
Throws:
IllegalNullArgumentException - if the given argument collection is null
IllegalEmptyArgumentException - if the given argument collection is empty

notEmpty

public static <T> T[] notEmpty(@Nonnull
                               T[] array)
Ensures that a passed map as a parameter of the calling method is not empty.

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.

Parameters:
array - a map which should not be empty
Returns:
the passed reference that is not empty
Throws:
IllegalNullArgumentException - if the given argument array is null
IllegalEmptyArgumentException - if the given argument array is empty

notEmpty

public static <T> T[] notEmpty(@Nonnull
                               T[] array,
                               @Nullable
                               String name)
Ensures that a passed map as a parameter of the calling method is not empty.

Parameters:
array - a map which should not be empty
name - name of object reference (in source code)
Returns:
the passed reference that is not empty
Throws:
IllegalNullArgumentException - if the given argument array is null
IllegalEmptyArgumentException - if the given argument array is empty

nothing

public static <T> T nothing(T t)
Do not perform any check and just return 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.

Parameters:
t - any object
Returns:
t

notNaN

public static double notNaN(double value)
Ensures that a double argument is not NaN (not a number).

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.

Parameters:
value - value which should not be NaN
Returns:
the given double value
Throws:
IllegalNaNArgumentException - if the given argument value is NaN
See Also:
Double.NaN

notNaN

public static double notNaN(double value,
                            @Nullable
                            String name)
Ensures that a double argument is not NaN (not a number).

Parameters:
value - value which should not be NaN
name - name of object reference (in source code)
Returns:
the given double value
Throws:
IllegalNaNArgumentException - if the given argument value is NaN
See Also:
Double.NaN

notNaN

public static float notNaN(float value)
Ensures that a double argument is not NaN (not a number).

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.

Parameters:
value - value which should not be NaN
Returns:
the given double value
Throws:
IllegalNaNArgumentException - if the given argument value is NaN
See Also:
Float.NaN

notNaN

public static float notNaN(float value,
                           @Nullable
                           String name)
Ensures that a double argument is not NaN (not a number).

Parameters:
value - value which should not be NaN
name - name of object reference (in source code)
Returns:
the given float value
Throws:
IllegalNaNArgumentException - if the given argument value is NaN
See Also:
Float.NaN

notNegative

public static double notNegative(@Nonnull
                                 double value)
Ensures that an double reference passed as a parameter to the calling method is not smaller than 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.

Parameters:
value - a number
Returns:
the non-null reference that was validated
Throws:
IllegalNegativeArgumentException - if the given argument reference is smaller than 0

notNegative

public static double notNegative(@Nonnull
                                 double value,
                                 @Nullable
                                 String name)
Ensures that an double reference passed as a parameter to the calling method is not smaller than 0.

Parameters:
value - a number
name - name of the number reference (in source code)
Returns:
the non-null reference that was validated
Throws:
IllegalNullArgumentException - if the given argument reference is smaller than 0

notNegative

public static float notNegative(@Nonnull
                                float value)
Ensures that an float reference passed as a parameter to the calling method is not smaller than 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.

Parameters:
value - a number
Returns:
the non-null reference that was validated
Throws:
IllegalNegativeArgumentException - if the given argument reference is smaller than 0

notNegative

public static float notNegative(@Nonnull
                                float value,
                                @Nullable
                                String name)
Ensures that an float reference passed as a parameter to the calling method is not smaller than 0.

Parameters:
value - a number
name - name of the number reference (in source code)
Returns:
the non-null reference that was validated
Throws:
IllegalNullArgumentException - if the given argument reference is smaller than 0

notNegative

public static int notNegative(@Nonnull
                              int value)
Ensures that an integer reference passed as a parameter to the calling method is not smaller than 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.

Parameters:
value - a number
Returns:
the non-null reference that was validated
Throws:
IllegalNegativeArgumentException - if the given argument reference is smaller than 0

notNegative

public static int notNegative(@Nonnull
                              int value,
                              @Nullable
                              String name)
Ensures that an integer reference passed as a parameter to the calling method is not smaller than 0.

Parameters:
value - a number
name - name of the number reference (in source code)
Returns:
the non-null reference that was validated
Throws:
IllegalNullArgumentException - if the given argument reference is smaller than 0

notNegative

public static long notNegative(@Nonnull
                               long value)
Ensures that an long reference passed as a parameter to the calling method is not smaller than 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.

Parameters:
value - a number
Returns:
the non-null reference that was validated
Throws:
IllegalNegativeArgumentException - if the given argument reference is smaller than 0

notNegative

public static long notNegative(@Nonnull
                               long value,
                               @Nullable
                               String name)
Ensures that an long reference passed as a parameter to the calling method is not smaller than 0.

Parameters:
value - a number
name - name of the number reference (in source code)
Returns:
the non-null reference that was validated
Throws:
IllegalNullArgumentException - if the given argument reference is smaller than 0

notNegative

public static short notNegative(@Nonnull
                                short value)
Ensures that an short reference passed as a parameter to the calling method is not smaller than 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.

Parameters:
value - a number
Returns:
the non-null reference that was validated
Throws:
IllegalNegativeArgumentException - if the given argument reference is smaller than 0

notNegative

public static short notNegative(@Nonnull
                                short value,
                                @Nullable
                                String name)
Ensures that an short reference passed as a parameter to the calling method is not smaller than 0.

Parameters:
value - a number
name - name of the number reference (in source code)
Returns:
the non-null reference that was validated
Throws:
IllegalNullArgumentException - if the given argument reference is smaller than 0

notNull

public static <T> T notNull(@Nonnull
                            T reference)
Ensures that an object reference passed as a parameter to the calling method is not 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.

Parameters:
reference - an object reference
Returns:
the non-null reference that was validated
Throws:
IllegalNullArgumentException - if the given argument reference is null

notNull

public static <T> T notNull(@Nonnull
                            T reference,
                            @Nullable
                            String name)
Ensures that an object reference passed as a parameter to the calling method is not null.

Parameters:
reference - an object reference
name - name of object reference (in source code)
Returns:
the non-null reference that was validated
Throws:
IllegalNullArgumentException - if the given argument reference is null

notPositive

public static double notPositive(@Nonnull
                                 double value)
Ensures that an double reference passed as a parameter to the calling method is not greater than 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.

Parameters:
value - a number
Returns:
the non-null reference that was validated
Throws:
IllegalPositiveArgumentException - if the given argument reference is smaller than 0

notPositive

public static double notPositive(@Nonnull
                                 double value,
                                 @Nullable
                                 String name)
Ensures that an double reference passed as a parameter to the calling method is not greater than 0.

Parameters:
value - a number
name - name of the number reference (in source code)
Returns:
the non-null reference that was validated
Throws:
IllegalNullArgumentException - if the given argument reference is smaller than 0

notPositive

public static float notPositive(@Nonnull
                                float value)
Ensures that an float reference passed as a parameter to the calling method is not greater than 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.

Parameters:
value - a number
Returns:
the non-null reference that was validated
Throws:
IllegalPositiveArgumentException - if the given argument reference is smaller than 0

notPositive

public static float notPositive(@Nonnull
                                float value,
                                @Nullable
                                String name)
Ensures that an float reference passed as a parameter to the calling method is not greater than 0.

Parameters:
value - a number
name - name of the number reference (in source code)
Returns:
the non-null reference that was validated
Throws:
IllegalNullArgumentException - if the given argument reference is smaller than 0

notPositive

public static int notPositive(@Nonnull
                              int value)
Ensures that an integer reference passed as a parameter to the calling method is not greater than 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.

Parameters:
value - a number
Returns:
the non-null reference that was validated
Throws:
IllegalPositiveArgumentException - if the given argument reference is smaller than 0

notPositive

public static int notPositive(@Nonnull
                              int value,
                              @Nullable
                              String name)
Ensures that an integer reference passed as a parameter to the calling method is not greater than 0.

Parameters:
value - a number
name - name of the number reference (in source code)
Returns:
the non-null reference that was validated
Throws:
IllegalNullArgumentException - if the given argument reference is smaller than 0

notPositive

public static long notPositive(@Nonnull
                               long value)
Ensures that an long reference passed as a parameter to the calling method is not greater than 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.

Parameters:
value - a number
Returns:
the non-null reference that was validated
Throws:
IllegalPositiveArgumentException - if the given argument reference is smaller than 0

notPositive

public static long notPositive(@Nonnull
                               long value,
                               @Nullable
                               String name)
Ensures that an long reference passed as a parameter to the calling method is not greater than 0.

Parameters:
value - a number
name - name of the number reference (in source code)
Returns:
the non-null reference that was validated
Throws:
IllegalNullArgumentException - if the given argument reference is smaller than 0

notPositive

public static short notPositive(@Nonnull
                                short value)
Ensures that an short reference passed as a parameter to the calling method is not greater than 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.

Parameters:
value - a number
Returns:
the non-null reference that was validated
Throws:
IllegalPositiveArgumentException - if the given argument reference is smaller than 0

notPositive

public static short notPositive(@Nonnull
                                short value,
                                @Nullable
                                String name)
Ensures that an short reference passed as a parameter to the calling method is not greater than 0.

Parameters:
value - a number
name - name of the number reference (in source code)
Returns:
the non-null reference that was validated
Throws:
IllegalNullArgumentException - if the given argument reference is smaller than 0

positionIndex

public static int positionIndex(int index,
                                int size)
Ensures that a given position index is valid within the size of an array, list or string ...

Parameters:
index - index of an array, list or string
size - size of an array list or string
Returns:
the index
Throws:
IllegalPositionIndexException - if the index is not a valid position index within an array, list or string of size size

range

public static void range(@Nonnegative
                         int start,
                         @Nonnegative
                         int end,
                         @Nonnegative
                         int size)
Ensures that the given arguments are a valid range. A range (start, end, size) is valid if the following conditions are true:

Parameters:
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)
Throws:
IllegalRangeException - if the given arguments do not form a valid range

stateIsTrue

public static void stateIsTrue(boolean expression)
Ensures that a given state is 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.

Parameters:
expression - an expression that must be true to indicate a valid state
Throws:
IllegalStateOfArgumentException - if the given arguments caused an invalid state

stateIsTrue

public 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.

Parameters:
expression - an expression that must be true to indicate a valid state
clazz - an subclass of RuntimeException which will be thrown if the given state is not valid
Throws:
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 instantiated

stateIsTrue

public static void stateIsTrue(boolean expression,
                               @Nonnull
                               String description)
Ensures that a given state is true.

Parameters:
expression - an expression that must be true to indicate a valid state
description - will be used in the error message to describe why the arguments caused an invalid state
Throws:
IllegalStateOfArgumentException - if the given arguments caused an invalid state

stateIsTrue

public static void stateIsTrue(boolean expression,
                               @Nonnull
                               String descriptionTemplate,
                               Object... descriptionTemplateArgs)
Ensures that a given state is true

Parameters:
expression - an expression that must be true to indicate a valid state
descriptionTemplate - format string template that explains why the state is invalid
descriptionTemplateArgs - format string template arguments to explain why the state is invalid
Throws:
IllegalStateOfArgumentException - if the given arguments caused an invalid state


Copyright © 2012-2013. All Rights Reserved.