Working through the Rocket FM series I said I would come back and explain this a little further so here we are. First lets take a look at the problem and then we can take a look at the solution.
If we take a look at a dump of our directories object as the tree is loaded (base directories) we can get a visual of what the structure is. What If I said to you please give me the object where the path is C:\dan\css. If you knew that this was the only level to search through you could easily do a loop looking at each path property. If I said to you though there could be 100 levels that you would have to search though. You still might say that you could start doing recursive loops. This gets to be a tedious process and we really need a better way to do this.
Fortunately we do have a better way of doing that and that's where the dictionary class comes into play. From the docs the dictionary class is
The Dictionary class lets you create a dynamic collection of properties, which uses strict equality (===) for key comparison on non-primitive object keys. When an object is used as a key, the object's identity is used to look up the object, and not the value returned from calling toString() on it. Primitive (built-in) objects, like Numbers, in a Dictionary collection behave in the same manner as they do when they are the property of a regular object.In our case we are know that every single item in our tree is unique because there can never be two directories with the same name. Everytime our directories object is filled we add a new item to our map and associate it with the path of that directory. We call our update map method and pass it the new list of directories. We loop the array and add the object to the map using the path as the reference. Here is a quick look at a dump of our map. As you can see, any time I need to get an object I can easily find it by the path of the directory.
Finally I can create a simple utility method for retreving the object I am looking for.
