File Hierarchy system with a web application logic question: List searching

Posted by molleman on Stack Overflow See other posts from Stack Overflow or by molleman
Published on 2010-05-30T21:15:47Z Indexed on 2010/05/30 21:22 UTC
Read the original article Hit count: 285

Filed under:
|
|
|
|

I need to search through a list of folders that could have more folders inside it, and add a new folder depending what folder is its parent.(the path is stored as a String for eg = "root/MyCom/home/") Then i fill in a field with a new folder name and add it to the final folder(eg "home/").

Below as you can see , I can navigate to the right location and add the new folder to a current folder, My trouble is that i cannot ensure that currentFolder element is placed back in the list it came from

how could i add a folder to a list of folders, that could be within a list of folders,that could be within a list of folders and endless more?

      YFUser user = (YFUser)getSession().getAttribute(SESSION_USER);

      Folder newFolder = new Folder();
      newFolder.setFolderName(foldername);

              // this is the path string (root/MyCom/home/) split in the different folder names

      String folderNames[] = folderLocationString.split("/");
      int folderNamesLength = folderNames.length;

      Folder root = user.getRoot();

      Folder currentFolder = root;

      for(int i=0;i<=folderNamesLength; i++){
         // because root is folderNames[i]

          String folderName = folderNames[i++];

          int currentFolderSize = currentFolder.getChildren.getSize();

          for(int o=1; o<= currentFolderSize ; o++){

              if(currentFolder.getChildren().get(o) instanceof Folder){
                if(folderName.equals(currentFolder.getChildren().get(o).getFolderName())){

                    currentFolder = currentFolder.getChildren().get(o);

                    if  (i == counter){
//now i am inside the correct folder and i add it to the list of folders within it
//the trouble is knowing how to re add this changed folder back to the list before it

                        currentFolder.getChildren.add(newFolder);
                    }

                }
              }
          }

      }

© Stack Overflow or respective owner

Related posts about java

Related posts about gwt