65 lines
1.9 KiB
Java
65 lines
1.9 KiB
Java
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<MPair> pairs = new HashSet<>();
|
|
|
|
public void add(Type sub, Type sup) {
|
|
pairs.add(new MPair(sub, sup, PairOperator.SMALLER));
|
|
}
|
|
|
|
public IFiniteClosure getFiniteClosure() {
|
|
return new FiniteClosure(pairs);
|
|
}
|
|
|
|
public void clear() {
|
|
pairs = new HashSet<>();
|
|
}
|
|
|
|
public IFiniteClosure getCollectionExample() {
|
|
TypeFactory tf = new TypeFactory();
|
|
|
|
Type collection = tf.getSimpleType("Collection");
|
|
Type set = tf.getSimpleType("Set", "T");
|
|
Type sortedSet = tf.getSimpleType("Set", "T");
|
|
Type TreeSet = tf.getSimpleType("TreeSet", "T");
|
|
Type hashSet = tf.getSimpleType("HashSet", "T");
|
|
Type linkedHashSet = tf.getSimpleType("LinkedHashSet", "T");
|
|
Type queue = tf.getSimpleType("Queue", "T");
|
|
Type deque = tf.getSimpleType("Deque", "T");
|
|
Type linkedList = tf.getSimpleType("LinkedList", "T");
|
|
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);
|
|
|
|
IFiniteClosure fc = getFiniteClosure();
|
|
clear();
|
|
return fc;
|
|
}
|
|
}
|