satisfyRequiredSet static method

bool satisfyRequiredSet({
  1. required Set<InterfaceAttribute> requiredSet,
  2. required Set<InterfaceAttribute> testSet,
})

True if, every non-optional attribute in requiredSet also exists in testSet. every optional attribute in requiredSet which also exist in testSet must have the same signature.

Implementation

static bool satisfyRequiredSet({
  required Set<InterfaceAttribute> requiredSet,
  required Set<InterfaceAttribute> testSet,
}) {
  for (final attribute in requiredSet) {
    if (attribute.optional) {
      for (final testAttribute in testSet) {
        if (attribute.attributeName == testAttribute.attributeName) {
          if (attribute.returnType != testAttribute.returnType ||
              !_setEquality.equals(
                  attribute.parameters, testAttribute.parameters)) {
            // this optional attribute also exists in testSet but with a different signature
            return false;
          }
          break;
        }
      }
    } else if (!testSet.contains(attribute)) {
      // this non-optional attribute does not exist in testSet
      return false;
    }
  }
  return true;
}