-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMovieDatabase.java
92 lines (74 loc) · 2.23 KB
/
MovieDatabase.java
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
import java.util.*;
import org.apache.commons.csv.*;
import edu.duke.FileResource;
public class MovieDatabase {
private static HashMap<String, Movie> ourMovies;
public static void initialize(String moviefile) {
if (ourMovies == null) {
ourMovies = new HashMap<String,Movie>();
loadMovies("data/" + moviefile);
}
}
private static void initialize() {
if (ourMovies == null) {
ourMovies = new HashMap<String,Movie>();
loadMovies("data/ratedmoviesfull.csv");
}
}
private static void loadMovies(String filename) {
FirstRatings fr = new FirstRatings();
ArrayList<Movie> list = fr.loadMovies(filename);
for (Movie m : list) {
ourMovies.put(m.getID(), m);
}
}
public static boolean containsID(String id) {
initialize();
return ourMovies.containsKey(id);
}
public static int getYear(String id) {
initialize();
return ourMovies.get(id).getYear();
}
public static String getGenres(String id) {
initialize();
return ourMovies.get(id).getGenres();
}
public static String getTitle(String id) {
initialize();
return ourMovies.get(id).getTitle();
}
public static Movie getMovie(String id) {
initialize();
return ourMovies.get(id);
}
public static String getPoster(String id) {
initialize();
return ourMovies.get(id).getPoster();
}
public static int getMinutes(String id) {
initialize();
return ourMovies.get(id).getMinutes();
}
public static String getCountry(String id) {
initialize();
return ourMovies.get(id).getCountry();
}
public static String getDirector(String id) {
initialize();
return ourMovies.get(id).getDirector();
}
public static int size() {
return ourMovies.size();
}
public static ArrayList<String> filterBy(Filter f) {
initialize();
ArrayList<String> list = new ArrayList<String>();
for(String id : ourMovies.keySet()) {
if (f.satisfies(id)) {
list.add(id);
}
}
return list;
}
}