public static Integer toInteger ( Object value ) { if ( value == null ) { return null ; } else if ( value instanceof Integer ) { return ( Integer ) value ; } else if ( value instanceof Number ) { return ( ( Number ) value ) . intValue ( ) ; } else { try { return Integer . valueOf ( value . toString ( ) . trim ( ) ) ; } catch ( NumberFormatException e ) { throw new ConversionException ( "failed to convert: '" + value + "' to Integer" , e ) ; } } }
Converts value to Integer if it can . If value is a Integer it is returned if it is a Number it is promoted to Integer and then returned in all other cases it converts the value to String then tries to parse Integer from it .