JavaTXCompilerInJavaTX/test/unify/FiniteClosureBuilder.java

65 lines
1.9 KiB
Java
Raw Normal View History

2015-11-07 15:21:17 +00:00
package unify;
import java.util.HashSet;
import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
2015-12-26 23:29:23 +00:00
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
2016-03-17 15:54:43 +00:00
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
2015-12-26 23:29:23 +00:00
import de.dhbwstuttgart.typeinference.unify.model.MPair.PairOperator;
2015-11-07 15:21:17 +00:00
public class FiniteClosureBuilder {
private Set<MPair> pairs = new HashSet<>();
2016-03-17 15:54:43 +00:00
public void add(UnifyType sub, UnifyType sup) {
2015-11-07 15:21:17 +00:00
pairs.add(new MPair(sub, sup, PairOperator.SMALLER));
}
public IFiniteClosure getFiniteClosure() {
2015-11-08 20:23:20 +00:00
return new FiniteClosure(pairs);
}
public void clear() {
2015-11-07 15:21:17 +00:00
pairs = new HashSet<>();
}
public IFiniteClosure getCollectionExample() {
TypeFactory tf = new TypeFactory();
2016-03-17 15:54:43 +00:00
UnifyType collection = tf.getSimpleType("Collection");
UnifyType set = tf.getSimpleType("Set", "T");
UnifyType sortedSet = tf.getSimpleType("Set", "T");
UnifyType TreeSet = tf.getSimpleType("TreeSet", "T");
UnifyType hashSet = tf.getSimpleType("HashSet", "T");
UnifyType linkedHashSet = tf.getSimpleType("LinkedHashSet", "T");
UnifyType queue = tf.getSimpleType("Queue", "T");
UnifyType deque = tf.getSimpleType("Deque", "T");
UnifyType linkedList = tf.getSimpleType("LinkedList", "T");
UnifyType list = tf.getSimpleType("List", "T");
UnifyType vector = tf.getSimpleType("Vector", "T");
UnifyType stack = tf.getSimpleType("Stack", "T");
UnifyType arrayList = tf.getSimpleType("ArrayList", "T");
2015-11-07 15:21:17 +00:00
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);
2015-11-08 20:23:20 +00:00
IFiniteClosure fc = getFiniteClosure();
clear();
return fc;
2015-11-07 15:21:17 +00:00
}
}