我想基于Comparator" c"从ArrayList返回前k个ratables。为了 。所以第一个元素是根据比较器c的第一个ratable。
这是我的代码
public static ArrayList<Ratable> getTopK(ArrayList<Ratable> list, int k, Comparator c) {
ArrayList<Ratable> ratables;
if (c.toString().contains("AlphabeticalComparator")) {
ratables = AlphabeticalComparator.compare(list);
} else if (c.toString().contains("NumberOfRatingsComparator")) {
ratables = NumberOfRatingsComparator.compare(list);
} else {
Scanner in = new Scanner(System.in);
System.out.println("Enter Extra Reviews and value of extra ratings: ");
int extraReviews = in.nextInt();
double extraRatings = in.nextDouble();
ratables = BayesianAverageComparator.compare(list, extraReviews, extraRatings);
}
ArrayList<Ratable> subList = new ArrayList<Ratable>(ratables.subList(0, k));
return subList;
}
}
我的自动编程器告诉我它没有以我需要的方式订购?
答案 0 :(得分:-1)
您可以使用 <img src="../../../assets/images/Logo.png" />
。