public Object toObject ( final String pString , final Class pType , final String pFormat ) throws ConversionException { if ( StringUtil . isEmpty ( pString ) ) { return null ; } try { if ( pType . equals ( BigInteger . class ) ) { return new BigInteger ( pString ) ; // No format? } if ( pType . equals ( BigDecimal . class ) ) { return new BigDecimal ( pString ) ; // No format? } NumberFormat format ; if ( pFormat == null ) { // Use system default format, using default locale format = sDefaultFormat ; } else { // Get format from cache format = getNumberFormat ( pFormat ) ; } Number num ; synchronized ( format ) { num = format . parse ( pString ) ; } if ( pType == Integer . TYPE || pType == Integer . class ) { return num . intValue ( ) ; } else if ( pType == Long . TYPE || pType == Long . class ) { return num . longValue ( ) ; } else if ( pType == Double . TYPE || pType == Double . class ) { return num . doubleValue ( ) ; } else if ( pType == Float . TYPE || pType == Float . class ) { return num . floatValue ( ) ; } else if ( pType == Byte . TYPE || pType == Byte . class ) { return num . byteValue ( ) ; } else if ( pType == Short . TYPE || pType == Short . class ) { return num . shortValue ( ) ; } return num ; } catch ( ParseException pe ) { throw new ConversionException ( pe ) ; } catch ( RuntimeException rte ) { throw new ConversionException ( rte ) ; } }
Converts the string to a number using the given format for parsing .