12
12
import utils .IO ;
13
13
import utils .Parser ;
14
14
import utils .Utils ;
15
+ import utils .exceptions .DataNotFoundException ;
16
+
17
+ import javax .xml .crypto .Data ;
15
18
16
19
/**
17
20
* In an attempt to keep this API organized, if you look at the blue alliance v3 documentation, all calls that start with /events/ or /event/
@@ -37,7 +40,7 @@ public class EventRequest extends Parser {
37
40
*/
38
41
public Team [] getEventTeams (String eventKey ) {
39
42
JSONArray teams = (JSONArray ) IO .doRequest ("event/" +eventKey +"/teams" );
40
- if (teams == null ) return null ;
43
+ if (teams == null ) throw new DataNotFoundException ( "Couldn't find any teams in event with key: " + eventKey ) ;
41
44
Team [] toGet = new Team [teams .size ()];
42
45
for (int i = 0 ; i < teams .size (); i ++) toGet [i ] = parseTeam (teams .get (i ));
43
46
return toGet ;
@@ -52,7 +55,7 @@ public Team[] getEventTeams(String eventKey) {
52
55
*/
53
56
public STeam [] getSEventTeams (String eventKey ) {
54
57
JSONArray teams = (JSONArray ) IO .doRequest ("event/" +eventKey +"/teams/simple" );
55
- if (teams == null ) return null ;
58
+ if (teams == null ) throw new DataNotFoundException ( "Couldn't find any simple teams in event with key: " + eventKey ) ;
56
59
STeam [] toGet = new STeam [teams .size ()];
57
60
for (int i = 0 ; i < teams .size (); i ++) toGet [i ] = parseSTeam (teams .get (i ));
58
61
return toGet ;
@@ -67,6 +70,7 @@ public STeam[] getSEventTeams(String eventKey) {
67
70
*/
68
71
public String [] getTeamKeys (String eventKey ) {
69
72
JSONArray keys = (JSONArray ) IO .doRequest ("event/" +eventKey +"/teams/keys" );
73
+ if (keys == null ) throw new DataNotFoundException ("Couldn't find any team keys in event with key: " +eventKey );
70
74
return Utils .jsonArrayToStringArray (keys );
71
75
}
72
76
@@ -79,7 +83,7 @@ public String[] getTeamKeys(String eventKey) {
79
83
*/
80
84
public Event [] getEvents (int year ) {
81
85
JSONArray events = (JSONArray ) IO .doRequest ("events/" +year );
82
- if (events == null ) return null ;
86
+ if (events == null ) throw new DataNotFoundException ( "Couldn't find any events in year: " + year ) ;
83
87
Event [] toGet = new Event [events .size ()];
84
88
for (int i = 0 ; i < events .size (); i ++) toGet [i ] = parseEvent (events .get (i ));
85
89
return toGet ;
@@ -93,8 +97,8 @@ public Event[] getEvents(int year) {
93
97
* @return SEvent[] containing all the events in the specified year
94
98
*/
95
99
public SEvent [] getSEvents (int year ) {
96
- JSONArray events = (JSONArray ) IO .doRequest ("events/" +" year/simple" );
97
- if (events == null ) return null ;
100
+ JSONArray events = (JSONArray ) IO .doRequest ("events/" +year + " /simple" );
101
+ if (events == null ) throw new DataNotFoundException ( "Couldn't find any simple events in year: " + year ) ;
98
102
SEvent [] toGet = new SEvent [events .size ()];
99
103
for (int i = 0 ; i < events .size (); i ++) toGet [i ] = parseSEvent (events .get (i ));
100
104
return toGet ;
@@ -109,6 +113,7 @@ public SEvent[] getSEvents(int year) {
109
113
*/
110
114
public String [] getEventKeys (int year ) {
111
115
JSONArray keys = (JSONArray ) IO .doRequest ("events/" +year +"/keys" );
116
+ if (keys == null ) throw new DataNotFoundException ("Couldn't find any event keys in year: " +year );
112
117
return Utils .jsonArrayToStringArray (keys );
113
118
}
114
119
@@ -120,7 +125,9 @@ public String[] getEventKeys(int year) {
120
125
* @return Event model representing the event associated with the event key
121
126
*/
122
127
public Event getEvent (String eventKey ) {
123
- return parseEvent (IO .doRequest ("event/" +eventKey ));
128
+ Event event = parseEvent (IO .doRequest ("event/" +eventKey ));
129
+ if (event == null ) throw new DataNotFoundException ("No event found with key: " +eventKey );
130
+ return event ;
124
131
}
125
132
126
133
/**
@@ -131,7 +138,9 @@ public Event getEvent(String eventKey) {
131
138
* @return Event model representing the event associated with the event key
132
139
*/
133
140
public SEvent getSEvent (String eventKey ) {
134
- return parseSEvent (IO .doRequest ("event/" +eventKey +"/simple" ));
141
+ SEvent event = parseSEvent (IO .doRequest ("event/" +eventKey +"/simple" ));
142
+ if (event == null ) throw new DataNotFoundException ("No simple event found with key: " +eventKey );
143
+ return event ;
135
144
}
136
145
137
146
@@ -143,7 +152,9 @@ public SEvent getSEvent(String eventKey) {
143
152
* @return EventOPR[] containing an EventOPR for each team
144
153
*/
145
154
public EventOPR [] getOprs (String eventKey ) {
146
- return parseOPRs (IO .doRequest ("event/" +eventKey +"/oprs" ));
155
+ EventOPR [] oprs = parseOPRs (IO .doRequest ("event/" +eventKey +"/oprs" ));
156
+ if (oprs == null ) throw new DataNotFoundException ("No oprs found for event with key: " +eventKey );
157
+ return oprs ;
147
158
}
148
159
149
160
/**
@@ -156,7 +167,9 @@ public EventOPR[] getOprs(String eventKey) {
156
167
* @return JSON String containing prediction information
157
168
*/
158
169
public String getPredictions (String eventKey ) {
159
- return (String ) IO .doRequest ("event/" +eventKey +"predictions" );
170
+ String s = (String ) IO .doRequest ("event/" +eventKey +"predictions" );
171
+ if (s == null ) throw new DataNotFoundException ("No predictions found for event with key: " +eventKey );
172
+ return s ;
160
173
}
161
174
162
175
/**
@@ -168,7 +181,7 @@ public String getPredictions(String eventKey) {
168
181
*/
169
182
public Match [] getMatches (String eventKey ) {
170
183
JSONArray matches = (JSONArray ) IO .doRequest ("event/" +eventKey +"/matches" );
171
- if (matches == null ) return null ;
184
+ if (matches == null ) throw new DataNotFoundException ( "No matches found for event with key: " + eventKey ) ;
172
185
Match [] toGet = new Match [matches .size ()];
173
186
for (int i = 0 ; i < matches .size (); i ++) toGet [i ] = parseMatch (matches .get (i ));
174
187
return toGet ;
@@ -182,8 +195,8 @@ public Match[] getMatches(String eventKey) {
182
195
* @return Match[] containing a Match object for each match in the specified event
183
196
*/
184
197
public SMatch [] getSMatches (String eventKey ) {
185
- JSONArray matches = (JSONArray ) IO .doRequest ("events /" +"year /simple" );
186
- if (matches == null ) return null ;
198
+ JSONArray matches = (JSONArray ) IO .doRequest ("event /" +eventKey + "/matches /simple" );
199
+ if (matches == null ) throw new DataNotFoundException ( "No simple matches found for event with key: " + eventKey ) ;
187
200
SMatch [] toGet = new SMatch [matches .size ()];
188
201
for (int i = 0 ; i < matches .size (); i ++) toGet [i ] = parseSMatch (matches .get (i ));
189
202
return toGet ;
@@ -198,6 +211,7 @@ public SMatch[] getSMatches(String eventKey) {
198
211
*/
199
212
public String [] getMatchKeys (String eventKey ) {
200
213
JSONArray keys = (JSONArray ) IO .doRequest ("event/" +eventKey +"/matches/keys" );
214
+ if (keys == null ) throw new DataNotFoundException ("No match keys found for event with key: " +eventKey );
201
215
return Utils .jsonArrayToStringArray (keys );
202
216
}
203
217
@@ -210,7 +224,7 @@ public String[] getMatchKeys(String eventKey) {
210
224
*/
211
225
public Award [] getEventAwards (String eventKey ) {
212
226
JSONArray array = (JSONArray ) IO .doRequest ("event/" +eventKey +"/awards" );
213
- if (array == null ) return null ;
227
+ if (array == null ) throw new DataNotFoundException ( "No awards found for event with key: " + eventKey ) ;
214
228
Award [] toReturn = new Award [array .size ()];
215
229
for (int i = 0 ; i < array .size (); i ++) toReturn [i ] = parseAward (array .get (i ));
216
230
return toReturn ;
0 commit comments