evaluate method

  1. @override
bool evaluate(
  1. CItem item
)
override

Evaluates this predicate against item. Implementations should be allocation-free and side-effect-free.

Implementation

@override
bool evaluate(CItem<dynamic> item) {
  final actual = field.extract(item);
  switch (op) {
    case PredicateOp.eq:
      return actual == value;
    case PredicateOp.neq:
      return actual != value;
    case PredicateOp.isNull:
      return actual == null;
    case PredicateOp.isNotNull:
      return actual != null;
    case PredicateOp.lt:
    case PredicateOp.lte:
    case PredicateOp.gt:
    case PredicateOp.gte:
      // Both sides null are not orderable; treat as "false" rather
      // than throw, matching SQL `NULL` comparison semantics.
      if (actual == null || value == null) return false;
      final cmp = (actual as Comparable<dynamic>).compareTo(value);
      switch (op) {
        case PredicateOp.lt:
          return cmp < 0;
        case PredicateOp.lte:
          return cmp <= 0;
        case PredicateOp.gt:
          return cmp > 0;
        case PredicateOp.gte:
          return cmp >= 0;
        default:
          throw StateError('unreachable');
      }
    case PredicateOp.like:
    case PredicateOp.inSet:
    case PredicateOp.between:
    case PredicateOp.contains:
    case PredicateOp.startsWith:
      throw UnimplementedError(
        'PredicateOp.${op.name} is reserved but not yet implemented.',
      );
  }
}