Refactor Line separator for Mac and add APIFootballProvider
This commit is contained in:
@@ -12,6 +12,7 @@ import org.json.simple.parser.JSONParser;
|
|||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@@ -77,7 +78,7 @@ public class APIFootballConnector {
|
|||||||
JSONObject object = null;
|
JSONObject object = null;
|
||||||
//JSON parser object to parse read file
|
//JSON parser object to parse read file
|
||||||
JSONParser jsonParser = new JSONParser();
|
JSONParser jsonParser = new JSONParser();
|
||||||
URL url = Resources.getResource((this.season + 1) + "\\API-Football\\" + filename + ".json");
|
URL url = Resources.getResource((this.season + 1) + File.separator + "API-Football" + File.separator + filename + ".json");
|
||||||
String jsonConfig = null;
|
String jsonConfig = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.json.simple.JSONObject;
|
|||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -55,7 +56,7 @@ public class APIFootballMatch extends BaseMatch {
|
|||||||
JSONObject object = null;
|
JSONObject object = null;
|
||||||
//JSON parser object to parse read file
|
//JSON parser object to parse read file
|
||||||
JSONParser jsonParser = new JSONParser();
|
JSONParser jsonParser = new JSONParser();
|
||||||
URL url = Resources.getResource((this.season + 1) + "\\API-Football\\" + filename);
|
URL url = Resources.getResource((this.season + 1) + File.separator + "API-Football" + File.separator + filename);
|
||||||
String jsonConfig = null;
|
String jsonConfig = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package de.jeyp91.apifootball;
|
||||||
|
|
||||||
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class APIFootballMatchesProvider {
|
||||||
|
|
||||||
|
APIFootballConnector conn;
|
||||||
|
public APIFootballMatchesProvider(int season) {
|
||||||
|
this.conn = new APIFootballConnector(season - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<APIFootballMatch> getAPIFootballMatchesFromConfig(JSONArray config) {
|
||||||
|
ArrayList<APIFootballMatch> apiFootballMatches = new ArrayList<>();
|
||||||
|
for (Object singleConfigObject : config) {
|
||||||
|
JSONObject singleConfig = (JSONObject) singleConfigObject;
|
||||||
|
String type = (String) singleConfig.get("type");
|
||||||
|
switch (type) {
|
||||||
|
case "AllMatchesOfMatchday":
|
||||||
|
int matchesLeague = ((Long) singleConfig.get("matchesLeague")).intValue();
|
||||||
|
int leagueMatchday = ((Long) singleConfig.get("leagueMatchday")).intValue();
|
||||||
|
apiFootballMatches.addAll(conn.getMatchDataByLeagueAndMatchday(matchesLeague, leagueMatchday));
|
||||||
|
break;
|
||||||
|
case "SingleMatch":
|
||||||
|
int matchLeague = ((Long) singleConfig.get("matchLeague")).intValue();
|
||||||
|
int matchId = ((Long) singleConfig.get("matchId")).intValue();
|
||||||
|
apiFootballMatches.add(conn.getMatchDataByLeagueAndMatchID(matchLeague, matchId));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return apiFootballMatches;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import org.json.simple.JSONObject;
|
|||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -29,7 +30,7 @@ public class TLWMatchdaysCreator {
|
|||||||
this.matches = matchesCreator.getMatches();
|
this.matches = matchesCreator.getMatches();
|
||||||
|
|
||||||
JSONParser jsonParser = new JSONParser();
|
JSONParser jsonParser = new JSONParser();
|
||||||
URL url = Resources.getResource(season + "\\" + configPath);
|
URL url = Resources.getResource(season + File.separator + configPath);
|
||||||
String jsonConfig = null;
|
String jsonConfig = null;
|
||||||
try {
|
try {
|
||||||
jsonConfig = Resources.toString(url, StandardCharsets.UTF_8);
|
jsonConfig = Resources.toString(url, StandardCharsets.UTF_8);
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import java.util.ArrayList;
|
|||||||
public abstract class TLWMatchesCreatorBase {
|
public abstract class TLWMatchesCreatorBase {
|
||||||
|
|
||||||
ArrayList<TLWMatch> TLWMatches;
|
ArrayList<TLWMatch> TLWMatches;
|
||||||
APIFootballConnector conn;
|
|
||||||
|
|
||||||
public TLWMatchesCreatorBase() {
|
public TLWMatchesCreatorBase() {
|
||||||
this.TLWMatches = new ArrayList<>();
|
this.TLWMatches = new ArrayList<>();
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
package de.jeyp91.tippliga;
|
package de.jeyp91.tippliga;
|
||||||
|
|
||||||
import com.google.common.io.Resources;
|
import com.google.common.io.Resources;
|
||||||
import de.jeyp91.apifootball.APIFootballConnector;
|
|
||||||
import de.jeyp91.apifootball.APIFootballMatch;
|
import de.jeyp91.apifootball.APIFootballMatch;
|
||||||
|
import de.jeyp91.apifootball.APIFootballMatchesProvider;
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -31,11 +32,15 @@ public class TLWMatchesCreatorFootball extends TLWMatchesCreatorBase {
|
|||||||
|
|
||||||
this.season = season;
|
this.season = season;
|
||||||
this.league = league;
|
this.league = league;
|
||||||
this.conn = new APIFootballConnector(season - 1);
|
|
||||||
|
|
||||||
URL url = Resources.getResource(season + "\\" + configFileName);
|
this.initConfigParamsFromFile(configFileName);
|
||||||
|
this.publicateMatchObjects();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initConfigParamsFromFile(String configFileName) {
|
||||||
|
|
||||||
|
URL url = Resources.getResource(season + File.separator + configFileName);
|
||||||
String jsonConfig = null;
|
String jsonConfig = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONParser jsonParser = new JSONParser();
|
JSONParser jsonParser = new JSONParser();
|
||||||
jsonConfig = Resources.toString(url, StandardCharsets.UTF_8);
|
jsonConfig = Resources.toString(url, StandardCharsets.UTF_8);
|
||||||
@@ -48,16 +53,16 @@ public class TLWMatchesCreatorFootball extends TLWMatchesCreatorBase {
|
|||||||
} catch (IOException | ParseException e) {
|
} catch (IOException | ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.publicateMatchObjects();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void publicateMatchObjects() {
|
private void publicateMatchObjects() {
|
||||||
|
|
||||||
|
APIFootballMatchesProvider provider = new APIFootballMatchesProvider(this.season);
|
||||||
|
|
||||||
for(int i = 0; i < this.matchdayConfig.size(); i++) {
|
for(int i = 0; i < this.matchdayConfig.size(); i++) {
|
||||||
int TLWMatchday = ((Long) ((JSONObject) this.matchdayConfig.get(i)).get("TLWMatchday")).intValue();
|
int TLWMatchday = ((Long) ((JSONObject) this.matchdayConfig.get(i)).get("TLWMatchday")).intValue();
|
||||||
JSONArray matchesConfig = (JSONArray)((JSONObject) this.matchdayConfig.get(i)).get("matchesConfig");
|
JSONArray matchesConfig = (JSONArray)((JSONObject) this.matchdayConfig.get(i)).get("matchesConfig");
|
||||||
ArrayList<APIFootballMatch> APIFootballMatches = getAPIFootballMatchesForMatchday(matchesConfig);
|
ArrayList<APIFootballMatch> APIFootballMatches = provider.getAPIFootballMatchesFromConfig(matchesConfig);
|
||||||
|
|
||||||
int tempNumberOfMatchesBackup = this.matchesPerMatchday;
|
int tempNumberOfMatchesBackup = this.matchesPerMatchday;
|
||||||
if(((JSONObject) this.matchdayConfig.get(i)).containsKey("numberOfMatches")) {
|
if(((JSONObject) this.matchdayConfig.get(i)).containsKey("numberOfMatches")) {
|
||||||
@@ -109,27 +114,6 @@ public class TLWMatchesCreatorFootball extends TLWMatchesCreatorBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<APIFootballMatch> getAPIFootballMatchesForMatchday(JSONArray config) {
|
|
||||||
ArrayList<APIFootballMatch> apiFootballMatches = new ArrayList<>();
|
|
||||||
for (Object singleConfigObject : config) {
|
|
||||||
JSONObject singleConfig = (JSONObject) singleConfigObject;
|
|
||||||
String type = (String) singleConfig.get("type");
|
|
||||||
switch (type) {
|
|
||||||
case "AllMatchesOfMatchday":
|
|
||||||
int matchesLeague = ((Long) singleConfig.get("matchesLeague")).intValue();
|
|
||||||
int leagueMatchday = ((Long) singleConfig.get("leagueMatchday")).intValue();
|
|
||||||
apiFootballMatches.addAll(conn.getMatchDataByLeagueAndMatchday(matchesLeague, leagueMatchday));
|
|
||||||
break;
|
|
||||||
case "SingleMatch":
|
|
||||||
int matchLeague = ((Long) singleConfig.get("matchLeague")).intValue();
|
|
||||||
int matchId = ((Long) singleConfig.get("matchId")).intValue();
|
|
||||||
apiFootballMatches.add(conn.getMatchDataByLeagueAndMatchID(matchLeague, matchId));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return apiFootballMatches;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getDaysDifference(Date date1, Date date2) {
|
private int getDaysDifference(Date date1, Date date2) {
|
||||||
long startTime = date1.getTime();
|
long startTime = date1.getTime();
|
||||||
long endTime = date2.getTime();
|
long endTime = date2.getTime();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.json.simple.JSONObject;
|
|||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -27,7 +28,7 @@ public class TLWMatchesCreatorTipperLeague extends TLWMatchesCreatorBase {
|
|||||||
this.matchdays = matchdays;
|
this.matchdays = matchdays;
|
||||||
|
|
||||||
URL matchPairConfigUrl = Resources.getResource("Tipper_Match_Pair_Config.json");
|
URL matchPairConfigUrl = Resources.getResource("Tipper_Match_Pair_Config.json");
|
||||||
URL tipperListUrl = Resources.getResource(season + "\\" + configFileName);
|
URL tipperListUrl = Resources.getResource(season + File.separator + configFileName);
|
||||||
URL tipperTeamConfigUrl = Resources.getResource("Tipper_Team_Config.json");
|
URL tipperTeamConfigUrl = Resources.getResource("Tipper_Team_Config.json");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.json.simple.JSONObject;
|
|||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -26,7 +27,7 @@ public class TLWMatchesCreatorTipperPokal extends TLWMatchesCreatorBase{
|
|||||||
this.league = league;
|
this.league = league;
|
||||||
this.matchdays = matchdays;
|
this.matchdays = matchdays;
|
||||||
|
|
||||||
URL tipperListUrl = Resources.getResource(season + "\\" + configFileName);
|
URL tipperListUrl = Resources.getResource(season + File.separator + configFileName);
|
||||||
URL tipperTeamConfigUrl = Resources.getResource("Tipper_Team_Config.json");
|
URL tipperTeamConfigUrl = Resources.getResource("Tipper_Team_Config.json");
|
||||||
|
|
||||||
this.TLWMatches = new ArrayList<>();
|
this.TLWMatches = new ArrayList<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user