I wrote the following two methods:
private Integer[] cutDownRecommendations(Shiur shiur, int numberOfRecs, int[] recommendationRaw)
{
Integer[] recommendation = new Integer[numberOfRecs];
ArrayList<String> speakers = shiur.getSpeakers();
//next count up all the scores
HashMap<Integer, Integer> findCount = new HashMap<>();
for(String speaker : speakers) {
ArrayList<Integer> relevantShiurim = speakerShiurMap.get(speaker);
for(int id : relevantShiurim) {
if(!findCount.containsKey(id)){
findCount.put(id,1);
}else{
int score = findCount.get(id);
findCount.put(id,++score);
}
}
}
recommendation = HashSetSortByValue.hashMapKeysSortByValue(findCount);
return recommendation;
}
In the "HashSetSortByValue" class I have the following method:
public static Comparable[] hashMapKeysSortByValue(HashMap<Comparable, Comparable> unsorted)
{
int len = unsorted.size();
Comparable[] orderedKeysByValue = new Comparable[len];
//convert keys into an array
Comparable[] keys = new Integer[len];
int position = 0;
for(Comparable item : unsorted.keySet()) keys[position++] = item;
Comparable[] values = new Integer[len];
position = 0;
for(Comparable item : unsorted.values()) values[position++] = item;
merge(values, keys);
//TODO fill this in
return orderedKeysByValue;
}
I'm getting compiler errors for the following line:
recommendation = HashSetSortByValue.hashMapKeysSortByValue(findCount);
return recommendation;
The error says:
The method hashMapKeysSortByValue(HashMap<Comparable,Comparable>) in the type HashSetSortByValue is not applicable for the arguments (HashMap<Integer,Integer>)
According to the java API the Integer class implements Comparable, so why am I getting this error?