I have a tree that consists of different type of objects for example
Tree
| \
apple cat
| \
dog grass
| \
door something
For example I can access the object something using Tree.getApple().getGrass().getSomething() where on every getter I have to check if the node exists. The problem is that the structure I use is pretty big and I want to have a utility class to speed this up.
I want only given the name of the object to be able to extract it from the structure. For example to have a method to which after I give Something.class as an argument to traverse the structure, return the object if it exists and return null otherwise. (I cannot have multiple occurrences of one class in the structure, i.e. I can have only one apple object)
Is that possible? What can I use to implement it?
Implement a visitor that traverses the three and implement the filter in the visitor.
Roughly: