@ 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 ; }
Parse a string to a value of the given class .