M.forEachPair(new IntObjectProcedure<Vector>() {
@Override
public boolean apply(int itemID, Vector itemFeatures) {
if (!alreadyRatedItems.contains(itemID)) {
double predictedRating = U.get(userID).dot(itemFeatures);
topKItems.offer(new GenericRecommendedItem(itemID, (float) predictedRating));
}
return true;
}
});
List<RecommendedItem> recommendedItems = Lists.newArrayListWithExpectedSize(recommendationsPerUser);
for (RecommendedItem topItem : topKItems.retrieve()) {
recommendedItems.add(new GenericRecommendedItem(topItem.getItemID(), Math.min(topItem.getValue(), maxRating)));
}
if (!topKItems.isEmpty()) {
ctx.write(userIDWritable, new RecommendedItemsWritable(recommendedItems));
}