我在GWT如何在哈希映射迭代,直到所需的对象
我有类FolderColection和文件夹, 在FolderColection类做的节目有哈希映射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);
}
}
在文件夹类
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
}
现在例如:所有文件夹
1.A
1.Aa
1.Aa1
2.Aa2
2.Ab
2.B
1.Ba
2.Bb
3.C
A,B,C文件夹位于FolderCollection中。 由于A也是一个文件夹,它包含FolderCollection(文件夹Aa,文件夹Ab)。 类似的文件夹Aa具有FolderCollection(文件夹Aa1,文件夹Aa2)。
我能够做到这一点,我已经在上面解释过了。
我很难找到对象,例如文件夹Aa1的对象。 假设我想更改文件夹Aa2的名称,因为我必须迭代到该对象。
请帮我解决这个问题。
我有路径,因为所有的文件夹名称被添加到树的小部件accordint parentTreeItem。
例如:如果我必须改变为Aa2的名字,那么 我有
String [] path ={A,Aa,Aa2};
一些帮助我,这将是很大的帮助。
如果您有路径,则不必通过散列映射_iterate_,只需从各个文件夹集合中获取每个路径元素的值即可。 – Thomas
@Thomas:确切地说,但我认为我必须为它编写递归代码。但我无法做到这一点。请告诉我一小段代码,以便我能理解。 – NewCodeLearner
btw,整理你的类,方法和变量的大小写。类+接口应该以大写字母,方法和变量小写字母开头。 – wmorrison365