vendredi 29 mai 2015

Collections.sort isn't sorting

I am building a web application using Java EE (although my problem is more Java based)

In a Servlet, I am getting a list of orders from the EJB. In this list of orders, there is a list of states for this order (sent, on dock, non received ...)

I want to sort this list of states by the date of the state. So I use a Collections.sort like that :

            for (Commande c : commandes) {
                c.getEtatList().sort(new Comparator<Etat>() {

                    @Override
                    public int compare(Etat o1, Etat o2) {
                        return o1.getDateEtat().compareTo(o2.getDateEtat());
                    }
                });
                c.getEtatList().sort(Collections.reverseOrder());
            }

But when I display the results, the states are not sorted.

I tried to reverse the order as you can see, but it isn't working neither.

As you also can see, I replaced the Collections.sort with the ListIWantToSort.sort. Still not working.

Any ideas on why it does not work or how I could repair it ?

Aucun commentaire:

Enregistrer un commentaire