• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating a TreeMap form Enumerated Zip Entries

 
Shawn Franks
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am completely Horrid when it comes to HashMaps.

Im looking for someone that can help me or show me the direction of creating i dynamic TreeMap.

What I want to accomplish is reading the content listing of a Zip archive which basically lists every file in string format with the entire directory path.

Thats the easy part.

I need to break down all of those entries and create a TreeMap from them so I can basically create a Structure i can access to display the files in something similar to a file explorer.

Any help would be greatly appreciated. or even other ways to view the contents of a zip file in an explorer type fashion as apposed to all files at once
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out javax.swing.JTree and javax.swing.tree.DefaultTreeModel. You'll find a link to a tutorial in the JTree API.
 
Shawn Franks
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:Check out javax.swing.JTree and javax.swing.tree.DefaultTreeModel. You'll find a link to a tutorial in the JTree API.


Unfortunately I need to do it without swing this is for a customized API so It pretty much needs to be done without any special components. Thank you though. I should have clarified when i asked for other ways so I didnt take your time.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand you correctly, you want a map of maps. Each key ("path element") points to a map containing the same thing.
 
Shawn Franks
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes that is pretty much correct.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What specifically are you having an issue with?
 
Shawn Franks
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand how I would dynamically create the tree map. Since the zip can have a multiple number of directories and there is no real way to tell it cannot be hard coded. If possibly you could show a little example of what you would do to list the contents of a zipfile and add them into a treemap just say the first directory and then the next sub directory and file so I can see how
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you with recursion? It's really only a half-dozen/dozen lines of code to create the map entries from each path.
 
Shawn Franks
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm fine with recursion.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So... if the map entry for the path element doesn't exist, create it. Pass the remaining path elements to the function (the recursive part), repeat until it's empty.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shawn Franks wrote:If possibly you could show a little example of what you would do to list the contents of a zipfile...

This is the part you should start with. Don't worry about data structures, just dump the list of contents to the console for a start. Don't try to eat the whole elephant at one sitting.
 
Shawn Franks
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand that much but my problem is I don't understand how to do the dynamic part of the tree. For instance if I mae a tree as treemap<string, string> abc = new treemap<string,string> and add the first directores and sub directories how do I add the next set because the tree is set for string string
 
Shawn Franks
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know how to dump the contents that's not the issue. I need to structure it
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It wouldn't *be* String, String--as I said previously, it'd be String, Map (or if I were doing it I might do String, MyMapClass)
 
Shawn Franks
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would string string map work?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what that means, you only get key and value types?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic