I am trying to sort an EList of functions by using Java's Comparator, but the list is not sorted after calling sort().
The way I implement it is this:
//Func.xtend <-- Start -->
public class NameComparator implements Comparator<Function_Name> {
override int compare (Function_Name function1, Function_Name function2)
{
return function1.func.compareToIgnoreCase(function2.func)
}
}
public class CheckNames {
def void checkDuplicateNames(Main_func para_func) {
var EList<Function_Name> functions = para_func.getContains()
var NameComparator pc = new NameComparator()
functions.sort(pc) //<-- sorting here
var Iterator<Function_Name> oIt = functions.iterator ()
while (oIt.hasNext)
{
var Function_Name func = oIt.next ()
System::out.println(func.func.toString)
}
}
}
// <-- End -->
Am I doing something wrong? Theoretically, after calling functions.sort(pc), the contents in variable "functions" should already be sorted, right? Or do I still need to do some processing?