package unify; import java.util.HashSet; import java.util.Set; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typinference.unify.model.FiniteClosure; import de.dhbwstuttgart.typinference.unify.model.MPair; import de.dhbwstuttgart.typinference.unify.model.MPair.PairOperator; import de.dhbwstuttgart.typinference.unify.model.Type; public class FiniteClosureBuilder { private Set pairs = new HashSet<>(); public void add(Type sub, Type sup) { pairs.add(new MPair(sub, sup, PairOperator.SMALLER)); } public IFiniteClosure getFiniteClosure() { FiniteClosure fc = new FiniteClosure(pairs); pairs = new HashSet<>(); return fc; } public IFiniteClosure getCollectionExample() { TypeFactory tf = new TypeFactory(); Type collection = tf.getSimpleType("Collection"); Type set = tf.getSimpleType("Set", "T"); Type sortedSet = tf.getSimpleType("Set", "K"); Type TreeSet = tf.getSimpleType("TreeSet", "T"); Type hashSet = tf.getSimpleType("HashSet", "Z"); Type linkedHashSet = tf.getSimpleType("LinkedHashSet", "T"); Type queue = tf.getSimpleType("Queue", "U"); Type deque = tf.getSimpleType("Deque", "U"); Type linkedList = tf.getSimpleType("LinkedList", "U"); Type list = tf.getSimpleType("List", "T"); Type vector = tf.getSimpleType("Vector", "T"); Type stack = tf.getSimpleType("Stack", "T"); Type arrayList = tf.getSimpleType("ArrayList", "T"); add(set, collection); add(sortedSet, set); add(TreeSet, sortedSet); add(hashSet, set); add(linkedHashSet, set); add(queue, collection); add(deque, queue); add(linkedList, deque); add(list, collection); add(linkedList, list); add(vector, list); add(arrayList, list); add(stack, vector); return getFiniteClosure(); } }