public static Integer[] getSharedUserIds(Item x, Item y) { List<Integer> sharedUsers = new ArrayList<Integer>(); for (Rating r : x.getAllRatings()) { // same user rated the item if (y.getUserRating(r.getUserId()) != null) { sharedUsers.add(r.getUserId()); } } return sharedUsers.toArray(new Integer[sharedUsers.size()]); }
public Item(Integer id, String name, List<Rating> ratings) { this.id = id; this.name = name; // load ratings into userId -> rating map. ratingsByUserId = new HashMap<Integer, Rating>(ratings.size()); for (Rating r : ratings) { ratingsByUserId.put(r.getUserId(), r); } }
/** * Updates existing user rating or adds a new user rating for this item. * * @param r rating to add. */ public void addUserRating(Rating r) { ratingsByUserId.put(r.getUserId(), r); }