From 532018241c798d5ed63284f04213745d9286b913 Mon Sep 17 00:00:00 2001 From: NoName11234 <47484268+NoName11234@users.noreply.github.com> Date: Mon, 19 Feb 2024 19:38:19 +0100 Subject: [PATCH] implemented class UnifyResultModelParallel --- .../unify/UnifyResultModelParallel.java | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModelParallel.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModelParallel.java index ca373d6e1..b6a1b8eb6 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModelParallel.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModelParallel.java @@ -1,2 +1,58 @@ -package de.dhbwstuttgart.typeinference.unify;public class UnifyResultModelParallel { +package de.dhbwstuttgart.typeinference.unify; + +import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; +import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; +import de.dhbwstuttgart.typeinference.constraints.Pair; +import de.dhbwstuttgart.typeinference.result.ResultSet; +import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.model.PairOperator; +import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; + +import java.util.*; +import java.util.concurrent.ForkJoinPool; +import java.util.stream.Collectors; + +public class UnifyResultModelParallel { + private ForkJoinPool pool; + private ConstraintSet cons; + private IFiniteClosure fc; + private List listeners = new ArrayList<>(); + + public UnifyResultModelParallel(ConstraintSet cons, IFiniteClosure fc){ + this.cons = cons; + this.fc = fc; + } + + public void setPool(ForkJoinPool pool){ + this.pool = pool; + } + public void addUnifyResultListener(UnifyResultListener listenerToAdd) { + listeners.add(listenerToAdd); + } + public void removeUnifyResultListener(UnifyResultListener listenerToRemove) { + listeners.remove(listenerToRemove); + } + public void notify(Set> eqPrimePrimeSet){ + pool.execute(()->{ + Object HashSet; + Set> eqPrimePrimeSetRet = eqPrimePrimeSet.stream().map(x -> { + Optional> res = new RuleSet().subst(x.stream().map(y -> { + if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT); + return y; //alle Paare a <.? b erden durch a =. b ersetzt + }).collect(Collectors.toCollection(HashSet::new))); + if (res.isPresent()) {//wenn subst ein Erg liefert wurde was veraendert + return new TypeUnifyTask().applyTypeUnificationRules(res.get(), fc); + } + else return x; //wenn nichts veraendert wurde wird x zurueckgegeben + }).collect(Collectors.toCollection(HashSet::new)); + List newResult = eqPrimePrimeSetRet.stream().map(unifyPairs -> + new ResultSet(UnifyTypeFactory.convert(unifyPairs, de.dhbwstuttgart.typeinference.constraints.Pair.generateTPHMap(cons)))) + .collect(Collectors.toList()); + UnifyResultEvent evt = new UnifyResultEvent(newResult); + + for (UnifyResultListener listener : listeners) { + listener.onNewTypeResultFound(evt); + } + }); + } }