@Test public void testCompareNumbers() { Number a = Random.getNegativeNumber(); Number b = Random.getPositiveNumber(); Assert.assertTrue(Numbers.compare(a, b) < 0); }
public static int compare(Number a, Number b) { Class<?> aClass = a.getClass(); Class<?> bClass = b.getClass(); if((aClass == int.class || aClass == Integer.class) && (bClass == int.class || bClass == Integer.class)) { return Integer.compare(a.intValue(), b.intValue()); } else if((aClass == long.class || aClass == Long.class) && (bClass == long.class || bClass == Long.class)) { return Long.compare(a.longValue(), b.longValue()); } else if((aClass == float.class || aClass == Float.class) && (bClass == float.class || bClass == Float.class)) { return Float.compare(a.floatValue(), b.floatValue()); } else if((aClass == double.class || aClass == Double.class) && (bClass == double.class || bClass == Double.class)) { return Double.compare(a.doubleValue(), b.doubleValue()); } else if((aClass == short.class || aClass == Short.class) && (bClass == short.class || bClass == Short.class)) { return Short.compare(a.shortValue(), b.shortValue()); } else if((aClass == byte.class || aClass == Byte.class) && (bClass == byte.class || bClass == Byte.class)) { return Byte.compare(a.byteValue(), b.byteValue()); } else { String fa = aClass == Link.class ? UnsignedLongs.toString(a.longValue()) : a.toString(); String sb = bClass == Link.class ? UnsignedLongs.toString(b.longValue()) : b.toString(); BigDecimal first = new BigDecimal(fa); BigDecimal second = new BigDecimal(sb); return first.compareTo(second); } }
Numbers { public static int compare(Number a, Number b) { Class<?> aClass = a.getClass(); Class<?> bClass = b.getClass(); if((aClass == int.class || aClass == Integer.class) && (bClass == int.class || bClass == Integer.class)) { return Integer.compare(a.intValue(), b.intValue()); } else if((aClass == long.class || aClass == Long.class) && (bClass == long.class || bClass == Long.class)) { return Long.compare(a.longValue(), b.longValue()); } else if((aClass == float.class || aClass == Float.class) && (bClass == float.class || bClass == Float.class)) { return Float.compare(a.floatValue(), b.floatValue()); } else if((aClass == double.class || aClass == Double.class) && (bClass == double.class || bClass == Double.class)) { return Double.compare(a.doubleValue(), b.doubleValue()); } else if((aClass == short.class || aClass == Short.class) && (bClass == short.class || bClass == Short.class)) { return Short.compare(a.shortValue(), b.shortValue()); } else if((aClass == byte.class || aClass == Byte.class) && (bClass == byte.class || bClass == Byte.class)) { return Byte.compare(a.byteValue(), b.byteValue()); } else { String fa = aClass == Link.class ? UnsignedLongs.toString(a.longValue()) : a.toString(); String sb = bClass == Link.class ? UnsignedLongs.toString(b.longValue()) : b.toString(); BigDecimal first = new BigDecimal(fa); BigDecimal second = new BigDecimal(sb); return first.compareTo(second); } } }
Numbers { public static int compare(Number a, Number b) { Class<?> aClass = a.getClass(); Class<?> bClass = b.getClass(); if((aClass == int.class || aClass == Integer.class) && (bClass == int.class || bClass == Integer.class)) { return Integer.compare(a.intValue(), b.intValue()); } else if((aClass == long.class || aClass == Long.class) && (bClass == long.class || bClass == Long.class)) { return Long.compare(a.longValue(), b.longValue()); } else if((aClass == float.class || aClass == Float.class) && (bClass == float.class || bClass == Float.class)) { return Float.compare(a.floatValue(), b.floatValue()); } else if((aClass == double.class || aClass == Double.class) && (bClass == double.class || bClass == Double.class)) { return Double.compare(a.doubleValue(), b.doubleValue()); } else if((aClass == short.class || aClass == Short.class) && (bClass == short.class || bClass == Short.class)) { return Short.compare(a.shortValue(), b.shortValue()); } else if((aClass == byte.class || aClass == Byte.class) && (bClass == byte.class || bClass == Byte.class)) { return Byte.compare(a.byteValue(), b.byteValue()); } else { String fa = aClass == Link.class ? UnsignedLongs.toString(a.longValue()) : a.toString(); String sb = bClass == Link.class ? UnsignedLongs.toString(b.longValue()) : b.toString(); BigDecimal first = new BigDecimal(fa); BigDecimal second = new BigDecimal(sb); return first.compareTo(second); } }  }
Numbers { public static int compare(Number a, Number b) { Class<?> aClass = a.getClass(); Class<?> bClass = b.getClass(); if((aClass == int.class || aClass == Integer.class) && (bClass == int.class || bClass == Integer.class)) { return Integer.compare(a.intValue(), b.intValue()); } else if((aClass == long.class || aClass == Long.class) && (bClass == long.class || bClass == Long.class)) { return Long.compare(a.longValue(), b.longValue()); } else if((aClass == float.class || aClass == Float.class) && (bClass == float.class || bClass == Float.class)) { return Float.compare(a.floatValue(), b.floatValue()); } else if((aClass == double.class || aClass == Double.class) && (bClass == double.class || bClass == Double.class)) { return Double.compare(a.doubleValue(), b.doubleValue()); } else if((aClass == short.class || aClass == Short.class) && (bClass == short.class || bClass == Short.class)) { return Short.compare(a.shortValue(), b.shortValue()); } else if((aClass == byte.class || aClass == Byte.class) && (bClass == byte.class || bClass == Byte.class)) { return Byte.compare(a.byteValue(), b.byteValue()); } else { String fa = aClass == Link.class ? UnsignedLongs.toString(a.longValue()) : a.toString(); String sb = bClass == Link.class ? UnsignedLongs.toString(b.longValue()) : b.toString(); BigDecimal first = new BigDecimal(fa); BigDecimal second = new BigDecimal(sb); return first.compareTo(second); } }  static Number add(Number a, Number b); static int compare(Number a, Number b); static Number divide(Number a, Number b); static Number incrementalAverage(Number running, Number number,
            int count); static boolean areEqual(Number a, Number b); @Deprecated static boolean isEqualTo(Number a, Number b); static boolean areEqualCastSafe(Object a, Object b); @Deprecated static boolean isEqualToCastSafe(Object a, Object b); static boolean isEven(Number number); static boolean isFloatingPoint(Number number); static boolean isGreaterThan(Number a, Number b); static boolean isGreaterThanOrEqualTo(Number a, Number b); static boolean isLessThan(Number a, Number b); static boolean isLessThanOrEqualTo(Number a, Number b); static boolean isOdd(Number number); static Number max(Number... numbers); static Number min(Number... numbers); static Number multiply(Number a, Number b); static double percent(Number numerator, Number denominator); static double round(Number value, int places); static Number scale(Number number, Number rawMin, Number rawMax,
            Number scaledMin, Number scaledMax); static BigDecimal toBigDecimal(Number number); }
Numbers { public static int compare(Number a, Number b) { Class<?> aClass = a.getClass(); Class<?> bClass = b.getClass(); if((aClass == int.class || aClass == Integer.class) && (bClass == int.class || bClass == Integer.class)) { return Integer.compare(a.intValue(), b.intValue()); } else if((aClass == long.class || aClass == Long.class) && (bClass == long.class || bClass == Long.class)) { return Long.compare(a.longValue(), b.longValue()); } else if((aClass == float.class || aClass == Float.class) && (bClass == float.class || bClass == Float.class)) { return Float.compare(a.floatValue(), b.floatValue()); } else if((aClass == double.class || aClass == Double.class) && (bClass == double.class || bClass == Double.class)) { return Double.compare(a.doubleValue(), b.doubleValue()); } else if((aClass == short.class || aClass == Short.class) && (bClass == short.class || bClass == Short.class)) { return Short.compare(a.shortValue(), b.shortValue()); } else if((aClass == byte.class || aClass == Byte.class) && (bClass == byte.class || bClass == Byte.class)) { return Byte.compare(a.byteValue(), b.byteValue()); } else { String fa = aClass == Link.class ? UnsignedLongs.toString(a.longValue()) : a.toString(); String sb = bClass == Link.class ? UnsignedLongs.toString(b.longValue()) : b.toString(); BigDecimal first = new BigDecimal(fa); BigDecimal second = new BigDecimal(sb); return first.compareTo(second); } }  static Number add(Number a, Number b); static int compare(Number a, Number b); static Number divide(Number a, Number b); static Number incrementalAverage(Number running, Number number,
            int count); static boolean areEqual(Number a, Number b); @Deprecated static boolean isEqualTo(Number a, Number b); static boolean areEqualCastSafe(Object a, Object b); @Deprecated static boolean isEqualToCastSafe(Object a, Object b); static boolean isEven(Number number); static boolean isFloatingPoint(Number number); static boolean isGreaterThan(Number a, Number b); static boolean isGreaterThanOrEqualTo(Number a, Number b); static boolean isLessThan(Number a, Number b); static boolean isLessThanOrEqualTo(Number a, Number b); static boolean isOdd(Number number); static Number max(Number... numbers); static Number min(Number... numbers); static Number multiply(Number a, Number b); static double percent(Number numerator, Number denominator); static double round(Number value, int places); static Number scale(Number number, Number rawMin, Number rawMax,
            Number scaledMin, Number scaledMax); static BigDecimal toBigDecimal(Number number);  }