Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , , ,

Sponsored Links



Editing subject of a Hashtable

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 23-02-2010
Member
 
Join Date: Dec 2009
Posts: 213
Editing subject of a Hashtable

Hello,
I have a list of objects in the Hashtable and I must change as a routine field (if field = a, then replace with "String", if = b. ..). This field is also a list (ArrayList). Hashtable containing "Subject". Object containing an ArrayList Attributes. Attribute containing a type field to edit. The problem is that I travel with my lists of nested loops, I get my item, modify it, but this change is not reflected in the object stored in my Hashtable. If I add the object, he will not write another. it's just the bins. Someone had a solution for this problem ...?
Reply With Quote
  #2  
Old 23-02-2010
Member
 
Join Date: Nov 2009
Posts: 335
Re: Editing subject of a Hashtable

Hello,
This topic is new to me, but still I have a code with me, check out if it works
Code:
for (Iterator it = listeObjets.values().iterator(); It.hasNext();) {
                Object obj = (Subject) it.next();
	for(Iterator it2 = (obj.getLesAttributs()).iterator(); it2.hasNext();)
                {
		Attribute at =(Attribute)it2.next();
String tp =(String) lesTypes.get(at.getType());
at.setType(tp);
	}
	for(Iterator it2 =(obj.getLesMethodes()).iterator(); it2.hasNext();) 
               {
		Method meth =(Method)it2.next();
String rt =(String)lesTypes.get(Meth.getRetour());
Meth.setRetour(rt);
					
		for(Iterator it3 =(Meth.getLesParametres()).iterator(); it3.hasNext();){
			Attribute at =(Attribute)it3.next();
String tp =(String)lesTypes.get(at.getType());
at.setType(tp);
		}
	}
}
Reply With Quote
  #3  
Old 23-02-2010
Member
 
Join Date: Nov 2009
Posts: 583
Re: Editing subject of a Hashtable

Hello,
The code that we propose you seems correct and after testing my home, it works. Are you sure your applications through this snippet? are you sure the lists are not empty? Only changes to objects associated attribute does not work, or as that of Method objects? Can you put a trace in the methods setType () and setRetour () to see if they fit right in and what is the parameter that receives, at last check if the assignment goes well, (view before / after)?
Reply With Quote
  #4  
Old 23-02-2010
Member
 
Join Date: Nov 2009
Posts: 447
Re: Editing subject of a Hashtable

Hello,
I also tested and no problems but I have simulated the setter. Can you show us your setter you ... because according to the instructions that you do in your setters you do not work on the elements contained in your Hashtable with the iterator you do not work by reference. If you need any more help with it, then please do ask and we will try to help sort your problem.
Reply With Quote
  #5  
Old 23-02-2010
Member
 
Join Date: Dec 2009
Posts: 213
Re: Editing subject of a Hashtable

Hello,
In fact, I build my objects call methods of successive and therefore I have declared my items locally and that there is only one object instance. So I solved the problem by recreating a new object when the insert in the list, and by transferring the info from my purpose built in the new. Anyway, thank you for your help.
Reply With Quote
  #6  
Old 23-02-2010
Member
 
Join Date: Dec 2009
Posts: 202
Re: Editing subject of a Hashtable

Hey,
Even I am trying this section of java, and I have a example just have a look at it
Code:
Map mp = new HashMap();    
    mp = new TreeMap();        // sorted mp
    
    // Add key/val pairs to the mp
    mp.put("x", new Integer(1));
    mp.put("y", new Integer(2));
    mp.put("z", new Integer(3));
    
    // Get number of entries in mp
    int size = mp.size();        // 2
    
    // Adding an entry whose key exists in the mp causes
    // the new val to replace the old val
    Object odval = mp.put("x", new Integer(9));  // 1
    
    // Remove an entry from the mp and 
    // return the val of the removed entry
    odval = mp.remove("c");  // 3
    
    // Iterate over all keys in the table 
    Iterator it = mp.keySet().iterator();
    while (it.hasNext()) {
        // Retrieve key
        Object key = it.next();
    }
    
    // Iterate over all vals in table 
    it = mp.vals().iterator();
    while (it.hasNext()) {
        // Get val
        Object val = it.next();
    }
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Editing subject of a Hashtable"
Thread Thread Starter Forum Replies Last Post
HashMap vs HashTable Joyjeet Software Development 6 04-01-2011 09:07 PM
Hashtable vs Vector Vodka Software Development 5 23-02-2010 02:43 AM
Manipulating a hashtable Miles Runner Software Development 5 12-02-2010 01:20 AM
Problem sorting a Hashtable Vodka Software Development 5 04-02-2010 05:16 AM
C# Hashtable vs list vs dictionary Zaafir Software Development 3 31-07-2009 01:36 PM


All times are GMT +5.5. The time now is 11:28 AM.