cancel
Showing results for 
Search instead for 
Did you mean: 

Comparison bet two nodes

Former Member
0 Kudos

Hi,

I have two nodes with same attributes.

I want to compare the data of the two nodes.

How to code this?

thanks,

anumit

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi,

There are 2 nodes N1 & N2. Both have the same number of attributes.

Now, the datas of the two nodes is same if values of all the attributes are same.

You have to now loop over all the attributes & compare the values.

for (int i=0; i<wdContext.getnodeN1().getAttributes().size(); i++)

{

if ( ! (wdContext.getnodeN1().getElementAt(i).toString().equals(wdContext.getnodeN2().getElementAt(i).toString() ) ) )

return false; // some attribute values do not match

}

return true; //comes here when all the attribute values have matched

Kind Regards,

Nitin

Former Member
0 Kudos

Hi,

Give a try, by sorting the data in the two nodes with respect to any key attribute and then try to compare the nodes.

Regards

Raghu

Former Member
0 Kudos

Hi Anumit,

You can do that in the following way:

1) Let us take the first node as Vn_Node1 and the second as Vn_Node2

2) Have a string variable:

String strVar=null;

3) Have a for loop :

for(int i=0 ; i<wdContext.nodeVn_node().size();i++){

strVar =wdContext.nodeVn_node().getElementAt(i)toString();

if(wdContext.nodeVn_Node2.getElementAt(i).toString().equals(strVar)){

here you can specify the variable that can be set something like dataQuality of integer type, eg,

dqScore+=10;

}

}

Hope it solves your problem.

The solution is applicable only if the structure of the two nodes is exactly same, i.e., the number and name of attributes in the nodes is same.

Regards.

Rajat

Former Member
0 Kudos

Hi,

For Example

The 2 nodes say n1 and n2 and attributes say A1 and A2

if you want to compare attribute A1 of n1 with an attribute of A2 of n2 the

use the code below

if(WdContext.currentnoden1.getA1.equals(WdContext.currentnoden2.getA2))

return true;

which menas that if both the values of the 2 nodes are equal then return true;

Regards

Padma N

Former Member
0 Kudos

Hi,

node1.attribute==node2.attribute

Regards,

Sunaina Reddy T