Skip to content
Snippets Groups Projects
Commit 63c18b36 authored by ivarnm's avatar ivarnm
Browse files

#89 Remove noSuchElementException

parent 66cd4cdf
No related branches found
No related tags found
2 merge requests!90Dev,!88Resolve "Remove noSuchElementException"
......@@ -116,12 +116,6 @@ public class QueryIntermediate {
}
}
private static void checkIteratorNotEmpty(JsonValue.JsonIterator iterator) throws NoSuchElementException {
if (!iterator.hasNext()) {
throw new NoSuchElementException("Response empty");
}
}
// ---------------- Games methods ----------------
public static Game getGameById(String gameId) throws IOException, NoSuchElementException {
String route = "games/gamename/" + gameId;
......@@ -139,7 +133,6 @@ public class QueryIntermediate {
checkStatusCode(response);
JsonValue base = jsonReader.parse(response[1]);
JsonValue.JsonIterator iterator = base.iterator();
checkIteratorNotEmpty(iterator);
while (iterator.hasNext()) {
Game game = json.fromJson(Game.class, iterator.next().toString());
games.add(game);
......@@ -155,7 +148,6 @@ public class QueryIntermediate {
checkStatusCode(response);
JsonValue base = jsonReader.parse(response[1]);
JsonValue.JsonIterator iterator = base.iterator();
checkIteratorNotEmpty(iterator);
while (iterator.hasNext()) {
Tournament tournament = json.fromJson(Tournament.class, iterator.next().toString());
tournaments.add(tournament);
......@@ -202,14 +194,13 @@ public class QueryIntermediate {
return createdTournament;
}
public static List<Point> getTournamentPoints(String tournamentId) throws IOException, NoSuchElementException {
public static List<Point> getTournamentPoints(String tournamentId) throws IOException {
String route = "rounds/all/" + tournamentId;
List<Point> points = new ArrayList<>();
String[] response = sendGetRequest(route);
checkStatusCode(response);
JsonValue base = jsonReader.parse(response[1]);
JsonValue.JsonIterator iterator = base.iterator();
checkIteratorNotEmpty(iterator);
while (iterator.hasNext()) {
Point point = json.fromJson(Point.class, iterator.next().toString());
points.add(point);
......@@ -227,14 +218,13 @@ public class QueryIntermediate {
}
// ---------------- Highscore methods ----------------
public static List<Highscore> getHighscoresForGame(String gameId) throws IOException, NoSuchElementException {
public static List<Highscore> getHighscoresForGame(String gameId) throws IOException {
String route = "highscores/gamescores/" + gameId;
List<Highscore> highscores = new ArrayList<>();
String[] response = sendGetRequest(route);
checkStatusCode(response);
JsonValue base = jsonReader.parse(response[1]);
JsonValue.JsonIterator iterator = base.iterator();
checkIteratorNotEmpty(iterator);
while (iterator.hasNext()) {
Highscore highscore = json.fromJson(Highscore.class, iterator.next().toString());
highscores.add(highscore);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment