I have a model class that contains 3 ArrayList
which are in order by parallel of the same size. <Object><Calendar><Long>
I want to sort it by the <Long>
Is this the most clean? is there a better way? This doesn't seem memory efficient.
public class ResultModel{
private ArrayList<Object> sets = new ArrayList<Object>();
private ArrayList<Calendar> dates=new ArrayList<Calendar>();
private ArrayList<Long> unixtimes=new ArrayList<Long>();
private class WinningSet implements Comparable<WinningSet>{
private long unixtime;
private Object set;
private Calendar date;
WinningSet(Object set,Calendar date,long unixtime){
this.unixtime=unixtime;
this.set=set;
this.date=date;
}
@Override
public int compareTo(WinningSet another) {
return (int) (this.unixtime-another.getUnixtime());
}
public long getUnixtime() {
return unixtime;
}
public Object getSet() {
return set;
}
public Calendar getDate() {
return date;
}
}
public void sortSelf(){
ArrayList<WinningSet> list=new ArrayList<WinningSet>();
for(int i=0;i<this.unixtimes.size();i++){
list.add(new WinningSet(this.sets.get(i),dates.get(i),unixtimes.get(i)));
}
Collections.sort(list,Collections.reverseOrder());
demap(list);
}
private void demap(ArrayList<WinningSet> list) {
ArrayList<Object> tSets = new ArrayList<Object>();
ArrayList<Calendar> tDates=new ArrayList<Calendar>();
ArrayList<Long> tUnixtimes=new ArrayList<Long>();
for(WinningSet temp:list){
tDates.add(temp.getDate());
tSets.add(temp.getSet());
tUnixtimes.add(temp.getUnixtime());
}
this.sets=tSets;
this.dates=tDates;
this.unixtimes=tUnixtimes;
}
}