Source:
static int compare(String aggregationName, Number value, Map<String, AggregatorFactory> aggregators, Object metricValueObj) { if (metricValueObj != null) { if (aggregators != null && aggregators.containsKey(aggregationName)) { metricValueObj = aggregators.get(aggregationName).finalizeComputation(metricValueObj); } if (metricValueObj instanceof Long || metricValueObj instanceof Integer) { long n = ((Number) metricValueObj).longValue(); if (value instanceof Long || value instanceof Integer) { return Longs.compare(n, value.longValue()); } else if (value instanceof Double || value instanceof Float) { return -compareDoubleToLong(value.doubleValue(), n); } else { throw new ISE("Number was[%s]?!?", value.getClass().getName()); } } else if (metricValueObj instanceof Double || metricValueObj instanceof Float) { double n = ((Number) metricValueObj).doubleValue(); if (value instanceof Long || value instanceof Integer) { return compareDoubleToLong(n, value.longValue()); } else if (value instanceof Double || value instanceof Float) { return Doubles.compare(n, value.doubleValue()); } else { throw new ISE("Number was[%s]?!?", value.getClass().getName()); } } else if (metricValueObj instanceof String) { String metricValueStr = (String) metricValueObj; if (LONG_PAT.matcher(metricValueStr).matches()) { long l = Long.parseLong(metricValueStr); return Long.compare(l, value.longValue()); } else { double d = Double.parseDouble(metricValueStr); return Double.compare(d, value.doubleValue()); } } else if (metricValueObj instanceof Number) { BigDecimal d = new BigDecimal(metricValueObj.toString()); return d.compareTo((BigDecimal) value); } else { throw new ISE("Unknown type of metric value: %s", metricValueObj); } } else { return Double.compare(0, value.doubleValue()); } }

Target:
static int compare(String aggregationName, Number value, Map<String, AggregatorFactory> aggregators, Object metricValueObj) { if (metricValueObj != null) { if (aggregators != null && aggregators.containsKey(aggregationName)) { metricValueObj = aggregators.get(aggregationName).finalizeComputation(metricValueObj); } if (metricValueObj instanceof Long || metricValueObj instanceof Integer) { long n = ((Number) metricValueObj).longValue(); if (value instanceof Long || value instanceof Integer) { return Longs.compare(n, value.longValue()); } else if (value instanceof Double || value instanceof Float) { return -compareDoubleToLong(value.doubleValue(), n); } else { throw new ISE("Number was[%s]?!?", value.getClass().getName()); } } else if (metricValueObj instanceof Double || metricValueObj instanceof Float) { double n = ((Number) metricValueObj).doubleValue(); if (value instanceof Long || value instanceof Integer) { return compareDoubleToLong(n, value.longValue()); } else if (value instanceof Double || value instanceof Float) { return Doubles.compare(n, value.doubleValue()); } else { throw new ISE("Number was[%s]?!?", value.getClass().getName()); } } else if (metricValueObj instanceof String) { String metricValueStr = (String) metricValueObj; if (LONG_PAT.matcher(metricValueStr).matches()) { long l = Long.parseLong(metricValueStr); return Long.compare(l, value.longValue()); } else { double d = Double.parseDouble(metricValueStr); return Double.compare(d, value.doubleValue()); } } else if (aggregators != null && aggregators.containsKey(aggregationName)) { AggregatorFactory aggregatorFactory = aggregators.get(aggregationName); return aggregatorFactory.getComparator() .compare( aggregatorFactory.deserialize(metricValueObj), aggregatorFactory.deserialize(value) ); } else { throw new ISE("Unknown type of metric value: %s", metricValueObj); } } else { return Double.compare(0, value.doubleValue()); } }