@Test public void testHighestClass() { Number[] numbers = { Byte.valueOf((byte)0), Short.valueOf((short)0), Integer.valueOf(0), Long.valueOf(0), Float.valueOf(0), Double.valueOf(0) }; for (int i = 0; i < numbers.length; i++) { for (int j = 0; j <= i; j++) { Class<? extends Number> clazz = NumberOperations.highestClass(numbers[i], numbers[j]); assertTrue( clazz.isInstance(numbers[i]) ); } } }
public static Class<? extends Number> highestClass(Number ...numbers) { int maxRank = -1; Class<? extends Number> result = null; for (Number n : numbers) { int rank = ClassInfo.get(n.getClass()).getRank(); if (rank > maxRank) { maxRank = rank; result = n.getClass(); } } return result; }
NumberOperations { public static Class<? extends Number> highestClass(Number ...numbers) { int maxRank = -1; Class<? extends Number> result = null; for (Number n : numbers) { int rank = ClassInfo.get(n.getClass()).getRank(); if (rank > maxRank) { maxRank = rank; result = n.getClass(); } } return result; } }
NumberOperations { public static Class<? extends Number> highestClass(Number ...numbers) { int maxRank = -1; Class<? extends Number> result = null; for (Number n : numbers) { int rank = ClassInfo.get(n.getClass()).getRank(); if (rank > maxRank) { maxRank = rank; result = n.getClass(); } } return result; }  }
NumberOperations { public static Class<? extends Number> highestClass(Number ...numbers) { int maxRank = -1; Class<? extends Number> result = null; for (Number n : numbers) { int rank = ClassInfo.get(n.getClass()).getRank(); if (rank > maxRank) { maxRank = rank; result = n.getClass(); } } return result; }  static Number add(Number n1, Number n2); static Number subtract(Number n1, Number n2); static Number multiply(Number n1, Number n2); static Number divide(Number n1, Number n2); static int compare(Number n1, Number n2); static float getFloatTolerance(); static void setFloatTolerance(float tol); static double getDoubleTolerance(); static void setFloatTolerance(double tol); static int intValue(Number number); static long longValue(Number number); static float floatValue(Number number); static double doubleValue(Number number); static Number copy(Number number); static Number newInstance(Number number, Class<? extends Number> clazz); static Number castNumber(Number number, Class<? extends Number> clazz); static Class<? extends Number> highestClass(Number ...numbers); static Class<? extends Number> lowestClass(Number ...numbers); }
NumberOperations { public static Class<? extends Number> highestClass(Number ...numbers) { int maxRank = -1; Class<? extends Number> result = null; for (Number n : numbers) { int rank = ClassInfo.get(n.getClass()).getRank(); if (rank > maxRank) { maxRank = rank; result = n.getClass(); } } return result; }  static Number add(Number n1, Number n2); static Number subtract(Number n1, Number n2); static Number multiply(Number n1, Number n2); static Number divide(Number n1, Number n2); static int compare(Number n1, Number n2); static float getFloatTolerance(); static void setFloatTolerance(float tol); static double getDoubleTolerance(); static void setFloatTolerance(double tol); static int intValue(Number number); static long longValue(Number number); static float floatValue(Number number); static double doubleValue(Number number); static Number copy(Number number); static Number newInstance(Number number, Class<? extends Number> clazz); static Number castNumber(Number number, Class<? extends Number> clazz); static Class<? extends Number> highestClass(Number ...numbers); static Class<? extends Number> lowestClass(Number ...numbers); static final float DEFAULT_FLOAT_TOL; static final double DEFAULT_DOUBLE_TOL; }