Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordwagelaar2015-06-19 03:54:28 -0400
committerdwagelaar2015-06-19 03:54:28 -0400
commitfe43639fac463224b45d96a9ae086148e762106b (patch)
treeb771047952a378039b9a3deedefa5a7302cfb35c /plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse
parent2ef39443e9ace54750b4d6cc9c74a5a2f4c05471 (diff)
downloadorg.eclipse.atl-fe43639fac463224b45d96a9ae086148e762106b.tar.gz
org.eclipse.atl-fe43639fac463224b45d96a9ae086148e762106b.tar.xz
org.eclipse.atl-fe43639fac463224b45d96a9ae086148e762106b.zip
Added LazyCollection.mappedBySingle().
Diffstat (limited to 'plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse')
-rw-r--r--plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/LazyCollection.java24
1 files changed, 24 insertions, 0 deletions
diff --git a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/LazyCollection.java b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/LazyCollection.java
index 54fec4d5..45419992 100644
--- a/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/LazyCollection.java
+++ b/plugins/org.eclipse.m2m.atl.emftvm/src/org/eclipse/m2m/atl/emftvm/util/LazyCollection.java
@@ -2392,6 +2392,30 @@ public abstract class LazyCollection<E> implements Collection<E> {
}
/**
+ * Returns a Map indexed by the return value(s) <code>x</code> of the
+ * body expression, containing a single element for which the
+ * body expression returns <code>x</code>.
+ * @param body the function to evaluate on each element
+ * @return the Map
+ */
+ public Map<Object, E> mappedBySingle(final CodeBlock body) {
+ final StackFrame frame = body.getParentFrame();
+ body.setParentFrame(null);
+ final Map<Object, E> result = new HashMap<Object, E>();
+ for (E e : this) {
+ Object key = body.execute(frame.getSubFrame(body, new Object[] { e }));
+ if (key instanceof Collection<?>) {
+ for (Object k : (Collection<?>) key) {
+ result.put(k, e);
+ }
+ } else {
+ result.put(key, e);
+ }
+ }
+ return result;
+ }
+
+ /**
* Updates the given maps for {@link #mappedBy(CodeBlock)}.
* @param key the map key
* @param e the map value

Back to the top