public class ValidatableUtil extends Object
Constructor and Description |
---|
ValidatableUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
endValidateDisabled()
End a nestable block where validation is disabled
|
static void |
requireNonNull(Object tested,
String name)
requires that a reference not be null, or throw an InvalidMarshallableException with an appropriate message
|
static void |
requireTrue(boolean test,
String msg)
requires a test flag be true, otherwise throw an InvalidMarshallableException with the message provided
|
static void |
startValidateDisabled()
Starts a nestable block where validation is disabled.
|
static <T> T |
validate(T t)
Check an object is valid, if it is Validatable, do nothing
|
static boolean |
validateEnabled()
Checks if validation is enabled.
|
public static boolean validateEnabled()
true
if validation is enabled, false
otherwise.public static void startValidateDisabled()
public static void endValidateDisabled()
public static <T> T validate(T t) throws InvalidMarshallableException
For logging purposes validate() can be turned off e.g. for toString() with the following patten
ValidatableUtil.startValidatableDisabled(); try { // some code } finally { ValidatableUtil.endValidateDisabled(); }
T
- the original objectt
- to testInvalidMarshallableException
- if validate() method failspublic static void requireNonNull(Object tested, String name) throws InvalidMarshallableException
tested
- referencename
- of referenceInvalidMarshallableException
- if tested is nullpublic static void requireTrue(boolean test, String msg) throws InvalidMarshallableException
test
- to check for truemsg
- to use if falseInvalidMarshallableException
- to throw is falseCopyright © 2023. All rights reserved.