[jdom-interest] Re: Comparators (was: Text class (Modified))

Noam Tamim noamt at yahoo.com
Sat Jun 2 17:47:21 PDT 2001


I tried sorting the result of elt.getChildren with the given Comparator. The
local list did sort, but the original content field of the Element remained
as it was:
<!-- input -->
<root>
    <e1>one</e1>
    <e2>two</e2>
    <e3>three</e3>
    <e4>four</e4>
</root>

after sorting the PartialList from getChildren, list.toString() :
[e4,e1,e3,e2]

output  - same as input.

 - Noam.





> class JDOMComparators {
>     public final static Comparator ElementTextComparator=new Comparator()
{
>         public int compare(Object o1, Object o2) {
>             Element e1=(Element)o1;
>             Element e2=(Element)o2;
>             return e1.getText().compareTo(e2.getText());
>         }
>     }
>     public final static Comparator TextComparator ...
>     // etc.
> }





More information about the jdom-interest mailing list