-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMovieRatingsProcessor.java
More file actions
104 lines (74 loc) · 3.28 KB
/
MovieRatingsProcessor.java
File metadata and controls
104 lines (74 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* SD2x Homework #5
* Implement the methods below according to the specification in the assignment description.
* Please be sure not to change the method signatures!
*/
import com.sun.javafx.scene.control.skin.VirtualFlow;
import java.util.*;
public class MovieRatingsProcessor {
public static List<String> getAlphabeticalMovies(TreeMap<String, PriorityQueue<Integer>> movieRatings) {
/* IMPLEMENT THIS METHOD! */
public static List<String> getAlphabeticalMovies (TreeMap < String, PriorityQueue < Integer >> movieRatings){
/* IMPLEMENT THIS METHOD! */
List<String> arr1 = new ArrayList<String>();
if (movieRatings == null || movieRatings.isEmpty()) return arr1;
PriorityQueue<String> alphaMovie = new PriorityQueue<String>();
for (Map.Entry<String, PriorityQueue<Integer>> entry : movieRatings.entrySet()) {
alphaMovie.add(entry.getKey());
}
arr1 = new ArrayList<String>(alphaMovie);
return arr1;
}
public static List<String> getAlphabeticalMoviesAboveRating
(TreeMap < String, PriorityQueue < Integer >> movieRatings,int rating){
/* IMPLEMENT THIS METHOD! */
List<String> movieAboveRating = new ArrayList<String>();
if (movieRatings == null || movieRatings.isEmpty()) return movieAboveRating;
for (Map.Entry<String, PriorityQueue<Integer>> entry : movieRatings.entrySet()) {
if (entry.getValue().poll() > rating) {
movieAboveRating.add(entry.getKey());
}
}
return movieAboveRating;
/*List<String> arr1 = new ArrayList<String>();
if (movieRatings == null || movieRatings.isEmpty()) return arr1;
PriorityQueue<String> alphaMovie = new PriorityQueue<String>();
for (Map.Entry<String,PriorityQueue<Integer>> entry : movieRatings.entrySet()){
if(entry.getValue().size()>0 & entry.getValue().peek()>rating) alphaMovie.add(entry.getKey());
}
arr1= new ArrayList<String>(alphaMovie);
return arr1;*/
}
public static TreeMap<String, Integer> removeAllRatingsBelow (TreeMap < String, PriorityQueue < Integer >> movieRatings,int rating){
TreeMap<String, Integer> nMap = new TreeMap<String, Integer>();
List<String> temp=new ArrayList<String>();
if (movieRatings == null || movieRatings.isEmpty()) return nMap;
for (Map.Entry<String, PriorityQueue<Integer>> entry : movieRatings.entrySet()) {
int count = 0;
while (!entry.getValue().isEmpty() && entry.getValue().peek() < rating) {
entry.getValue().poll();
count++;
}
if(count>0) nMap.put(entry.getKey(), count);
if(entry.getValue().isEmpty()) temp.add(entry.getKey());
}
if (movieRatings == null || movieRatings.isEmpty()) return nMap;
movieRatings.remove(temp);
return nMap;
}
}
}
/*TreeMap<String,Integer> aaaa = new TreeMap<String, Integer>();
if (movieRatings == null || movieRatings.isEmpty()) return aaaa;
for (Map.Entry<String,PriorityQueue<Integer>> entry : movieRatings.entrySet()){
if(entry.getValue().peek()>= rating) continue;
int count=0;
while(entry.getValue().size()>0 && entry.getValue().peek()< rating){
entry.getValue().poll();
count++;
}
aaaa.put(entry.getKey(),count);
if(entry.getValue().isEmpty()) movieRatings.remove(entry.getKey());
}
return aaaa;
}*/