import java.util.*;
class ListTest {
static class Test {
int a_;
String b_;
Test(){
a_ = 0;
b_ = "";
}
}
static private int getKeyListIndex(Test a) {
int index = 0;
for (String it : keyList) {
if (a.b_.compareTo(it) == 0) {
return index;
}
index++;
}
return index;
}
static private List<String> keyList = new ArrayList<>();
static public class TestComparator implements Comparator<Test> {
public int compare(Test a, Test b) {
return getKeyListIndex(a) - getKeyListIndex(b);
}
}
private static List<Test> test_list = new ArrayList<>();
public static void main(String[] argv) {
keyList.add("second");
keyList.add("first");
keyList.add("third");
Test a = new Test();
a.a_ = 2;
a.b_ = "first";
Test az = new Test();
az.a_ = 100;
az.b_ = "firstest";
Test b = new Test();
b.a_ = 1;
b.b_ = "second";
Test c = new Test();
c.a_ = 5;
c.b_ = "third";
test_list.add(a);
test_list.add(az);
test_list.add(b);
test_list.add(c);
System.out.println("before");
for (Test it : test_list) {
System.out.println(it.a_ + ":" + it.b_);
}
Collections.sort(test_list, new TestComparator());
System.out.println("");
System.out.println("after");
for (Test it : test_list) {
System.out.println(it.a_ + ":" + it.b_);
}
}
}