Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Filter Folder And Files Into Tree (Composite Pattern)

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