public final class Constraints extends Object
ValidationException exceptions.
Useful for identifying data integration errors early and clearly at runtime.
For example, if the contract of a public method states it does not
allow null arguments, Constraints can be used to validate that
contract. Doing this clearly indicates a contract violation when it
occurs and protects the class's invariants.
| Modifier and Type | Method and Description |
|---|---|
static void |
hasText(String text,
String message)
Assert that the given String has valid text content; that is, it must not
be
null and must contain at least one non-whitespace character. |
static void |
hasText(String text,
String message,
ErrorExtEnum errorCode)
Assert that the given String has valid text content; that is, it must not
be
null and must contain at least one non-whitespace character. |
static void |
isNull(Object object,
String message)
Assert that an object is
null. |
static void |
isNull(Object object,
String message,
ErrorExtEnum errorCode)
Assert that an object is
null. |
static void |
isTrue(Boolean expression,
String message)
Assert a boolean expression, throwing
IllegalArgumentException
if the test result is false. |
static void |
isTrue(Boolean expression,
String message,
ErrorExtEnum errorCode)
Assert a boolean expression, throwing
IllegalArgumentException
if the test result is false. |
static void |
notNull(Object object,
String message)
Assert that an object is not
null. |
static void |
notNull(Object object,
String message,
ErrorExtEnum errorCode)
Assert that an object is not
null. |
static void |
state(boolean expression,
String message)
Assert a boolean expression, throwing
IllegalStateException
if the test result is false. |
public static void hasText(String text, String message) throws IllegalDataException
null and must contain at least one non-whitespace character.text - the String to checkmessage - the exception message to use if the assertion failsIllegalDataException - occurs if text is null or does not contain nor non-whitespace
character.public static void hasText(String text, String message, ErrorExtEnum errorCode) throws IllegalDataException
null and must contain at least one non-whitespace character.text - the String to checkmessage - the exception message to use if the assertion failserrorCode - the internal error codeIllegalDataException - occurs if text is null or does not contain nor non-whitespace
character.public static void notNull(Object object, String message)
null.
Assert.notNull(clazz, "The class must not be null");
object - the object to checkmessage - the exception message to use if the assertion failsIllegalArgumentException - if the object is nullpublic static void notNull(Object object, String message, ErrorExtEnum errorCode)
null.
Assert.notNull(clazz, "The class must not be null");
object - the object to checkmessage - the exception message to use if the assertion failserrorCode - the internal error codeIllegalArgumentException - if the object is nullpublic static void isNull(Object object, String message)
null.
Assert.isNull(clazz, "The class must be null");
object - the object to checkmessage - the exception message to use if the assertion failsIllegalArgumentException - if the object is not nullpublic static void isNull(Object object, String message, ErrorExtEnum errorCode)
null.
Assert.isNull(clazz, "The class must be null");
object - the object to checkmessage - the exception message to use if the assertion failserrorCode - the internal error codeIllegalArgumentException - if the object is not nullpublic static void isTrue(Boolean expression, String message)
IllegalArgumentException
if the test result is false.expression - a boolean expressionmessage - the exception message to use if the assertion failsIllegalArgumentException - if expression is falsepublic static void isTrue(Boolean expression, String message, ErrorExtEnum errorCode)
IllegalArgumentException
if the test result is false.expression - a boolean expressionmessage - the exception message to use if the assertion failserrorCode - the internal error codeIllegalArgumentException - if expression is falsepublic static void state(boolean expression,
String message)
IllegalStateException
if the test result is false. Call isTrue if you wish to
throw IllegalArgumentException on an assertion failure.
Assert.state(id == null, "The id property must not already be initialized");
expression - a boolean expressionmessage - the exception message to use if the assertion failsIllegalStateException - if expression is falseCopyright © 2018 Pivotal Software, Inc.. All rights reserved.