-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwikiGUIController.java
More file actions
263 lines (221 loc) · 6.54 KB
/
wikiGUIController.java
File metadata and controls
263 lines (221 loc) · 6.54 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
/**
* Interface between "Back End" Movie Interpreter--Wikipedia Parser and User
* GUI. Essentially converts requested endpoint into String to be display in
* results section of GUI
*
* @author Chae Jubb
* @version 1.0
*
*/
public class wikiGUIController {
private MovieInterpreter info;
/**
* Constructor. Associates a Movie Interpreter object with the instantiated
* GUI Controller
*/
public wikiGUIController() {
info = new MovieInterpreter();
}
/**
* Best Picture Interpreter. Searches based on given Key:Value pair
*
* @param option1
* "Key" e.g. Production company(s)
* @param option2
* "Value" e.g. Disney
* @return String representation of search result
*/
public String bestPictureSearch(String option1, String option2) {
if (option1.equals("Production company")) {
option1 = "Production company(s)";
}
ArrayList<HashedInfo> response = this.info.bestPictureSearch(option1,
option2);
String strResponse = "";
if (response.size() == 0) {
throw new BadArgumentException();
}
for (HashedInfo h : response) {
strResponse += h.getHasher().get("Film") + "\n";
}
return strResponse;
}
/**
* Best Original Screenplay Writers Interpreter. Searches for movie and
* returns writers
*
* @param option1
* Film to be searched for
* @return String representation of writers if award won. Else, error
* message.
*/
public String bestOrigScreenplay(String option1) {
String[] response = this.info.originalScreenplayWriters(option1);
String strResponse = "";
if (response[0].equals("Film Not Found")) {
return "Film did not win nomination!";
}
for (String s : response) {
strResponse += s + "\n";
}
return strResponse;
}
/**
* Best Actor in Roles interpreter
*
* @param option1
* The role to be searched for
* @return String representation of actors nominated for Best Actor playing
* given role
*/
public String bestActorRole(String option1) {
ArrayList<String> response = this.info.bestLeadingActor(option1);
String strResponse = "";
if (response.size() == 0) {
throw new BadArgumentException();
}
for (String s : response) {
strResponse += s + "\n";
}
return strResponse;
}
/**
* Given a year, finds the Best Actress nominees for a given year and returns
* their age at the time of the ceremony year
*
* @param option1
* Year to be searched for
* @return String representation of actresses and their ages and movies
*/
public String actressAge(String option1) {
int op1;
try {
op1 = Integer.parseInt(option1);
} catch (Exception e) {
throw new BadArgumentException("Not an integer!");
}
ArrayList<HashedInfo> response = this.info.getCategoryYearInfo(
"Best Actress", op1);
String strResponse = "", tempString = "";
for (HashedInfo h : response) {
tempString = "";
tempString += "Name:\t" + h.getHasher().get("Name");
tempString += "; Age at Time:\t" + h.getHasher().get("Age");
tempString += "; Movie:\t" + h.getHasher().get("Movie");
strResponse += tempString + "\n";
}
return strResponse;
}
/**
* Interprets search result for directors being nominated for at least a
* given number of Best Director awards
*
* @param option1
* Threshold number of awards
* @return String representation of director name and associated movies
*/
public String directorThreshold(String option1) {
int op1;
try {
op1 = Integer.parseInt(option1);
} catch (Exception e) {
throw new BadArgumentException("Not an integer!");
}
ArrayList<Person> response = this.info.bestDirectorThreshold(op1);
String strResponse = "", tempString = "";
for (Person p : response) {
tempString = "";
tempString += "Name:\t" + p.getName();
tempString += "\t\tMovies:\t" + p.getMovie();
strResponse += tempString + "\n";
}
return strResponse;
}
/**
* Interprets Top Foreign Country end point.
*
* @return String representation of Country along with nom count and nom'ed
* movies
*/
@SuppressWarnings("unchecked")
public String topForeign() {
Object[] response = this.info.getMaxForeignWins();
String strResponse = "";
ArrayList<String> movies = (ArrayList<String>) response[2];
strResponse += "Winning Country: " + response[0] + ", with ";
strResponse += response[1] + " nominations!\n\n";
strResponse += "The movies are: \n";
for (String s : movies) {
strResponse += s + "\n";
}
return strResponse;
}
/**
* Interprets (category) starring (actor or actress) end point
*
* @param option1
* Category to be searched
* @param option2
* Actor to be searched for among nominated movies in given
* category
* @return String representation of movies nominated in given category and
* starring given person
*/
public String nomStarring(String option1, String option2) {
option1 = option1.trim().replace(' ', '_'); // converts spaces to
// underscores
ArrayList<String> response;
try {
response = this.info.getCategoryStarring(option1, option2);
} catch (Exception e) {
throw new BadArgumentException();
}
String strResponse = "";
for (String s : response) {
strResponse += s + "\n";
}
return strResponse;
}
/**
* Interprets "quad threat" end point.
*
* @return String representation of movies nominated for Best Picture, Best
* Director, Best Actor, and Best Actress along with total win count
*/
public String quadThreat() {
HashMap<String, Integer> response = this.info.getQuadThreat();
String strResponse = "", curMovie;
Iterator<String> movies = response.keySet().iterator();
while (movies.hasNext()) {
curMovie = movies.next();
strResponse += curMovie + ", winning ";
strResponse += response.get(curMovie) + " awards!\n";
}
return strResponse;
}
/**
* Interprets best picture count end point
*
* @return Number of films nominated for Best Picture
*/
public String bestPictureCount() {
String count = this.info.getBestPictureCount();
String strResponse = count
+ " different movies have been nominated for Best Picture. Wow!";
return strResponse;
}
/**
* Interprets best actor count end point
*
* @return Number of films nominated for Best Actor
*/
public String bestActorCount() {
String count = this.info.getBestActorCount();
String strResponse = count
+ " different nominations have been handed out for Best Actor. Wow!";
return strResponse;
}
}