Remove Gist
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package de.jeyp91.teamidmatcher;
|
||||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import de.jeyp91.ResourceProvider;
|
||||
import de.jeyp91.StatusHolder;
|
||||
import de.jeyp91.apifootball.APIFootballMatch;
|
||||
import org.apache.logging.log4j.*;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class TeamIDMatcher {
|
||||
|
||||
private static HashBiMap<Integer, Integer> ids = null;
|
||||
private static final Logger logger = LogManager.getLogger(TeamIDMatcher.class);
|
||||
private static JSONArray teams;
|
||||
private static boolean init = false;
|
||||
public static final int HOME = 0;
|
||||
public static final int GUEST = 1;
|
||||
|
||||
private static void initBiMap() {
|
||||
if(!init) {
|
||||
ids = HashBiMap.create();
|
||||
|
||||
teams = ResourceProvider.getTeamIDMatcherConfig();
|
||||
|
||||
for (Object team : teams) {
|
||||
int tippligaID = ((Long) ((JSONObject) team).get("tippligaID")).intValue();
|
||||
int apiFootballID = ((Long) ((JSONObject) team).get("apiFootballID")).intValue();
|
||||
ids.put(tippligaID, apiFootballID);
|
||||
}
|
||||
|
||||
init = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer getApiFootballIdFromTippligaId(int id) {
|
||||
initBiMap();
|
||||
if(ids.containsKey(id)) {
|
||||
return ids.get(id);
|
||||
} else {
|
||||
logger.error("Tippliga ID: " + id + " not in ID Matcher.");
|
||||
StatusHolder.setError();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer getTippligaIdFromApiFootballId(APIFootballMatch match, int homeguest) {
|
||||
Integer apiFootballId = homeguest == HOME ? match.getTeamIdHome() : match.getTeamIdGuest();
|
||||
Integer tlwId = null;
|
||||
if(apiFootballId == null) return null;
|
||||
initBiMap();
|
||||
if(ids.inverse().containsKey(apiFootballId)) {
|
||||
tlwId = ids.inverse().get(apiFootballId);
|
||||
} else {
|
||||
String teamname = homeguest == HOME ? match.getTeamNameHome() : match.getTeamNameGuest();
|
||||
logger.error("Could not find id " + apiFootballId + " for " + teamname);
|
||||
StatusHolder.setError();
|
||||
}
|
||||
return tlwId;
|
||||
}
|
||||
|
||||
public static String getTeamNameFromTippligaId(Integer id) {
|
||||
initBiMap();
|
||||
String name = "";
|
||||
for(Object team : teams) {
|
||||
int tippligaID = ((Long)((JSONObject) team).get("tippligaID")).intValue();
|
||||
if(id == tippligaID) {
|
||||
name = (((JSONObject) team).get("teamname")).toString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user