}
} while (parent != null);
}
// create bare nodes for each element
PermissibleObjectTreeNode rootNode = new PermissibleObjectTreeNode();
for (Comment comment : commentSet) {
PermissibleObjectTreeNode node = new PermissibleObjectTreeNode();
node.setObject(comment);
if (comment.getParentComment() == null) {
if (!rootNode.getChildren().containsKey(comment)) {
rootNode.getChildren().put(comment, node);
}
} else {
// try to find parent in rootNode tree
PermissibleObjectTreeNode parent = findParentCommentNode(rootNode, node);
if (parent == null) {
// this nodes parent cannot be found, let's add all of his parents
List<Comment> parentComments = new ArrayList<Comment>();
Comment parentComment = comment.getParentComment();
do {
if (parentComment != null) {
parentComments.add(parentComment);
parentComment = parentComment.getParentComment();
}
} while (parent != null);
if (parentComments.size() == 0) {
rootNode.getChildren().put(comment, node);
} else {
// reverse the order of the list and add/find existing parents
Collections.reverse(parentComments);
for (Comment myParentComment : parentComments) {
PermissibleObjectTreeNode myParentCommentNode = new PermissibleObjectTreeNode();
myParentCommentNode.setObject(myParentComment);
PermissibleObjectTreeNode parentParent = findParentCommentNode(rootNode, myParentCommentNode);
if (parentParent == null) {
rootNode.getChildren().put(myParentComment, myParentCommentNode);
} else {
if (!parentParent.getChildren().containsKey(myParentComment)) {
parentParent.getChildren().put(myParentComment, myParentCommentNode);
}
}
}
// we better find it now
parent = findParentCommentNode(rootNode, node);