cancel
Showing results for 
Search instead for 
Did you mean: 

How to retrieve the several attributes of a HashMap

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Greg_Austin
Active Participant
0 Kudos

What kind of object is the value in your HashMap?

Former Member
0 Kudos

It's a Nodeelement.

Greg_Austin
Active Participant
0 Kudos

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.

Former Member
0 Kudos

GREAT THANKS.

this was the line i've been looking for:

elem2 = (IPrivateItemCostView.ITestElement)hash.get(e.getKey().toString());

Former Member
0 Kudos

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

http://www.sam-solutions.net

Answers (0)