evaluateOperator method

bool evaluateOperator(
  1. dynamic leftStatement,
  2. String operator,
  3. dynamic rightStatement
)

Evaluates the result of a given leftStatement, an operator and a rightStatement.

Implementation

bool evaluateOperator(
    dynamic leftStatement, String operator, dynamic rightStatement) {
  dynamic left;
  dynamic right;
  if (leftStatement is DateTime || rightStatement is DateTime) {
    left = tryParseDateTime(leftStatement);
    right = tryParseDateTime(rightStatement);
  } else if (leftStatement is num || rightStatement is num) {
    left = tryParseDouble(leftStatement);
    right = tryParseDouble(rightStatement);
  } else if (leftStatement is bool || rightStatement is bool) {
    left = tryParseBool(leftStatement);
    right = tryParseBool(rightStatement);
  } else {
    left = leftStatement;
    right = rightStatement;
  }

  switch (operator) {
    case "==":
    case "equal":
      return left == right;
    case "!=":
    case "notEqual":
      return left != right;
    case ">":
    case "greater":
      return left > right;
    case ">=":
    case "greaterEqual":
      return left >= right;
    case "<":
    case "less":
      return left < right;
    case "<=":
    case "lessEqual":
      return left <= right;
    case "contain":
    case "not contain":
      var result = false;
      if (left is Map) {
        result = left.containsKey(right);
      } else if (left != null) {
        left.contains(right);
      }
      return operator == "contain" ? result : !result;
    default:
      return false;
  }
}