Skip to content

Commit

Permalink
fix(policy-check):[eclipse-tractusx#649] fix isSameAs method for AND …
Browse files Browse the repository at this point in the history
…constraints

(must have same amount of constraints to ensure that there isn't any subset match in any direction)
  • Loading branch information
dsmf committed Jul 12, 2024
1 parent 87c4805 commit 4ef0814
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,33 @@ private boolean isValidOnList(final Constraint constraint, final List<Constraint
}

private boolean isSameAs(final Constraint constraint, final Constraints acceptedConstraints) {

if (constraint instanceof AtomicConstraint atomicConstraint) {
return acceptedConstraints.getOr().stream().anyMatch(p -> isSameAs(atomicConstraint, p))
|| acceptedConstraints.getAnd().stream().anyMatch(p -> isSameAs(atomicConstraint, p));
}

if (constraint instanceof AndConstraint andConstraint) {

// AND means the number of constraints must be the same
if (acceptedConstraints.getAnd() != null
&& acceptedConstraints.getAnd().size() != andConstraint.getConstraints().size()) {
return false;
}

return andConstraint.getConstraints()
.stream()
.allMatch(constr -> isInList(constr, Optional.ofNullable(acceptedConstraints.getAnd())
.orElse(Collections.emptyList())));
}

if (constraint instanceof OrConstraint orConstraint) {
return orConstraint.getConstraints()
.stream()
.anyMatch(constr -> isInList(constr, Optional.ofNullable(acceptedConstraints.getOr())
.orElse(Collections.emptyList())));
}

return false;
}

Expand Down

0 comments on commit 4ef0814

Please sign in to comment.