には 5 つのエントリが保存されていArrayList<ArrayList<Double>> selected
ます。これらの各エントリは、 と の 2 つのパラメータで指定されrank
ますcd
。
rank = [1.0, 2.0, 3.1, 1.2, 2.1]
cd = [6.2, 5.2, 7.1, 8.0, 1.1]
これらのエントリを降順 (つまり、3.1、2.1、2.0、1.2、1.1 )で並べる必要があります。2 番目の順序付け ( by ) は、 によって既に順序付けされているエントリに適用する必要があります。rank
cd
cd
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);
問題は、注文前にエントリに割り当てられた ID を取得する方法がわからないことです。たとえば、これは ID の順不同のシーケンスです: 1、2、3、4、5、およびこれは順序付け後の ID のシーケンスです: 5、3、4、1、2. これらの ID を取得する方法は?