0
I have a class called Object and within it possesses a Collection of Events, so to sum up:
public class Objeto{
private Collection<Evento> eventos;
}
In the Event class, I have my attributes and among them, I own a:
@Getter
@Setter
@Column
@Temporal(TemporalType.TIMESTAMP)
private Date horario;
On my screen I’ll get a Collection
of Object. I need the following:
If in my Event class that is within Object I own the field horario
. I need my Collection
Object is ordered in descending order to horario
. Ex:
10/12/2015 10:00
10/12/2015 09:00
...
I tried so but unsuccessfully:
@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 solve ?
would like to add an Addendum on Arraylist: here. I believe I can help you understand your question. In your solution you use the Collection interface which in turn is the parent interface of the List interface.
– pss1suporte