NumberInRange { @ArgumentsChecked @Throws(IllegalNullArgumentException.class) public static double checkDouble(@Nonnull final Number number) { Check.notNull(number, "number"); if (!isInDoubleRange(number)) { throw new IllegalNumberRangeException(number.toString(), DOUBLE_MIN, DOUBLE_MAX); } return number.doubleValue(); } private  NumberInRange(); @ArgumentsChecked @Throws(IllegalNullArgumentException.class) static byte checkByte(@Nonnull final Number number); @ArgumentsChecked @Throws(IllegalNullArgumentException.class) static double checkDouble(@Nonnull final Number number); @ArgumentsChecked @Throws(IllegalNullArgumentException.class) static float checkFloat(@Nonnull final Number number); @ArgumentsChecked @Throws(IllegalNullArgumentException.class) static int checkInteger(@Nonnull final Number number); @ArgumentsChecked @Throws(IllegalNullArgumentException.class) static int checkLong(@Nonnull final Number number); @ArgumentsChecked @Throws(IllegalNullArgumentException.class) static short checkShort(@Nonnull final Number number); static boolean isInByteRange(@Nonnull final Number number); static boolean isInDoubleRange(@Nonnull final Number number); static boolean isInFloatRange(@Nonnull final Number number); static boolean isInIntegerRange(@Nonnull final Number number); static boolean isInLongRange(@Nonnull final Number number); @ArgumentsChecked @Throws(IllegalNullArgumentException.class) static boolean isInRange(@Nonnull final Number number, @Nonnull final BigDecimal min, @Nonnull final BigDecimal max); @ArgumentsChecked @Throws(IllegalNullArgumentException.class) static boolean isInRange(@Nonnull final Number number, @Nonnull final BigInteger min, @Nonnull final BigInteger max); static boolean isInShortRange(@Nonnull final Number number); static final BigInteger BYTE_MIN; static final BigInteger BYTE_MAX; static final BigInteger SHORT_MIN; static final BigInteger SHORT_MAX; static final BigInteger INTEGER_MIN; static final BigInteger INTEGER_MAX; static final BigInteger LONG_MIN; static final BigInteger LONG_MAX; static final BigDecimal FLOAT_MAX; static final BigDecimal FLOAT_MIN; static final BigDecimal DOUBLE_MAX; static final BigDecimal DOUBLE_MIN; }
@Test public void testCheckDouble_Ok() { double l = NumberInRange.checkDouble(Double.valueOf(4.1d)); Assert.assertEquals(4.1d, l, 0.0); }
@Test(expected=IllegalNumberRangeException.class) public void testCheckDoublet_Fail() { NumberInRange.checkDouble(new BigDecimal("1E309")); }