@Test(expected=IllegalNumberArgumentException.class) public void testInRange_Decimal_Fail() { NumberInRange.isInRange(new FakeNumber(), new BigDecimal(Integer.MIN_VALUE), new BigDecimal(Integer.MAX_VALUE)); }
@ArgumentsChecked @Throws(IllegalNullArgumentException.class) public static boolean isInRange(@Nonnull final Number number, @Nonnull final BigDecimal min, @Nonnull final BigDecimal max) { Check.notNull(number, "number"); Check.notNull(min, "min"); Check.notNull(max, "max"); BigDecimal bigDecimal = null; if (number instanceof Byte || number instanceof Short || number instanceof Integer || number instanceof Long) { bigDecimal = new BigDecimal(number.longValue()); } else if (number instanceof Float || number instanceof Double) { bigDecimal = new BigDecimal(number.doubleValue()); } else if (number instanceof BigInteger) { bigDecimal = new BigDecimal((BigInteger) number); } else if (number instanceof BigDecimal) { bigDecimal = (BigDecimal) number; } else { throw new IllegalNumberArgumentException("Return value is no known subclass of 'java.lang.Number': " + number.getClass().getName()); } return max.compareTo(bigDecimal) >= 0 && min.compareTo(bigDecimal) <= 0; }
NumberInRange { @ArgumentsChecked @Throws(IllegalNullArgumentException.class) public static boolean isInRange(@Nonnull final Number number, @Nonnull final BigDecimal min, @Nonnull final BigDecimal max) { Check.notNull(number, "number"); Check.notNull(min, "min"); Check.notNull(max, "max"); BigDecimal bigDecimal = null; if (number instanceof Byte || number instanceof Short || number instanceof Integer || number instanceof Long) { bigDecimal = new BigDecimal(number.longValue()); } else if (number instanceof Float || number instanceof Double) { bigDecimal = new BigDecimal(number.doubleValue()); } else if (number instanceof BigInteger) { bigDecimal = new BigDecimal((BigInteger) number); } else if (number instanceof BigDecimal) { bigDecimal = (BigDecimal) number; } else { throw new IllegalNumberArgumentException("Return value is no known subclass of 'java.lang.Number': " + number.getClass().getName()); } return max.compareTo(bigDecimal) >= 0 && min.compareTo(bigDecimal) <= 0; } }
NumberInRange { @ArgumentsChecked @Throws(IllegalNullArgumentException.class) public static boolean isInRange(@Nonnull final Number number, @Nonnull final BigDecimal min, @Nonnull final BigDecimal max) { Check.notNull(number, "number"); Check.notNull(min, "min"); Check.notNull(max, "max"); BigDecimal bigDecimal = null; if (number instanceof Byte || number instanceof Short || number instanceof Integer || number instanceof Long) { bigDecimal = new BigDecimal(number.longValue()); } else if (number instanceof Float || number instanceof Double) { bigDecimal = new BigDecimal(number.doubleValue()); } else if (number instanceof BigInteger) { bigDecimal = new BigDecimal((BigInteger) number); } else if (number instanceof BigDecimal) { bigDecimal = (BigDecimal) number; } else { throw new IllegalNumberArgumentException("Return value is no known subclass of 'java.lang.Number': " + number.getClass().getName()); } return max.compareTo(bigDecimal) >= 0 && min.compareTo(bigDecimal) <= 0; } private  NumberInRange(); }
NumberInRange { @ArgumentsChecked @Throws(IllegalNullArgumentException.class) public static boolean isInRange(@Nonnull final Number number, @Nonnull final BigDecimal min, @Nonnull final BigDecimal max) { Check.notNull(number, "number"); Check.notNull(min, "min"); Check.notNull(max, "max"); BigDecimal bigDecimal = null; if (number instanceof Byte || number instanceof Short || number instanceof Integer || number instanceof Long) { bigDecimal = new BigDecimal(number.longValue()); } else if (number instanceof Float || number instanceof Double) { bigDecimal = new BigDecimal(number.doubleValue()); } else if (number instanceof BigInteger) { bigDecimal = new BigDecimal((BigInteger) number); } else if (number instanceof BigDecimal) { bigDecimal = (BigDecimal) number; } else { throw new IllegalNumberArgumentException("Return value is no known subclass of 'java.lang.Number': " + number.getClass().getName()); } return max.compareTo(bigDecimal) >= 0 && min.compareTo(bigDecimal) <= 0; } 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); }
NumberInRange { @ArgumentsChecked @Throws(IllegalNullArgumentException.class) public static boolean isInRange(@Nonnull final Number number, @Nonnull final BigDecimal min, @Nonnull final BigDecimal max) { Check.notNull(number, "number"); Check.notNull(min, "min"); Check.notNull(max, "max"); BigDecimal bigDecimal = null; if (number instanceof Byte || number instanceof Short || number instanceof Integer || number instanceof Long) { bigDecimal = new BigDecimal(number.longValue()); } else if (number instanceof Float || number instanceof Double) { bigDecimal = new BigDecimal(number.doubleValue()); } else if (number instanceof BigInteger) { bigDecimal = new BigDecimal((BigInteger) number); } else if (number instanceof BigDecimal) { bigDecimal = (BigDecimal) number; } else { throw new IllegalNumberArgumentException("Return value is no known subclass of 'java.lang.Number': " + number.getClass().getName()); } return max.compareTo(bigDecimal) >= 0 && min.compareTo(bigDecimal) <= 0; } 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; }