There are 5 entries stored in ArrayList<ArrayList<Double>> selected. Each of these entries is specified by two parameters - rank and cd:
rank = [1.0, 2.0, 3.1, 1.2, 2.1]
cd = [6.2, 5.2, 7.1, 8.0, 1.1]
I need to order these entries, firstly, by rank and, secondly, by cd in descending order (i.e. 3.1, 2.1, 2.0, 1.2, 1.1). The second ordering (by cd) must be applied to entries that have been already ordered by rank.
ArrayList<Double> rank = new ArrayList<Double>();
ArrayList<Double> cd = new ArrayList<Double>();
ArrayList<ArrayList<Double>> selected = new ArrayList<ArrayList<Double>>();
for (int i=0; i<len; i++) {
rank.add(getRank(i));
cd.add(getCub_len(i));
}
selected.add(0,rank);
selected.add(1,cd);
Comparator<ArrayList<Double>> comparatorRank = new Comparator<ArrayList<Double>>()
{
public int compare(ArrayList<Double> a, ArrayList<Double> b)
{
return (int) (a.get(0) - b.get(0));
}
};
Comparator<ArrayList<Double>> comparatorCD = new Comparator<ArrayList<Double>>()
{
public int compare(ArrayList<Double> a, ArrayList<Double> b)
{
return (int) (a.get(1) - b.get(1));
}
};
Collections.sort(selected, comparatorRank);
Collections.sort(selected, comparatorCD);
The problem is that I don't know how to get IDs that have been assigned to entries before ordering. For instance, this is unordered sequence of IDs: 1, 2, 3, 4, 5, and this is the sequence of IDs after ordering: 5, 3, 4, 1, 2. How to get these IDs?