I have a class called Object and inside it has a Collection of Events , summarizing it like this:
public class Objeto{
private Collection<Evento> eventos;
}
In the Event class, I have my attributes and I have one of them:
@Getter
@Setter
@Column
@Temporal(TemporalType.TIMESTAMP)
private Date horario;
On my screen I'm going to get a% object_with%. I need the following:
If in my Event class that is inside Object I have the Collection
field. I need my% object% to be sorted in descending order to horario
. Ex:
10/12/2015 10:00
10/12/2015 09:00
...
I tried this way but without success:
@SuppressWarnings("deprecation")
public Collection<Objeto> ordenarLista() {
Collection<Objeto> objetos = service.findAll();
Collection<Objeto> lista = new ArrayList<Objeto>();
Date referencia = new Date("10/01/2000 00:00:00");
for (Objeto objeto : objetos) {
for (Evento evento : objeto.getEventos()){
if (evento.getHorario().after(referencia)){
lista.add(objeto);
referencia = evento.getHorario();
}
}
}
return lista;
}
Does anyone know how I can resolve?