compare static method

int compare(
  1. Object? l,
  2. Object? r, [
  3. TypeComparator comparator = const StandardTypeComparator()
])

Negative, zero or positive as l is less than, equal to or greater than r, for <, <=, > and >=: null comes before everything, numbers compare by value, and values that cannot be ordered fail with SpelMessage.notComparable. comparator decides, the standard one by default.

SpelOperations.compare(1, 2.5) < 0; // true
SpelOperations.compare(null, 'a') < 0; // true
SpelOperations.compare('a', 1); // throws

Spring (Java):

// OpLT, OpLE, OpGT, OpGE: context.getTypeComparator().compare(l, r)

Implementation

static int compare(
  Object? l,
  Object? r, [
  TypeComparator comparator = const StandardTypeComparator(),
]) {
  if (!comparator.canCompare(l, r)) {
    throw SpelEvaluationException(
      SpelMessage.notComparable,
      inserts: [_typeName(l), _typeName(r)],
    );
  }
  return comparator.compare(l, r);
}