List<RecommendedItem> recommended = topRecsByUserID.get(userID);
if (recommended == null) {
return Collections.emptyList();
}
User theUser = getDataModel().getUser(userID);
List<RecommendedItem> rescored = new ArrayList<RecommendedItem>(recommended.size());
// Only add items the user doesn't already have a preference for.
// And that the rescorer doesn't "reject".
for (RecommendedItem recommendedItem : recommended) {
Item item = recommendedItem.getItem();
if (rescorer != null && rescorer.isFiltered(item)) {
continue;
}
if (theUser.getPreferenceFor(item.getID()) == null &&
(rescorer == null || !Double.isNaN(rescorer.rescore(item, recommendedItem.getValue())))) {
rescored.add(recommendedItem);
}
}
Collections.sort(rescored, new ByRescoreComparator(rescorer));