/* * SD2x Homework #5 * Implement the method below according to the specification in the assignment description. * Please be sure not to change the method signature! */ import java.util.List; import java.util.PriorityQueue; import java.util.TreeMap; public class MovieRatingsParser { public static TreeMap> parseMovieRatings(List allUsersRatings) { TreeMap> movieRatings = new TreeMap>(); if(allUsersRatings == null) return movieRatings; for(UserMovieRating m : allUsersRatings){ if(m == null) continue; if(m.getMovie() == null) continue; if(m.getMovie().isEmpty()) continue; if(m.getUserRating() < 0) continue; if(!movieRatings.containsKey(m.getMovie().toLowerCase())){ PriorityQueue ratingHeap = new PriorityQueue(); ratingHeap.add(m.getUserRating()); movieRatings.put(m.getMovie().toLowerCase(), ratingHeap); continue; } movieRatings.get(m.getMovie().toLowerCase()).add(m.getUserRating()); } return movieRatings; } }