element method

bool element(
  1. E element,
  2. C collective, {
  3. Function? action,
})

Validates whether a specific element can be added to the collective.

Parameters:

  • element: The element to validate
  • collective: The target collective
  • action: Optional action context for the validation

Returns true if the element is allowed, false otherwise.

Implementation

bool element(E element, C collective, {Function? action}) {

  final tested = Set<TestObject>.identity();

  bool process(TestObject obj) {
    if (tested.add(obj)) {
      for (var e in obj) {
        if (e is TestCollectiveElementRule<E,C>) {
          try {
            if (e.element(element, collective, action: action) == false) {
              return false;
            }
          } on Exception catch(_) {}
        }
        else if (e is TestObject) {
          return process(e);
        }
      }
    }
    return true;
  }

  return process(this);
}