public static int toInt ( Object val ) { if ( val == null ) { return 0 ; } if ( val instanceof Number ) { return ( ( Number ) val ) . intValue ( ) ; } if ( val instanceof String ) { return Integer . parseInt ( ( String ) val ) ; } throw new IllegalArgumentException ( "Cannot convert " + val ) ; }
Converts the parameter to an integer value if possible . Throws an IllegalArgumentException if the parameter cannot be converted to an integer .