com.pastdev.httpcomponents.factory.ValueOfValueFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of server Show documentation
Show all versions of server Show documentation
A set of interfaces and factories for building servers.
The newest version!
package com.pastdev.httpcomponents.factory;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class ValueOfValueFactory {
public static T valueOf( String valueString, Class type ) {
if ( valueString == null || type == String.class ) {
return type.cast( valueString );
}
Method method;
try {
method = type.getDeclaredMethod( "valueOf", String.class );
return type.cast( method.invoke( null, valueString ) );
}
catch ( NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
throw new IllegalArgumentException( "Class " + type + " not supported", e );
}
}
}