Beispiel #1
0
 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()]);
 }
Beispiel #2
0
 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);
   }
 }
Beispiel #3
0
 /**
  * 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);
 }