private int doCompare()

in src/main/java/org/apache/commons/jexl3/JexlArithmetic.java [1959:2013]


    private int doCompare(final Object left, final Object right, final JexlOperator operator) {
        final boolean strictCast = isStrict(operator);
        if (left != null && right != null) {
            if (left instanceof BigDecimal || right instanceof BigDecimal) {
                final BigDecimal l = toBigDecimal(strictCast, left);
                final BigDecimal r = toBigDecimal(strictCast, right);
                return l.compareTo(r);
            }
            if (left instanceof BigInteger || right instanceof BigInteger) {
                try {
                    final BigInteger l = toBigInteger(strictCast, left);
                    final BigInteger r = toBigInteger(strictCast, right);
                    return l.compareTo(r);
                } catch (final ArithmeticException xconvert) {
                    // ignore it, continue in sequence
                }
            }
            if (isFloatingPoint(left) || isFloatingPoint(right)) {
                final double lhs = toDouble(strictCast, left);
                final double rhs = toDouble(strictCast, right);
                if (Double.isNaN(lhs)) {
                    if (Double.isNaN(rhs)) {
                        return 0;
                    }
                    return -1;
                }
                if (Double.isNaN(rhs)) {
                    // lhs is not NaN
                    return +1;
                }
                return Double.compare(lhs, rhs);
            }
            if (isNumberable(left) || isNumberable(right)) {
                try {
                    final long lhs = toLong(strictCast, left);
                    final long rhs = toLong(strictCast, right);
                    return Long.compare(lhs, rhs);
                } catch (final ArithmeticException xconvert) {
                    // ignore it, continue in sequence
                }
            }
            if (left instanceof String || right instanceof String) {
                return toString(left).compareTo(toString(right));
            }
            if (JexlOperator.EQ == operator) {
                return left.equals(right) ? 0 : -1;
            }
            if (left instanceof Comparable<?>) {
                @SuppressWarnings("unchecked") // OK because of instanceof check above
                final Comparable<Object> comparable = (Comparable<Object>) left;
                return comparable.compareTo(right);
            }
        }
        throw new ArithmeticException("Object comparison:(" + left + " " + operator + " " + right + ")");
    }