Home arrow static arrow Java Programming [Archive] - Tree data in Memory
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Tree data in Memory
This topic has 6 replies on 1 page.

Posts:9
Registered: 8/3/04
Tree data in Memory  
Aug 3, 2004 9:15 PM



 
Dear Friends,

I need your good suggestion on the following,

I am working on a GUI application. The data is nothing but a Tree. There are 6 levels and top most is Root node. In the remaining 5 levels each and every node can have any number of child nodes. The required data is in the form of XML when stored in disk.

When I load it into Memory, I dont want it to be a XML dueto memory constratints. Which is the best way to hold the Tree data in memory, so that I can manipulate the nodes easily(Remove, add, copy etc) . My node data contains just Identifier and Label. I tried with Vector, List, HashTable but manipulation is becoming difficult. Please suggest.

In summary I would like to know which is the best way to have Tree data in memory.

Best Regards,
Prasanna
 

Posts:2,909
Registered: 13.8.2003
Re: Tree data in Memory  
Aug 3, 2004 10:32 PM (reply 1 of 6)



 
DefaultMutableTreeNode is a class (unless I'm wrong) that you can use, check it up on the API. It's also easy to use with JTree if you need to display your tree.
 

Posts:31,095
Registered: 4/30/99
Re: Tree data in Memory  
Aug 3, 2004 10:55 PM (reply 2 of 6)



 
If you have an XML document on disk then the easiest thing to do is to parse it into a DOM in memory. Use a DocumentBuilder for this. Manipulating the nodes is not all that easy but once you understand how it works, it isn't that bad. This also has the advantage that you can use a Transformer to write the modified tree back to disk as a new XML document.
 

Posts:9
Registered: 8/3/04
Re: Tree data in Memory  
Aug 4, 2004 3:06 AM (reply 3 of 6)



 
Hi, Thanks for the info. I will give a try and get back to you

Best Regards,
Prasanna
 

Posts:9
Registered: 8/3/04
Re: Tree data in Memory  
Aug 4, 2004 3:07 AM (reply 4 of 6)



 
Dear Dr. Clap
I agree on DOM method, Infact I tried it before posting the query. The problem is if I have a big tree with 500 to 700 elements then memory occupied by DOM is becoming more. Thats why I dropped having it as DOM.
Best Regards,
Prasanna
 

Posts:8,813
Registered: 10/4/00
Re: Tree data in Memory  
Aug 4, 2004 5:35 AM (reply 5 of 6)



 
Put each node as the user object in a DefaultMutableTreeNode. This will require you to create at least one custom class to hold the data. Maybe more depending on what your data looks like. Make the toString() method of these classes be the value you want to display in the tree. It will probably be more work to read/write your files without a DOM, but that's the price you pay for a smaller memory footprint.
 

Posts:9
Registered: 8/3/04
Re: Tree data in Memory  
Aug 5, 2004 2:50 AM (reply 6 of 6)



 
Thanks Mr.britta. I am proceeding as you and Mr.Kayaman suggested.
Thanks to Mr.Kayaman and Dr.Clap

Best Regards,
Prasanna
 
This topic has 6 replies on 1 page.