1212import utils .IO ;
1313import utils .Parser ;
1414import utils .Utils ;
15+ import utils .exceptions .DataNotFoundException ;
16+
17+ import javax .xml .crypto .Data ;
1518
1619/**
1720 * 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 {
3740 */
3841 public Team [] getEventTeams (String eventKey ) {
3942 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 ) ;
4144 Team [] toGet = new Team [teams .size ()];
4245 for (int i = 0 ; i < teams .size (); i ++) toGet [i ] = parseTeam (teams .get (i ));
4346 return toGet ;
@@ -52,7 +55,7 @@ public Team[] getEventTeams(String eventKey) {
5255 */
5356 public STeam [] getSEventTeams (String eventKey ) {
5457 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 ) ;
5659 STeam [] toGet = new STeam [teams .size ()];
5760 for (int i = 0 ; i < teams .size (); i ++) toGet [i ] = parseSTeam (teams .get (i ));
5861 return toGet ;
@@ -67,6 +70,7 @@ public STeam[] getSEventTeams(String eventKey) {
6770 */
6871 public String [] getTeamKeys (String eventKey ) {
6972 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 );
7074 return Utils .jsonArrayToStringArray (keys );
7175 }
7276
@@ -79,7 +83,7 @@ public String[] getTeamKeys(String eventKey) {
7983 */
8084 public Event [] getEvents (int year ) {
8185 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 ) ;
8387 Event [] toGet = new Event [events .size ()];
8488 for (int i = 0 ; i < events .size (); i ++) toGet [i ] = parseEvent (events .get (i ));
8589 return toGet ;
@@ -93,8 +97,8 @@ public Event[] getEvents(int year) {
9397 * @return SEvent[] containing all the events in the specified year
9498 */
9599 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 ) ;
98102 SEvent [] toGet = new SEvent [events .size ()];
99103 for (int i = 0 ; i < events .size (); i ++) toGet [i ] = parseSEvent (events .get (i ));
100104 return toGet ;
@@ -109,6 +113,7 @@ public SEvent[] getSEvents(int year) {
109113 */
110114 public String [] getEventKeys (int year ) {
111115 JSONArray keys = (JSONArray ) IO .doRequest ("events/" +year +"/keys" );
116+ if (keys == null ) throw new DataNotFoundException ("Couldn't find any event keys in year: " +year );
112117 return Utils .jsonArrayToStringArray (keys );
113118 }
114119
@@ -120,7 +125,9 @@ public String[] getEventKeys(int year) {
120125 * @return Event model representing the event associated with the event key
121126 */
122127 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 ;
124131 }
125132
126133 /**
@@ -131,7 +138,9 @@ public Event getEvent(String eventKey) {
131138 * @return Event model representing the event associated with the event key
132139 */
133140 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 ;
135144 }
136145
137146
@@ -143,7 +152,9 @@ public SEvent getSEvent(String eventKey) {
143152 * @return EventOPR[] containing an EventOPR for each team
144153 */
145154 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 ;
147158 }
148159
149160 /**
@@ -156,7 +167,9 @@ public EventOPR[] getOprs(String eventKey) {
156167 * @return JSON String containing prediction information
157168 */
158169 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 ;
160173 }
161174
162175 /**
@@ -168,7 +181,7 @@ public String getPredictions(String eventKey) {
168181 */
169182 public Match [] getMatches (String eventKey ) {
170183 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 ) ;
172185 Match [] toGet = new Match [matches .size ()];
173186 for (int i = 0 ; i < matches .size (); i ++) toGet [i ] = parseMatch (matches .get (i ));
174187 return toGet ;
@@ -182,8 +195,8 @@ public Match[] getMatches(String eventKey) {
182195 * @return Match[] containing a Match object for each match in the specified event
183196 */
184197 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 ) ;
187200 SMatch [] toGet = new SMatch [matches .size ()];
188201 for (int i = 0 ; i < matches .size (); i ++) toGet [i ] = parseSMatch (matches .get (i ));
189202 return toGet ;
@@ -198,6 +211,7 @@ public SMatch[] getSMatches(String eventKey) {
198211 */
199212 public String [] getMatchKeys (String eventKey ) {
200213 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 );
201215 return Utils .jsonArrayToStringArray (keys );
202216 }
203217
@@ -210,7 +224,7 @@ public String[] getMatchKeys(String eventKey) {
210224 */
211225 public Award [] getEventAwards (String eventKey ) {
212226 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 ) ;
214228 Award [] toReturn = new Award [array .size ()];
215229 for (int i = 0 ; i < array .size (); i ++) toReturn [i ] = parseAward (array .get (i ));
216230 return toReturn ;
0 commit comments