• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Creating a TreeMap form Enumerated Zip Entries

 
Ranch Hand
Posts: 30
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 30
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 30
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes that is pretty much correct.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What specifically are you having an issue with?
 
Shawn Franks
Ranch Hand
Posts: 30
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 30
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm fine with recursion.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28245
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 30
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 30
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 30
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would string string map work?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure what that means, you only get key and value types?
 
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic