Wednesday, April 09, 2008

Compare two properties files

I had two properties files and the parameter names were almost same in those two files. I had to go through them to find difference in the values. Searching for any utility didnt get a positive result. So, implemented the following logic.

Load both the file data into a hash map

(the param will be the key; we will end up having two hash maps)

for loop into sorted keys of first map

{

if (key exist in second map)
{

if
(firstMap.valueof(key) == secondMap.valueof(key))

{


key = firstMap.valueof(key) in both maps

}
else

{


key differs in the maps with firstMap.valueof(key)


and secondMap.valueof(key)



}

}

else

{

key exist only in first map


}

}

for loop into sorted keys of second map

{

if (key not exist in first map)

{

key exist only in second map


}

}

No comments: