From 8e2d4e1c7080496efd3aa5e0bb2b1d56581c87b3 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Fri, 8 May 2020 11:04:05 +0200 Subject: [PATCH] modified: ../src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java new file: ../src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingExtend.java --- .../typeinference/unify/TypeUnifyTask.java | 7 +- .../unify/model/OrderingExtend.java | 89 +++++++++++++++++++ 2 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingExtend.java diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 9be3c74d..2d63eafd 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -723,6 +723,8 @@ public class TypeUnifyTask extends RecursiveTask>> { nextSetasListRest.remove(a_next); } } + + List> maxElementsTest = oup.maxElements(nextSetasListRest); //Alle maximale Elemente in nextSetasListRest bestimmen List> nextSetasListRestTest; do { @@ -739,7 +741,7 @@ public class TypeUnifyTask extends RecursiveTask>> { }} } while(!nextSetasListRestTest.equals(nextSetasListRest)); - + writeLog("maxElementsTest: " + maxElementsTest.equals(nextSetasListRest)); } else if (variance == -1) { a = oup.min(nextSetasList.iterator()); @@ -759,7 +761,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } } //Alle minimalen Elemente in nextSetasListRest bestimmen - + List> minElementsTest = oup.minElements(nextSetasListRest); List> nextSetasListRestTest; do { nextSetasListRestTest = new ArrayList>(nextSetasListRest); @@ -775,6 +777,7 @@ public class TypeUnifyTask extends RecursiveTask>> { }} } while(!nextSetasListRestTest.equals(nextSetasListRest)); + writeLog("minElementsTest: " + minElementsTest.equals(nextSetasListRest)); } else if (variance == 2) { a = nextSetasList.remove(0); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingExtend.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingExtend.java new file mode 100644 index 00000000..8fa32343 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingExtend.java @@ -0,0 +1,89 @@ +package de.dhbwstuttgart.typeinference.unify.model; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +public abstract class OrderingExtend extends com.google.common.collect.Ordering { + + public List maxElements(Iterable iterable) { + ArrayList ret = new ArrayList<>(); + while (iterable.iterator().hasNext()) { + Set believe = new HashSet<>(); + + T max = max(iterable); + ret.add(max); + + Iterator it = iterable.iterator(); + while (it.hasNext()) { + T elem = it.next(); + if (!(compare(max, elem) == 1) && !max.equals(elem)) { + believe.add(elem); + } + } + iterable = believe; + } + return ret; + } + + public List minElements(Iterable iterable) { + ArrayList ret = new ArrayList<>(); + while (iterable.iterator().hasNext()) { + Set believe = new HashSet<>(); + + T min = min(iterable); + ret.add(min); + + Iterator it = iterable.iterator(); + while (it.hasNext()) { + T elem = it.next(); + if (!(compare(min, elem) == -1) && !min.equals(elem)) { + believe.add(elem); + } + } + iterable = believe; + } + return ret; + } + + + public List smallerEqThan(T elem, Iterable iterable) { + List ret = smallerThan(elem, iterable); + ret.add(elem); + return ret; + + } + + public List smallerThan(T elem, Iterable iterable) { + ArrayList ret = new ArrayList<>(); + Iterator it = iterable.iterator(); + while (it.hasNext()) { + T itElem = it.next(); + if (!itElem.equals(elem) && compare(elem, itElem) == 1) { + ret.add(itElem); + } + } + return ret; + } + + public List greaterEqThan(T elem, Iterable iterable) { + List ret = greaterThan(elem, iterable); + ret.add(elem); + return ret; + + } + + public List greaterThan(T elem, Iterable iterable) { + ArrayList ret = new ArrayList<>(); + Iterator it = iterable.iterator(); + while (it.hasNext()) { + T itElem = it.next(); + if (!itElem.equals(elem) && (compare(elem, itElem) == -1)) { + ret.add(itElem); + } + } + return ret; + } +}