* their associated tree nodes.
*/
final JsonStringMap<WorkspaceNode> idToNode = JsonCollections.createMap();
final JsonArray<WorkspaceNode> rootNodes = JsonCollections.createArray();
for (int i = 0; i < workspaces.size(); i++) {
WorkspaceInfo value = workspaces.get(i);
WorkspaceNode node = new WorkspaceNode(value);
rootNodes.add(node);
idToNode.put(value.getId(), node);
}
/*
* Iterate over the list of workspaces and add each workspace as a child of
* its parent.
*/
int count = rootNodes.size();
for (int i = 0; i < count; i++) {
WorkspaceNode node = rootNodes.get(i);
WorkspaceInfo workspace = node.getWorkspace();
WorkspaceNode parentNode = idToNode.get(workspace.getParentId());
if (parentNode != null) {
parentNode.addChild(node);
// This node has a parent, so it is not a root node.
rootNodes.remove(i);