compare static method

bool compare(
  1. dynamic value1,
  2. String operation,
  3. dynamic value2
)

Perform comparison operation over two arguments. The operation can be performed over values of any type.

  • value1 the first argument to compare
  • operation the comparison operation: '==' ('=', 'EQ'), '!= ' ('<>', 'NE'); '<'/'>' ('LT'/'GT'), '<='/'>=' ('LE'/'GE'); 'LIKE'.
  • value2 the second argument to compare Returns result of the comparison operation

Implementation

static bool compare(dynamic value1, String operation, dynamic value2) {
  operation = operation.toUpperCase();

  if (operation == '=' || operation == '==' || operation == 'EQ') {
    return ObjectComparator.areEqual(value1, value2);
  }
  if (operation == '!=' || operation == '<>' || operation == 'NE') {
    return ObjectComparator.areNotEqual(value1, value2);
  }
  if (operation == '<' || operation == 'LT') {
    return ObjectComparator.isLess(value1, value2);
  }
  if (operation == '<=' || operation == 'LE' || operation == 'LTE') {
    return ObjectComparator.areEqual(value1, value2) ||
        ObjectComparator.isLess(value1, value2);
  }
  if (operation == '>' || operation == 'GT') {
    return ObjectComparator.isGreater(value1, value2);
  }
  if (operation == '>=' || operation == 'GE' || operation == 'GTE') {
    return ObjectComparator.areEqual(value1, value2) ||
        ObjectComparator.isGreater(value1, value2);
  }
  if (operation == 'LIKE') return ObjectComparator.match(value1, value2);

  return false;
}