/** Table pairing team abbreviations (code) with full team names. */ public static final String[][] teamNames = new String[][] { {"ANA","Anaheim Angels"}, {"ATL","Atlanta Braves"}, {"ARI","Arizona Diamondbacks"}, {"BAL","Baltimore Orioles"}, {"BOS","Boston Red Sox"}, {"CHC","Chicago Cubs"}, {"CIN","Cincinnati Reds"}, {"CLE","Cleveland Indians"}, {"COL","Colorado Rockies"}, {"CWS","Chicago White Sox"}, {"DET","Detroit Tigers"}, {"FLA","Florida Marlins"}, {"HOU","Houston Astros"}, {"KC","Kansas City Royals"}, {"LA","Los Angeles Dodgers"}, {"MIL","Milwaukee Brewers"}, {"MIN","Minnesota Twins"}, {"MON","Montreal Expos"}, {"NYM","New York Mets"}, {"NYY","New York Yankees"}, {"OAK","Oakland Athletics"}, {"PHI","Philadelphia Phillies"}, {"PIT","Pittsburgh Pirates"}, {"SD","San Diego Padres"}, {"SEA","Seattle Mariners"}, {"SF","San Francisco Giants"}, {"STL","St. Louis Cardinals"}, {"TB","Tampa Bay Devil Rays"}, {"TEX","Texas Rangers"}, {"TOR","Toronto Blue Jays"} }; /** Given a full team name (or a significant part of a full team name), * convert it to a team code; or given a * team code, convert it to a full team name. "Significant" means * 5 or more exactly matching letters. * For example, all of the following * will return "TB": "Tampa Bay Devil Rays", "Tampa", "Devil", * etc. On the other hand, if the input is "TB" then "Tampa Bay Devil Rays" * is returned. If part of a full name occurs in more than one full name, * there is no guarantee about which matching team is returned. * @param tname any string * @return the code for a name, or the name for a code; or null * if the given string is not found. */ public static String convertTeamName(String tname) { if (tname == null || tname.length() == 0) { return null; } String trimmedNameLC = tname.trim().toLowerCase(); for (int n = 0; n < teamNames.length; n++) { if (trimmedNameLC.equalsIgnoreCase(teamNames[n][0])) { return teamNames[n][1]; } if (trimmedNameLC.equalsIgnoreCase(teamNames[n][1])) { return teamNames[n][0]; } } //No exact match found if (trimmedNameLC.length() < 5) { return null; //not enough for a reliable partial match } //make a last-gasp attempt to match something for (int n = 0; n < teamNames.length; n++) { if (teamNames[n][1].toLowerCase().indexOf(trimmedNameLC) >= 0) { return teamNames[n][0]; } } return null; }