in openjpa-lib/src/main/java/org/apache/openjpa/lib/util/StringUtil.java [251:312]
public static <T> T parse(String val, Class<T> type) {
if (type == null) {
throw new NullPointerException("target type must not be null");
}
// handle primitives
if (type == byte.class) {
return (T) (val == null ? BYTE_ZERO : Byte.valueOf(val));
}
if (type == char.class) {
return (T) (val == null ? CHAR_ZERO : parseCharString(val));
}
if (type == double.class) {
return (T) (val == null ? DOUBLE_ZERO : Double.valueOf(val));
}
if (type == float.class) {
return (T) (val == null ? FLOAT_ZERO : Float.valueOf(val));
}
if (type == int.class) {
return (T) (val == null ? INTEGER_ZERO : Integer.valueOf(val));
}
if (type == long.class) {
return (T) (val == null ? LONG_ZERO : Long.valueOf(val));
}
if (type == short.class) {
return (T) (val == null ? SHORT_ZERO : Short.valueOf(val));
}
if (type == boolean.class) {
return (T) (val == null ? Boolean.FALSE : Boolean.valueOf(val));
}
if (type == void.class) {
throw new IllegalStateException("Cannot parse void type");
}
// handle wrapper types
if (type == Byte.class) {
return (T) (val == null ? null : Byte.valueOf(val));
}
if (type == Character.class) {
return (T) (val == null ? null : parseCharString(val));
}
if (type == Double.class) {
return (T) (val == null ? null : Double.valueOf(val));
}
if (type == Float.class) {
return (T) (val == null ? null : Float.valueOf(val));
}
if (type == Integer.class) {
return (T) (val == null ? null : Integer.valueOf(val));
}
if (type == Long.class) {
return (T) (val == null ? null : Long.valueOf(val));
}
if (type == Short.class) {
return (T) (val == null ? null : Short.valueOf(val));
}
if (type == Boolean.class) {
return (T) (val == null ? null : Boolean.valueOf(val));
}
throw new IllegalArgumentException("Unsupported type: " + type.getCanonicalName());
}