From fdc6b3d9839e21de632c30396c35815ea2fcf8f0 Mon Sep 17 00:00:00 2001 From: OszkarSemerath Date: Wed, 7 Mar 2018 12:33:00 -0500 Subject: copyMap bugfix --- .../mit/inf/dslreasoner/util/CollectionsUtil.xtend | 30 +++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/util/CollectionsUtil.xtend') diff --git a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/util/CollectionsUtil.xtend b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/util/CollectionsUtil.xtend index 25cddc05..cad0330a 100644 --- a/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/util/CollectionsUtil.xtend +++ b/Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/util/CollectionsUtil.xtend @@ -8,16 +8,27 @@ import java.util.Set import org.eclipse.xtext.xbase.lib.Functions.Function1 import java.util.HashMap import java.util.LinkedHashMap +import org.eclipse.emf.ecore.EObject class CollectionsUtil { public def static TO lookup(FROM from, Map map) { if(map.containsKey(from)) { return map.get(from) - } else throw new IllegalArgumentException(''' - The map does not contains the key "«from.toString»"! - --- Elements: --- - «FOR entry : map.entrySet SEPARATOR '\n'»«entry.key» -> «entry.value»«ENDFOR» - -----------------'''); + } else { + val proxys = map.values.filter(EObject).filter[it.eIsProxy] + var message = ''' + The map does not contains the key "«from.toString»"! + --- Elements: --- + «FOR entry : map.entrySet SEPARATOR '\n'»«entry.key» -> «entry.value»«ENDFOR» + -----------------''' + if(!proxys.empty) { + message = ''' + The map contains Proxy objects: «proxys.toList» + «message» + ''' + } + throw new IllegalArgumentException(message); + } } public def TO ifThenElse(FROM source, Function1 condition, Function1 ifTrue, Function1 ifFalse) { if(condition.apply(source)) { @@ -50,10 +61,17 @@ class CollectionsUtil { } } def public static Map copyMap(Map oldMap, Iterable newValues, Function1 indexExtractor) { - val Map valueIndexes = oldMap.values.toMap[to|indexExtractor.apply(to)]; + val Map valueIndexes = newValues.toMap[to|indexExtractor.apply(to)]; val res = oldMap.mapValues[value | indexExtractor.apply(value).lookup(valueIndexes)] +// println('''from:''') +// newValues.forEach[println(it)] +// println('''old:''') +// oldMap.values.forEach[println(it)] +// println('''new:''') +// res.values.forEach[println(it)] return res } + def public static Map bijectiveInverse(Map m) { m.keySet.toMap[x|x.lookup(m)] } def public static Map> inverse(Map m) { val res = new LinkedHashMap> -- cgit v1.2.3-54-g00ecf