Map in Map ArrayStoreException [message #949253] |
Thu, 18 October 2012 21:08 |
John M. Messages: 198 Registered: July 2010 |
Senior Member |
|
|
Hello,
I don't know what exactly happened, but at the moment I can't use EMap in EMap any longer.
I used the recipe http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_create_a_Map_in_EMF.3F
EMap<String, EMap<String, FieldData>> headerData = command.getHeaderData();
BasicEMap<String, FieldData> hData = new BasicEMap<String, FieldData>();
FieldData d = DataFactory.eINSTANCE.createFieldData();
hData.put(key, d);
// ...
headerData.put(key, hData);
The following code leads into the ArrayStoreException.
I don't understand, why it suddenly stopped working.
Is there a problem with using EMaps in EMaps?
|
|
|
|
Re: Map in Map ArrayStoreException [message #949607 is a reply to message #949253] |
Fri, 19 October 2012 05:45 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
John,<br>
<br>
Comments below.<br>
<br>
<div class="moz-cite-prefix">On 18/10/2012 11:08 PM, John M. wrote:<br>
</div>
<blockquote cite="mid:k5pr4v$3ni$1@xxxxxxxxe.org" type="cite">Hello,
<br>
<br>
I don't know what exactly happened, but at the moment I can't use
EMap in EMap any longer.
<br>
I used the recipe
<a class="moz-txt-link-freetext" href="http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_create_a_Map_in_EMF.3F">http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_create_a_Map_in_EMF.3F</a><br>
<br>
<br>
EMap<String, EMap<String, FieldData>> headerData =
command.getHeaderData();
<br>
BasicEMap<String, FieldData> hData = new
BasicEMap<String, FieldData>();
<br>
FieldData d = DataFactory.eINSTANCE.createFieldData();
<br>
hData.put(key, d);
<br>
// ...
<br>
headerData.put(key, hData);
<br>
<br>
<br>
The following code leads into the ArrayStoreException.
<br>
</blockquote>
You must allow the framework to create right implementation classes
because EMaps are lists and what you do above will try to add the
elements of hData to the head data's value feature, which is
strongly typed to expect map entries that are the right type of
EObject sublcass, i.e., the map entry class for String/FieldData.
You can only create such things reflectively with
EcoreUtil.create(EClass) but them must do an unsafe cast: This
should work better without such casts.<br>
<blockquote>headerData.put(key, ECollections.emptyEMap());<br>
EMap<String, FieldData>> hData = headerData.get(key);<br>
hData.put(key, d);<br>
</blockquote>
<br>
<blockquote cite="mid:k5pr4v$3ni$1@xxxxxxxxe.org" type="cite">
<br>
I don't understand, why it suddenly stopped working.
<br>
Is there a problem with using EMaps in EMaps?
<br>
</blockquote>
<br>
</body>
</html>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.24820 seconds