Comparing hashmaps of hashmaps
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jennifer_Pinkham
Posted On:   Thursday, March 21, 2002 01:32 PM

I am a Perl programmer by nature and I need to know how to compare values in what would be in Perl two hashes of hashes. In Java, I have two HashMaps, one for the "current" data value and one for the "LastKnownGood" data value. The first hashmap is keyed on server name. This hashmap contains a hashmap (for each server) of various data keys and values. I need to know how, when iterating through my "current" value map, to compare that value to the same data key of the same server in the "LastKnownGood" map. This was a breeze in Perl, but I am totally stumped in how to do this in Java. Any help would be much appreciated.    More>>

I am a Perl programmer by nature and I need to know how to compare values in
what would be in Perl two hashes of hashes. In Java, I have two HashMaps,
one for the "current" data value and
one for the "LastKnownGood" data value.
The first hashmap is keyed on server name. This hashmap contains a hashmap (for each server) of various data keys and values. I need to know how, when iterating through my "current" value map, to compare that value to the same data key of the same server in the "LastKnownGood" map.


This was a breeze in Perl, but I am totally stumped in how to do this in Java. Any help would be much appreciated.

   <<Less

Re: Comparing hashmaps of hashmaps

Posted By:   Anonymous  
Posted On:   Saturday, March 30, 2002 09:56 AM

Hi, is this something like you needed?


Iterator serverNames = current.keySet().iterator();
Iterator keys = null;
String serverName = null;
String key = null;
String currentValue = null;
String lastGoodValue = null;
while(serverNames.hasNext()){
serverName = (String)serverNames.next();
keys = ((HashMap)current.get(serverName)).keySet().iterator();
while(keys.hasNext()){
key = (String)keys.next();
currentValue = (String)((HashMap)(HashMap)current.get(serverName)).get(key);
lastGoodValue = (String)((HashMap)(HashMap)lastKnownGood.get(serverName)).get(key);
//Compare currentValue and lastGoodValue
System.out.println(currentValue);
System.out.println(lastGoodValue);
}
}

It iterates through "current" HashMap and compares values in every "server" HashMap to same named "server" HashMap in "lastKnownGood" HashMap. I didn't include any null checking..

About | Sitemap | Contact