Simplify generateConstraints

This commit is contained in:
Till Schnell 2021-05-10 18:02:23 +02:00
parent 76a291ab41
commit fd7628cb40

View File

@ -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<Pair> generateConstraints (
Map<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphMap) {
ConstraintSet<Pair> constraintSet = new ConstraintSet<>();
tphMap.forEach( (tph, refType) -> {
ConstraintSet<Pair> constraintSet2 = generateConstraints(refType, tph);
constraintSet.addAll(constraintSet2);
return tphMap.entrySet().stream().map(ConstraintsGenerationUtils::generateConstraints)
.reduce(
new ConstraintSet<>(),
(cs, c) -> {
cs.addAll(c);
return cs;
});
return constraintSet;
}
/**
* 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<Pair> generateConstraints (
Map.Entry<? extends TypePlaceholder, ? extends RefTypeOrTPHOrWildcardOrGeneric> tphEntry) {
return generateConstraints(tphEntry.getValue(), tphEntry.getKey());
}
/**