I'm facing the following issue and I've been racking my brain looking for a solution, but nothing comes to my mind by now:
I have a file system hierarchy, something like:
/HANDLERS/HANDLER1
/HANDLERS/HANDLER2
/HANDLERS/HANDLER3
and
/MODULES/PROGRAMMING/PROGRAMMER1
/MODULES/PROGRAMMING/PROGRAMMER2
/MODULES/PROGRAMMING/PROGRAMMER3
/MODULES/TESTING/TESTING1
/MODULES/TESTING/TESTING2
and so on.
I want to create a "tree" assuming "/" which is the root is already created. And the structure shown in the image I attach is the goal.
I need a method called
void createNode(String path){
}
In my requirements, this method will always receive the full path and do something like the following:
void create(String fullPath){
//Here I use a method which splits the fullPath into a String array to get every part that will represent a node, for example, if the fullPath is /MODULE/PROGRAMMING/PROHRAMMER1 I use:
String[] singleNodes = separateNodes(fullPath);//I get:MODULE,PROGRAMMING AND PROGRAMMER
//Then I use a loop to iterate the elements
for (String s : singleNodes) {
}
//WHAT CAN I DO HERE?
}
But I don't have idea on how to work inside the loop, I need to check if the node exists, if it exists, I just have to add the missing part, for instance, if I send /MODULES/PROGRAMMING/PROGRAMMER1, if I send for the very first time, it will create the whole thing, but if then I send /MODULES/PROGRAMMING/PROGRAMMER2, it just have to add PROGRAMMER2.
If somebody could help me I will really appretiate it, thanks in advance.