一、前言
通过apache的commons-lang3(3.3.2)源码包中的org.apache.commons.lang3.reflect.FieldUtils属性工具类,对类及属性名称获取属性对象getField、类的所有属性数组对象getAllFields、获取属性序列集合getAllFieldsList及读取指定类对象、属性名称的对象readDeclaredStaticField等。
二、源码说明
1.FieldUtils
package org.apache.commons.lang3.reflect;@b@@b@import java.lang.reflect.Field;@b@import java.lang.reflect.Modifier;@b@import java.util.ArrayList;@b@import java.util.Iterator;@b@import java.util.List;@b@import org.apache.commons.lang3.ClassUtils;@b@import org.apache.commons.lang3.StringUtils;@b@import org.apache.commons.lang3.Validate;@b@@b@public class FieldUtils@b@{@b@ public static Field getField(Class<?> cls, String fieldName)@b@ {@b@ Field field = getField(cls, fieldName, false);@b@ MemberUtils.setAccessibleWorkaround(field);@b@ return field;@b@ }@b@@b@ public static Field getField(Class<?> cls, String fieldName, boolean forceAccess)@b@ {@b@ label76: Field match;@b@ Validate.isTrue((cls != null) ? 1 : false, "The class must not be null", new Object[0]);@b@ Validate.isTrue(StringUtils.isNotBlank(fieldName), "The field name must not be blank/empty", new Object[0]);@b@@b@ Class acls = cls; if (acls != null);@b@ try@b@ {@b@ Field field = acls.getDeclaredField(fieldName);@b@@b@ if (!(Modifier.isPublic(field.getModifiers())))@b@ if (forceAccess)@b@ field.setAccessible(true);@b@ else@b@ break label76:@b@@b@@b@ return field;@b@ }@b@ catch (NoSuchFieldException i$)@b@ {@b@ while (true) {@b@ acls = acls.getSuperclass();@b@ }@b@@b@ match = null;@b@ Iterator i$ = ClassUtils.getAllInterfaces(cls).iterator(); if (!(i$.hasNext())) break label164; Class class1 = (Class)i$.next();@b@ try {@b@ Field test = class1.getField(fieldName);@b@ Validate.isTrue((match == null) ? 1 : false, "Reference to field %s is ambiguous relative to %s; a matching field exists on two or more implemented interfaces.", new Object[] { fieldName, cls });@b@@b@ match = test;@b@ }@b@ catch (NoSuchFieldException ex) {@b@ }@b@ }@b@ label164: return match;@b@ }@b@@b@ public static Field getDeclaredField(Class<?> cls, String fieldName)@b@ {@b@ return getDeclaredField(cls, fieldName, false);@b@ }@b@@b@ public static Field getDeclaredField(Class<?> cls, String fieldName, boolean forceAccess)@b@ {@b@ Validate.isTrue((cls != null) ? 1 : false, "The class must not be null", new Object[0]);@b@ Validate.isTrue(StringUtils.isNotBlank(fieldName), "The field name must not be blank/empty", new Object[0]);@b@ try@b@ {@b@ Field field = cls.getDeclaredField(fieldName);@b@ if (!(MemberUtils.isAccessible(field)))@b@ if (forceAccess)@b@ field.setAccessible(true);@b@ else@b@ return null;@b@@b@@b@ return field;@b@ }@b@ catch (NoSuchFieldException e) {@b@ }@b@ return null;@b@ }@b@@b@ public static Field[] getAllFields(Class<?> cls)@b@ {@b@ List allFieldsList = getAllFieldsList(cls);@b@ return ((Field[])allFieldsList.toArray(new Field[allFieldsList.size()]));@b@ }@b@@b@ public static List<Field> getAllFieldsList(Class<?> cls)@b@ {@b@ Validate.isTrue((cls != null) ? 1 : false, "The class must not be null", new Object[0]);@b@ List allFields = new ArrayList();@b@ Class currentClass = cls;@b@ while (currentClass != null) {@b@ Field[] declaredFields = currentClass.getDeclaredFields();@b@ Field[] arr$ = declaredFields; int len$ = arr$.length; for (int i$ = 0; i$ < len$; ++i$) { Field field = arr$[i$];@b@ allFields.add(field);@b@ }@b@ currentClass = currentClass.getSuperclass();@b@ }@b@ return allFields;@b@ }@b@@b@ public static Object readStaticField(Field field)@b@ throws IllegalAccessException@b@ {@b@ return readStaticField(field, false);@b@ }@b@@b@ public static Object readStaticField(Field field, boolean forceAccess)@b@ throws IllegalAccessException@b@ {@b@ Validate.isTrue((field != null) ? 1 : false, "The field must not be null", new Object[0]);@b@ Validate.isTrue(Modifier.isStatic(field.getModifiers()), "The field '%s' is not static", new Object[] { field.getName() });@b@ return readField(field, (Object)null, forceAccess);@b@ }@b@@b@ public static Object readStaticField(Class<?> cls, String fieldName)@b@ throws IllegalAccessException@b@ {@b@ return readStaticField(cls, fieldName, false);@b@ }@b@@b@ public static Object readStaticField(Class<?> cls, String fieldName, boolean forceAccess)@b@ throws IllegalAccessException@b@ {@b@ Field field = getField(cls, fieldName, forceAccess);@b@ Validate.isTrue((field != null) ? 1 : false, "Cannot locate field '%s' on %s", new Object[] { fieldName, cls });@b@@b@ return readStaticField(field, false);@b@ }@b@@b@ public static Object readDeclaredStaticField(Class<?> cls, String fieldName)@b@ throws IllegalAccessException@b@ {@b@ return readDeclaredStaticField(cls, fieldName, false);@b@ }@b@@b@ public static Object readDeclaredStaticField(Class<?> cls, String fieldName, boolean forceAccess)@b@ throws IllegalAccessException@b@ {@b@ Field field = getDeclaredField(cls, fieldName, forceAccess);@b@ Validate.isTrue((field != null) ? 1 : false, "Cannot locate declared field %s.%s", new Object[] { cls.getName(), fieldName });@b@@b@ return readStaticField(field, false);@b@ }@b@@b@ public static Object readField(Field field, Object target)@b@ throws IllegalAccessException@b@ {@b@ return readField(field, target, false);@b@ }@b@@b@ public static Object readField(Field field, Object target, boolean forceAccess)@b@ throws IllegalAccessException@b@ {@b@ Validate.isTrue((field != null) ? 1 : false, "The field must not be null", new Object[0]);@b@ if ((forceAccess) && (!(field.isAccessible())))@b@ field.setAccessible(true);@b@ else@b@ MemberUtils.setAccessibleWorkaround(field);@b@@b@ return field.get(target);@b@ }@b@@b@ public static Object readField(Object target, String fieldName)@b@ throws IllegalAccessException@b@ {@b@ return readField(target, fieldName, false);@b@ }@b@@b@ public static Object readField(Object target, String fieldName, boolean forceAccess)@b@ throws IllegalAccessException@b@ {@b@ Validate.isTrue((target != null) ? 1 : false, "target object must not be null", new Object[0]);@b@ Class cls = target.getClass();@b@ Field field = getField(cls, fieldName, forceAccess);@b@ Validate.isTrue((field != null) ? 1 : false, "Cannot locate field %s on %s", new Object[] { fieldName, cls });@b@@b@ return readField(field, target, false);@b@ }@b@@b@ public static Object readDeclaredField(Object target, String fieldName)@b@ throws IllegalAccessException@b@ {@b@ return readDeclaredField(target, fieldName, false);@b@ }@b@@b@ public static Object readDeclaredField(Object target, String fieldName, boolean forceAccess)@b@ throws IllegalAccessException@b@ {@b@ Validate.isTrue((target != null) ? 1 : false, "target object must not be null", new Object[0]);@b@ Class cls = target.getClass();@b@ Field field = getDeclaredField(cls, fieldName, forceAccess);@b@ Validate.isTrue((field != null) ? 1 : false, "Cannot locate declared field %s.%s", new Object[] { cls, fieldName });@b@@b@ return readField(field, target, false);@b@ }@b@@b@ public static void writeStaticField(Field field, Object value)@b@ throws IllegalAccessException@b@ {@b@ writeStaticField(field, value, false);@b@ }@b@@b@ public static void writeStaticField(Field field, Object value, boolean forceAccess)@b@ throws IllegalAccessException@b@ {@b@ Validate.isTrue((field != null) ? 1 : false, "The field must not be null", new Object[0]);@b@ Validate.isTrue(Modifier.isStatic(field.getModifiers()), "The field %s.%s is not static", new Object[] { field.getDeclaringClass().getName(), field.getName() });@b@@b@ writeField(field, (Object)null, value, forceAccess);@b@ }@b@@b@ public static void writeStaticField(Class<?> cls, String fieldName, Object value)@b@ throws IllegalAccessException@b@ {@b@ writeStaticField(cls, fieldName, value, false);@b@ }@b@@b@ public static void writeStaticField(Class<?> cls, String fieldName, Object value, boolean forceAccess)@b@ throws IllegalAccessException@b@ {@b@ Field field = getField(cls, fieldName, forceAccess);@b@ Validate.isTrue((field != null) ? 1 : false, "Cannot locate field %s on %s", new Object[] { fieldName, cls });@b@@b@ writeStaticField(field, value, false);@b@ }@b@@b@ public static void writeDeclaredStaticField(Class<?> cls, String fieldName, Object value)@b@ throws IllegalAccessException@b@ {@b@ writeDeclaredStaticField(cls, fieldName, value, false);@b@ }@b@@b@ public static void writeDeclaredStaticField(Class<?> cls, String fieldName, Object value, boolean forceAccess)@b@ throws IllegalAccessException@b@ {@b@ Field field = getDeclaredField(cls, fieldName, forceAccess);@b@ Validate.isTrue((field != null) ? 1 : false, "Cannot locate declared field %s.%s", new Object[] { cls.getName(), fieldName });@b@@b@ writeField(field, (Object)null, value, false);@b@ }@b@@b@ public static void writeField(Field field, Object target, Object value)@b@ throws IllegalAccessException@b@ {@b@ writeField(field, target, value, false);@b@ }@b@@b@ public static void writeField(Field field, Object target, Object value, boolean forceAccess)@b@ throws IllegalAccessException@b@ {@b@ Validate.isTrue((field != null) ? 1 : false, "The field must not be null", new Object[0]);@b@ if ((forceAccess) && (!(field.isAccessible())))@b@ field.setAccessible(true);@b@ else@b@ MemberUtils.setAccessibleWorkaround(field);@b@@b@ field.set(target, value);@b@ }@b@@b@ public static void removeFinalModifier(Field field)@b@ {@b@ removeFinalModifier(field, true);@b@ }@b@@b@ public static void removeFinalModifier(Field field, boolean forceAccess)@b@ {@b@ Validate.isTrue((field != null) ? 1 : false, "The field must not be null", new Object[0]);@b@ try@b@ {@b@ if (Modifier.isFinal(field.getModifiers()))@b@ {@b@ Field modifiersField = Field.class.getDeclaredField("modifiers");@b@ boolean doForceAccess = (forceAccess) && (!(modifiersField.isAccessible()));@b@ if (doForceAccess)@b@ modifiersField.setAccessible(true);@b@ try@b@ {@b@ modifiersField.setInt(field, field.getModifiers() & 0xFFFFFFEF);@b@ } finally {@b@ if (doForceAccess)@b@ modifiersField.setAccessible(false);@b@ }@b@ }@b@ }@b@ catch (NoSuchFieldException ignored)@b@ {@b@ }@b@ catch (IllegalAccessException ignored)@b@ {@b@ }@b@ }@b@@b@ public static void writeField(Object target, String fieldName, Object value)@b@ throws IllegalAccessException@b@ {@b@ writeField(target, fieldName, value, false);@b@ }@b@@b@ public static void writeField(Object target, String fieldName, Object value, boolean forceAccess)@b@ throws IllegalAccessException@b@ {@b@ Validate.isTrue((target != null) ? 1 : false, "target object must not be null", new Object[0]);@b@ Class cls = target.getClass();@b@ Field field = getField(cls, fieldName, forceAccess);@b@ Validate.isTrue((field != null) ? 1 : false, "Cannot locate declared field %s.%s", new Object[] { cls.getName(), fieldName });@b@@b@ writeField(field, target, value, false);@b@ }@b@@b@ public static void writeDeclaredField(Object target, String fieldName, Object value)@b@ throws IllegalAccessException@b@ {@b@ writeDeclaredField(target, fieldName, value, false);@b@ }@b@@b@ public static void writeDeclaredField(Object target, String fieldName, Object value, boolean forceAccess)@b@ throws IllegalAccessException@b@ {@b@ Validate.isTrue((target != null) ? 1 : false, "target object must not be null", new Object[0]);@b@ Class cls = target.getClass();@b@ Field field = getDeclaredField(cls, fieldName, forceAccess);@b@ Validate.isTrue((field != null) ? 1 : false, "Cannot locate declared field %s.%s", new Object[] { cls.getName(), fieldName });@b@@b@ writeField(field, target, value, false);@b@ }@b@}
2.依赖工具类ClassUtils、StringUtils及Validate
package org.apache.commons.lang3;@b@@b@import java.lang.reflect.Method;@b@import java.lang.reflect.Modifier;@b@import java.util.ArrayList;@b@import java.util.Collections;@b@import java.util.HashMap;@b@import java.util.HashSet;@b@import java.util.Iterator;@b@import java.util.LinkedHashSet;@b@import java.util.List;@b@import java.util.Map;@b@import java.util.Map.Entry;@b@import java.util.Set;@b@import org.apache.commons.lang3.mutable.MutableObject;@b@@b@public class ClassUtils@b@{@b@ public static final char PACKAGE_SEPARATOR_CHAR = 46;@b@ public static final String PACKAGE_SEPARATOR = String.valueOf('.');@b@ public static final char INNER_CLASS_SEPARATOR_CHAR = 36;@b@ public static final String INNER_CLASS_SEPARATOR = String.valueOf('$');@b@ private static final Map<Class<?>, Class<?>> primitiveWrapperMap = new HashMap();@b@ private static final Map<Class<?>, Class<?>> wrapperPrimitiveMap;@b@ private static final Map<String, String> abbreviationMap;@b@ private static final Map<String, String> reverseAbbreviationMap;@b@@b@ public static String getShortClassName(Object object, String valueIfNull)@b@ {@b@ if (object == null)@b@ return valueIfNull;@b@@b@ return getShortClassName(object.getClass());@b@ }@b@@b@ public static String getShortClassName(Class<?> cls)@b@ {@b@ if (cls == null)@b@ return "";@b@@b@ return getShortClassName(cls.getName());@b@ }@b@@b@ public static String getShortClassName(String className)@b@ {@b@ if (StringUtils.isEmpty(className)) {@b@ return "";@b@ }@b@@b@ StringBuilder arrayPrefix = new StringBuilder();@b@@b@ if (className.startsWith("[")) {@b@ while (className.charAt(0) == '[') {@b@ className = className.substring(1);@b@ arrayPrefix.append("[]");@b@ }@b@@b@ if ((className.charAt(0) == 'L') && (className.charAt(className.length() - 1) == ';')) {@b@ className = className.substring(1, className.length() - 1);@b@ }@b@@b@ if (reverseAbbreviationMap.containsKey(className))@b@ className = (String)reverseAbbreviationMap.get(className);@b@@b@ }@b@@b@ int lastDotIdx = className.lastIndexOf(46);@b@ int innerIdx = className.indexOf(36, (lastDotIdx == -1) ? 0 : lastDotIdx + 1);@b@@b@ String out = className.substring(lastDotIdx + 1);@b@ if (innerIdx != -1)@b@ out = out.replace('$', '.');@b@@b@ return new StringBuilder().append(out).append(arrayPrefix).toString();@b@ }@b@@b@ public static String getSimpleName(Class<?> cls)@b@ {@b@ if (cls == null)@b@ return "";@b@@b@ return cls.getSimpleName();@b@ }@b@@b@ public static String getSimpleName(Object object, String valueIfNull)@b@ {@b@ if (object == null)@b@ return valueIfNull;@b@@b@ return getSimpleName(object.getClass());@b@ }@b@@b@ public static String getPackageName(Object object, String valueIfNull)@b@ {@b@ if (object == null)@b@ return valueIfNull;@b@@b@ return getPackageName(object.getClass());@b@ }@b@@b@ public static String getPackageName(Class<?> cls)@b@ {@b@ if (cls == null)@b@ return "";@b@@b@ return getPackageName(cls.getName());@b@ }@b@@b@ public static String getPackageName(String className)@b@ {@b@ if (StringUtils.isEmpty(className)) {@b@ return "";@b@ }@b@@b@ while (className.charAt(0) == '[') {@b@ className = className.substring(1);@b@ }@b@@b@ if ((className.charAt(0) == 'L') && (className.charAt(className.length() - 1) == ';')) {@b@ className = className.substring(1);@b@ }@b@@b@ int i = className.lastIndexOf(46);@b@ if (i == -1)@b@ return "";@b@@b@ return className.substring(0, i);@b@ }@b@@b@ public static List<Class<?>> getAllSuperclasses(Class<?> cls)@b@ {@b@ if (cls == null)@b@ return null;@b@@b@ List classes = new ArrayList();@b@ Class superclass = cls.getSuperclass();@b@ while (superclass != null) {@b@ classes.add(superclass);@b@ superclass = superclass.getSuperclass();@b@ }@b@ return classes;@b@ }@b@@b@ public static List<Class<?>> getAllInterfaces(Class<?> cls)@b@ {@b@ if (cls == null) {@b@ return null;@b@ }@b@@b@ LinkedHashSet interfacesFound = new LinkedHashSet();@b@ getAllInterfaces(cls, interfacesFound);@b@@b@ return new ArrayList(interfacesFound);@b@ }@b@@b@ private static void getAllInterfaces(Class<?> cls, HashSet<Class<?>> interfacesFound)@b@ {@b@ while (cls != null) {@b@ Class[] interfaces = cls.getInterfaces();@b@@b@ Class[] arr$ = interfaces; int len$ = arr$.length; for (int i$ = 0; i$ < len$; ++i$) { Class i = arr$[i$];@b@ if (interfacesFound.add(i))@b@ getAllInterfaces(i, interfacesFound);@b@@b@ }@b@@b@ cls = cls.getSuperclass();@b@ }@b@ }@b@@b@ public static List<Class<?>> convertClassNamesToClasses(List<String> classNames)@b@ {@b@ if (classNames == null)@b@ return null;@b@@b@ List classes = new ArrayList(classNames.size());@b@ for (String className : classNames)@b@ try {@b@ classes.add(Class.forName(className));@b@ } catch (Exception ex) {@b@ classes.add(null);@b@ }@b@@b@ return classes;@b@ }@b@@b@ public static List<String> convertClassesToClassNames(List<Class<?>> classes)@b@ {@b@ if (classes == null)@b@ return null;@b@@b@ List classNames = new ArrayList(classes.size());@b@ for (Class cls : classes)@b@ if (cls == null)@b@ classNames.add(null);@b@ else@b@ classNames.add(cls.getName());@b@@b@@b@ return classNames;@b@ }@b@@b@ public static boolean isAssignable(Class<?>[] classArray, Class<?>[] toClassArray)@b@ {@b@ return isAssignable(classArray, toClassArray, SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_5));@b@ }@b@@b@ public static boolean isAssignable(Class<?>[] classArray, Class<?>[] toClassArray, boolean autoboxing)@b@ {@b@ if (!(ArrayUtils.isSameLength(classArray, toClassArray)))@b@ return false;@b@@b@ if (classArray == null)@b@ classArray = ArrayUtils.EMPTY_CLASS_ARRAY;@b@@b@ if (toClassArray == null)@b@ toClassArray = ArrayUtils.EMPTY_CLASS_ARRAY;@b@@b@ for (int i = 0; i < classArray.length; ++i)@b@ if (!(isAssignable(classArray[i], toClassArray[i], autoboxing)))@b@ return false;@b@@b@@b@ return true;@b@ }@b@@b@ public static boolean isPrimitiveOrWrapper(Class<?> type)@b@ {@b@ if (type == null)@b@ return false;@b@@b@ return ((type.isPrimitive()) || (isPrimitiveWrapper(type)));@b@ }@b@@b@ public static boolean isPrimitiveWrapper(Class<?> type)@b@ {@b@ return wrapperPrimitiveMap.containsKey(type);@b@ }@b@@b@ public static boolean isAssignable(Class<?> cls, Class<?> toClass)@b@ {@b@ return isAssignable(cls, toClass, SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_5));@b@ }@b@@b@ public static boolean isAssignable(Class<?> cls, Class<?> toClass, boolean autoboxing)@b@ {@b@ if (toClass == null) {@b@ return false;@b@ }@b@@b@ if (cls == null) {@b@ return (!(toClass.isPrimitive()));@b@ }@b@@b@ if (autoboxing) {@b@ if ((cls.isPrimitive()) && (!(toClass.isPrimitive()))) {@b@ cls = primitiveToWrapper(cls);@b@ if (cls == null)@b@ return false;@b@ }@b@@b@ if ((toClass.isPrimitive()) && (!(cls.isPrimitive()))) {@b@ cls = wrapperToPrimitive(cls);@b@ if (cls == null)@b@ return false;@b@ }@b@ }@b@@b@ if (cls.equals(toClass))@b@ return true;@b@@b@ if (cls.isPrimitive()) {@b@ if (!(toClass.isPrimitive()))@b@ return false;@b@@b@ if (Integer.TYPE.equals(cls)) {@b@ return ((Long.TYPE.equals(toClass)) || (Float.TYPE.equals(toClass)) || (Double.TYPE.equals(toClass)));@b@ }@b@@b@ if (Long.TYPE.equals(cls)) {@b@ return ((Float.TYPE.equals(toClass)) || (Double.TYPE.equals(toClass)));@b@ }@b@@b@ if (Boolean.TYPE.equals(cls))@b@ return false;@b@@b@ if (Double.TYPE.equals(cls))@b@ return false;@b@@b@ if (Float.TYPE.equals(cls))@b@ return Double.TYPE.equals(toClass);@b@@b@ if (Character.TYPE.equals(cls)) {@b@ return ((Integer.TYPE.equals(toClass)) || (Long.TYPE.equals(toClass)) || (Float.TYPE.equals(toClass)) || (Double.TYPE.equals(toClass)));@b@ }@b@@b@ if (Short.TYPE.equals(cls)) {@b@ return ((Integer.TYPE.equals(toClass)) || (Long.TYPE.equals(toClass)) || (Float.TYPE.equals(toClass)) || (Double.TYPE.equals(toClass)));@b@ }@b@@b@ if (Byte.TYPE.equals(cls)) {@b@ return ((Short.TYPE.equals(toClass)) || (Integer.TYPE.equals(toClass)) || (Long.TYPE.equals(toClass)) || (Float.TYPE.equals(toClass)) || (Double.TYPE.equals(toClass)));@b@ }@b@@b@ return false;@b@ }@b@ return toClass.isAssignableFrom(cls);@b@ }@b@@b@ public static Class<?> primitiveToWrapper(Class<?> cls)@b@ {@b@ Class convertedClass = cls;@b@ if ((cls != null) && (cls.isPrimitive()))@b@ convertedClass = (Class)primitiveWrapperMap.get(cls);@b@@b@ return convertedClass;@b@ }@b@@b@ public static Class<?>[] primitivesToWrappers(Class<?>[] classes)@b@ {@b@ if (classes == null) {@b@ return null;@b@ }@b@@b@ if (classes.length == 0) {@b@ return classes;@b@ }@b@@b@ Class[] convertedClasses = new Class[classes.length];@b@ for (int i = 0; i < classes.length; ++i)@b@ convertedClasses[i] = primitiveToWrapper(classes[i]);@b@@b@ return convertedClasses;@b@ }@b@@b@ public static Class<?> wrapperToPrimitive(Class<?> cls)@b@ {@b@ return ((Class)wrapperPrimitiveMap.get(cls));@b@ }@b@@b@ public static Class<?>[] wrappersToPrimitives(Class<?>[] classes)@b@ {@b@ if (classes == null) {@b@ return null;@b@ }@b@@b@ if (classes.length == 0) {@b@ return classes;@b@ }@b@@b@ Class[] convertedClasses = new Class[classes.length];@b@ for (int i = 0; i < classes.length; ++i)@b@ convertedClasses[i] = wrapperToPrimitive(classes[i]);@b@@b@ return convertedClasses;@b@ }@b@@b@ public static boolean isInnerClass(Class<?> cls)@b@ {@b@ return ((cls != null) && (cls.getEnclosingClass() != null));@b@ }@b@@b@ public static Class<?> getClass(ClassLoader classLoader, String className, boolean initialize)@b@ throws ClassNotFoundException@b@ {@b@ try@b@ {@b@ Class clazz;@b@ if (abbreviationMap.containsKey(className)) {@b@ String clsName = new StringBuilder().append("[").append((String)abbreviationMap.get(className)).toString();@b@ clazz = Class.forName(clsName, initialize, classLoader).getComponentType();@b@ } else {@b@ clazz = Class.forName(toCanonicalName(className), initialize, classLoader);@b@ }@b@ return clazz;@b@ }@b@ catch (ClassNotFoundException ex) {@b@ int lastDotIndex = className.lastIndexOf(46);@b@@b@ if (lastDotIndex != -1);@b@ try {@b@ return getClass(classLoader, new StringBuilder().append(className.substring(0, lastDotIndex)).append('$').append(className.substring(lastDotIndex + 1)).toString(), initialize);@b@ }@b@ catch (ClassNotFoundException ex2)@b@ {@b@ throw ex;@b@ }@b@ }@b@ }@b@@b@ public static Class<?> getClass(ClassLoader classLoader, String className)@b@ throws ClassNotFoundException@b@ {@b@ return getClass(classLoader, className, true);@b@ }@b@@b@ public static Class<?> getClass(String className)@b@ throws ClassNotFoundException@b@ {@b@ return getClass(className, true);@b@ }@b@@b@ public static Class<?> getClass(String className, boolean initialize)@b@ throws ClassNotFoundException@b@ {@b@ ClassLoader contextCL = Thread.currentThread().getContextClassLoader();@b@ ClassLoader loader = (contextCL == null) ? ClassUtils.class.getClassLoader() : contextCL;@b@ return getClass(loader, className, initialize);@b@ }@b@@b@ public static Method getPublicMethod(Class<?> cls, String methodName, Class<?>[] parameterTypes)@b@ throws SecurityException, NoSuchMethodException@b@ {@b@ Method declaredMethod = cls.getMethod(methodName, parameterTypes);@b@ if (Modifier.isPublic(declaredMethod.getDeclaringClass().getModifiers())) {@b@ return declaredMethod;@b@ }@b@@b@ List candidateClasses = new ArrayList();@b@ candidateClasses.addAll(getAllInterfaces(cls));@b@ candidateClasses.addAll(getAllSuperclasses(cls));@b@@b@ Iterator i$ = candidateClasses.iterator();@b@ while (true) { label64: Class candidateClass;@b@ Method candidateMethod;@b@ while (true) { if (!(i$.hasNext())) break label137; candidateClass = (Class)i$.next();@b@ if (Modifier.isPublic(candidateClass.getModifiers()))@b@ break;@b@ }@b@ try@b@ {@b@ candidateMethod = candidateClass.getMethod(methodName, parameterTypes);@b@ } catch (NoSuchMethodException ex) {@b@ break label64:@b@ }@b@ if (Modifier.isPublic(candidateMethod.getDeclaringClass().getModifiers()))@b@ return candidateMethod;@b@@b@ }@b@@b@ label137: throw new NoSuchMethodException(new StringBuilder().append("Can't find a public method for ").append(methodName).append(" ").append(ArrayUtils.toString(parameterTypes)).toString());@b@ }@b@@b@ private static String toCanonicalName(String className)@b@ {@b@ className = StringUtils.deleteWhitespace(className);@b@ if (className == null)@b@ throw new NullPointerException("className must not be null.");@b@ if (className.endsWith("[]")) {@b@ StringBuilder classNameBuffer = new StringBuilder();@b@ while (className.endsWith("[]")) {@b@ className = className.substring(0, className.length() - 2);@b@ classNameBuffer.append("[");@b@ }@b@ String abbreviation = (String)abbreviationMap.get(className);@b@ if (abbreviation != null)@b@ classNameBuffer.append(abbreviation);@b@ else@b@ classNameBuffer.append("L").append(className).append(";");@b@@b@ className = classNameBuffer.toString();@b@ }@b@ return className;@b@ }@b@@b@ public static Class<?>[] toClass(Object[] array)@b@ {@b@ if (array == null)@b@ return null;@b@ if (array.length == 0)@b@ return ArrayUtils.EMPTY_CLASS_ARRAY;@b@@b@ Class[] classes = new Class[array.length];@b@ for (int i = 0; i < array.length; ++i)@b@ classes[i] = ((array[i] == null) ? null : array[i].getClass());@b@@b@ return classes;@b@ }@b@@b@ public static String getShortCanonicalName(Object object, String valueIfNull)@b@ {@b@ if (object == null)@b@ return valueIfNull;@b@@b@ return getShortCanonicalName(object.getClass().getName());@b@ }@b@@b@ public static String getShortCanonicalName(Class<?> cls)@b@ {@b@ if (cls == null)@b@ return "";@b@@b@ return getShortCanonicalName(cls.getName());@b@ }@b@@b@ public static String getShortCanonicalName(String canonicalName)@b@ {@b@ return getShortClassName(getCanonicalName(canonicalName));@b@ }@b@@b@ public static String getPackageCanonicalName(Object object, String valueIfNull)@b@ {@b@ if (object == null)@b@ return valueIfNull;@b@@b@ return getPackageCanonicalName(object.getClass().getName());@b@ }@b@@b@ public static String getPackageCanonicalName(Class<?> cls)@b@ {@b@ if (cls == null)@b@ return "";@b@@b@ return getPackageCanonicalName(cls.getName());@b@ }@b@@b@ public static String getPackageCanonicalName(String canonicalName)@b@ {@b@ return getPackageName(getCanonicalName(canonicalName));@b@ }@b@@b@ private static String getCanonicalName(String className)@b@ {@b@ className = StringUtils.deleteWhitespace(className);@b@ if (className == null)@b@ return null;@b@@b@ int dim = 0;@b@ while (className.startsWith("[")) {@b@ ++dim;@b@ className = className.substring(1);@b@ }@b@ if (dim < 1)@b@ return className;@b@@b@ if (className.startsWith("L")) {@b@ className = className.substring(1, (className.endsWith(";")) ? className.length() - 1 : className.length());@b@ }@b@ else if (className.length() > 0) {@b@ className = (String)reverseAbbreviationMap.get(className.substring(0, 1));@b@ }@b@@b@ StringBuilder canonicalClassNameBuffer = new StringBuilder(className);@b@ for (int i = 0; i < dim; ++i)@b@ canonicalClassNameBuffer.append("[]");@b@@b@ return canonicalClassNameBuffer.toString();@b@ }@b@@b@ public static Iterable<Class<?>> hierarchy(Class<?> type)@b@ {@b@ return hierarchy(type, Interfaces.EXCLUDE);@b@ }@b@@b@ public static Iterable<Class<?>> hierarchy(Class<?> type, Interfaces interfacesBehavior)@b@ {@b@ Iterable classes = new Iterable(type)@b@ {@b@ public Iterator<Class<?>> iterator()@b@ {@b@ MutableObject next = new MutableObject(this.val$type);@b@ return new Iterator(this, next)@b@ {@b@ public boolean hasNext()@b@ {@b@ return (this.val$next.getValue() != null);@b@ }@b@@b@ public Class<?> next()@b@ {@b@ Class result = (Class)this.val$next.getValue();@b@ this.val$next.setValue(result.getSuperclass());@b@ return result;@b@ }@b@@b@ public void remove()@b@ {@b@ throw new UnsupportedOperationException();@b@ }@b@@b@ };@b@ }@b@@b@ };@b@ if (interfacesBehavior != Interfaces.INCLUDE)@b@ return classes;@b@@b@ return new Iterable(classes)@b@ {@b@ public Iterator<Class<?>> iterator()@b@ {@b@ Set seenInterfaces = new HashSet();@b@ Iterator wrapped = this.val$classes.iterator();@b@@b@ return new Iterator(this, wrapped, seenInterfaces)@b@ {@b@ Iterator<Class<?>> interfaces;@b@@b@ public boolean hasNext() {@b@ return ((this.interfaces.hasNext()) || (this.val$wrapped.hasNext()));@b@ }@b@@b@ public Class<?> next()@b@ {@b@ if (this.interfaces.hasNext()) {@b@ Class nextInterface = (Class)this.interfaces.next();@b@ this.val$seenInterfaces.add(nextInterface);@b@ return nextInterface;@b@ }@b@ Class nextSuperclass = (Class)this.val$wrapped.next();@b@ Set currentInterfaces = new LinkedHashSet();@b@ walkInterfaces(currentInterfaces, nextSuperclass);@b@ this.interfaces = currentInterfaces.iterator();@b@ return nextSuperclass;@b@ }@b@@b@ private void walkInterfaces(, Class<?> c) {@b@ Class[] arr$ = c.getInterfaces(); int len$ = arr$.length; for (int i$ = 0; i$ < len$; ++i$) { Class iface = arr$[i$];@b@ if (!(this.val$seenInterfaces.contains(iface)))@b@ addTo.add(iface);@b@@b@ walkInterfaces(addTo, iface);@b@ }@b@ }@b@@b@ public void remove()@b@ {@b@ throw new UnsupportedOperationException();@b@ }@b@ };@b@ }@b@ };@b@ }@b@@b@ static@b@ {@b@ primitiveWrapperMap.put(Boolean.TYPE, Boolean.class);@b@ primitiveWrapperMap.put(Byte.TYPE, Byte.class);@b@ primitiveWrapperMap.put(Character.TYPE, Character.class);@b@ primitiveWrapperMap.put(Short.TYPE, Short.class);@b@ primitiveWrapperMap.put(Integer.TYPE, Integer.class);@b@ primitiveWrapperMap.put(Long.TYPE, Long.class);@b@ primitiveWrapperMap.put(Double.TYPE, Double.class);@b@ primitiveWrapperMap.put(Float.TYPE, Float.class);@b@ primitiveWrapperMap.put(Void.TYPE, Void.TYPE);@b@@b@ wrapperPrimitiveMap = new HashMap();@b@@b@ for (Class primitiveClass : primitiveWrapperMap.keySet()) {@b@ Class wrapperClass = (Class)primitiveWrapperMap.get(primitiveClass);@b@ if (!(primitiveClass.equals(wrapperClass))) {@b@ wrapperPrimitiveMap.put(wrapperClass, primitiveClass);@b@ }@b@@b@ }@b@@b@ Map m = new HashMap();@b@ m.put("int", "I");@b@ m.put("boolean", "Z");@b@ m.put("float", "F");@b@ m.put("long", "J");@b@ m.put("short", "S");@b@ m.put("byte", "B");@b@ m.put("double", "D");@b@ m.put("char", "C");@b@ m.put("void", "V");@b@ Map r = new HashMap();@b@ for (Map.Entry e : m.entrySet())@b@ r.put(e.getValue(), e.getKey());@b@@b@ abbreviationMap = Collections.unmodifiableMap(m);@b@ reverseAbbreviationMap = Collections.unmodifiableMap(r);@b@ }@b@@b@ public static enum Interfaces@b@ {@b@ INCLUDE, EXCLUDE;@b@ }@b@}
package org.apache.commons.lang3;@b@@b@import java.io.UnsupportedEncodingException;@b@import java.nio.charset.Charset;@b@import java.text.Normalizer;@b@import java.text.Normalizer.Form;@b@import java.util.ArrayList;@b@import java.util.Arrays;@b@import java.util.Iterator;@b@import java.util.List;@b@import java.util.Locale;@b@import java.util.regex.Matcher;@b@import java.util.regex.Pattern;@b@@b@public class StringUtils@b@{@b@ public static final String SPACE = " ";@b@ public static final String EMPTY = "";@b@ public static final String LF = "\n";@b@ public static final String CR = "\r";@b@ public static final int INDEX_NOT_FOUND = -1;@b@ private static final int PAD_LIMIT = 8192;@b@ private static final Pattern WHITESPACE_PATTERN = Pattern.compile("(?: |\\u00A0|\\s|[\\s&&[^ ]])\\s*");@b@@b@ public static boolean isEmpty(CharSequence cs)@b@ {@b@ return ((cs == null) || (cs.length() == 0));@b@ }@b@@b@ public static boolean isNotEmpty(CharSequence cs)@b@ {@b@ return (!(isEmpty(cs)));@b@ }@b@@b@ public static boolean isAnyEmpty(CharSequence[] css)@b@ {@b@ if (ArrayUtils.isEmpty(css))@b@ return true;@b@@b@ CharSequence[] arr$ = css; int len$ = arr$.length; for (int i$ = 0; i$ < len$; ++i$) { CharSequence cs = arr$[i$];@b@ if (isEmpty(cs))@b@ return true;@b@ }@b@@b@ return false;@b@ }@b@@b@ public static boolean isNoneEmpty(CharSequence[] css)@b@ {@b@ return (!(isAnyEmpty(css)));@b@ }@b@@b@ public static boolean isBlank(CharSequence cs)@b@ {@b@ int strLen;@b@ if (cs != null) if ((strLen = cs.length()) != 0) break label17;@b@ return true;@b@@b@ for (int i = 0; i < strLen; ++i)@b@ if (!(Character.isWhitespace(cs.charAt(i))))@b@ label17: return false;@b@@b@@b@ return true;@b@ }@b@@b@ public static boolean isNotBlank(CharSequence cs)@b@ {@b@ return (!(isBlank(cs)));@b@ }@b@@b@ public static boolean isAnyBlank(CharSequence[] css)@b@ {@b@ if (ArrayUtils.isEmpty(css))@b@ return true;@b@@b@ CharSequence[] arr$ = css; int len$ = arr$.length; for (int i$ = 0; i$ < len$; ++i$) { CharSequence cs = arr$[i$];@b@ if (isBlank(cs))@b@ return true;@b@ }@b@@b@ return false;@b@ }@b@@b@ public static boolean isNoneBlank(CharSequence[] css)@b@ {@b@ return (!(isAnyBlank(css)));@b@ }@b@@b@ public static String trim(String str)@b@ {@b@ return ((str == null) ? null : str.trim());@b@ }@b@@b@ public static String trimToNull(String str)@b@ {@b@ String ts = trim(str);@b@ return ((isEmpty(ts)) ? null : ts);@b@ }@b@@b@ public static String trimToEmpty(String str)@b@ {@b@ return ((str == null) ? "" : str.trim());@b@ }@b@@b@ public static String strip(String str)@b@ {@b@ return strip(str, null);@b@ }@b@@b@ public static String stripToNull(String str)@b@ {@b@ if (str == null)@b@ return null;@b@@b@ str = strip(str, null);@b@ return ((str.isEmpty()) ? null : str);@b@ }@b@@b@ public static String stripToEmpty(String str)@b@ {@b@ return ((str == null) ? "" : strip(str, null));@b@ }@b@@b@ public static String strip(String str, String stripChars)@b@ {@b@ if (isEmpty(str))@b@ return str;@b@@b@ str = stripStart(str, stripChars);@b@ return stripEnd(str, stripChars);@b@ }@b@@b@ public static String stripStart(String str, String stripChars)@b@ {@b@ int strLen;@b@ if (str != null) if ((strLen = str.length()) != 0) break label15;@b@ return str;@b@@b@ label15: int start = 0;@b@ if (stripChars == null) while (true) {@b@ if ((start == strLen) || (!(Character.isWhitespace(str.charAt(start))))) break label76;@b@ ++start;@b@ }@b@ if (stripChars.isEmpty())@b@ return str;@b@@b@ while ((start != strLen) && (stripChars.indexOf(str.charAt(start)) != -1)) {@b@ ++start;@b@ }@b@@b@ label76: return str.substring(start);@b@ }@b@@b@ public static String stripEnd(String str, String stripChars)@b@ {@b@ int end;@b@ if (str != null) if ((end = str.length()) != 0) break label15;@b@ return str;@b@@b@ if (stripChars == null) while (true) {@b@ label15: if ((end == 0) || (!(Character.isWhitespace(str.charAt(end - 1))))) break label76;@b@ --end;@b@ }@b@ if (stripChars.isEmpty())@b@ return str;@b@@b@ while ((end != 0) && (stripChars.indexOf(str.charAt(end - 1)) != -1)) {@b@ --end;@b@ }@b@@b@ label76: return str.substring(0, end);@b@ }@b@@b@ public static String[] stripAll(String[] strs)@b@ {@b@ return stripAll(strs, null);@b@ }@b@@b@ public static String[] stripAll(String[] strs, String stripChars)@b@ {@b@ int strsLen;@b@ if (strs != null) if ((strsLen = strs.length) != 0) break label13;@b@ return strs;@b@@b@ label13: String[] newArr = new String[strsLen];@b@ for (int i = 0; i < strsLen; ++i)@b@ newArr[i] = strip(strs[i], stripChars);@b@@b@ return newArr;@b@ }@b@@b@ public static String stripAccents(String input)@b@ {@b@ if (input == null)@b@ return null;@b@@b@ Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");@b@ String decomposed = Normalizer.normalize(input, Normalizer.Form.NFD);@b@@b@ return pattern.matcher(decomposed).replaceAll("");@b@ }@b@@b@ public static boolean equals(CharSequence cs1, CharSequence cs2)@b@ {@b@ if (cs1 == cs2)@b@ return true;@b@@b@ if ((cs1 == null) || (cs2 == null))@b@ return false;@b@@b@ if ((cs1 instanceof String) && (cs2 instanceof String))@b@ return cs1.equals(cs2);@b@@b@ return CharSequenceUtils.regionMatches(cs1, false, 0, cs2, 0, Math.max(cs1.length(), cs2.length()));@b@ }@b@@b@ public static boolean equalsIgnoreCase(CharSequence str1, CharSequence str2)@b@ {@b@ if ((str1 == null) || (str2 == null))@b@ return (str1 == str2);@b@ if (str1 == str2)@b@ return true;@b@ if (str1.length() != str2.length())@b@ return false;@b@@b@ return CharSequenceUtils.regionMatches(str1, true, 0, str2, 0, str1.length());@b@ }@b@@b@ public static int indexOf(CharSequence seq, int searchChar)@b@ {@b@ if (isEmpty(seq))@b@ return -1;@b@@b@ return CharSequenceUtils.indexOf(seq, searchChar, 0);@b@ }@b@@b@ public static int indexOf(CharSequence seq, int searchChar, int startPos)@b@ {@b@ if (isEmpty(seq))@b@ return -1;@b@@b@ return CharSequenceUtils.indexOf(seq, searchChar, startPos);@b@ }@b@@b@ public static int indexOf(CharSequence seq, CharSequence searchSeq)@b@ {@b@ if ((seq == null) || (searchSeq == null))@b@ return -1;@b@@b@ return CharSequenceUtils.indexOf(seq, searchSeq, 0);@b@ }@b@@b@ public static int indexOf(CharSequence seq, CharSequence searchSeq, int startPos)@b@ {@b@ if ((seq == null) || (searchSeq == null))@b@ return -1;@b@@b@ return CharSequenceUtils.indexOf(seq, searchSeq, startPos);@b@ }@b@@b@ public static int ordinalIndexOf(CharSequence str, CharSequence searchStr, int ordinal)@b@ {@b@ return ordinalIndexOf(str, searchStr, ordinal, false);@b@ }@b@@b@ private static int ordinalIndexOf(CharSequence str, CharSequence searchStr, int ordinal, boolean lastIndex)@b@ {@b@ if ((str == null) || (searchStr == null) || (ordinal <= 0))@b@ return -1;@b@@b@ if (searchStr.length() == 0)@b@ return ((lastIndex) ? str.length() : 0);@b@@b@ int found = 0;@b@ int index = (lastIndex) ? str.length() : -1;@b@ do {@b@ if (lastIndex)@b@ index = CharSequenceUtils.lastIndexOf(str, searchStr, index - 1);@b@ else@b@ index = CharSequenceUtils.indexOf(str, searchStr, index + 1);@b@@b@ if (index < 0)@b@ return index;@b@@b@ ++found; }@b@ while (found < ordinal);@b@ return index;@b@ }@b@@b@ public static int indexOfIgnoreCase(CharSequence str, CharSequence searchStr)@b@ {@b@ return indexOfIgnoreCase(str, searchStr, 0);@b@ }@b@@b@ public static int indexOfIgnoreCase(CharSequence str, CharSequence searchStr, int startPos)@b@ {@b@ if ((str == null) || (searchStr == null))@b@ return -1;@b@@b@ if (startPos < 0)@b@ startPos = 0;@b@@b@ int endLimit = str.length() - searchStr.length() + 1;@b@ if (startPos > endLimit)@b@ return -1;@b@@b@ if (searchStr.length() == 0)@b@ return startPos;@b@@b@ for (int i = startPos; i < endLimit; ++i)@b@ if (CharSequenceUtils.regionMatches(str, true, i, searchStr, 0, searchStr.length()))@b@ return i;@b@@b@@b@ return -1;@b@ }@b@@b@ public static int lastIndexOf(CharSequence seq, int searchChar)@b@ {@b@ if (isEmpty(seq))@b@ return -1;@b@@b@ return CharSequenceUtils.lastIndexOf(seq, searchChar, seq.length());@b@ }@b@@b@ public static int lastIndexOf(CharSequence seq, int searchChar, int startPos)@b@ {@b@ if (isEmpty(seq))@b@ return -1;@b@@b@ return CharSequenceUtils.lastIndexOf(seq, searchChar, startPos);@b@ }@b@@b@ public static int lastIndexOf(CharSequence seq, CharSequence searchSeq)@b@ {@b@ if ((seq == null) || (searchSeq == null))@b@ return -1;@b@@b@ return CharSequenceUtils.lastIndexOf(seq, searchSeq, seq.length());@b@ }@b@@b@ public static int lastOrdinalIndexOf(CharSequence str, CharSequence searchStr, int ordinal)@b@ {@b@ return ordinalIndexOf(str, searchStr, ordinal, true);@b@ }@b@@b@ public static int lastIndexOf(CharSequence seq, CharSequence searchSeq, int startPos)@b@ {@b@ if ((seq == null) || (searchSeq == null))@b@ return -1;@b@@b@ return CharSequenceUtils.lastIndexOf(seq, searchSeq, startPos);@b@ }@b@@b@ public static int lastIndexOfIgnoreCase(CharSequence str, CharSequence searchStr)@b@ {@b@ if ((str == null) || (searchStr == null))@b@ return -1;@b@@b@ return lastIndexOfIgnoreCase(str, searchStr, str.length());@b@ }@b@@b@ public static int lastIndexOfIgnoreCase(CharSequence str, CharSequence searchStr, int startPos)@b@ {@b@ if ((str == null) || (searchStr == null))@b@ return -1;@b@@b@ if (startPos > str.length() - searchStr.length())@b@ startPos = str.length() - searchStr.length();@b@@b@ if (startPos < 0)@b@ return -1;@b@@b@ if (searchStr.length() == 0) {@b@ return startPos;@b@ }@b@@b@ for (int i = startPos; i >= 0; --i)@b@ if (CharSequenceUtils.regionMatches(str, true, i, searchStr, 0, searchStr.length()))@b@ return i;@b@@b@@b@ return -1;@b@ }@b@@b@ public static boolean contains(CharSequence seq, int searchChar)@b@ {@b@ if (isEmpty(seq))@b@ return false;@b@@b@ return (CharSequenceUtils.indexOf(seq, searchChar, 0) >= 0);@b@ }@b@@b@ public static boolean contains(CharSequence seq, CharSequence searchSeq)@b@ {@b@ if ((seq == null) || (searchSeq == null))@b@ return false;@b@@b@ return (CharSequenceUtils.indexOf(seq, searchSeq, 0) >= 0);@b@ }@b@@b@ public static boolean containsIgnoreCase(CharSequence str, CharSequence searchStr)@b@ {@b@ if ((str == null) || (searchStr == null))@b@ return false;@b@@b@ int len = searchStr.length();@b@ int max = str.length() - len;@b@ for (int i = 0; i <= max; ++i)@b@ if (CharSequenceUtils.regionMatches(str, true, i, searchStr, 0, len))@b@ return true;@b@@b@@b@ return false;@b@ }@b@@b@ public static boolean containsWhitespace(CharSequence seq)@b@ {@b@ if (isEmpty(seq))@b@ return false;@b@@b@ int strLen = seq.length();@b@ for (int i = 0; i < strLen; ++i)@b@ if (Character.isWhitespace(seq.charAt(i)))@b@ return true;@b@@b@@b@ return false;@b@ }@b@@b@ public static int indexOfAny(CharSequence cs, char[] searchChars)@b@ {@b@ if ((isEmpty(cs)) || (ArrayUtils.isEmpty(searchChars)))@b@ return -1;@b@@b@ int csLen = cs.length();@b@ int csLast = csLen - 1;@b@ int searchLen = searchChars.length;@b@ int searchLast = searchLen - 1;@b@ for (int i = 0; i < csLen; ++i) {@b@ char ch = cs.charAt(i);@b@ for (int j = 0; j < searchLen; ++j)@b@ if (searchChars[j] == ch) {@b@ if ((i < csLast) && (j < searchLast) && (Character.isHighSurrogate(ch)))@b@ {@b@ if (searchChars[(j + 1)] != cs.charAt(i + 1)) break label121;@b@ return i;@b@ }@b@@b@ return i;@b@ }@b@@b@ }@b@@b@ label121: return -1;@b@ }@b@@b@ public static int indexOfAny(CharSequence cs, String searchChars)@b@ {@b@ if ((isEmpty(cs)) || (isEmpty(searchChars)))@b@ return -1;@b@@b@ return indexOfAny(cs, searchChars.toCharArray());@b@ }@b@@b@ public static boolean containsAny(CharSequence cs, char[] searchChars)@b@ {@b@ if ((isEmpty(cs)) || (ArrayUtils.isEmpty(searchChars)))@b@ return false;@b@@b@ int csLength = cs.length();@b@ int searchLength = searchChars.length;@b@ int csLast = csLength - 1;@b@ int searchLast = searchLength - 1;@b@ for (int i = 0; i < csLength; ++i) {@b@ char ch = cs.charAt(i);@b@ for (int j = 0; j < searchLength; ++j)@b@ if (searchChars[j] == ch) {@b@ if (Character.isHighSurrogate(ch)) {@b@ if (j == searchLast)@b@ {@b@ return true;@b@ }@b@ if ((i >= csLast) || (searchChars[(j + 1)] != cs.charAt(i + 1))) break label120;@b@ return true;@b@ }@b@@b@ return true;@b@ }@b@@b@ }@b@@b@ label120: return false;@b@ }@b@@b@ public static boolean containsAny(CharSequence cs, CharSequence searchChars)@b@ {@b@ if (searchChars == null)@b@ return false;@b@@b@ return containsAny(cs, CharSequenceUtils.toCharArray(searchChars));@b@ }@b@@b@ public static int indexOfAnyBut(CharSequence cs, char[] searchChars)@b@ {@b@ if ((isEmpty(cs)) || (ArrayUtils.isEmpty(searchChars)))@b@ return -1;@b@@b@ int csLen = cs.length();@b@ int csLast = csLen - 1;@b@ int searchLen = searchChars.length;@b@ int searchLast = searchLen - 1;@b@@b@ for (int i = 0; i < csLen; ++i) {@b@ char ch = cs.charAt(i);@b@ for (int j = 0; j < searchLen; ++j) {@b@ if (searchChars[j] == ch) {@b@ if ((i >= csLast) || (j >= searchLast) || (!(Character.isHighSurrogate(ch)))) break label127;@b@ if (searchChars[(j + 1)] == cs.charAt(i + 1)) {@b@ break label127:@b@ }@b@@b@ }@b@@b@ }@b@@b@ return i;@b@ }@b@ label127: return -1;@b@ }@b@@b@ public static int indexOfAnyBut(CharSequence seq, CharSequence searchChars)@b@ {@b@ if ((isEmpty(seq)) || (isEmpty(searchChars)))@b@ return -1;@b@@b@ int strLen = seq.length();@b@ for (int i = 0; i < strLen; ++i) {@b@ char ch = seq.charAt(i);@b@ boolean chFound = CharSequenceUtils.indexOf(searchChars, ch, 0) >= 0;@b@ if ((i + 1 < strLen) && (Character.isHighSurrogate(ch))) {@b@ char ch2 = seq.charAt(i + 1);@b@ if ((chFound) && (CharSequenceUtils.indexOf(searchChars, ch2, 0) < 0))@b@ return i;@b@@b@ }@b@ else if (!(chFound)) {@b@ return i;@b@ }@b@ }@b@@b@ return -1;@b@ }@b@@b@ public static boolean containsOnly(CharSequence cs, char[] valid)@b@ {@b@ if ((valid == null) || (cs == null))@b@ return false;@b@@b@ if (cs.length() == 0)@b@ return true;@b@@b@ if (valid.length == 0)@b@ return false;@b@@b@ return (indexOfAnyBut(cs, valid) == -1);@b@ }@b@@b@ public static boolean containsOnly(CharSequence cs, String validChars)@b@ {@b@ if ((cs == null) || (validChars == null))@b@ return false;@b@@b@ return containsOnly(cs, validChars.toCharArray());@b@ }@b@@b@ public static boolean containsNone(CharSequence cs, char[] searchChars)@b@ {@b@ if ((cs == null) || (searchChars == null))@b@ return true;@b@@b@ int csLen = cs.length();@b@ int csLast = csLen - 1;@b@ int searchLen = searchChars.length;@b@ int searchLast = searchLen - 1;@b@ for (int i = 0; i < csLen; ++i) {@b@ char ch = cs.charAt(i);@b@ for (int j = 0; j < searchLen; ++j)@b@ if (searchChars[j] == ch) {@b@ if (Character.isHighSurrogate(ch)) {@b@ if (j == searchLast)@b@ {@b@ return false;@b@ }@b@ if ((i >= csLast) || (searchChars[(j + 1)] != cs.charAt(i + 1))) break label115;@b@ return false;@b@ }@b@@b@ return false;@b@ }@b@@b@ }@b@@b@ label115: return true;@b@ }@b@@b@ public static boolean containsNone(CharSequence cs, String invalidChars)@b@ {@b@ if ((cs == null) || (invalidChars == null))@b@ return true;@b@@b@ return containsNone(cs, invalidChars.toCharArray());@b@ }@b@@b@ public static int indexOfAny(CharSequence str, CharSequence[] searchStrs)@b@ {@b@ if ((str == null) || (searchStrs == null))@b@ return -1;@b@@b@ int sz = searchStrs.length;@b@@b@ int ret = 2147483647;@b@@b@ int tmp = 0;@b@ for (int i = 0; i < sz; ++i) {@b@ CharSequence search = searchStrs[i];@b@ if (search == null)@b@ break label69:@b@@b@ tmp = CharSequenceUtils.indexOf(str, search, 0);@b@ if (tmp == -1) {@b@ break label69:@b@ }@b@@b@ if (tmp < ret)@b@ ret = tmp;@b@@b@ }@b@@b@ label69: return ((ret == 2147483647) ? -1 : ret);@b@ }@b@@b@ public static int lastIndexOfAny(CharSequence str, CharSequence[] searchStrs)@b@ {@b@ if ((str == null) || (searchStrs == null))@b@ return -1;@b@@b@ int sz = searchStrs.length;@b@ int ret = -1;@b@ int tmp = 0;@b@ for (int i = 0; i < sz; ++i) {@b@ CharSequence search = searchStrs[i];@b@ if (search == null)@b@ break label64:@b@@b@ tmp = CharSequenceUtils.lastIndexOf(str, search, str.length());@b@ if (tmp > ret)@b@ ret = tmp;@b@ }@b@@b@ label64: return ret;@b@ }@b@@b@ public static String substring(String str, int start)@b@ {@b@ if (str == null) {@b@ return null;@b@ }@b@@b@ if (start < 0) {@b@ start = str.length() + start;@b@ }@b@@b@ if (start < 0)@b@ start = 0;@b@@b@ if (start > str.length()) {@b@ return "";@b@ }@b@@b@ return str.substring(start);@b@ }@b@@b@ public static String substring(String str, int start, int end)@b@ {@b@ if (str == null) {@b@ return null;@b@ }@b@@b@ if (end < 0)@b@ end = str.length() + end;@b@@b@ if (start < 0) {@b@ start = str.length() + start;@b@ }@b@@b@ if (end > str.length()) {@b@ end = str.length();@b@ }@b@@b@ if (start > end) {@b@ return "";@b@ }@b@@b@ if (start < 0)@b@ start = 0;@b@@b@ if (end < 0) {@b@ end = 0;@b@ }@b@@b@ return str.substring(start, end);@b@ }@b@@b@ public static String left(String str, int len)@b@ {@b@ if (str == null)@b@ return null;@b@@b@ if (len < 0)@b@ return "";@b@@b@ if (str.length() <= len)@b@ return str;@b@@b@ return str.substring(0, len);@b@ }@b@@b@ public static String right(String str, int len)@b@ {@b@ if (str == null)@b@ return null;@b@@b@ if (len < 0)@b@ return "";@b@@b@ if (str.length() <= len)@b@ return str;@b@@b@ return str.substring(str.length() - len);@b@ }@b@@b@ public static String mid(String str, int pos, int len)@b@ {@b@ if (str == null)@b@ return null;@b@@b@ if ((len < 0) || (pos > str.length()))@b@ return "";@b@@b@ if (pos < 0)@b@ pos = 0;@b@@b@ if (str.length() <= pos + len)@b@ return str.substring(pos);@b@@b@ return str.substring(pos, pos + len);@b@ }@b@@b@ public static String substringBefore(String str, String separator)@b@ {@b@ if ((isEmpty(str)) || (separator == null))@b@ return str;@b@@b@ if (separator.isEmpty())@b@ return "";@b@@b@ int pos = str.indexOf(separator);@b@ if (pos == -1)@b@ return str;@b@@b@ return str.substring(0, pos);@b@ }@b@@b@ public static String substringAfter(String str, String separator)@b@ {@b@ if (isEmpty(str))@b@ return str;@b@@b@ if (separator == null)@b@ return "";@b@@b@ int pos = str.indexOf(separator);@b@ if (pos == -1)@b@ return "";@b@@b@ return str.substring(pos + separator.length());@b@ }@b@@b@ public static String substringBeforeLast(String str, String separator)@b@ {@b@ if ((isEmpty(str)) || (isEmpty(separator)))@b@ return str;@b@@b@ int pos = str.lastIndexOf(separator);@b@ if (pos == -1)@b@ return str;@b@@b@ return str.substring(0, pos);@b@ }@b@@b@ public static String substringAfterLast(String str, String separator)@b@ {@b@ if (isEmpty(str))@b@ return str;@b@@b@ if (isEmpty(separator))@b@ return "";@b@@b@ int pos = str.lastIndexOf(separator);@b@ if ((pos == -1) || (pos == str.length() - separator.length()))@b@ return "";@b@@b@ return str.substring(pos + separator.length());@b@ }@b@@b@ public static String substringBetween(String str, String tag)@b@ {@b@ return substringBetween(str, tag, tag);@b@ }@b@@b@ public static String substringBetween(String str, String open, String close)@b@ {@b@ if ((str == null) || (open == null) || (close == null))@b@ return null;@b@@b@ int start = str.indexOf(open);@b@ if (start != -1) {@b@ int end = str.indexOf(close, start + open.length());@b@ if (end != -1)@b@ return str.substring(start + open.length(), end);@b@ }@b@@b@ return null;@b@ }@b@@b@ public static String[] substringsBetween(String str, String open, String close)@b@ {@b@ if ((str == null) || (isEmpty(open)) || (isEmpty(close)))@b@ return null;@b@@b@ int strLen = str.length();@b@ if (strLen == 0)@b@ return ArrayUtils.EMPTY_STRING_ARRAY;@b@@b@ int closeLen = close.length();@b@ int openLen = open.length();@b@ List list = new ArrayList();@b@ int pos = 0;@b@ while (pos < strLen - closeLen) {@b@ int start = str.indexOf(open, pos);@b@ if (start < 0)@b@ break;@b@@b@ start += openLen;@b@ int end = str.indexOf(close, start);@b@ if (end < 0)@b@ break;@b@@b@ list.add(str.substring(start, end));@b@ pos = end + closeLen;@b@ }@b@ if (list.isEmpty())@b@ return null;@b@@b@ return ((String[])list.toArray(new String[list.size()]));@b@ }@b@@b@ public static String[] split(String str)@b@ {@b@ return split(str, null, -1);@b@ }@b@@b@ public static String[] split(String str, char separatorChar)@b@ {@b@ return splitWorker(str, separatorChar, false);@b@ }@b@@b@ public static String[] split(String str, String separatorChars)@b@ {@b@ return splitWorker(str, separatorChars, -1, false);@b@ }@b@@b@ public static String[] split(String str, String separatorChars, int max)@b@ {@b@ return splitWorker(str, separatorChars, max, false);@b@ }@b@@b@ public static String[] splitByWholeSeparator(String str, String separator)@b@ {@b@ return splitByWholeSeparatorWorker(str, separator, -1, false);@b@ }@b@@b@ public static String[] splitByWholeSeparator(String str, String separator, int max)@b@ {@b@ return splitByWholeSeparatorWorker(str, separator, max, false);@b@ }@b@@b@ public static String[] splitByWholeSeparatorPreserveAllTokens(String str, String separator)@b@ {@b@ return splitByWholeSeparatorWorker(str, separator, -1, true);@b@ }@b@@b@ public static String[] splitByWholeSeparatorPreserveAllTokens(String str, String separator, int max)@b@ {@b@ return splitByWholeSeparatorWorker(str, separator, max, true);@b@ }@b@@b@ private static String[] splitByWholeSeparatorWorker(String str, String separator, int max, boolean preserveAllTokens)@b@ {@b@ if (str == null) {@b@ return null;@b@ }@b@@b@ int len = str.length();@b@@b@ if (len == 0) {@b@ return ArrayUtils.EMPTY_STRING_ARRAY;@b@ }@b@@b@ if ((separator == null) || ("".equals(separator)))@b@ {@b@ return splitWorker(str, null, max, preserveAllTokens);@b@ }@b@@b@ int separatorLength = separator.length();@b@@b@ ArrayList substrings = new ArrayList();@b@ int numberOfSubstrings = 0;@b@ int beg = 0;@b@ int end = 0;@b@ while (true) { while (true) { while (true) { while (true) { if (end >= len) break label216;@b@ end = str.indexOf(separator, beg);@b@@b@ if (end <= -1) break label197;@b@ if (end <= beg) break label147;@b@ ++numberOfSubstrings;@b@@b@ if (numberOfSubstrings != max) break;@b@ end = len;@b@ substrings.add(str.substring(beg));@b@ }@b@@b@ substrings.add(str.substring(beg, end));@b@@b@ beg = end + separatorLength;@b@ }@b@@b@ if (preserveAllTokens) {@b@ label147: ++numberOfSubstrings;@b@ if (numberOfSubstrings == max) {@b@ end = len;@b@ substrings.add(str.substring(beg));@b@ } else {@b@ substrings.add("");@b@ }@b@ }@b@ beg = end + separatorLength;@b@ }@b@@b@ label197: substrings.add(str.substring(beg));@b@ end = len;@b@ }@b@@b@ label216: return ((String[])substrings.toArray(new String[substrings.size()]));@b@ }@b@@b@ public static String[] splitPreserveAllTokens(String str)@b@ {@b@ return splitWorker(str, null, -1, true);@b@ }@b@@b@ public static String[] splitPreserveAllTokens(String str, char separatorChar)@b@ {@b@ return splitWorker(str, separatorChar, true);@b@ }@b@@b@ private static String[] splitWorker(String str, char separatorChar, boolean preserveAllTokens)@b@ {@b@ if (str == null)@b@ return null;@b@@b@ int len = str.length();@b@ if (len == 0)@b@ return ArrayUtils.EMPTY_STRING_ARRAY;@b@@b@ List list = new ArrayList();@b@ int i = 0; int start = 0;@b@ boolean match = false;@b@ boolean lastMatch = false;@b@ while (true) { while (true) { if (i >= len) break label109;@b@ if (str.charAt(i) != separatorChar) break;@b@ if ((match) || (preserveAllTokens)) {@b@ list.add(str.substring(start, i));@b@ match = false;@b@ lastMatch = true;@b@ }@b@ start = ++i;@b@ }@b@@b@ lastMatch = false;@b@ match = true;@b@ ++i;@b@ }@b@ if ((match) || ((preserveAllTokens) && (lastMatch)))@b@ label109: list.add(str.substring(start, i));@b@@b@ return ((String[])list.toArray(new String[list.size()]));@b@ }@b@@b@ public static String[] splitPreserveAllTokens(String str, String separatorChars)@b@ {@b@ return splitWorker(str, separatorChars, -1, true);@b@ }@b@@b@ public static String[] splitPreserveAllTokens(String str, String separatorChars, int max)@b@ {@b@ return splitWorker(str, separatorChars, max, true);@b@ }@b@@b@ private static String[] splitWorker(String str, String separatorChars, int max, boolean preserveAllTokens)@b@ {@b@ if (str == null)@b@ return null;@b@@b@ int len = str.length();@b@ if (len == 0)@b@ return ArrayUtils.EMPTY_STRING_ARRAY;@b@@b@ List list = new ArrayList();@b@ int sizePlus1 = 1;@b@ int i = 0; int start = 0;@b@ boolean match = false;@b@ boolean lastMatch = false;@b@ if (separatorChars == null) while (true) {@b@ while (true) {@b@ if (i >= len) break label331;@b@ if (!(Character.isWhitespace(str.charAt(i)))) break;@b@ if ((match) || (preserveAllTokens)) {@b@ lastMatch = true;@b@ if (sizePlus1++ == max) {@b@ i = len;@b@ lastMatch = false;@b@ }@b@ list.add(str.substring(start, i));@b@ match = false;@b@ }@b@ start = ++i;@b@ }@b@@b@ lastMatch = false;@b@ match = true;@b@ ++i;@b@ }@b@ if (separatorChars.length() == 1)@b@ {@b@ char sep = separatorChars.charAt(0);@b@ while (true) { while (true) { if (i >= len) break label239;@b@ if (str.charAt(i) != sep) break;@b@ if ((match) || (preserveAllTokens)) {@b@ lastMatch = true;@b@ if (sizePlus1++ == max) {@b@ i = len;@b@ lastMatch = false;@b@ }@b@ list.add(str.substring(start, i));@b@ match = false;@b@ }@b@ start = ++i;@b@ }@b@@b@ lastMatch = false;@b@ match = true;@b@ label239: ++i; }@b@ } else {@b@ while (true) {@b@ while (true) {@b@ if (i >= len) break label331;@b@ if (separatorChars.indexOf(str.charAt(i)) < 0) break;@b@ if ((match) || (preserveAllTokens)) {@b@ lastMatch = true;@b@ if (sizePlus1++ == max) {@b@ i = len;@b@ lastMatch = false;@b@ }@b@ list.add(str.substring(start, i));@b@ match = false;@b@ }@b@ start = ++i;@b@ }@b@@b@ lastMatch = false;@b@ match = true;@b@ ++i;@b@ }@b@ }@b@ if ((match) || ((preserveAllTokens) && (lastMatch)))@b@ label331: list.add(str.substring(start, i));@b@@b@ return ((String[])list.toArray(new String[list.size()]));@b@ }@b@@b@ public static String[] splitByCharacterType(String str)@b@ {@b@ return splitByCharacterType(str, false);@b@ }@b@@b@ public static String[] splitByCharacterTypeCamelCase(String str)@b@ {@b@ return splitByCharacterType(str, true);@b@ }@b@@b@ private static String[] splitByCharacterType(String str, boolean camelCase)@b@ {@b@ if (str == null)@b@ return null;@b@@b@ if (str.isEmpty())@b@ return ArrayUtils.EMPTY_STRING_ARRAY;@b@@b@ char[] c = str.toCharArray();@b@ List list = new ArrayList();@b@ int tokenStart = 0;@b@ int currentType = Character.getType(c[tokenStart]);@b@ for (int pos = tokenStart + 1; pos < c.length; ++pos) {@b@ int type = Character.getType(c[pos]);@b@ if (type == currentType)@b@ break label162:@b@@b@ if ((camelCase) && (type == 2) && (currentType == 1)) {@b@ int newTokenStart = pos - 1;@b@ if (newTokenStart != tokenStart) {@b@ list.add(new String(c, tokenStart, newTokenStart - tokenStart));@b@ tokenStart = newTokenStart;@b@ }@b@ } else {@b@ list.add(new String(c, tokenStart, pos - tokenStart));@b@ tokenStart = pos;@b@ }@b@ currentType = type;@b@ }@b@ label162: list.add(new String(c, tokenStart, c.length - tokenStart));@b@ return ((String[])list.toArray(new String[list.size()]));@b@ }@b@@b@ public static <T> String join(T[] elements)@b@ {@b@ return join(elements, null);@b@ }@b@@b@ public static String join(Object[] array, char separator)@b@ {@b@ if (array == null)@b@ return null;@b@@b@ return join(array, separator, 0, array.length);@b@ }@b@@b@ public static String join(long[] array, char separator)@b@ {@b@ if (array == null)@b@ return null;@b@@b@ return join(array, separator, 0, array.length);@b@ }@b@@b@ public static String join(int[] array, char separator)@b@ {@b@ if (array == null)@b@ return null;@b@@b@ return join(array, separator, 0, array.length);@b@ }@b@@b@ public static String join(short[] array, char separator)@b@ {@b@ if (array == null)@b@ return null;@b@@b@ return join(array, separator, 0, array.length);@b@ }@b@@b@ public static String join(byte[] array, char separator)@b@ {@b@ if (array == null)@b@ return null;@b@@b@ return join(array, separator, 0, array.length);@b@ }@b@@b@ public static String join(char[] array, char separator)@b@ {@b@ if (array == null)@b@ return null;@b@@b@ return join(array, separator, 0, array.length);@b@ }@b@@b@ public static String join(float[] array, char separator)@b@ {@b@ if (array == null)@b@ return null;@b@@b@ return join(array, separator, 0, array.length);@b@ }@b@@b@ public static String join(double[] array, char separator)@b@ {@b@ if (array == null)@b@ return null;@b@@b@ return join(array, separator, 0, array.length);@b@ }@b@@b@ public static String join(Object[] array, char separator, int startIndex, int endIndex)@b@ {@b@ if (array == null)@b@ return null;@b@@b@ int noOfItems = endIndex - startIndex;@b@ if (noOfItems <= 0)@b@ return "";@b@@b@ StringBuilder buf = new StringBuilder(noOfItems * 16);@b@ for (int i = startIndex; i < endIndex; ++i) {@b@ if (i > startIndex)@b@ buf.append(separator);@b@@b@ if (array[i] != null)@b@ buf.append(array[i]);@b@ }@b@@b@ return buf.toString();@b@ }@b@@b@ public static String join(long[] array, char separator, int startIndex, int endIndex)@b@ {@b@ if (array == null)@b@ return null;@b@@b@ int noOfItems = endIndex - startIndex;@b@ if (noOfItems <= 0)@b@ return "";@b@@b@ StringBuilder buf = new StringBuilder(noOfItems * 16);@b@ for (int i = startIndex; i < endIndex; ++i) {@b@ if (i > startIndex)@b@ buf.append(separator);@b@@b@ buf.append(array[i]);@b@ }@b@ return buf.toString();@b@ }@b@@b@ public static String join(int[] array, char separator, int startIndex, int endIndex)@b@ {@b@ if (array == null)@b@ return null;@b@@b@ int noOfItems = endIndex - startIndex;@b@ if (noOfItems <= 0)@b@ return "";@b@@b@ StringBuilder buf = new StringBuilder(noOfItems * 16);@b@ for (int i = startIndex; i < endIndex; ++i) {@b@ if (i > startIndex)@b@ buf.append(separator);@b@@b@ buf.append(array[i]);@b@ }@b@ return buf.toString();@b@ }@b@@b@ public static String join(byte[] array, char separator, int startIndex, int endIndex)@b@ {@b@ if (array == null)@b@ return null;@b@@b@ int noOfItems = endIndex - startIndex;@b@ if (noOfItems <= 0)@b@ return "";@b@@b@ StringBuilder buf = new StringBuilder(noOfItems * 16);@b@ for (int i = startIndex; i < endIndex; ++i) {@b@ if (i > startIndex)@b@ buf.append(separator);@b@@b@ buf.append(array[i]);@b@ }@b@ return buf.toString();@b@ }@b@@b@ public static String join(short[] array, char separator, int startIndex, int endIndex)@b@ {@b@ if (array == null)@b@ return null;@b@@b@ int noOfItems = endIndex - startIndex;@b@ if (noOfItems <= 0)@b@ return "";@b@@b@ StringBuilder buf = new StringBuilder(noOfItems * 16);@b@ for (int i = startIndex; i < endIndex; ++i) {@b@ if (i > startIndex)@b@ buf.append(separator);@b@@b@ buf.append(array[i]);@b@ }@b@ return buf.toString();@b@ }@b@@b@ public static String join(char[] array, char separator, int startIndex, int endIndex)@b@ {@b@ if (array == null)@b@ return null;@b@@b@ int noOfItems = endIndex - startIndex;@b@ if (noOfItems <= 0)@b@ return "";@b@@b@ StringBuilder buf = new StringBuilder(noOfItems * 16);@b@ for (int i = startIndex; i < endIndex; ++i) {@b@ if (i > startIndex)@b@ buf.append(separator);@b@@b@ buf.append(array[i]);@b@ }@b@ return buf.toString();@b@ }@b@@b@ public static String join(double[] array, char separator, int startIndex, int endIndex)@b@ {@b@ if (array == null)@b@ return null;@b@@b@ int noOfItems = endIndex - startIndex;@b@ if (noOfItems <= 0)@b@ return "";@b@@b@ StringBuilder buf = new StringBuilder(noOfItems * 16);@b@ for (int i = startIndex; i < endIndex; ++i) {@b@ if (i > startIndex)@b@ buf.append(separator);@b@@b@ buf.append(array[i]);@b@ }@b@ return buf.toString();@b@ }@b@@b@ public static String join(float[] array, char separator, int startIndex, int endIndex)@b@ {@b@ if (array == null)@b@ return null;@b@@b@ int noOfItems = endIndex - startIndex;@b@ if (noOfItems <= 0)@b@ return "";@b@@b@ StringBuilder buf = new StringBuilder(noOfItems * 16);@b@ for (int i = startIndex; i < endIndex; ++i) {@b@ if (i > startIndex)@b@ buf.append(separator);@b@@b@ buf.append(array[i]);@b@ }@b@ return buf.toString();@b@ }@b@@b@ public static String join(Object[] array, String separator)@b@ {@b@ if (array == null)@b@ return null;@b@@b@ return join(array, separator, 0, array.length);@b@ }@b@@b@ public static String join(Object[] array, String separator, int startIndex, int endIndex)@b@ {@b@ if (array == null)@b@ return null;@b@@b@ if (separator == null) {@b@ separator = "";@b@ }@b@@b@ int noOfItems = endIndex - startIndex;@b@ if (noOfItems <= 0) {@b@ return "";@b@ }@b@@b@ StringBuilder buf = new StringBuilder(noOfItems * 16);@b@@b@ for (int i = startIndex; i < endIndex; ++i) {@b@ if (i > startIndex)@b@ buf.append(separator);@b@@b@ if (array[i] != null)@b@ buf.append(array[i]);@b@ }@b@@b@ return buf.toString();@b@ }@b@@b@ public static String join(Iterator<?> iterator, char separator)@b@ {@b@ if (iterator == null)@b@ return null;@b@@b@ if (!(iterator.hasNext()))@b@ return "";@b@@b@ Object first = iterator.next();@b@ if (!(iterator.hasNext()))@b@ {@b@ String result = ObjectUtils.toString(first);@b@ return result;@b@ }@b@@b@ StringBuilder buf = new StringBuilder(256);@b@ if (first != null) {@b@ buf.append(first);@b@ }@b@@b@ while (iterator.hasNext()) {@b@ buf.append(separator);@b@ Object obj = iterator.next();@b@ if (obj != null)@b@ buf.append(obj);@b@@b@ }@b@@b@ return buf.toString();@b@ }@b@@b@ public static String join(Iterator<?> iterator, String separator)@b@ {@b@ if (iterator == null)@b@ return null;@b@@b@ if (!(iterator.hasNext()))@b@ return "";@b@@b@ Object first = iterator.next();@b@ if (!(iterator.hasNext()))@b@ {@b@ String result = ObjectUtils.toString(first);@b@ return result;@b@ }@b@@b@ StringBuilder buf = new StringBuilder(256);@b@ if (first != null) {@b@ buf.append(first);@b@ }@b@@b@ while (iterator.hasNext()) {@b@ if (separator != null)@b@ buf.append(separator);@b@@b@ Object obj = iterator.next();@b@ if (obj != null)@b@ buf.append(obj);@b@ }@b@@b@ return buf.toString();@b@ }@b@@b@ public static String join(Iterable<?> iterable, char separator)@b@ {@b@ if (iterable == null)@b@ return null;@b@@b@ return join(iterable.iterator(), separator);@b@ }@b@@b@ public static String join(Iterable<?> iterable, String separator)@b@ {@b@ if (iterable == null)@b@ return null;@b@@b@ return join(iterable.iterator(), separator);@b@ }@b@@b@ public static String deleteWhitespace(String str)@b@ {@b@ if (isEmpty(str))@b@ return str;@b@@b@ int sz = str.length();@b@ char[] chs = new char[sz];@b@ int count = 0;@b@ for (int i = 0; i < sz; ++i)@b@ if (!(Character.isWhitespace(str.charAt(i))))@b@ chs[(count++)] = str.charAt(i);@b@@b@@b@ if (count == sz)@b@ return str;@b@@b@ return new String(chs, 0, count);@b@ }@b@@b@ public static String removeStart(String str, String remove)@b@ {@b@ if ((isEmpty(str)) || (isEmpty(remove)))@b@ return str;@b@@b@ if (str.startsWith(remove))@b@ return str.substring(remove.length());@b@@b@ return str;@b@ }@b@@b@ public static String removeStartIgnoreCase(String str, String remove)@b@ {@b@ if ((isEmpty(str)) || (isEmpty(remove)))@b@ return str;@b@@b@ if (startsWithIgnoreCase(str, remove))@b@ return str.substring(remove.length());@b@@b@ return str;@b@ }@b@@b@ public static String removeEnd(String str, String remove)@b@ {@b@ if ((isEmpty(str)) || (isEmpty(remove)))@b@ return str;@b@@b@ if (str.endsWith(remove))@b@ return str.substring(0, str.length() - remove.length());@b@@b@ return str;@b@ }@b@@b@ public static String removeEndIgnoreCase(String str, String remove)@b@ {@b@ if ((isEmpty(str)) || (isEmpty(remove)))@b@ return str;@b@@b@ if (endsWithIgnoreCase(str, remove))@b@ return str.substring(0, str.length() - remove.length());@b@@b@ return str;@b@ }@b@@b@ public static String remove(String str, String remove)@b@ {@b@ if ((isEmpty(str)) || (isEmpty(remove)))@b@ return str;@b@@b@ return replace(str, remove, "", -1);@b@ }@b@@b@ public static String remove(String str, char remove)@b@ {@b@ if ((isEmpty(str)) || (str.indexOf(remove) == -1))@b@ return str;@b@@b@ char[] chars = str.toCharArray();@b@ int pos = 0;@b@ for (int i = 0; i < chars.length; ++i)@b@ if (chars[i] != remove)@b@ chars[(pos++)] = chars[i];@b@@b@@b@ return new String(chars, 0, pos);@b@ }@b@@b@ public static String replaceOnce(String text, String searchString, String replacement)@b@ {@b@ return replace(text, searchString, replacement, 1);@b@ }@b@@b@ public static String replacePattern(String source, String regex, String replacement)@b@ {@b@ return Pattern.compile(regex, 32).matcher(source).replaceAll(replacement);@b@ }@b@@b@ public static String removePattern(String source, String regex)@b@ {@b@ return replacePattern(source, regex, "");@b@ }@b@@b@ public static String replace(String text, String searchString, String replacement)@b@ {@b@ return replace(text, searchString, replacement, -1);@b@ }@b@@b@ public static String replace(String text, String searchString, String replacement, int max)@b@ {@b@ if ((isEmpty(text)) || (isEmpty(searchString)) || (replacement == null) || (max == 0))@b@ return text;@b@@b@ int start = 0;@b@ int end = text.indexOf(searchString, start);@b@ if (end == -1)@b@ return text;@b@@b@ int replLength = searchString.length();@b@ int increase = replacement.length() - replLength;@b@ increase = (increase < 0) ? 0 : increase;@b@ increase *= ((max > 64) ? 64 : (max < 0) ? 16 : max);@b@ StringBuilder buf = new StringBuilder(text.length() + increase);@b@ while (end != -1) {@b@ buf.append(text.substring(start, end)).append(replacement);@b@ start = end + replLength;@b@ if (--max == 0)@b@ break;@b@@b@ end = text.indexOf(searchString, start);@b@ }@b@ buf.append(text.substring(start));@b@ return buf.toString();@b@ }@b@@b@ public static String replaceEach(String text, String[] searchList, String[] replacementList)@b@ {@b@ return replaceEach(text, searchList, replacementList, false, 0);@b@ }@b@@b@ public static String replaceEachRepeatedly(String text, String[] searchList, String[] replacementList)@b@ {@b@ int timeToLive = (searchList == null) ? 0 : searchList.length;@b@ return replaceEach(text, searchList, replacementList, true, timeToLive);@b@ }@b@@b@ private static String replaceEach(String text, String[] searchList, String[] replacementList, boolean repeat, int timeToLive)@b@ {@b@ label205: int i;@b@ if ((text == null) || (text.isEmpty()) || (searchList == null) || (searchList.length == 0) || (replacementList == null) || (replacementList.length == 0))@b@ {@b@ return text;@b@ }@b@@b@ if (timeToLive < 0) {@b@ throw new IllegalStateException("Aborting to protect against StackOverflowError - output of one loop is the input of another");@b@ }@b@@b@ int searchLength = searchList.length;@b@ int replacementLength = replacementList.length;@b@@b@ if (searchLength != replacementLength) {@b@ throw new IllegalArgumentException(new StringBuilder().append("Search and Replace array lengths don't match: ").append(searchLength).append(" vs ").append(replacementLength).toString());@b@ }@b@@b@ boolean[] noMoreMatchesForReplIndex = new boolean[searchLength];@b@@b@ int textIndex = -1;@b@ int replaceIndex = -1;@b@ int tempIndex = -1;@b@@b@ for (int i = 0; i < searchLength; ++i) {@b@ if ((noMoreMatchesForReplIndex[i] == 0) && (searchList[i] != null) && (!(searchList[i].isEmpty()))) { if (replacementList[i] == null)@b@ {@b@ break label205:@b@ }@b@ tempIndex = text.indexOf(searchList[i]);@b@@b@ if (tempIndex == -1) {@b@ noMoreMatchesForReplIndex[i] = true;@b@ }@b@ else if ((textIndex == -1) || (tempIndex < textIndex)) {@b@ textIndex = tempIndex;@b@ replaceIndex = i;@b@ }@b@@b@ }@b@@b@ }@b@@b@ if (textIndex == -1) {@b@ return text;@b@ }@b@@b@ int start = 0;@b@@b@ int increase = 0;@b@@b@ for (int i = 0; i < searchList.length; ++i)@b@ if (searchList[i] != null) { if (replacementList[i] == null)@b@ break label283:@b@@b@ int greater = replacementList[i].length() - searchList[i].length();@b@ if (greater > 0)@b@ increase += 3 * greater;@b@ }@b@@b@@b@ label283: increase = Math.min(increase, text.length() / 5);@b@@b@ StringBuilder buf = new StringBuilder(text.length() + increase);@b@@b@ while (textIndex != -1)@b@ {@b@ for (i = start; i < textIndex; ++i)@b@ buf.append(text.charAt(i));@b@@b@ buf.append(replacementList[replaceIndex]);@b@@b@ start = textIndex + searchList[replaceIndex].length();@b@@b@ textIndex = -1;@b@ replaceIndex = -1;@b@ tempIndex = -1;@b@@b@ label477: for (i = 0; i < searchLength; ++i)@b@ if ((noMoreMatchesForReplIndex[i] == 0) && (searchList[i] != null) && (!(searchList[i].isEmpty()))) { if (replacementList[i] == null)@b@ {@b@ break label477:@b@ }@b@ tempIndex = text.indexOf(searchList[i], start);@b@@b@ if (tempIndex == -1) {@b@ noMoreMatchesForReplIndex[i] = true;@b@ }@b@ else if ((textIndex == -1) || (tempIndex < textIndex)) {@b@ textIndex = tempIndex;@b@ replaceIndex = i;@b@ }@b@ }@b@@b@@b@ }@b@@b@ int textLength = text.length();@b@ for (int i = start; i < textLength; ++i)@b@ buf.append(text.charAt(i));@b@@b@ String result = buf.toString();@b@ if (!(repeat)) {@b@ return result;@b@ }@b@@b@ return replaceEach(result, searchList, replacementList, repeat, timeToLive - 1);@b@ }@b@@b@ public static String replaceChars(String str, char searchChar, char replaceChar)@b@ {@b@ if (str == null)@b@ return null;@b@@b@ return str.replace(searchChar, replaceChar);@b@ }@b@@b@ public static String replaceChars(String str, String searchChars, String replaceChars)@b@ {@b@ if ((isEmpty(str)) || (isEmpty(searchChars)))@b@ return str;@b@@b@ if (replaceChars == null)@b@ replaceChars = "";@b@@b@ boolean modified = false;@b@ int replaceCharsLength = replaceChars.length();@b@ int strLength = str.length();@b@ StringBuilder buf = new StringBuilder(strLength);@b@ for (int i = 0; i < strLength; ++i) {@b@ char ch = str.charAt(i);@b@ int index = searchChars.indexOf(ch);@b@ if (index >= 0) {@b@ modified = true;@b@ if (index < replaceCharsLength)@b@ buf.append(replaceChars.charAt(index));@b@ }@b@ else {@b@ buf.append(ch);@b@ }@b@ }@b@ if (modified)@b@ return buf.toString();@b@@b@ return str;@b@ }@b@@b@ public static String overlay(String str, String overlay, int start, int end)@b@ {@b@ if (str == null)@b@ return null;@b@@b@ if (overlay == null)@b@ overlay = "";@b@@b@ int len = str.length();@b@ if (start < 0)@b@ start = 0;@b@@b@ if (start > len)@b@ start = len;@b@@b@ if (end < 0)@b@ end = 0;@b@@b@ if (end > len)@b@ end = len;@b@@b@ if (start > end) {@b@ int temp = start;@b@ start = end;@b@ end = temp;@b@ }@b@ return new StringBuilder(len + start - end + overlay.length() + 1).append(str.substring(0, start)).append(overlay).append(str.substring(end)).toString();@b@ }@b@@b@ public static String chomp(String str)@b@ {@b@ if (isEmpty(str)) {@b@ return str;@b@ }@b@@b@ if (str.length() == 1) {@b@ char ch = str.charAt(0);@b@ if ((ch == '\r') || (ch == '\n'))@b@ return "";@b@@b@ return str;@b@ }@b@@b@ int lastIdx = str.length() - 1;@b@ char last = str.charAt(lastIdx);@b@@b@ if (last == '\n')@b@ if (str.charAt(lastIdx - 1) == '\r')@b@ --lastIdx;@b@@b@ else if (last != '\r')@b@ ++lastIdx;@b@@b@ return str.substring(0, lastIdx);@b@ }@b@@b@ @Deprecated@b@ public static String chomp(String str, String separator)@b@ {@b@ return removeEnd(str, separator);@b@ }@b@@b@ public static String chop(String str)@b@ {@b@ if (str == null)@b@ return null;@b@@b@ int strLen = str.length();@b@ if (strLen < 2)@b@ return "";@b@@b@ int lastIdx = strLen - 1;@b@ String ret = str.substring(0, lastIdx);@b@ char last = str.charAt(lastIdx);@b@ if ((last == '\n') && (ret.charAt(lastIdx - 1) == '\r'))@b@ return ret.substring(0, lastIdx - 1);@b@@b@ return ret;@b@ }@b@@b@ public static String repeat(String str, int repeat)@b@ {@b@ if (str == null)@b@ return null;@b@@b@ if (repeat <= 0)@b@ return "";@b@@b@ int inputLength = str.length();@b@ if ((repeat == 1) || (inputLength == 0))@b@ return str;@b@@b@ if ((inputLength == 1) && (repeat <= 8192)) {@b@ return repeat(str.charAt(0), repeat);@b@ }@b@@b@ int outputLength = inputLength * repeat;@b@ switch (inputLength)@b@ {@b@ case 1:@b@ return repeat(str.charAt(0), repeat);@b@ case 2:@b@ char ch0 = str.charAt(0);@b@ char ch1 = str.charAt(1);@b@ char[] output2 = new char[outputLength];@b@ for (int i = repeat * 2 - 2; i >= 0; ) {@b@ output2[i] = ch0;@b@ output2[(i + 1)] = ch1;@b@@b@ --i; --i;@b@ }@b@@b@ return new String(output2);@b@ }@b@ StringBuilder buf = new StringBuilder(outputLength);@b@ for (int i = 0; i < repeat; ++i)@b@ buf.append(str);@b@@b@ return buf.toString();@b@ }@b@@b@ public static String repeat(String str, String separator, int repeat)@b@ {@b@ if ((str == null) || (separator == null)) {@b@ return repeat(str, repeat);@b@ }@b@@b@ String result = repeat(new StringBuilder().append(str).append(separator).toString(), repeat);@b@ return removeEnd(result, separator);@b@ }@b@@b@ public static String repeat(char ch, int repeat)@b@ {@b@ char[] buf = new char[repeat];@b@ for (int i = repeat - 1; i >= 0; --i)@b@ buf[i] = ch;@b@@b@ return new String(buf);@b@ }@b@@b@ public static String rightPad(String str, int size)@b@ {@b@ return rightPad(str, size, ' ');@b@ }@b@@b@ public static String rightPad(String str, int size, char padChar)@b@ {@b@ if (str == null)@b@ return null;@b@@b@ int pads = size - str.length();@b@ if (pads <= 0)@b@ return str;@b@@b@ if (pads > 8192)@b@ return rightPad(str, size, String.valueOf(padChar));@b@@b@ return str.concat(repeat(padChar, pads));@b@ }@b@@b@ public static String rightPad(String str, int size, String padStr)@b@ {@b@ if (str == null)@b@ return null;@b@@b@ if (isEmpty(padStr))@b@ padStr = " ";@b@@b@ int padLen = padStr.length();@b@ int strLen = str.length();@b@ int pads = size - strLen;@b@ if (pads <= 0)@b@ return str;@b@@b@ if ((padLen == 1) && (pads <= 8192)) {@b@ return rightPad(str, size, padStr.charAt(0));@b@ }@b@@b@ if (pads == padLen)@b@ return str.concat(padStr);@b@ if (pads < padLen)@b@ return str.concat(padStr.substring(0, pads));@b@@b@ char[] padding = new char[pads];@b@ char[] padChars = padStr.toCharArray();@b@ for (int i = 0; i < pads; ++i)@b@ padding[i] = padChars[(i % padLen)];@b@@b@ return str.concat(new String(padding));@b@ }@b@@b@ public static String leftPad(String str, int size)@b@ {@b@ return leftPad(str, size, ' ');@b@ }@b@@b@ public static String leftPad(String str, int size, char padChar)@b@ {@b@ if (str == null)@b@ return null;@b@@b@ int pads = size - str.length();@b@ if (pads <= 0)@b@ return str;@b@@b@ if (pads > 8192)@b@ return leftPad(str, size, String.valueOf(padChar));@b@@b@ return repeat(padChar, pads).concat(str);@b@ }@b@@b@ public static String leftPad(String str, int size, String padStr)@b@ {@b@ if (str == null)@b@ return null;@b@@b@ if (isEmpty(padStr))@b@ padStr = " ";@b@@b@ int padLen = padStr.length();@b@ int strLen = str.length();@b@ int pads = size - strLen;@b@ if (pads <= 0)@b@ return str;@b@@b@ if ((padLen == 1) && (pads <= 8192)) {@b@ return leftPad(str, size, padStr.charAt(0));@b@ }@b@@b@ if (pads == padLen)@b@ return padStr.concat(str);@b@ if (pads < padLen)@b@ return padStr.substring(0, pads).concat(str);@b@@b@ char[] padding = new char[pads];@b@ char[] padChars = padStr.toCharArray();@b@ for (int i = 0; i < pads; ++i)@b@ padding[i] = padChars[(i % padLen)];@b@@b@ return new String(padding).concat(str);@b@ }@b@@b@ public static int length(CharSequence cs)@b@ {@b@ return ((cs == null) ? 0 : cs.length());@b@ }@b@@b@ public static String center(String str, int size)@b@ {@b@ return center(str, size, ' ');@b@ }@b@@b@ public static String center(String str, int size, char padChar)@b@ {@b@ if ((str == null) || (size <= 0))@b@ return str;@b@@b@ int strLen = str.length();@b@ int pads = size - strLen;@b@ if (pads <= 0)@b@ return str;@b@@b@ str = leftPad(str, strLen + pads / 2, padChar);@b@ str = rightPad(str, size, padChar);@b@ return str;@b@ }@b@@b@ public static String center(String str, int size, String padStr)@b@ {@b@ if ((str == null) || (size <= 0))@b@ return str;@b@@b@ if (isEmpty(padStr))@b@ padStr = " ";@b@@b@ int strLen = str.length();@b@ int pads = size - strLen;@b@ if (pads <= 0)@b@ return str;@b@@b@ str = leftPad(str, strLen + pads / 2, padStr);@b@ str = rightPad(str, size, padStr);@b@ return str;@b@ }@b@@b@ public static String upperCase(String str)@b@ {@b@ if (str == null)@b@ return null;@b@@b@ return str.toUpperCase();@b@ }@b@@b@ public static String upperCase(String str, Locale locale)@b@ {@b@ if (str == null)@b@ return null;@b@@b@ return str.toUpperCase(locale);@b@ }@b@@b@ public static String lowerCase(String str)@b@ {@b@ if (str == null)@b@ return null;@b@@b@ return str.toLowerCase();@b@ }@b@@b@ public static String lowerCase(String str, Locale locale)@b@ {@b@ if (str == null)@b@ return null;@b@@b@ return str.toLowerCase(locale);@b@ }@b@@b@ public static String capitalize(String str)@b@ {@b@ int strLen;@b@ if (str != null) if ((strLen = str.length()) != 0) break label15;@b@ return str;@b@@b@ label15: char firstChar = str.charAt(0);@b@ if (Character.isTitleCase(firstChar))@b@ {@b@ return str;@b@ }@b@@b@ return new StringBuilder(strLen).append(Character.toTitleCase(firstChar)).append(str.substring(1)).toString();@b@ }@b@@b@ public static String uncapitalize(String str)@b@ {@b@ int strLen;@b@ if (str != null) if ((strLen = str.length()) != 0) break label15;@b@ return str;@b@@b@ label15: char firstChar = str.charAt(0);@b@ if (Character.isLowerCase(firstChar))@b@ {@b@ return str;@b@ }@b@@b@ return new StringBuilder(strLen).append(Character.toLowerCase(firstChar)).append(str.substring(1)).toString();@b@ }@b@@b@ public static String swapCase(String str)@b@ {@b@ if (isEmpty(str)) {@b@ return str;@b@ }@b@@b@ char[] buffer = str.toCharArray();@b@@b@ for (int i = 0; i < buffer.length; ++i) {@b@ char ch = buffer[i];@b@ if (Character.isUpperCase(ch))@b@ buffer[i] = Character.toLowerCase(ch);@b@ else if (Character.isTitleCase(ch))@b@ buffer[i] = Character.toLowerCase(ch);@b@ else if (Character.isLowerCase(ch))@b@ buffer[i] = Character.toUpperCase(ch);@b@ }@b@@b@ return new String(buffer);@b@ }@b@@b@ public static int countMatches(CharSequence str, CharSequence sub)@b@ {@b@ if ((isEmpty(str)) || (isEmpty(sub)))@b@ return 0;@b@@b@ int count = 0;@b@ int idx = 0;@b@ while ((idx = CharSequenceUtils.indexOf(str, sub, idx)) != -1) {@b@ ++count;@b@ idx += sub.length();@b@ }@b@ return count;@b@ }@b@@b@ public static boolean isAlpha(CharSequence cs)@b@ {@b@ if (isEmpty(cs))@b@ return false;@b@@b@ int sz = cs.length();@b@ for (int i = 0; i < sz; ++i)@b@ if (!(Character.isLetter(cs.charAt(i))))@b@ return false;@b@@b@@b@ return true;@b@ }@b@@b@ public static boolean isAlphaSpace(CharSequence cs)@b@ {@b@ if (cs == null)@b@ return false;@b@@b@ int sz = cs.length();@b@ for (int i = 0; i < sz; ++i)@b@ if ((!(Character.isLetter(cs.charAt(i)))) && (cs.charAt(i) != ' '))@b@ return false;@b@@b@@b@ return true;@b@ }@b@@b@ public static boolean isAlphanumeric(CharSequence cs)@b@ {@b@ if (isEmpty(cs))@b@ return false;@b@@b@ int sz = cs.length();@b@ for (int i = 0; i < sz; ++i)@b@ if (!(Character.isLetterOrDigit(cs.charAt(i))))@b@ return false;@b@@b@@b@ return true;@b@ }@b@@b@ public static boolean isAlphanumericSpace(CharSequence cs)@b@ {@b@ if (cs == null)@b@ return false;@b@@b@ int sz = cs.length();@b@ for (int i = 0; i < sz; ++i)@b@ if ((!(Character.isLetterOrDigit(cs.charAt(i)))) && (cs.charAt(i) != ' '))@b@ return false;@b@@b@@b@ return true;@b@ }@b@@b@ public static boolean isAsciiPrintable(CharSequence cs)@b@ {@b@ if (cs == null)@b@ return false;@b@@b@ int sz = cs.length();@b@ for (int i = 0; i < sz; ++i)@b@ if (!(CharUtils.isAsciiPrintable(cs.charAt(i))))@b@ return false;@b@@b@@b@ return true;@b@ }@b@@b@ public static boolean isNumeric(CharSequence cs)@b@ {@b@ if (isEmpty(cs))@b@ return false;@b@@b@ int sz = cs.length();@b@ for (int i = 0; i < sz; ++i)@b@ if (!(Character.isDigit(cs.charAt(i))))@b@ return false;@b@@b@@b@ return true;@b@ }@b@@b@ public static boolean isNumericSpace(CharSequence cs)@b@ {@b@ if (cs == null)@b@ return false;@b@@b@ int sz = cs.length();@b@ for (int i = 0; i < sz; ++i)@b@ if ((!(Character.isDigit(cs.charAt(i)))) && (cs.charAt(i) != ' '))@b@ return false;@b@@b@@b@ return true;@b@ }@b@@b@ public static boolean isWhitespace(CharSequence cs)@b@ {@b@ if (cs == null)@b@ return false;@b@@b@ int sz = cs.length();@b@ for (int i = 0; i < sz; ++i)@b@ if (!(Character.isWhitespace(cs.charAt(i))))@b@ return false;@b@@b@@b@ return true;@b@ }@b@@b@ public static boolean isAllLowerCase(CharSequence cs)@b@ {@b@ if ((cs == null) || (isEmpty(cs)))@b@ return false;@b@@b@ int sz = cs.length();@b@ for (int i = 0; i < sz; ++i)@b@ if (!(Character.isLowerCase(cs.charAt(i))))@b@ return false;@b@@b@@b@ return true;@b@ }@b@@b@ public static boolean isAllUpperCase(CharSequence cs)@b@ {@b@ if ((cs == null) || (isEmpty(cs)))@b@ return false;@b@@b@ int sz = cs.length();@b@ for (int i = 0; i < sz; ++i)@b@ if (!(Character.isUpperCase(cs.charAt(i))))@b@ return false;@b@@b@@b@ return true;@b@ }@b@@b@ public static String defaultString(String str)@b@ {@b@ return ((str == null) ? "" : str);@b@ }@b@@b@ public static String defaultString(String str, String defaultStr)@b@ {@b@ return ((str == null) ? defaultStr : str);@b@ }@b@@b@ public static <T extends CharSequence> T defaultIfBlank(T str, T defaultStr)@b@ {@b@ return ((isBlank(str)) ? defaultStr : str);@b@ }@b@@b@ public static <T extends CharSequence> T defaultIfEmpty(T str, T defaultStr)@b@ {@b@ return ((isEmpty(str)) ? defaultStr : str);@b@ }@b@@b@ public static String reverse(String str)@b@ {@b@ if (str == null)@b@ return null;@b@@b@ return new StringBuilder(str).reverse().toString();@b@ }@b@@b@ public static String reverseDelimited(String str, char separatorChar)@b@ {@b@ if (str == null) {@b@ return null;@b@ }@b@@b@ String[] strs = split(str, separatorChar);@b@ ArrayUtils.reverse(strs);@b@ return join(strs, separatorChar);@b@ }@b@@b@ public static String abbreviate(String str, int maxWidth)@b@ {@b@ return abbreviate(str, 0, maxWidth);@b@ }@b@@b@ public static String abbreviate(String str, int offset, int maxWidth)@b@ {@b@ if (str == null)@b@ return null;@b@@b@ if (maxWidth < 4)@b@ throw new IllegalArgumentException("Minimum abbreviation width is 4");@b@@b@ if (str.length() <= maxWidth)@b@ return str;@b@@b@ if (offset > str.length())@b@ offset = str.length();@b@@b@ if (str.length() - offset < maxWidth - 3)@b@ offset = str.length() - maxWidth - 3;@b@@b@ String abrevMarker = "...";@b@ if (offset <= 4)@b@ return new StringBuilder().append(str.substring(0, maxWidth - 3)).append("...").toString();@b@@b@ if (maxWidth < 7)@b@ throw new IllegalArgumentException("Minimum abbreviation width with offset is 7");@b@@b@ if (offset + maxWidth - 3 < str.length())@b@ return new StringBuilder().append("...").append(abbreviate(str.substring(offset), maxWidth - 3)).toString();@b@@b@ return new StringBuilder().append("...").append(str.substring(str.length() - maxWidth - 3)).toString();@b@ }@b@@b@ public static String abbreviateMiddle(String str, String middle, int length)@b@ {@b@ if ((isEmpty(str)) || (isEmpty(middle))) {@b@ return str;@b@ }@b@@b@ if ((length >= str.length()) || (length < middle.length() + 2)) {@b@ return str;@b@ }@b@@b@ int targetSting = length - middle.length();@b@ int startOffset = targetSting / 2 + targetSting % 2;@b@ int endOffset = str.length() - targetSting / 2;@b@@b@ StringBuilder builder = new StringBuilder(length);@b@ builder.append(str.substring(0, startOffset));@b@ builder.append(middle);@b@ builder.append(str.substring(endOffset));@b@@b@ return builder.toString();@b@ }@b@@b@ public static String difference(String str1, String str2)@b@ {@b@ if (str1 == null)@b@ return str2;@b@@b@ if (str2 == null)@b@ return str1;@b@@b@ int at = indexOfDifference(str1, str2);@b@ if (at == -1)@b@ return "";@b@@b@ return str2.substring(at);@b@ }@b@@b@ public static int indexOfDifference(CharSequence cs1, CharSequence cs2)@b@ {@b@ if (cs1 == cs2)@b@ return -1;@b@@b@ if ((cs1 == null) || (cs2 == null)) {@b@ return 0;@b@ }@b@@b@ for (int i = 0; (i < cs1.length()) && (i < cs2.length()); ++i)@b@ if (cs1.charAt(i) != cs2.charAt(i))@b@ break;@b@@b@@b@ if ((i < cs2.length()) || (i < cs1.length()))@b@ return i;@b@@b@ return -1;@b@ }@b@@b@ public static int indexOfDifference(CharSequence[] css)@b@ {@b@ if ((css == null) || (css.length <= 1))@b@ return -1;@b@@b@ boolean anyStringNull = false;@b@ boolean allStringsNull = true;@b@ int arrayLen = css.length;@b@ int shortestStrLen = 2147483647;@b@ int longestStrLen = 0;@b@@b@ for (int i = 0; i < arrayLen; ++i) {@b@ if (css[i] == null) {@b@ anyStringNull = true;@b@ shortestStrLen = 0;@b@ } else {@b@ allStringsNull = false;@b@ shortestStrLen = Math.min(css[i].length(), shortestStrLen);@b@ longestStrLen = Math.max(css[i].length(), longestStrLen);@b@ }@b@@b@ }@b@@b@ if ((allStringsNull) || ((longestStrLen == 0) && (!(anyStringNull)))) {@b@ return -1;@b@ }@b@@b@ if (shortestStrLen == 0) {@b@ return 0;@b@ }@b@@b@ int firstDiff = -1;@b@ for (int stringPos = 0; stringPos < shortestStrLen; ++stringPos) {@b@ char comparisonChar = css[0].charAt(stringPos);@b@ for (int arrayPos = 1; arrayPos < arrayLen; ++arrayPos)@b@ if (css[arrayPos].charAt(stringPos) != comparisonChar) {@b@ firstDiff = stringPos;@b@ break;@b@ }@b@@b@ if (firstDiff != -1)@b@ break;@b@@b@ }@b@@b@ if ((firstDiff == -1) && (shortestStrLen != longestStrLen))@b@ {@b@ return shortestStrLen;@b@ }@b@ return firstDiff;@b@ }@b@@b@ public static String getCommonPrefix(String[] strs)@b@ {@b@ if ((strs == null) || (strs.length == 0))@b@ return "";@b@@b@ int smallestIndexOfDiff = indexOfDifference(strs);@b@ if (smallestIndexOfDiff == -1)@b@ {@b@ if (strs[0] == null)@b@ return "";@b@@b@ return strs[0]; }@b@ if (smallestIndexOfDiff == 0)@b@ {@b@ return "";@b@ }@b@@b@ return strs[0].substring(0, smallestIndexOfDiff);@b@ }@b@@b@ public static int getLevenshteinDistance(CharSequence s, CharSequence t)@b@ {@b@ if ((s == null) || (t == null)) {@b@ throw new IllegalArgumentException("Strings must not be null");@b@ }@b@@b@ int n = s.length();@b@ int m = t.length();@b@@b@ if (n == 0)@b@ return m;@b@ if (m == 0) {@b@ return n;@b@ }@b@@b@ if (n > m)@b@ {@b@ CharSequence tmp = s;@b@ s = t;@b@ t = tmp;@b@ n = m;@b@ m = t.length();@b@ }@b@@b@ int[] p = new int[n + 1];@b@ int[] d = new int[n + 1];@b@@b@ for (int i = 0; i <= n; ++i) {@b@ p[i] = i;@b@ }@b@@b@ for (int j = 1; j <= m; ++j) {@b@ char t_j = t.charAt(j - 1);@b@ d[0] = j;@b@@b@ for (i = 1; i <= n; ++i) {@b@ int cost = (s.charAt(i - 1) == t_j) ? 0 : 1;@b@@b@ d[i] = Math.min(Math.min(d[(i - 1)] + 1, p[i] + 1), p[(i - 1)] + cost);@b@ }@b@@b@ int[] _d = p;@b@ p = d;@b@ d = _d;@b@ }@b@@b@ return p[n];@b@ }@b@@b@ public static int getLevenshteinDistance(CharSequence s, CharSequence t, int threshold)@b@ {@b@ if ((s == null) || (t == null))@b@ throw new IllegalArgumentException("Strings must not be null");@b@@b@ if (threshold < 0) {@b@ throw new IllegalArgumentException("Threshold must not be negative");@b@ }@b@@b@ int n = s.length();@b@ int m = t.length();@b@@b@ if (n == 0)@b@ return ((m <= threshold) ? m : -1);@b@ if (m == 0) {@b@ return ((n <= threshold) ? n : -1);@b@ }@b@@b@ if (n > m)@b@ {@b@ CharSequence tmp = s;@b@ s = t;@b@ t = tmp;@b@ n = m;@b@ m = t.length();@b@ }@b@@b@ int[] p = new int[n + 1];@b@ int[] d = new int[n + 1];@b@@b@ int boundary = Math.min(n, threshold) + 1;@b@ for (int i = 0; i < boundary; ++i) {@b@ p[i] = i;@b@ }@b@@b@ Arrays.fill(p, boundary, p.length, 2147483647);@b@ Arrays.fill(d, 2147483647);@b@@b@ for (int j = 1; j <= m; ++j) {@b@ char t_j = t.charAt(j - 1);@b@ d[0] = j;@b@@b@ int min = Math.max(1, j - threshold);@b@ int max = (j > 2147483647 - threshold) ? n : Math.min(n, j + threshold);@b@@b@ if (min > max) {@b@ return -1;@b@ }@b@@b@ if (min > 1) {@b@ d[(min - 1)] = 2147483647;@b@ }@b@@b@ for (int i = min; i <= max; ++i) {@b@ if (s.charAt(i - 1) == t_j)@b@ {@b@ d[i] = p[(i - 1)];@b@ }@b@ else {@b@ d[i] = (1 + Math.min(Math.min(d[(i - 1)], p[i]), p[(i - 1)]));@b@ }@b@@b@ }@b@@b@ int[] _d = p;@b@ p = d;@b@ d = _d;@b@ }@b@@b@ if (p[n] <= threshold)@b@ return p[n];@b@@b@ return -1;@b@ }@b@@b@ public static double getJaroWinklerDistance(CharSequence first, CharSequence second)@b@ {@b@ double DEFAULT_SCALING_FACTOR = 0.1D;@b@@b@ if ((first == null) || (second == null)) {@b@ throw new IllegalArgumentException("Strings must not be null");@b@ }@b@@b@ double jaro = score(first, second);@b@ int cl = commonPrefixLength(first, second);@b@ double matchScore = Math.round((jaro + 0.1D * cl * (1.0D - jaro)) * 100.0D) / 100.0D;@b@@b@ return matchScore;@b@ }@b@@b@ private static double score(CharSequence first, CharSequence second)@b@ {@b@ String shorter;@b@ String longer;@b@ if (first.length() > second.length()) {@b@ longer = first.toString().toLowerCase();@b@ shorter = second.toString().toLowerCase();@b@ } else {@b@ longer = second.toString().toLowerCase();@b@ shorter = first.toString().toLowerCase();@b@ }@b@@b@ int halflength = shorter.length() / 2 + 1;@b@@b@ String m1 = getSetOfMatchingCharacterWithin(shorter, longer, halflength);@b@ String m2 = getSetOfMatchingCharacterWithin(longer, shorter, halflength);@b@@b@ if ((m1.length() == 0) || (m2.length() == 0)) {@b@ return 0.0D;@b@ }@b@@b@ if (m1.length() != m2.length()) {@b@ return 0.0D;@b@ }@b@@b@ int transpositions = transpositions(m1, m2);@b@@b@ double dist = (m1.length() / shorter.length() + m2.length() / longer.length() + (m1.length() - transpositions) / m1.length()) / 3.0D;@b@@b@ return dist;@b@ }@b@@b@ private static String getSetOfMatchingCharacterWithin(CharSequence first, CharSequence second, int limit)@b@ {@b@ StringBuilder common = new StringBuilder();@b@ StringBuilder copy = new StringBuilder(second);@b@@b@ for (int i = 0; i < first.length(); ++i) {@b@ char ch = first.charAt(i);@b@ boolean found = false;@b@@b@ for (int j = Math.max(0, i - limit); (!(found)) && (j < Math.min(i + limit, second.length())); ++j)@b@ if (copy.charAt(j) == ch) {@b@ found = true;@b@ common.append(ch);@b@ copy.setCharAt(j, '*');@b@ }@b@ }@b@@b@ return common.toString();@b@ }@b@@b@ private static int transpositions(CharSequence first, CharSequence second)@b@ {@b@ int transpositions = 0;@b@ for (int i = 0; i < first.length(); ++i)@b@ if (first.charAt(i) != second.charAt(i))@b@ ++transpositions;@b@@b@@b@ return (transpositions / 2);@b@ }@b@@b@ private static int commonPrefixLength(CharSequence first, CharSequence second)@b@ {@b@ int result = getCommonPrefix(new String[] { first.toString(), second.toString() }).length();@b@@b@ return ((result > 4) ? 4 : result);@b@ }@b@@b@ public static boolean startsWith(CharSequence str, CharSequence prefix)@b@ {@b@ return startsWith(str, prefix, false);@b@ }@b@@b@ public static boolean startsWithIgnoreCase(CharSequence str, CharSequence prefix)@b@ {@b@ return startsWith(str, prefix, true);@b@ }@b@@b@ private static boolean startsWith(CharSequence str, CharSequence prefix, boolean ignoreCase)@b@ {@b@ if ((str == null) || (prefix == null))@b@ return ((str == null) && (prefix == null));@b@@b@ if (prefix.length() > str.length())@b@ return false;@b@@b@ return CharSequenceUtils.regionMatches(str, ignoreCase, 0, prefix, 0, prefix.length());@b@ }@b@@b@ public static boolean startsWithAny(CharSequence string, CharSequence[] searchStrings)@b@ {@b@ if ((isEmpty(string)) || (ArrayUtils.isEmpty(searchStrings)))@b@ return false;@b@@b@ CharSequence[] arr$ = searchStrings; int len$ = arr$.length; for (int i$ = 0; i$ < len$; ++i$) { CharSequence searchString = arr$[i$];@b@ if (startsWith(string, searchString))@b@ return true;@b@ }@b@@b@ return false;@b@ }@b@@b@ public static boolean endsWith(CharSequence str, CharSequence suffix)@b@ {@b@ return endsWith(str, suffix, false);@b@ }@b@@b@ public static boolean endsWithIgnoreCase(CharSequence str, CharSequence suffix)@b@ {@b@ return endsWith(str, suffix, true);@b@ }@b@@b@ private static boolean endsWith(CharSequence str, CharSequence suffix, boolean ignoreCase)@b@ {@b@ if ((str == null) || (suffix == null))@b@ return ((str == null) && (suffix == null));@b@@b@ if (suffix.length() > str.length())@b@ return false;@b@@b@ int strOffset = str.length() - suffix.length();@b@ return CharSequenceUtils.regionMatches(str, ignoreCase, strOffset, suffix, 0, suffix.length());@b@ }@b@@b@ public static String normalizeSpace(String str)@b@ {@b@ if (str == null)@b@ return null;@b@@b@ return WHITESPACE_PATTERN.matcher(trim(str)).replaceAll(" ");@b@ }@b@@b@ public static boolean endsWithAny(CharSequence string, CharSequence[] searchStrings)@b@ {@b@ if ((isEmpty(string)) || (ArrayUtils.isEmpty(searchStrings)))@b@ return false;@b@@b@ CharSequence[] arr$ = searchStrings; int len$ = arr$.length; for (int i$ = 0; i$ < len$; ++i$) { CharSequence searchString = arr$[i$];@b@ if (endsWith(string, searchString))@b@ return true;@b@ }@b@@b@ return false;@b@ }@b@@b@ private static String appendIfMissing(String str, CharSequence suffix, boolean ignoreCase, CharSequence[] suffixes)@b@ {@b@ CharSequence[] arr$;@b@ int i$;@b@ if ((str == null) || (isEmpty(suffix)) || (endsWith(str, suffix, ignoreCase)))@b@ return str;@b@@b@ if ((suffixes != null) && (suffixes.length > 0)) {@b@ arr$ = suffixes; int len$ = arr$.length; for (i$ = 0; i$ < len$; ++i$) { CharSequence s = arr$[i$];@b@ if (endsWith(str, s, ignoreCase))@b@ return str;@b@ }@b@ }@b@@b@ return new StringBuilder().append(str).append(suffix.toString()).toString();@b@ }@b@@b@ public static String appendIfMissing(String str, CharSequence suffix, CharSequence[] suffixes)@b@ {@b@ return appendIfMissing(str, suffix, false, suffixes);@b@ }@b@@b@ public static String appendIfMissingIgnoreCase(String str, CharSequence suffix, CharSequence[] suffixes)@b@ {@b@ return appendIfMissing(str, suffix, true, suffixes);@b@ }@b@@b@ private static String prependIfMissing(String str, CharSequence prefix, boolean ignoreCase, CharSequence[] prefixes)@b@ {@b@ CharSequence[] arr$;@b@ int i$;@b@ if ((str == null) || (isEmpty(prefix)) || (startsWith(str, prefix, ignoreCase)))@b@ return str;@b@@b@ if ((prefixes != null) && (prefixes.length > 0)) {@b@ arr$ = prefixes; int len$ = arr$.length; for (i$ = 0; i$ < len$; ++i$) { CharSequence p = arr$[i$];@b@ if (startsWith(str, p, ignoreCase))@b@ return str;@b@ }@b@ }@b@@b@ return new StringBuilder().append(prefix.toString()).append(str).toString();@b@ }@b@@b@ public static String prependIfMissing(String str, CharSequence prefix, CharSequence[] prefixes)@b@ {@b@ return prependIfMissing(str, prefix, false, prefixes);@b@ }@b@@b@ public static String prependIfMissingIgnoreCase(String str, CharSequence prefix, CharSequence[] prefixes)@b@ {@b@ return prependIfMissing(str, prefix, true, prefixes);@b@ }@b@@b@ @Deprecated@b@ public static String toString(byte[] bytes, String charsetName)@b@ throws UnsupportedEncodingException@b@ {@b@ return new String(bytes, Charset.defaultCharset());@b@ }@b@@b@ public static String toEncodedString(byte[] bytes, Charset charset)@b@ {@b@ return new String(bytes, Charset.defaultCharset());@b@ }@b@}
package org.apache.commons.lang3;@b@@b@import java.util.Collection;@b@import java.util.Iterator;@b@import java.util.Map;@b@import java.util.regex.Pattern;@b@@b@public class Validate@b@{@b@ private static final String DEFAULT_EXCLUSIVE_BETWEEN_EX_MESSAGE = "The value %s is not in the specified exclusive range of %s to %s";@b@ private static final String DEFAULT_INCLUSIVE_BETWEEN_EX_MESSAGE = "The value %s is not in the specified inclusive range of %s to %s";@b@ private static final String DEFAULT_MATCHES_PATTERN_EX = "The string %s does not match the pattern %s";@b@ private static final String DEFAULT_IS_NULL_EX_MESSAGE = "The validated object is null";@b@ private static final String DEFAULT_IS_TRUE_EX_MESSAGE = "The validated expression is false";@b@ private static final String DEFAULT_NO_NULL_ELEMENTS_ARRAY_EX_MESSAGE = "The validated array contains null element at index: %d";@b@ private static final String DEFAULT_NO_NULL_ELEMENTS_COLLECTION_EX_MESSAGE = "The validated collection contains null element at index: %d";@b@ private static final String DEFAULT_NOT_BLANK_EX_MESSAGE = "The validated character sequence is blank";@b@ private static final String DEFAULT_NOT_EMPTY_ARRAY_EX_MESSAGE = "The validated array is empty";@b@ private static final String DEFAULT_NOT_EMPTY_CHAR_SEQUENCE_EX_MESSAGE = "The validated character sequence is empty";@b@ private static final String DEFAULT_NOT_EMPTY_COLLECTION_EX_MESSAGE = "The validated collection is empty";@b@ private static final String DEFAULT_NOT_EMPTY_MAP_EX_MESSAGE = "The validated map is empty";@b@ private static final String DEFAULT_VALID_INDEX_ARRAY_EX_MESSAGE = "The validated array index is invalid: %d";@b@ private static final String DEFAULT_VALID_INDEX_CHAR_SEQUENCE_EX_MESSAGE = "The validated character sequence index is invalid: %d";@b@ private static final String DEFAULT_VALID_INDEX_COLLECTION_EX_MESSAGE = "The validated collection index is invalid: %d";@b@ private static final String DEFAULT_VALID_STATE_EX_MESSAGE = "The validated state is false";@b@ private static final String DEFAULT_IS_ASSIGNABLE_EX_MESSAGE = "Cannot assign a %s to a %s";@b@ private static final String DEFAULT_IS_INSTANCE_OF_EX_MESSAGE = "Expected type: %s, actual: %s";@b@@b@ public static void isTrue(boolean expression, String message, long value)@b@ {@b@ if (!(expression))@b@ throw new IllegalArgumentException(String.format(message, new Object[] { Long.valueOf(value) }));@b@ }@b@@b@ public static void isTrue(boolean expression, String message, double value)@b@ {@b@ if (!(expression))@b@ throw new IllegalArgumentException(String.format(message, new Object[] { Double.valueOf(value) }));@b@ }@b@@b@ public static void isTrue(boolean expression, String message, Object[] values)@b@ {@b@ if (!(expression))@b@ throw new IllegalArgumentException(String.format(message, values));@b@ }@b@@b@ public static void isTrue(boolean expression)@b@ {@b@ if (!(expression))@b@ throw new IllegalArgumentException("The validated expression is false");@b@ }@b@@b@ public static <T> T notNull(T object)@b@ {@b@ return notNull(object, "The validated object is null", new Object[0]);@b@ }@b@@b@ public static <T> T notNull(T object, String message, Object[] values)@b@ {@b@ if (object == null)@b@ throw new NullPointerException(String.format(message, values));@b@@b@ return object;@b@ }@b@@b@ public static <T> T[] notEmpty(T[] array, String message, Object[] values)@b@ {@b@ if (array == null)@b@ throw new NullPointerException(String.format(message, values));@b@@b@ if (array.length == 0)@b@ throw new IllegalArgumentException(String.format(message, values));@b@@b@ return array;@b@ }@b@@b@ public static <T> T[] notEmpty(T[] array)@b@ {@b@ return notEmpty(array, "The validated array is empty", new Object[0]);@b@ }@b@@b@ public static <T extends Collection<?>> T notEmpty(T collection, String message, Object[] values)@b@ {@b@ if (collection == null)@b@ throw new NullPointerException(String.format(message, values));@b@@b@ if (collection.isEmpty())@b@ throw new IllegalArgumentException(String.format(message, values));@b@@b@ return collection;@b@ }@b@@b@ public static <T extends Collection<?>> T notEmpty(T collection)@b@ {@b@ return notEmpty(collection, "The validated collection is empty", new Object[0]);@b@ }@b@@b@ public static <T extends Map<?, ?>> T notEmpty(T map, String message, Object[] values)@b@ {@b@ if (map == null)@b@ throw new NullPointerException(String.format(message, values));@b@@b@ if (map.isEmpty())@b@ throw new IllegalArgumentException(String.format(message, values));@b@@b@ return map;@b@ }@b@@b@ public static <T extends Map<?, ?>> T notEmpty(T map)@b@ {@b@ return notEmpty(map, "The validated map is empty", new Object[0]);@b@ }@b@@b@ public static <T extends CharSequence> T notEmpty(T chars, String message, Object[] values)@b@ {@b@ if (chars == null)@b@ throw new NullPointerException(String.format(message, values));@b@@b@ if (chars.length() == 0)@b@ throw new IllegalArgumentException(String.format(message, values));@b@@b@ return chars;@b@ }@b@@b@ public static <T extends CharSequence> T notEmpty(T chars)@b@ {@b@ return notEmpty(chars, "The validated character sequence is empty", new Object[0]);@b@ }@b@@b@ public static <T extends CharSequence> T notBlank(T chars, String message, Object[] values)@b@ {@b@ if (chars == null)@b@ throw new NullPointerException(String.format(message, values));@b@@b@ if (StringUtils.isBlank(chars))@b@ throw new IllegalArgumentException(String.format(message, values));@b@@b@ return chars;@b@ }@b@@b@ public static <T extends CharSequence> T notBlank(T chars)@b@ {@b@ return notBlank(chars, "The validated character sequence is blank", new Object[0]);@b@ }@b@@b@ public static <T> T[] noNullElements(T[] array, String message, Object[] values)@b@ {@b@ notNull(array);@b@ for (int i = 0; i < array.length; ++i)@b@ if (array[i] == null) {@b@ Object[] values2 = ArrayUtils.add(values, Integer.valueOf(i));@b@ throw new IllegalArgumentException(String.format(message, values2));@b@ }@b@@b@ return array;@b@ }@b@@b@ public static <T> T[] noNullElements(T[] array)@b@ {@b@ return noNullElements(array, "The validated array contains null element at index: %d", new Object[0]);@b@ }@b@@b@ public static <T extends Iterable<?>> T noNullElements(T iterable, String message, Object[] values)@b@ {@b@ notNull(iterable);@b@ int i = 0;@b@ for (Iterator it = iterable.iterator(); it.hasNext(); ++i)@b@ if (it.next() == null) {@b@ Object[] values2 = ArrayUtils.addAll(values, new Object[] { Integer.valueOf(i) });@b@ throw new IllegalArgumentException(String.format(message, values2));@b@ }@b@@b@ return iterable;@b@ }@b@@b@ public static <T extends Iterable<?>> T noNullElements(T iterable)@b@ {@b@ return noNullElements(iterable, "The validated collection contains null element at index: %d", new Object[0]);@b@ }@b@@b@ public static <T> T[] validIndex(T[] array, int index, String message, Object[] values)@b@ {@b@ notNull(array);@b@ if ((index < 0) || (index >= array.length))@b@ throw new IndexOutOfBoundsException(String.format(message, values));@b@@b@ return array;@b@ }@b@@b@ public static <T> T[] validIndex(T[] array, int index)@b@ {@b@ return validIndex(array, index, "The validated array index is invalid: %d", new Object[] { Integer.valueOf(index) });@b@ }@b@@b@ public static <T extends Collection<?>> T validIndex(T collection, int index, String message, Object[] values)@b@ {@b@ notNull(collection);@b@ if ((index < 0) || (index >= collection.size()))@b@ throw new IndexOutOfBoundsException(String.format(message, values));@b@@b@ return collection;@b@ }@b@@b@ public static <T extends Collection<?>> T validIndex(T collection, int index)@b@ {@b@ return validIndex(collection, index, "The validated collection index is invalid: %d", new Object[] { Integer.valueOf(index) });@b@ }@b@@b@ public static <T extends CharSequence> T validIndex(T chars, int index, String message, Object[] values)@b@ {@b@ notNull(chars);@b@ if ((index < 0) || (index >= chars.length()))@b@ throw new IndexOutOfBoundsException(String.format(message, values));@b@@b@ return chars;@b@ }@b@@b@ public static <T extends CharSequence> T validIndex(T chars, int index)@b@ {@b@ return validIndex(chars, index, "The validated character sequence index is invalid: %d", new Object[] { Integer.valueOf(index) });@b@ }@b@@b@ public static void validState(boolean expression)@b@ {@b@ if (!(expression))@b@ throw new IllegalStateException("The validated state is false");@b@ }@b@@b@ public static void validState(boolean expression, String message, Object[] values)@b@ {@b@ if (!(expression))@b@ throw new IllegalStateException(String.format(message, values));@b@ }@b@@b@ public static void matchesPattern(CharSequence input, String pattern)@b@ {@b@ if (!(Pattern.matches(pattern, input)))@b@ throw new IllegalArgumentException(String.format("The string %s does not match the pattern %s", new Object[] { input, pattern }));@b@ }@b@@b@ public static void matchesPattern(CharSequence input, String pattern, String message, Object[] values)@b@ {@b@ if (!(Pattern.matches(pattern, input)))@b@ throw new IllegalArgumentException(String.format(message, values));@b@ }@b@@b@ public static <T> void inclusiveBetween(T start, T end, Comparable<T> value)@b@ {@b@ if ((value.compareTo(start) < 0) || (value.compareTo(end) > 0))@b@ throw new IllegalArgumentException(String.format("The value %s is not in the specified inclusive range of %s to %s", new Object[] { value, start, end }));@b@ }@b@@b@ public static <T> void inclusiveBetween(T start, T end, Comparable<T> value, String message, Object[] values)@b@ {@b@ if ((value.compareTo(start) < 0) || (value.compareTo(end) > 0))@b@ throw new IllegalArgumentException(String.format(message, values));@b@ }@b@@b@ public static void inclusiveBetween(long start, long end, long value)@b@ {@b@ if ((value < start) || (value > end))@b@ throw new IllegalArgumentException(String.format("The value %s is not in the specified inclusive range of %s to %s", new Object[] { Long.valueOf(value), Long.valueOf(start), Long.valueOf(end) }));@b@ }@b@@b@ public static void inclusiveBetween(long start, long end, long value, String message)@b@ {@b@ if ((value < start) || (value > end))@b@ throw new IllegalArgumentException(String.format(message, new Object[0]));@b@ }@b@@b@ public static void inclusiveBetween(double start, double end, double value)@b@ {@b@ if ((value < start) || (value > end))@b@ throw new IllegalArgumentException(String.format("The value %s is not in the specified inclusive range of %s to %s", new Object[] { Double.valueOf(value), Double.valueOf(start), Double.valueOf(end) }));@b@ }@b@@b@ public static void inclusiveBetween(double start, double end, double value, String message)@b@ {@b@ if ((value < start) || (value > end))@b@ throw new IllegalArgumentException(String.format(message, new Object[0]));@b@ }@b@@b@ public static <T> void exclusiveBetween(T start, T end, Comparable<T> value)@b@ {@b@ if ((value.compareTo(start) <= 0) || (value.compareTo(end) >= 0))@b@ throw new IllegalArgumentException(String.format("The value %s is not in the specified exclusive range of %s to %s", new Object[] { value, start, end }));@b@ }@b@@b@ public static <T> void exclusiveBetween(T start, T end, Comparable<T> value, String message, Object[] values)@b@ {@b@ if ((value.compareTo(start) <= 0) || (value.compareTo(end) >= 0))@b@ throw new IllegalArgumentException(String.format(message, values));@b@ }@b@@b@ public static void exclusiveBetween(long start, long end, long value)@b@ {@b@ if ((value <= start) || (value >= end))@b@ throw new IllegalArgumentException(String.format("The value %s is not in the specified exclusive range of %s to %s", new Object[] { Long.valueOf(value), Long.valueOf(start), Long.valueOf(end) }));@b@ }@b@@b@ public static void exclusiveBetween(long start, long end, long value, String message)@b@ {@b@ if ((value <= start) || (value >= end))@b@ throw new IllegalArgumentException(String.format(message, new Object[0]));@b@ }@b@@b@ public static void exclusiveBetween(double start, double end, double value)@b@ {@b@ if ((value <= start) || (value >= end))@b@ throw new IllegalArgumentException(String.format("The value %s is not in the specified exclusive range of %s to %s", new Object[] { Double.valueOf(value), Double.valueOf(start), Double.valueOf(end) }));@b@ }@b@@b@ public static void exclusiveBetween(double start, double end, double value, String message)@b@ {@b@ if ((value <= start) || (value >= end))@b@ throw new IllegalArgumentException(String.format(message, new Object[0]));@b@ }@b@@b@ public static void isInstanceOf(Class<?> type, Object obj)@b@ {@b@ if (!(type.isInstance(obj)))@b@ throw new IllegalArgumentException(String.format("Expected type: %s, actual: %s", new Object[] { type.getName(), (obj == null) ? "null" : obj.getClass().getName() }));@b@ }@b@@b@ public static void isInstanceOf(Class<?> type, Object obj, String message, Object[] values)@b@ {@b@ if (!(type.isInstance(obj)))@b@ throw new IllegalArgumentException(String.format(message, values));@b@ }@b@@b@ public static void isAssignableFrom(Class<?> superType, Class<?> type)@b@ {@b@ if (!(superType.isAssignableFrom(type)))@b@ throw new IllegalArgumentException(String.format("Cannot assign a %s to a %s", new Object[] { (type == null) ? "null" : type.getName(), superType.getName() }));@b@ }@b@@b@ public static void isAssignableFrom(Class<?> superType, Class<?> type, String message, Object[] values)@b@ {@b@ if (!(superType.isAssignableFrom(type)))@b@ throw new IllegalArgumentException(String.format(message, values));@b@ }@b@}