public static Integer getIntegerSetting ( Map < String , Object > settings , String key , Integer defaultVal ) { final Object value = settings . get ( key ) ; if ( value == null ) { return defaultVal ; } if ( value instanceof Number ) { return ( ( Number ) value ) . intValue ( ) ; } if ( value instanceof String ) { try { return Integer . parseInt ( ( String ) value ) ; } catch ( NumberFormatException e ) { return defaultVal ; } } return defaultVal ; }
Gets an Integer value for the key returning the default value given if not specified or not a valid numeric value .