in hugegraph-common/src/main/java/org/apache/hugegraph/util/NumericUtil.java [329:360]
public static int compareNumber(Object first, Number second) {
if (first == null) {
E.checkArgument(first != null,
"The first parameter can't be null");
}
if (second == null) {
E.checkArgument(second != null,
"The second parameter can't be null");
}
if (first instanceof Number && first instanceof Comparable &&
first.getClass().equals(second.getClass())) {
@SuppressWarnings("unchecked")
Comparable<Number> cmpFirst = (Comparable<Number>) first;
return cmpFirst.compareTo(second);
}
Function<Object, BigDecimal> toBig = (number) -> {
try {
return new BigDecimal(number.toString());
} catch (NumberFormatException e) {
throw new IllegalArgumentException(String.format(
"Can't compare between '%s' and '%s', " +
"they must be numbers", first, second));
}
};
BigDecimal n1 = toBig.apply(first);
BigDecimal n2 = toBig.apply(second);
return n1.compareTo(n2);
}