Package net.apartium.cocoabeans
Class Ensures
java.lang.Object
net.apartium.cocoabeans.Ensures
Helper class used to validate conditions
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidisFalse(boolean bool) Makes sure given condition is falsestatic voidisFalse(boolean bool, RuntimeException ex) Makes sure given condition is falsestatic voidMakes sure given condition is falsestatic voidisTrue(boolean bool) Makes sure given condition is truestatic voidisTrue(boolean bool, RuntimeException ex) Makes sure given condition is truestatic voidMakes sure given condition is truestatic voidlargerThan(int num1, int num2, RuntimeException ex) Makes sure given number is larger than second given number.static voidlargerThan(int num1, int num2, String message) Makes sure given number is larger than second given number.static voidnotEmpty(Object[] array, RuntimeException ex) Make sure that given array is not null or emptystatic voidMakes sure that given array is not null or emptystatic voidnotEmpty(String string, RuntimeException ex) Validates if a String is empty or notstatic voidMakes sure given string is not null or emptystatic voidnotEmpty(Collection<?> collection, RuntimeException ex) Makes sure that given collection is not null or emptystatic voidnotEmpty(Collection<?> collection, String message) Makes sure that given collection is not null or emptystatic voidnotEmpty(Map<?, ?> map, RuntimeException ex) Makes sure that given map is not null or emptystatic voidMakes sure that given map is not null or emptystatic voidnotNull(Object obj, RuntimeException ex) Checks if an object is null.static voidMake sure an object is not null.
-
Constructor Details
-
Ensures
public Ensures()
-
-
Method Details
-
notEmpty
Validates if a String is empty or not- Parameters:
string- the String instance to perform the validation onex- the exception to throw if the String is empty- Throws:
RuntimeException- ex if argument does not match requested precondition
-
notNull
Checks if an object is null.- Parameters:
obj- the object instance to checkex- the exception to throw if the object is null, if null will be replaced by npe- Throws:
RuntimeException- ex if argument does not match requested precondition
-
notEmpty
Makes sure that given collection is not null or empty- Parameters:
collection- the collection to checkex- the exception to throw if the object does not match requested precondition- Throws:
RuntimeException- ex if argument does not match requested precondition
-
notEmpty
Makes sure that given collection is not null or empty- Parameters:
collection- the collection to checkmessage- the message, "+-" will be replaced to "cannot be null or empty"- Throws:
RuntimeException- ex if argument does not match requested precondition
-
notEmpty
Makes sure that given map is not null or empty- Parameters:
map- the map to checkex- the exception to throw if the object does not match requested precondition- Throws:
RuntimeException- ex if argument does not match requested precondition
-
notEmpty
Makes sure that given map is not null or empty- Parameters:
map- the map object to checkmessage- the message, "+-" will be replaced to "cannot be null or empty"- Throws:
RuntimeException- if argument does not match requested precondition
-
notEmpty
Make sure that given array is not null or empty- Parameters:
array- the array to checkex- the exception to throw if the object is invalid- Throws:
RuntimeException- ex if argument does not match requested precondition
-
notEmpty
Makes sure that given array is not null or empty- Parameters:
array- the array to checkmessage- the message, "+-" will be replaced to "cannot be null or empty"- Throws:
RuntimeException- ex if argument does not match requested precondition
-
notNull
Make sure an object is not null.- Parameters:
obj- the object to checkmessage- the message to throw with the exception if the object is null, +- will be replaced with "cannot be null"- Throws:
NullPointerException- ex if argument does not match requested precondition
-
notEmpty
Makes sure given string is not null or empty- Parameters:
string- the String instance to validate onmessage- the message to throw with the exception if the String is empty, "+-" will be replaced to "cannot be null or empty"- Throws:
RuntimeException- if argument does not match requested precondition
-
largerThan
Makes sure given number is larger than second given number.- Parameters:
num1- the first numbernum2- the second numberex- the exception to throw if not larger than- Throws:
RuntimeException- if argument does not match requested precondition
-
largerThan
Makes sure given number is larger than second given number.- Parameters:
num1- the first numbernum2- the second numbermessage- the message, "+-" will be replaced to "must be larger than"- Throws:
RuntimeException- if argument does not match requested precondition
-
isTrue
public static void isTrue(boolean bool) Makes sure given condition is true- Parameters:
bool- the condition- Throws:
RuntimeException- if argument does not match requested precondition
-
isTrue
Makes sure given condition is true- Parameters:
bool- the conditionmessage- the message to send with the exception, "+-" will be replaced with "must be true"- Throws:
RuntimeException- if argument does not match requested precondition
-
isTrue
Makes sure given condition is true- Parameters:
bool- the conditionex- the exception to throw if the boolean is false- Throws:
RuntimeException- ex if argument does not match requested precondition
-
isFalse
Makes sure given condition is false- Parameters:
bool- the conditionex- the exception to throw if the boolean is true- Throws:
RuntimeException- ex if argument does not match requested precondition
-
isFalse
@AvailableSince("0.0.40") public static void isFalse(boolean bool) Makes sure given condition is false- Parameters:
bool- the condition- Throws:
RuntimeException- if argument does not match requested precondition
-
isFalse
Makes sure given condition is false- Parameters:
bool- the conditionmessage- the message to send with the exception, "+-" will be replaced with "must be false"- Throws:
RuntimeException- if argument does not match requested precondition
-