I have an ArrayList of objects, in every object I have a date and an hour that I have casted to int for the sorting. I have already sorted the list of object by the date and now I want to sort the same array list by the hour keeping the sorting of the date.
A little example of the situation:
I have an event object with method getDateEvent() and getHourEvent() that returns a value sortable of data and hour like YYYYMMDD and HHMM
And an arraylist of event already sorted by the date so i have to order the arraylist by the hour keeping the date sorted.
My code is actually this :
private ArrayList<Evento> SortingHour(ArrayList<Evento> SortingList){
int t=0;
int counter=0;
ArrayList<Evento> finale = new ArrayList<>();
ArrayList<Evento>[] Array = new ArrayList[SortingList.size()];
while(counter<SortingList.size()){
if( SortingList.get(counter).getDateEvent()).equals(SortingList.get(counter+1).getDateEvent()))) {
Array[t].add(SortingList.get(counter));
Array[t].add(SortingList.get(counter+1));
counter++;
}else{
t++;
Array[t].add(SortingList.get(counter));}
counter++;
}
for(int c=0;c<t;c++) {
for (int c1 = 0; c1 < Array[c].size(); c1++) {
for (int c2 = 0; c2 < Array[c].size(); c2++) {
if (Integer.parseInt(Array[c].get(c1).getHourEvent()) < Integer.parseInt(Array[c].get(c2).getHourEvent())) {
Collections.swap(Array[c], c1, c2);
}
}
}
}
for(int c=0; c<t;c++){
finale.addAll(Array[c]);
}
return finale;
}