package org.springframework.util;import java.util.Collection;import java.util.Map;publicabstractclassAssert{publicstaticvoidstate(boolean expression, String message){if(!expression){thrownewIllegalStateException(message);}}/**
* @deprecated as of 4.3.7, in favor of {@link #state(boolean, String)}
*/@Deprecatedpublicstaticvoidstate(boolean expression){state(expression,"[Assertion failed] - this state invariant must be true");}publicstaticvoidisTrue(boolean expression, String message){if(!expression){thrownewIllegalArgumentException(message);}}/**
* @deprecated as of 4.3.7, in favor of {@link #isTrue(boolean, String)}
*/@DeprecatedpublicstaticvoidisTrue(boolean expression){isTrue(expression,"[Assertion failed] - this expression must be true");}publicstaticvoidisNull(Object object, String message){if(object != null){thrownewIllegalArgumentException(message);}}/**
* @deprecated as of 4.3.7, in favor of {@link #isNull(Object, String)}
*/@DeprecatedpublicstaticvoidisNull(Object object){isNull(object,"[Assertion failed] - the object argument must be null");}publicstaticvoidnotNull(Object object, String message){if(object == null){thrownewIllegalArgumentException(message);}}/**
* @deprecated as of 4.3.7, in favor of {@link #notNull(Object, String)}
*/@DeprecatedpublicstaticvoidnotNull(Object object){notNull(object,"[Assertion failed] - this argument is required; it must not be null");}publicstaticvoidhasLength(String text, String message){if(!StringUtils.hasLength(text)){thrownewIllegalArgumentException(message);}}/**
* @deprecated as of 4.3.7, in favor of {@link #hasLength(String, String)}
*/@DeprecatedpublicstaticvoidhasLength(String text){hasLength(text,"[Assertion failed] - this String argument must have length; it must not be null or empty");}publicstaticvoidhasText(String text, String message){if(!StringUtils.hasText(text)){thrownewIllegalArgumentException(message);}}/**
* @deprecated as of 4.3.7, in favor of {@link #hasText(String, String)}
*/@DeprecatedpublicstaticvoidhasText(String text){hasText(text,"[Assertion failed] - this String argument must have text; it must not be null, empty, or blank");}publicstaticvoiddoesNotContain(String textToSearch, String substring, String message){if(StringUtils.hasLength(textToSearch)&& StringUtils.hasLength(substring)&&
textToSearch.contains(substring)){thrownewIllegalArgumentException(message);}}/**
* @deprecated as of 4.3.7, in favor of {@link #doesNotContain(String, String, String)}
*/@DeprecatedpublicstaticvoiddoesNotContain(String textToSearch, String substring){doesNotContain(textToSearch, substring,"[Assertion failed] - this String argument must not contain the substring ["+ substring +"]");}publicstaticvoidnotEmpty(Object[] array, String message){if(ObjectUtils.isEmpty(array)){thrownewIllegalArgumentException(message);}}/**
* @deprecated as of 4.3.7, in favor of {@link #notEmpty(Object[], String)}
*/@DeprecatedpublicstaticvoidnotEmpty(Object[] array){notEmpty(array,"[Assertion failed] - this array must not be empty: it must contain at least 1 element");}publicstaticvoidnoNullElements(Object[] array, String message){if(array != null){for(Object element : array){if(element == null){thrownewIllegalArgumentException(message);}}}}/**
* @deprecated as of 4.3.7, in favor of {@link #noNullElements(Object[], String)}
*/@DeprecatedpublicstaticvoidnoNullElements(Object[] array){noNullElements(array,"[Assertion failed] - this array must not contain any null elements");}publicstaticvoidnotEmpty(Collection<?> collection, String message){if(CollectionUtils.isEmpty(collection)){thrownewIllegalArgumentException(message);}}/**
* @deprecated as of 4.3.7, in favor of {@link #notEmpty(Collection, String)}
*/@DeprecatedpublicstaticvoidnotEmpty(Collection<?> collection){notEmpty(collection,"[Assertion failed] - this collection must not be empty: it must contain at least 1 element");}publicstaticvoidnotEmpty(Map<?,?> map, String message){if(CollectionUtils.isEmpty(map)){thrownewIllegalArgumentException(message);}}/**
* @deprecated as of 4.3.7, in favor of {@link #notEmpty(Map, String)}
*/@DeprecatedpublicstaticvoidnotEmpty(Map<?,?> map){notEmpty(map,"[Assertion failed] - this map must not be empty; it must contain at least one entry");}publicstaticvoidisInstanceOf(Class<?> type, Object obj, String message){notNull(type,"Type to check against must not be null");if(!type.isInstance(obj)){instanceCheckFailed(type, obj, message);}}publicstaticvoidisInstanceOf(Class<?> type, Object obj){isInstanceOf(type, obj,"");}publicstaticvoidisAssignable(Class<?> superType, Class<?> subType, String message){notNull(superType,"Super type to check against must not be null");if(subType == null ||!superType.isAssignableFrom(subType)){assignableCheckFailed(superType, subType, message);}}publicstaticvoidisAssignable(Class<?> superType, Class<?> subType){isAssignable(superType, subType,"");}privatestaticvoidinstanceCheckFailed(Class<?> type, Object obj, String msg){
String className =(obj != null ? obj.getClass().getName():"null");
String result ="";boolean defaultMessage =true;if(StringUtils.hasLength(msg)){if(endsWithSeparator(msg)){
result = msg +" ";}else{
result =messageWithTypeName(msg, className);
defaultMessage =false;}}if(defaultMessage){
result = result +("Object of class ["+ className +"] must be an instance of "+ type);}thrownewIllegalArgumentException(result);}privatestaticvoidassignableCheckFailed(Class<?> superType, Class<?> subType, String msg){
String result ="";boolean defaultMessage =true;if(StringUtils.hasLength(msg)){if(endsWithSeparator(msg)){
result = msg +" ";}else{
result =messageWithTypeName(msg, subType);
defaultMessage =false;}}if(defaultMessage){
result = result +(subType +" is not assignable to "+ superType);}thrownewIllegalArgumentException(result);}privatestaticbooleanendsWithSeparator(String msg){return(msg.endsWith(":")|| msg.endsWith(";")|| msg.endsWith(",")|| msg.endsWith("."));}privatestatic String messageWithTypeName(String msg, Object typeName){return msg +(msg.endsWith(" ")?"":": ")+ typeName;}}