Parse a string to a value of the given class.

@param v
The string to parse.
@param cls
The class to parse it to.

@return The parsed value may be null.
9928
@SuppressWarnings("unchecked")
    private <T> T parseString(String v, Class<T> cls) {
        Object value;
        if (v == null || v.length() == 0) {
            value = null;
        } else if (cls == String.class) {
            value = v;
        } else if (cls == Boolean.class || cls == boolean.class) {
            if (v.equalsIgnoreCase("true")) {
                value = Boolean.TRUE;
            } else if (v.equalsIgnoreCase("false")) {
                value = Boolean.FALSE;
            } else {
                throw new IllegalStateException(
                        "Expected true/false, found text '" + v + "'.");
            }
        } else if (cls == Integer.class || cls == int.class) {
            value = Integer.valueOf(v);
        } else if (cls == Long.class || cls == long.class) {
            value = Long.valueOf(v);
        } else if (cls == Float.class || cls == float.class) {
            value = Float.valueOf(v);
        } else if (cls == Double.class || cls == double.class) {
            value = Double.valueOf(v);
        } else if (cls == BigDecimal.class) {
            value = new BigDecimal(v);
        } else if (XMLGregorianCalendar.class == cls) {
            value = MwsUtl.getDTF().newXMLGregorianCalendar(v);
        } else if (Enum.class.isAssignableFrom(cls)) {
            value = MwsUtl.getEnumValue(cls, v);
        } else {
            throw new IllegalArgumentException(String.format("Unable to parse String %s to Class %s", v, cls));
        }
        return (T) value;
    }
72150
@SuppressWarnings("unchecked")
        public static <T> ClassSup<T> cls(String clsName) {
                try {
                        return mapper.get(clsName, () -> (ClassSup<T>) cls(Class.forName(clsName)));
                } catch (Exception e) {
                        throw $(e);
                }
        }
341343
function stringToObject( classStr, Class ) {
			Class = Class || window;
			var classStrArr = classStr.split(".");
			for ( var n = 0; Class && n < classStrArr.length; n++) {
				Class = Class[classStrArr[n]];
			}
			return Class;
		}
207914
public static String getPackageName(final Class<?> cls) {
        if (cls == null) {
            return StringUtils.EMPTY;
        }
        return getPackageName(cls.getName());
    }
1013811
@SuppressWarnings("unchecked")
    private <T> TypedStringConverter<T> findConverterQuiet(final Class<T> cls) {
        if (cls == null) {
            throw new IllegalArgumentException("Class must not be null");
        }
        TypedStringConverter<T> conv = (TypedStringConverter<T>) registered.get(cls);
        if (conv == CACHED_NULL) {
            return null;
        }
        if (conv == null) {
            try {
                conv = findAnyConverter(cls);
            } catch (RuntimeException ex) {
                registered.putIfAbsent(cls, CACHED_NULL);
                throw ex;
            }
            if (conv == null) {
                registered.putIfAbsent(cls, CACHED_NULL);
                return null;
            }
            registered.putIfAbsent(cls, conv);
        }
        return conv;
    }
1051534
public static String valueToString(Object v) {
        if (v.getClass().isArray()) {
            if (v.getClass().getComponentType().isPrimitive()) {
                Class<?> c = v.getClass().getComponentType();
                if (c == int.class) {
                    return Arrays.toString((int[]) v);
                } else if (c == double.class) {
                    return Arrays.toString((double[]) v);
                } else if (c == float.class) {
                    return Arrays.toString((float[]) v);
                } else if (c == long.class) {
                    return Arrays.toString((long[]) v);
                } else if (c == byte.class) {
                    return Arrays.toString((byte[]) v);
                } else if (c == short.class) {
                    return Arrays.toString((short[]) v);
                } else {
                    return v.toString();
                }
            } else {
                return Arrays.toString((Object[]) v);
            }
        } else {
            return v.toString();
        }
    }
973692
private static Class _loadClass(ClassLoading cl, String className, Class defaultValue, Set<Throwable> exceptions) {
	className = className.trim();
	if (StringUtil.isEmpty(className)) return defaultValue;

	Class clazz = checkPrimaryTypesBytecodeDef(className, null);
	if (clazz != null) return clazz;

	// array in the format boolean[] or java.lang.String[]
	if (className.endsWith("[]")) {

	    StringBuilder pureCN = new StringBuilder(className);
	    int dimensions = 0;
	    do {
		pureCN.delete(pureCN.length() - 2, pureCN.length());
		dimensions++;
	    }
	    while (pureCN.lastIndexOf("[]") == pureCN.length() - 2);

	    clazz = __loadClass(cl, pureCN.toString(), null, exceptions);

	    if (clazz != null) {

		for (int i = 0; i < dimensions; i++)
		    clazz = toArrayClass(clazz);
		return clazz;
	    }
	}

	// array in the format [C or [Ljava.lang.String;
	else if (className.charAt(0) == '[') {

	    StringBuilder pureCN = new StringBuilder(className);
	    int dimensions = 0;

	    do {
		pureCN.delete(0, 1);
		dimensions++;
	    }
	    while (pureCN.charAt(0) == '[');

	    clazz = __loadClass(cl, pureCN.toString(), null, exceptions);
	    if (clazz != null) {
		for (int i = 0; i < dimensions; i++)
		    clazz = toArrayClass(clazz);
		return clazz;
	    }
	}
	return __loadClass(cl, className, defaultValue, exceptions);
    }
1192625
@SuppressWarnings("unchecked")
	public static <T> ValueArray<T> createValueArray(Class<? extends Value> cls) {
		if (ByteValue.class.isAssignableFrom(cls)) {
			return (ValueArray<T>) new ByteValueArray();
		} else if (CharValue.class.isAssignableFrom(cls)) {
			return (ValueArray<T>) new CharValueArray();
		} else if (DoubleValue.class.isAssignableFrom(cls)) {
			return (ValueArray<T>) new DoubleValueArray();
		} else if (FloatValue.class.isAssignableFrom(cls)) {
			return (ValueArray<T>) new FloatValueArray();
		} else if (IntValue.class.isAssignableFrom(cls)) {
			return (ValueArray<T>) new IntValueArray();
		} else if (LongValue.class.isAssignableFrom(cls)) {
			return (ValueArray<T>) new LongValueArray();
		} else if (NullValue.class.isAssignableFrom(cls)) {
			return (ValueArray<T>) new NullValueArray();
		} else if (ShortValue.class.isAssignableFrom(cls)) {
			return (ValueArray<T>) new ShortValueArray();
		} else if (StringValue.class.isAssignableFrom(cls)) {
			return (ValueArray<T>) new StringValueArray();
		} else {
			throw new IllegalArgumentException("Unable to create unbounded ValueArray for type " + cls);
		}
	}
732571
public <T> T readObject(Class<T> cls) {
    return kryo.readObject(input, cls);
  }
596224
public static final<E extends Enum> E getEnumValue(String str, Class<E> enumClass) {
        str = str.trim();
        if (StringUtils.isBlank(str)) return null;
        for (E e : enumClass.getEnumConstants()) {
            if (e.toString().equalsIgnoreCase(str)) return e;
        }
        throw new IllegalArgumentException("Invalid enum string provided for ["+enumClass+"]: " + str);
    }
252368
public <T> T parse(String input, Class<T> clazz) {
		try {
			if (String.class.equals(clazz)) {
				return (T) input;
			}

			StringParser<T> parser = getParser(clazz, input);
			if (parser == null) {
				throw new ParserException(String.format("Cannot parse to %s : %s", clazz.getName(), input));
			}

			return parser.parse(input);
		}
		catch (NumberFormatException e) {
			throw new ParserException(e.getMessage());
		}
	}
1252370
public static Object getParameterValueFromString(String parameterClass, String value) throws Exception {
	   return getParameterValueFromString(parameterClass, value, null);
   }
438110
@SuppressWarnings("unchecked")
    static <T> T getEnumValue(Class<T> cls, String name) {
        HashMap<String, Object> enumMap = enumMaps.get(cls);
        if (enumMap == null) {
            T[] consts = cls.getEnumConstants();
            enumMap = new HashMap<String, Object>(consts.length);
            for (T e : consts) {
                enumMap.put(((Enum<?>) e).toString(), e);
            }
            enumMaps.put(cls, enumMap);
        }
        T v = (T) enumMap.get(name);
        if (v == null) {
            v = (T) enumMap.get("Other");
        }
        return v;
    }
1092473
synchronized public Class toClass()
        throws ClassNotFoundException, UtilEvalError
    {
        if ( asClass != null )
            return asClass;

        reset();

        // "var" means untyped, return null class
        if ( evalName.equals("var") )
            return asClass = null;

        /* Try straightforward class name first */
        Class clas = namespace.getClass( evalName );

        if ( clas == null )
        {
            /*
                Try toObject() which knows how to work through inner classes
                and see what we end up with
            */
            Object obj = null;
            try {
                // Null interpreter and callstack references.
                // class only resolution should not require them.
                obj = toObject( null, null, true );
            } catch ( UtilEvalError  e ) { } // couldn't resolve it

            if ( obj instanceof ClassIdentifier )
                clas = ((ClassIdentifier)obj).getTargetClass();
        }

        if ( clas == null )
            throw new ClassNotFoundException(
                "Class: " + value+ " not found in namespace");

        asClass = clas;
        return asClass;
    }
994517
@SuppressWarnings("unchecked")
	public static @Nullable <T> T as(Object object, Class<T> cls) {
		return cls.isInstance(object) ? (T) object : null;
	}
380722
@Override
    public StringConverter<?> findConverter(Class<?> cls) {
        if (cls == Byte[].class) {
            return ByteArrayStringConverter.INSTANCE;
        }
        return null;
    }
219308
@Override
	public ZooClass getClass(Class<?> cls) {
		DBTracer.logCall(this, cls);
		checkValidityRead();
		return sm.locateSchema(cls, null);
	}