JavaPatternMatching/test/unify/FiniteClosureBuilder.java
2016-03-28 01:01:46 +02:00

85 lines
2.6 KiB
Java

package unify;
import java.util.HashSet;
import java.util.Set;
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.MPair;
import de.dhbwstuttgart.typeinference.unify.model.Type;
import de.dhbwstuttgart.typeinference.unify.model.MPair.PairOperator;
import de.dhbwstuttgart.typeinference.unifynew.TypeFactory;
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();
/* Collection */
Type collection = tf.getSimpleType("Collection");
Type set = tf.getSimpleType("Set", "T");
//Type sortedSet = tf.getSimpleType("SortedSet", "T"); Sorted set bei den Unit-Tests vergessen
// nachträgliches einfügen zu aufwendig
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, set);
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);
/* Map */
Type map = tf.getSimpleType("Map", "K", "V");
Type sortedMap = tf.getSimpleType("SortedMap", "K", "V");
Type navigableMap = tf.getSimpleType("NavigableMap", "K", "V");
Type treeMap = tf.getSimpleType("TreeMap", "K", "V");
Type hashMap = tf.getSimpleType("HashMap", "K", "V");
Type hashtable = tf.getSimpleType("Hashtable", "K", "V");
Type linkedHashMap = tf.getSimpleType("LinkedHashMap", "K", "V");
add(sortedMap, map);
add(hashMap, map);
add(hashtable, map);
add(navigableMap, sortedMap);
add(treeMap, navigableMap);
add(linkedHashMap, hashMap);
IFiniteClosure fc = getFiniteClosure();
clear();
return fc;
}
}