public final class TypeConverter
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private static java.util.Map<java.lang.Class<?>,java.lang.Class<?>> |
PRIMITIVES
A map of primitive to objects.
|
private static java.lang.String |
VALUE_OF_METHOD |
| Modifier | Constructor and Description |
|---|---|
private |
TypeConverter() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.Boolean |
getBooleanValue(java.lang.String source)
Returns a Boolean value from a String.
|
static <T> T |
getType(java.lang.Class<T> targetType,
java.lang.String source)
A generic method that returns the
String as the specified Java type. |
private static <T> T |
getTypeViaStringConstructor(java.lang.String source,
java.lang.Class<T> targetType) |
static <T> T |
getTypeViaValueOfMethod(java.lang.String source,
java.lang.Class<T> targetType) |
static boolean |
isConvertable(java.lang.Class<?> targetType)
Tests if the class can safely be converted from a String to the
specified type.
|
private static final java.lang.String VALUE_OF_METHOD
private static final java.util.Map<java.lang.Class<?>,java.lang.Class<?>> PRIMITIVES
public static <T> T getType(java.lang.Class<T> targetType,
java.lang.String source)
String as the specified Java type.T - the type to returnsource - the string value to converttargetType - public static boolean isConvertable(java.lang.Class<?> targetType)
targetType - the type to convert topublic static java.lang.Boolean getBooleanValue(java.lang.String source)
Returns a Boolean value from a String. Unlike Boolean.#valueOf(String), this
method takes more String options. The following String values will return true:
While the following values will return false:
source - public static <T> T getTypeViaValueOfMethod(java.lang.String source,
java.lang.Class<T> targetType)
throws java.lang.NoSuchMethodException
T - source - targetType - java.lang.NoSuchMethodExceptionprivate static <T> T getTypeViaStringConstructor(java.lang.String source,
java.lang.Class<T> targetType)
T - source - targetType - java.lang.IllegalArgumentExceptionjava.lang.InstantiationExceptionjava.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetException