diff options
author | OszkarSemerath <oszkar.semerath@gmail.com> | 2018-03-07 12:33:00 -0500 |
---|---|---|
committer | OszkarSemerath <oszkar.semerath@gmail.com> | 2018-03-07 12:33:00 -0500 |
commit | fdc6b3d9839e21de632c30396c35815ea2fcf8f0 (patch) | |
tree | 6ef182434db0ae3473fe63b7e47a727b3b79d9fc /Framework | |
parent | Path as additional parameter (diff) | |
download | VIATRA-Generator-fdc6b3d9839e21de632c30396c35815ea2fcf8f0.tar.gz VIATRA-Generator-fdc6b3d9839e21de632c30396c35815ea2fcf8f0.tar.zst VIATRA-Generator-fdc6b3d9839e21de632c30396c35815ea2fcf8f0.zip |
copyMap bugfix
Diffstat (limited to 'Framework')
-rw-r--r-- | Framework/hu.bme.mit.inf.dslreasoner.logic.model/src/hu/bme/mit/inf/dslreasoner/util/CollectionsUtil.xtend | 30 |
1 files changed, 24 insertions, 6 deletions
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 | |||
8 | import org.eclipse.xtext.xbase.lib.Functions.Function1 | 8 | import org.eclipse.xtext.xbase.lib.Functions.Function1 |
9 | import java.util.HashMap | 9 | import java.util.HashMap |
10 | import java.util.LinkedHashMap | 10 | import java.util.LinkedHashMap |
11 | import org.eclipse.emf.ecore.EObject | ||
11 | 12 | ||
12 | class CollectionsUtil { | 13 | class CollectionsUtil { |
13 | public def static <FROM,TO> TO lookup(FROM from, Map<? super FROM,TO> map) { | 14 | public def static <FROM,TO> TO lookup(FROM from, Map<? super FROM,TO> map) { |
14 | if(map.containsKey(from)) { | 15 | if(map.containsKey(from)) { |
15 | return map.get(from) | 16 | return map.get(from) |
16 | } else throw new IllegalArgumentException(''' | 17 | } else { |
17 | The map does not contains the key "«from.toString»"! | 18 | val proxys = map.values.filter(EObject).filter[it.eIsProxy] |
18 | --- Elements: --- | 19 | var message = ''' |
19 | «FOR entry : map.entrySet SEPARATOR '\n'»«entry.key» -> «entry.value»«ENDFOR» | 20 | The map does not contains the key "«from.toString»"! |
20 | -----------------'''); | 21 | --- Elements: --- |
22 | «FOR entry : map.entrySet SEPARATOR '\n'»«entry.key» -> «entry.value»«ENDFOR» | ||
23 | -----------------''' | ||
24 | if(!proxys.empty) { | ||
25 | message = ''' | ||
26 | The map contains Proxy objects: «proxys.toList» | ||
27 | «message» | ||
28 | ''' | ||
29 | } | ||
30 | throw new IllegalArgumentException(message); | ||
31 | } | ||
21 | } | 32 | } |
22 | public def <FROM,TO> TO ifThenElse(FROM source, Function1<FROM,Boolean> condition, Function1<FROM,TO> ifTrue, Function1<FROM,TO> ifFalse) { | 33 | public def <FROM,TO> TO ifThenElse(FROM source, Function1<FROM,Boolean> condition, Function1<FROM,TO> ifTrue, Function1<FROM,TO> ifFalse) { |
23 | if(condition.apply(source)) { | 34 | if(condition.apply(source)) { |
@@ -50,10 +61,17 @@ class CollectionsUtil { | |||
50 | } | 61 | } |
51 | } | 62 | } |
52 | def public static <From,To,Property> Map<From,To> copyMap(Map<From,To> oldMap, Iterable<To> newValues, Function1<To,Property> indexExtractor) { | 63 | def public static <From,To,Property> Map<From,To> copyMap(Map<From,To> oldMap, Iterable<To> newValues, Function1<To,Property> indexExtractor) { |
53 | val Map<Property,To> valueIndexes = oldMap.values.toMap[to|indexExtractor.apply(to)]; | 64 | val Map<Property,To> valueIndexes = newValues.toMap[to|indexExtractor.apply(to)]; |
54 | val res = oldMap.mapValues[value | indexExtractor.apply(value).lookup(valueIndexes)] | 65 | val res = oldMap.mapValues[value | indexExtractor.apply(value).lookup(valueIndexes)] |
66 | // println('''from:''') | ||
67 | // newValues.forEach[println(it)] | ||
68 | // println('''old:''') | ||
69 | // oldMap.values.forEach[println(it)] | ||
70 | // println('''new:''') | ||
71 | // res.values.forEach[println(it)] | ||
55 | return res | 72 | return res |
56 | } | 73 | } |
74 | |||
57 | def public static <From,To> Map<To,From> bijectiveInverse(Map<From,To> m) { m.keySet.toMap[x|x.lookup(m)] } | 75 | def public static <From,To> Map<To,From> bijectiveInverse(Map<From,To> m) { m.keySet.toMap[x|x.lookup(m)] } |
58 | def public static <From,To> Map<To,List<From>> inverse(Map<From,To> m) { | 76 | def public static <From,To> Map<To,List<From>> inverse(Map<From,To> m) { |
59 | val res = new LinkedHashMap<To,List<From>> | 77 | val res = new LinkedHashMap<To,List<From>> |