Package com.cedarsoftware.util
Class Convention
java.lang.Object
com.cedarsoftware.util.Convention
Utility class containing common defensive programming helpers.
Convention offers a set of static convenience methods for
validating method arguments such as null checks or ensuring that a
string is not empty. The class is not intended to be instantiated.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidthrowIfClassNotFound(String fullyQualifiedClassName, ClassLoader loader) Verify that the supplied class can be loaded.static voidthrowIfFalse(boolean logic, String message) Throws an exception if the logic is false.static <K,V> void throwIfKeyExists(Map<K, V> map, K key, String message) static voidthrowIfNull(Object value, String message) Throws an exception if nullstatic voidthrowIfNullOrEmpty(String value, String message) Throws an exception if null or empty
-
Method Details
-
throwIfNull
Throws an exception if null- Parameters:
value- object to check if nullmessage- message to use when thrown- Throws:
IllegalArgumentException- if the string passed in is null or empty
-
throwIfNullOrEmpty
Throws an exception if null or empty- Parameters:
value- string to checkmessage- message to use when thrown- Throws:
IllegalArgumentException- if the string passed in is null or empty
-
throwIfClassNotFound
Verify that the supplied class can be loaded.- Parameters:
fullyQualifiedClassName- fully qualified name of the class to look uploader- theClassLoaderused to locate the class- Throws:
IllegalArgumentException- if the class cannot be resolved
-
throwIfKeyExists
-
throwIfFalse
Throws an exception if the logic is false.- Parameters:
logic- test to see if we need to throw the exception.message- to include in the exception explaining why the the assertion failed
-