public int toInteger ( Object val ) { if ( val == null ) { return 0 ; } else if ( val instanceof Double ) { if ( ! Double . isNaN ( ( ( Double ) val ) . doubleValue ( ) ) ) { return 0 ; } else { return ( ( Double ) val ) . intValue ( ) ; } } else if ( val instanceof Number ) { return ( ( Number ) val ) . intValue ( ) ; } else if ( val instanceof String ) { if ( "" . equals ( val ) ) { return 0 ; } return Integer . parseInt ( ( String ) val ) ; } else if ( val instanceof Boolean ) { return ( ( Boolean ) val ) . booleanValue ( ) ? 1 : 0 ; } else if ( val instanceof Character ) { return ( ( Character ) val ) . charValue ( ) ; } throw new ArithmeticException ( "Integer coercion: " + val . getClass ( ) . getName ( ) + ":(" + val + ")" ) ; }
Coerce to a int .