NumberHelper { public static Class<? extends Number> getHighestCommonNumberClass(final Number... numbers) { return getHighestCommonNumberClass(false, numbers); } private  NumberHelper(final BiFunction<Number, Number, Number> add,
                         final BiFunction<Number, Number, Number> sub,
                         final BiFunction<Number, Number, Number> mul,
                         final BiFunction<Number, Number, Number> div,
                         final BiFunction<Number, Number, Number> min,
                         final BiFunction<Number, Number, Number> max,
                         final BiFunction<Number, Number, Integer> cmp
    ); static Class<? extends Number> getHighestCommonNumberClass(final Number... numbers); static Class<? extends Number> getHighestCommonNumberClass(final boolean forceFloatingPoint, final Number... numbers); static Number add(final Number a, final Number b); static Number sub(final Number a, final Number b); static Number mul(final Number a, final Number b); static Number div(final Number a, final Number b); static Number div(final Number a, final Number b, final boolean forceFloatingPoint); static Number min(final Number a, final Number b); static Comparable min(final Comparable a, final Comparable b); static Number max(final Number a, final Number b); static Comparable max(final Comparable a, final Comparable b); static Integer compare(final Number a, final Number b); final BiFunction<Number, Number, Number> add; final BiFunction<Number, Number, Number> sub; final BiFunction<Number, Number, Number> mul; final BiFunction<Number, Number, Number> div; final BiFunction<Number, Number, Number> min; final BiFunction<Number, Number, Number> max; final BiFunction<Number, Number, Integer> cmp; }
@Test public void shouldReturnHighestCommonNumberClass() { for (final Quartet<Number, Number, Class<? extends Number>, Class<? extends Number>> q : COMMON_NUMBER_CLASSES) { assertEquals(q.getValue2(), getHighestCommonNumberClass(q.getValue0(), q.getValue1())); assertEquals(q.getValue2(), getHighestCommonNumberClass(q.getValue1(), q.getValue0())); assertEquals(q.getValue3(), getHighestCommonNumberClass(true, q.getValue0(), q.getValue1())); assertEquals(q.getValue3(), getHighestCommonNumberClass(true, q.getValue1(), q.getValue0())); } for (final Number number : EACH_NUMBER_TYPE) { assertEquals(number.getClass(), getHighestCommonNumberClass(number, Double.NaN)); assertEquals(number.getClass(), getHighestCommonNumberClass(Double.NaN, number)); assertEquals(number.getClass(), getHighestCommonNumberClass(number, null)); assertEquals(number.getClass(), getHighestCommonNumberClass(null, number)); } }