public static int checkedCast ( long value ) { int valueI = ( int ) value ; if ( valueI != value ) { throw new IllegalArgumentException ( String . format ( "Overflow casting %d to an int" , value ) ) ; } return valueI ; }
Cast value to a an int or throw an exception if there is an overflow .