Search code examples
javagwtgwt2

How iterate in Hashmap till the required object


i am doing programming in GWT

i have class FolderColection and Folder, in FolderColection Class there is Hashmap hm

public class folderCollection{

  public Map<String,Folder>FolderCollection = new HashMap<String,Folder>();

  public void addFolder(Folder folder){
    String folderKey = folder.getKey();
    FolderCollection.put(folderKey, folder);
  }
}

In Folder class

public Class Folder{
  // Not a complete code , but an idea of a code 
  String name;
  String dateOfcreation;

  private FolderCollection  folderCollection = new FolderCollection();
  // Folder can also have many sub folders
  //More variables
  // all get set methods 
}

Now for example : all are folders

 1.A
    1.Aa
      1.Aa1
      2.Aa2
    2.Ab
 2.B
    1.Ba
    2.Bb
 3.C

A, B , C Folders are in FolderCollection. As A is also a folder and it contains FolderCollection (Folder Aa , Folder Ab). Similarly Folder Aa has FolderCollection of (Folder Aa1, Folder Aa2).

I able to make this which i have explained above.

I have difficulty in Accesing the object for example object of Folder Aa1. Suppose I want to change the name of Folder Aa2, for that i have to iterate till that object.

Please Help me to solve this.

i have path as all the folder names are added in tree widget accordint to the parentsTreeItem.

ex: if i have to change name of Aa2 then I have

 String [] path ={A,Aa,Aa2};

Some Help me with this will be of great Help.


Solution

  • If you have the path you don't have to iterate through the hashmap, just get the value for each path element from the respective folder collection.