* This method recursively adds leaves to the group's leaf
**/ @SuppressWarnings("unchecked")
private ResultTreeNode getResultTree(Matcher m, int groupIndex) {
// Create the leaf for the current group and add it to the used groups vector
usedGroups.add(groupIndex);
ResultTreeNode treeNode = new ResultTreeNode(m.group(groupIndex), "", m.start(groupIndex), m.end(groupIndex));
// Seek for children
for (int i = groupIndex+1; i < m.groupCount(); i++) {
// if the group #i is contained by the current group and has never been added in the tree, add it !
if (m.start(i) >= m.start(groupIndex) && m.end(i) <= m.end(groupIndex) && !usedGroups.contains(i)) {
ResultTreeNode child = getResultTree(m, i);
treeNode.add(child);
}
}
return treeNode;
}