public static List doDiffValidateListProperty()

in oas-validator/oas-validator-core/src/main/java/org/apache/servicecomb/toolkit/oasv/diffvalidation/util/OasObjectDiffValidatorUtils.java [105:161]


  public static <T> List<OasDiffViolation> doDiffValidateListProperty(
    OasDiffValidationContext context,
    String listPropertyName,
    OasObjectPropertyLocation leftOwnerLocation,
    List<T> leftListProperty,
    OasObjectPropertyLocation rightOwnerLocation,
    List<T> rightListProperty,
    OasObjectType elementType,
    Function<T, ?> elementKeyMapper,
    List<? extends OasObjectDiffValidator<T>> validators) {

    assertOwnerLocationNotNull(leftOwnerLocation, rightOwnerLocation);

    if (leftListProperty == null) {
      leftListProperty = emptyList();
    }

    if (rightListProperty == null) {
      rightListProperty = emptyList();
    }

    List<OasDiffViolation> violations = new ArrayList<>();

    for (int i = 0; i < leftListProperty.size(); i++) {
      T leftElement = leftListProperty.get(i);
      Object leftElementKey = elementKeyMapper.apply(leftElement);
      OasObjectPropertyLocation leftElementLoc =
        leftOwnerLocation.property(listPropertyName + "[" + i + "]", elementType);

      int rightElementIndex = indexOf(rightListProperty, leftElementKey, elementKeyMapper);
      if (rightElementIndex == -1) {
        violations.addAll(doDiffValidateProperty(context, leftElementLoc, leftElement, null, null, validators));
      } else {
        T rightElement = rightListProperty.get(rightElementIndex);
        OasObjectPropertyLocation rightElementLoc =
          rightOwnerLocation.property(listPropertyName + "[" + rightElementIndex + "]", elementType);
        violations.addAll(
          doDiffValidateProperty(context, leftElementLoc, leftElement, rightElementLoc, rightElement, validators));
      }
    }

    for (int i = 0; i < rightListProperty.size(); i++) {
      T rightElement = rightListProperty.get(i);
      Object rightElementKey = elementKeyMapper.apply(rightElement);
      OasObjectPropertyLocation rightElementLoc =
        rightOwnerLocation.property(listPropertyName + "[" + i + "]", elementType);

      int leftElementIndex = indexOf(leftListProperty, rightElementKey, elementKeyMapper);
      if (leftElementIndex != -1) {
        continue;
      }
      violations.addAll(doDiffValidateProperty(context, null, null, rightElementLoc, rightElement, validators));

    }
    return violations;

  }