diff --git a/src/main/java/de/dhbwstuttgart/inferWildcards/ConstraintsGenerationUtils.java b/src/main/java/de/dhbwstuttgart/inferWildcards/ConstraintsGenerationUtils.java index a33b2759..08c042c2 100644 --- a/src/main/java/de/dhbwstuttgart/inferWildcards/ConstraintsGenerationUtils.java +++ b/src/main/java/de/dhbwstuttgart/inferWildcards/ConstraintsGenerationUtils.java @@ -2,6 +2,7 @@ package de.dhbwstuttgart.inferWildcards; import java.util.HashSet; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import de.dhbwstuttgart.parser.NullToken; @@ -55,12 +56,27 @@ public final class ConstraintsGenerationUtils */ public static ConstraintSet generateConstraints ( Map tphMap) { - ConstraintSet constraintSet = new ConstraintSet<>(); - tphMap.forEach( (tph, refType) -> { - ConstraintSet constraintSet2 = generateConstraints(refType, tph); - constraintSet.addAll(constraintSet2); - }); - return constraintSet; + return tphMap.entrySet().stream().map(ConstraintsGenerationUtils::generateConstraints) + .reduce( + new ConstraintSet<>(), + (cs, c) -> { + cs.addAll(c); + return cs; + }); + } + + /** + * Generate the constraints for a single RefType type placeholder pair to infer + * the wildcards for the generic parameter type. + * + * @param tphEntry {@link Entry} of {@link TypePlaceholder} and + * {@link RefTypeOrTPHOrWildcardOrGeneric} + * @return {@link ConstraintSet} of {@link Pair} generated containing the + * constraints. + */ + private static ConstraintSet generateConstraints ( + Map.Entry tphEntry) { + return generateConstraints(tphEntry.getValue(), tphEntry.getKey()); } /**