import java.util.*;
class Main{
int[] height;
int[] etc1;
int[] etc2;
public static void main
(String[] args
){ Main m = new Main();
System.
out.
println("---初期状態----"); m.print();
System.
out.
println("---height順----"); m.sortHeight();
m.print();
System.
out.
println("---name順------"); m.sortName();
m.print();
}
public Main(){
name
= new String[]{"A",
"B",
"C"}; height = new int[]{200, 300, 100};
etc1 = new int[]{20, 30, 10 };
etc2 = new int[]{2, 3, 1 };
}
public void print(){
for(int i=0; i<height.length; i++){
System.
out.
println(name
[i
]+":"+height
[i
]+" "+etc1
[i
]+" "+etc2
[i
]); }
}
RowRef[] makeRows(){
ColSet cs = new ColSet(name, height, etc1, etc2);
RowRef[] rows = new RowRef[name.length];
for(int i=0; i<name.length; i++){
rows[i] = new RowRef(cs, i);
}
return rows;
}
void sortHeight(){
RowRef[] rows = makeRows();
Arrays.
sort(rows,
new Comparator
<RowRef
>(){ public int compare(RowRef o1, RowRef o2){return o1.cs.height[o1.row]-o2.cs.height[o2.row];}
});
rebuild(rows);
}
void sortName(){
RowRef[] rows = makeRows();
Arrays.
sort(rows,
new Comparator
<RowRef
>(){ public int compare(RowRef o1, RowRef o2){return o1.cs.name[o1.row].compareTo(o2.cs.name[o2.row]);}
});
rebuild(rows);
}
void rebuild(RowRef[] rows){
int[] height = new int[rows.length];
int[] etc1 = new int[rows.length];
int[] etc2 = new int[rows.length];
for(int i=0; i<rows.length; i++){
name [i] = rows[i].cs.name [rows[i].row];
height[i] = rows[i].cs.height[rows[i].row];
etc1 [i] = rows[i].cs.etc1 [rows[i].row];
etc2 [i] = rows[i].cs.etc2 [rows[i].row];
}
this.name = name ;
this.height = height;
this.etc1 = etc1 ;
this.etc2 = etc2 ;
}
}
class ColSet{
public int[] height;
public int[] etc1;
public int[] etc2;
public ColSet
(String[] name,
int[] height,
int[] etc1,
int[] etc2
){ this.name=name;
this.height=height;
this.etc1=etc1;
this.etc2=etc2;
}
}
class RowRef{
public ColSet cs;
public int row;
public RowRef(ColSet cs, int row){this.cs=cs; this.row=row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