in extensions/commons-csv/src/main/java/org/apache/batchee/csv/mapper/Primitives.java [111:144]
public Object valueFor(final Class<?> type, final String value) {
final Method valueOf = Mapping.PRIMITIVES.get(type);
if (valueOf != null) {
if (value == null || value.trim().isEmpty()) {
return Mapping.PRIMITIVE_DEFAULTS.get(type);
}
try {
return valueOf.invoke(null, value);
} catch (final IllegalAccessException e) {
throw new IllegalArgumentException(e);
} catch (InvocationTargetException e) {
throw new IllegalArgumentException(e.getCause());
}
} else if (char.class == type) {
if (value == null || value.trim().isEmpty()) {
return Mapping.PRIMITIVE_DEFAULTS.get(type);
}
return value.charAt(0);
}
if (value == null) {
return null;
}
final Class<?> currentType = value.getClass();
final Class<?> primitive = Mapping.WRAPPERS.get(currentType);
if (primitive != null && type == primitive) {
return Mapping.CONVERTERS.get(currentType).convert(value);
}
return null;
}