<html><head><meta name="qrichtext" content="1" /></head><body style="font-size:11pt;font-family:Myriad Pro">
<p><span style="font-family:Courier New">Hi,</span></p>
<p></p>
<p><span style="font-family:Courier New">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.</span></p>
<p></p>
<p><span style="font-family:Courier New">void sort(List list, Comparator c) {</span></p>
<p><span style="font-family:Courier New"> Element[] a = (Element[]) list.toArray(new Element[list.size()]);</span></p>
<p><span style="font-family:Courier New"> Arrays.sort(a, c);</span></p>
<p><span style="font-family:Courier New"> for (int i = 0; i < a.length; i++) {</span></p>
<p><span style="font-family:Courier New"> a[i].detach(); //removes Element also from "list"</span></p>
<p><span style="font-family:Courier New"> }</span></p>
<p><span style="font-family:Courier New"> for (int i = 0; i < a.length; i++) {</span></p>
<p><span style="font-family:Courier New"> list.add(a[i]); //readd Element to "list" in the right order</span></p>
<p><span style="font-family:Courier New"> }</span></p>
<p><span style="font-family:Courier New">}</span></p>
<p></p>
<p><span style="font-family:Courier New">regards</span></p>
<p></p>
<p><span style="font-family:Courier New">Thomas</span></p>
<p></p>
</body></html>