I have a JavaTree ,its all node has a name and assigned value. I want to add these names and values to HashMap. But, I can't take all results to HashMap finally. It take only one value in one time. I used following code.
public HashMap<String, Double> printAll(TreeNode root) {
HashMap<String, Double> allContainNodes = new HashMap<String, Double>();
NodeInfor nodeObj = (NodeInfor) ((DefaultMutableTreeNode) root).getUserObject();
Enumeration children = root.children();
if (children != null)
while (children.hasMoreElements()) {
printAll((TreeNode) children.nextElement());
}
}
allContainNodes .put(nodeObj.name, nodeObj.specVal);
return allContainNodes;
}