on 05-10-2007 2:35 PM
Hi @ all,
I have defined a HashMap which holds Elements with several attributes (like nr, description, planned, changed)
the key is the nr and the value are the rest attributes.
Now I would like to get the values and reassign them to a Node.
Can Someone tell me how to make this?
Here is my code-beginning:
public void getPlanpEl( java.lang.String intentNr )
{
for (final Iterator i = planpMap.entrySet().iterator(); i.hasNext();)
{
final Map.Entry e = (Map.Entry) i.next();
String key = e.getKey().toString().substring(0, 8);
if (key.equals(intentNr))
{
IPublicIntentCust.IIntentionElement newIntentionElement = wdContext.nodeIntention().createIntentionElement();
// provide node elements with data
newIntentionElement.setIntnr(<b>e.getValue()</b>);
Thanks
Claudi
What kind of object is the value in your HashMap?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm not 100% sure what you are trying to do but here is some code I threw together that builds a node and elements from node elements in a hash.
IWDMessageManager mess = wdComponentAPI.getMessageManager();
HashMap hash = new HashMap();
IPrivateItemCostView.ITestNode node = wdContext.nodeTest();
IPrivateItemCostView.ITestElement elem;
IPrivateItemCostView.ITestElement elem2;
//create some test elements and put them in the hash
elem = wdContext.createTestElement();
elem.setValue1("here1");
elem.setValue2("here2");
hash.put("test1", elem);
elem = wdContext.createTestElement();
elem.setValue1("here3");
elem.setValue2("here4");
hash.put("test2", elem);
Iterator i = hash.entrySet().iterator();
//loop through the hash and create and fill the node.
while (i.hasNext()){
Map.Entry e;
//get the element from the hash
e = (Map.Entry)i.next();
elem2 = (IPrivateItemCostView.ITestElement)hash.get(e.getKey().toString());
//create a new node element
elem = (IPrivateItemCostView.ITestElement)node.createTestElement();
elem.setValue1(elem2.getValue1());
elem.setValue2(elem2.getValue2());
//add the element to the node
node.addElement(elem);
}
//loop through the newly created node and print the values
for (int x = 0; x < node.size(); x++)
{
elem = node.getTestElementAt(x);
mess.reportSuccess("elem " + x + " value1 = " + elem.getValue1());
mess.reportSuccess("elem " + x + " value2 = " + elem.getValue2());
}
Hope this helps.
Claudia,
Small advise, instead of that line use:
elem2 = (IPrivateItemCostView.ITestElement)e.getValue();
This makes your code a bit faster while it saves unnecessary (in this case) hash lookup.
Valery Silaev
SaM Solutions
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.