static private < T > T parseInteger ( String s , Class < T > return_type ) { try { java . math . BigDecimal num = new java . math . BigDecimal ( s ) ; T result = ( T ) num . getClass ( ) . getDeclaredMethod ( return_type . getSimpleName ( ) + "ValueExact" , new Class [ 0 ] ) . invoke ( num ) ; return result ; } catch ( InvocationTargetException ite ) { throw new NumberFormatException ( "The expression's numeric value is out of the range of type " + return_type . getSimpleName ( ) ) ; } catch ( NoSuchMethodException nsme ) { throw new IllegalArgumentException ( return_type . getSimpleName ( ) + " is not an integer data type" ) ; } catch ( IllegalAccessException iae ) { throw H2O . fail ( "Cannot parse expression as " + return_type . getSimpleName ( ) + " (Illegal Access)" ) ; } }
Parses a string into an integer data type specified by parameter return_type . Accepts any format that is accepted by java s BigDecimal class . - Throws a NumberFormatException if the evaluated string is not an integer or if the value is too large to be stored into return_type without overflow . - Throws an IllegalAgumentException if return_type is not an integer data type .