Hi,
I was searching for help on sorting childrens of a Element. As you propably allready noticed you cannot simply use Collecetions.sort(List, Comparator). I was investigating the issue and some of it's solutions. All of them need to copy the children List, which didn't sound good to me on large scale batch processes. I would really like to see some kind of support for this on the next JDOM release. For the moment I would like to contribute my current solution and would like to hear your suggestions on that.
void sort(List list, Comparator c) {
Element[] a = (Element[]) list.toArray(new Element[list.size()]);
Arrays.sort(a, c);
for (int i = 0; i < a.length; i++) {
a[i].detach(); //removes Element also from "list"
}
for (int i = 0; i < a.length; i++) {
list.add(a[i]); //readd Element to "list" in the right order
}
}
regards
Thomas