Click here to Skip to main content
15,886,061 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm creating a HashMap. While creating it, I can see that keys are assigned proper distinct values, but, after creation, when I iterate it, all the keys are yielding only one value. Below is my code:
Java
public void prepareAccountMap(HashMap<String, Object> masterMap, GAReadConfigType config, Properties prop){
    int count=0;
    for(Map.Entry<String, Object> entry : masterMap.entrySet()){
        String key = entry.getKey();
        keyList.add(count, key);
        count++;
        String childFile = (String)entry.getValue();
        System.out.println("First loop, childFile :"+childFile);
        if(childFile!=null){

            /*
             * 1) prop.getProperty gets the path from properties file
             * 2) config.readConfig reads the xml file and prepares a HashMap
            */
            HashMap<String, Object> tempChildMap = config.readConfig(prop.getProperty(GAConstants.GA_XML_CHILD)+ childFile);

            accountMap.put(key, tempChildMap.get(GAConstants.GA_DUMMY_KEY));
            GAAccountBean beanTest = (GAAccountBean)tempChildMap.get(GAConstants.GA_DUMMY_KEY);
            System.out.println("First loop, key :"+key);
            System.out.println("First loop, bean dimension :"+beanTest.getDimensionsFromXML().trim());
        }
      }
    System.out.println("");
    for(Map.Entry<String, Object> entry : accountMap.entrySet()){
        String key = entry.getKey();
        GAAccountBean tempBean = (GAAccountBean)accountMap.get(key);
        System.out.println("Second Loop, key :"+key);
        System.out.println("Second Loop, tempBean dimension :"+tempBean.getDimensionsFromXML().trim());
    }
}

Below is the console ouput:
First loop, childFile :\Acct_38058226\Prop_66591454\Prof_68497513\NJTReport2.xml
First loop, key :NJTReport2.xml
First loop, bean dimension :ga:visitorType,ga:date
First loop, childFile :\Acct_38058226\Prop_66591454\Prof_68497513\TestReportNJT1.xml
First loop, key :TestReportNJT1.xml
First loop, bean dimension :ga:browser,ga:date

Second Loop, key :NJTReport2.xml
Second Loop, tempBean dimension :ga:browser,ga:date
Second Loop, key :TestReportNJT1.xml
Second Loop, tempBean dimension :ga:browser,ga:date
Since the value stored in HashMap is a bean, I'm printing one property of the bean. Hope I'm clear with my question. If not, please let me know the caveat and I shall fill it.Thanks in advance!!
Posted
Comments
Shubhashish_Mandal 3-Apr-13 1:59am    
You have to look in this section :
HashMap<string, object=""> tempChildMap = config.readConfig(prop.getProperty(GAConstants.GA_XML_CHILD)+ childFile);

you have to print this map. What actually store in this map in each iteration. As per output, it seems to me that the map is always set with same value in each iteration
AdiCivils 3-Apr-13 3:08am    
Oh, just saw your reply.... yes, the problem was lying while setting this map. I had to create a new bean for every iteration which I missed.... Although I resolved it, my sincere thanks to you Shubhashish for replying..Thank you :)

1 solution

I've solved it!! Had to create a new object for every bean.....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900