public final class ValidationUtils extends Object
Modifier and Type | Method and Description |
---|---|
static void |
assertAllAreNull(String messageIfNull,
Object... objects)
Asserts that all of the objects are null.
|
static int |
assertIsPositive(int num,
String fieldName)
Asserts that the given number is positive (non-negative and non-zero).
|
static <T> T[] |
assertNotEmpty(T[] array,
String fieldName)
Asserts that the given array is not empty (non-null and non-empty).
|
static <T extends Collection<?>> |
assertNotEmpty(T collection,
String fieldName)
Asserts that the given collection is not empty (non-null and non-empty).
|
static <T> T |
assertNotNull(T object,
String fieldName)
Asserts that the given object is non-null and returns it.
|
static String |
assertStringNotEmpty(String string,
String fieldName)
Asserts that the given string is not empty (non-null and non-empty).
|
public static <T> T assertNotNull(T object, String fieldName) throws IllegalArgumentException
T
- type to evaluateobject
- Object to assert onfieldName
- Field name to display in exception message if nullIllegalArgumentException
- If object was nullpublic static void assertAllAreNull(String messageIfNull, Object... objects) throws IllegalArgumentException
messageIfNull
- exception message to return if nullobjects
- objects to evaluateIllegalArgumentException
- if any object provided was NOT null.public static int assertIsPositive(int num, String fieldName)
num
- Number to validatefieldName
- Field name to display in exception message if not positive.public static <T extends Collection<?>> T assertNotEmpty(T collection, String fieldName) throws IllegalArgumentException
T
- type of elements in given collection.collection
- collection to validate.fieldName
- field name to display in exception message if empty.IllegalArgumentException
- if the collection provided was empty.public static <T> T[] assertNotEmpty(T[] array, String fieldName) throws IllegalArgumentException
T
- type of elements in given array.array
- array to validate.fieldName
- field name to display in exception message if empty.IllegalArgumentException
- if the array provided was empty.public static String assertStringNotEmpty(String string, String fieldName) throws IllegalArgumentException
string
- string to validate.fieldName
- field name to display in exception message if empty.IllegalArgumentException
- if the string provided was empty.Copyright © 2023. All rights reserved.