importjava.util.Collection;/**
* @author yue.wu
* @description TODO
* @date 2022/10/25 15:59
*/publicclassValidationUtils{publicValidationUtils(){}/**
* Asserts that the given object is non-null and returns it.
*
* @param object Object to assert on
* @param fieldName Field name to display in exception message if null
* @return Object if non null
* @throws IllegalArgumentException If object was null
*/publicstatic<T>TassertNotNull(T object,String fieldName)throwsIllegalArgumentException{if(object ==null){thrownewIllegalArgumentException(String.format("%s cannot be null", fieldName));}return object;}/**
* Asserts that all of the objects are null.
*
* @throws IllegalArgumentException if any object provided was NOT null.
*/publicstaticvoidassertAllAreNull(String messageIfNull,Object... objects)throwsIllegalArgumentException{for(Object object : objects){if(object !=null){thrownewIllegalArgumentException(messageIfNull);}}}/**
* Asserts that all of the objects are null.
*
* @throws IllegalArgumentException if any object provided was NOT null.
*/publicstaticvoidassertAllNotNull(String messageIfNull,Object... objects)throwsIllegalArgumentException{for(Object object : objects){if(object ==null){thrownewIllegalArgumentException(messageIfNull);}}}/**
* Asserts that the given number is positive (non-negative and non-zero).
*
* @param num Number to validate
* @param fieldName Field name to display in exception message if not positive.
* @return Number if positive.
*/publicstaticintassertIsPositive(int num,String fieldName){if(num <=0){thrownewIllegalArgumentException(String.format("%s must be positive", fieldName));}return num;}publicstatic<TextendsCollection<?>>TassertNotEmpty(T collection,String fieldName)throwsIllegalArgumentException{assertNotNull(collection, fieldName);if(collection.isEmpty()){thrownewIllegalArgumentException(String.format("%s cannot be empty", fieldName));}return collection;}publicstatic<T>T[]assertNotEmpty(T[] array,String fieldName)throwsIllegalArgumentException{assertNotNull(array, fieldName);if(array.length ==0){thrownewIllegalArgumentException(String.format("%s cannot be empty", fieldName));}return array;}publicstaticStringassertStringNotEmpty(String string,String fieldName)throwsIllegalArgumentException{assertNotNull(string, fieldName);if(string.isEmpty()){thrownewIllegalArgumentException(String.format("%s cannot be empty", fieldName));}return string;}}