public static int safeToInt ( long value ) { if ( value > Integer . MAX_VALUE || value < Integer . MIN_VALUE ) { throw new ArithmeticException ( "Calculation overflows an int: " + value ) ; } return ( int ) value ; }
Safely convert a long to an int .