Filter Folder And Files Into Tree (Composite Pattern)
posted 1 year ago
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.