Hi Danny,

I think it may be because you have not implemented the compare method?
One simple comparator I use for sorts looks like this:

public class TermComparator implements Comparator  {
    public int compare(Object term1, Object term2) {
        String first = ((Term) term1).getText().toUpperCase();
        String second = ((Term) term2).getText().toUpperCase();
        return first.compareTo(second);
    }

This is pre-1.5 so not generic etc, and it obviously uses the built in
String.compareTo(..) method, so for integers you need to replace with
code to comply with the Comparator.compare(..) contract:

"Compares its two arguments for order. Returns a negative integer,
zero, or a positive integer as the first argument is less than, equal
to, or greater than the second."

I actually use this on the server before list to the client since I
thought it would probably be faster in Java than in javascript and it
always has to be done and in alpha order only. Subsequently I have
considered that this puts additional pressure on the server, so even
if it would be technically slower on client, if not materially so,
then maybe better on the client.

regards
gregor

On Mar 19, 7:49 am, Danny Schimke <[email protected]> wrote:
> Hello!
>
> I have a list with objects I've got from "backend-side". Every object has a
> getSort() method, which returns an integer value. I've never worked with
> Comparator before, but I tried like the following:
>
> public List<Objecttype> getObjectListe() {
>     List<Objecttype> sortedList = model.getObjects();
>     Collections.sort(sortedList, new Comparator<Objecttype>() {
>         public int compare(Objecttype o1, Objecttype o2) {
>             // compare the o1.getSort() value with o2.getSort() value here
>         }
>     });
>     return sortedList;
>
> }
>
> And this is the error I got:
>
> [ERROR] Uncaught exception escaped
> java.lang.UnsupportedOperationException: null
>     at
> com.incowia.tkbase.unternehmenspflege.core.client.BaseReferenceList.toArray(BaseReferenceList.java:166)
>     at java.util.Collections.sort(Collections.java:158)
>
> What have I to do, to sort my list?
>
> -Danny
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to