Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Filter Folder And Files Into Tree (Composite Pattern)  RSS feed

Alexander Moosly
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cannot create sort method to put folders and files into tree structure. I am using composite pattern, I have Leaf (File) and Node(Directory). And also I have a list of Entries. I cannot figure out how to elagantly to sort them and create tree structure.
Here is an example of output

I can determine in what directory put entry only by path. I have no idea how to do this correctly.
I have two classes (composite pattern) EntryFile and EntryFolder they both extends Entry, EntryFolder in turn has method to add Entry objects.
Whole list of files and directories are represented NOT by the File class. They are JarEntry,so there is only isDirectory() method, therefore there is only ability to sort this Entries by path.
Please suggest how to do this. My brain doesn't want to work.
thanks in advance.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!