1
2 package hoplugins.teamAnalyzer.manager;
3
4 import hoplugins.Commons;
5
6 import hoplugins.teamAnalyzer.vo.Team;
7
8 import plugins.ILigaTabellenEintrag;
9 import plugins.IMatchKurzInfo;
10 import plugins.IMatchLineup;
11 import plugins.IPaarung;
12 import plugins.ISpielePanel;
13 import plugins.ISpielplan;
14
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.Collection;
18 import java.util.HashMap;
19 import java.util.Iterator;
20 import java.util.List;
21 import java.util.Map;
22
23
24 /***
25 * TODO Missing Class Documentation
26 *
27 * @author TODO Author Name
28 */
29 public class TeamManager {
30
31
32 private static Map teams = null;
33 private static boolean updated = false;
34
35
36
37 /***
38 * TODO Missing Method Documentation
39 *
40 * @return TODO Missing Return Method Documentation
41 */
42 public static Team getNextCupOpponent() {
43 Team team = new Team();
44 int teamId = Commons.getModel().getBasics().getTeamId();
45 IMatchKurzInfo[] cupMatches = Commons.getModel().getMatchesKurzInfo(teamId,
46 ISpielePanel.NUR_EIGENE_POKALSPIELE,
47 false);
48 IMatchKurzInfo[] friendlyMatches = Commons.getModel().getMatchesKurzInfo(teamId,
49 ISpielePanel.NUR_EIGENE_FREUNDSCHAFTSSPIELE,
50 false);
51 List l = new ArrayList();
52
53 l.addAll(Arrays.asList(friendlyMatches));
54 l.addAll(Arrays.asList(cupMatches));
55
56 Object[] matches = l.toArray();
57
58 for (int i = 0; i < matches.length; i++) {
59 IMatchKurzInfo match = (IMatchKurzInfo) matches[i];
60
61 if (match.getMatchStatus() != IMatchKurzInfo.FINISHED) {
62 if (match.getHeimID() == teamId) {
63 team.setName(match.getGastName());
64 team.setTeamId(match.getGastID());
65 } else {
66 team.setName(match.getHeimName());
67 team.setTeamId(match.getHeimID());
68 }
69
70 return team;
71 }
72 }
73
74 return team;
75 }
76
77 /***
78 * TODO Missing Method Documentation
79 *
80 * @return TODO Missing Return Method Documentation
81 */
82 public static Team getNextLeagueOpponent() {
83 ISpielplan league = getDivisionMatches();
84
85 if (league != null) {
86 List matches = league.getPaarungenBySpieltag(Commons.getModel().getBasics().getSpieltag());
87
88 for (Iterator iter = matches.iterator(); iter.hasNext();) {
89 IPaarung element = (IPaarung) iter.next();
90
91 if (element.getHeimId() == Commons.getModel().getBasics().getTeamId()) {
92 Team t = new Team();
93
94 t.setName(element.getGastName());
95 t.setTeamId(element.getGastId());
96
97 return t;
98 }
99
100 if (element.getGastId() == Commons.getModel().getBasics().getTeamId()) {
101 Team t = new Team();
102
103 t.setName(element.getHeimName());
104 t.setTeamId(element.getHeimId());
105
106 return t;
107 }
108 }
109 }
110
111 return getNextQualificationOpponent();
112 }
113
114 /***
115 * TODO Missing Method Documentation
116 *
117 * @param teamId TODO Missing Method Parameter Documentation
118 *
119 * @return TODO Missing Return Method Documentation
120 */
121 public static Team getTeam(int teamId) {
122 return (Team) teams.get(teamId + "");
123 }
124
125 /***
126 * TODO Missing Method Documentation
127 *
128 * @param teamId TODO Missing Method Parameter Documentation
129 *
130 * @return TODO Missing Return Method Documentation
131 */
132 public static boolean isTeamInList(int teamId) {
133 if (teams.get(teamId + "") != null) {
134 return true;
135 }
136
137 return false;
138 }
139
140 /***
141 * TODO Missing Method Documentation
142 *
143 * @return TODO Missing Return Method Documentation
144 */
145 public static Collection getTeams() {
146 if (teams == null) {
147 teams = new HashMap();
148
149 List l = loadDivisionTeams();
150
151 for (Iterator iter = l.iterator(); iter.hasNext();) {
152 Team element = (Team) iter.next();
153
154 teams.put(element.getTeamId() + "", element);
155 }
156
157 Team qualTeam = getNextQualificationOpponent();
158
159 if (qualTeam.getTeamId() != 0) {
160 teams.put(qualTeam.getTeamId() + "", qualTeam);
161 }
162
163 Team cupTeam = getNextCupOpponent();
164
165 if (cupTeam.getTeamId() != 0) {
166 teams.put(cupTeam.getTeamId() + "", cupTeam);
167 }
168 }
169
170 return teams.values();
171 }
172
173 /***
174 * TODO Missing Method Documentation
175 *
176 * @return TODO Missing Return Method Documentation
177 */
178 public static boolean isUpdated() {
179 updated = !updated;
180
181 return !updated;
182 }
183
184 /***
185 * TODO Missing Method Documentation
186 *
187 * @param team TODO Missing Method Parameter Documentation
188 */
189 public static void addFavouriteTeam(Team team) {
190 if (!isTeamInList(team.getTeamId())) {
191 teams.put(team.getTeamId() + "", team);
192 }
193
194 forceUpdate();
195 }
196
197 /***
198 * TODO Missing Method Documentation
199 */
200 public static void clean() {
201 teams = null;
202 updated = true;
203 }
204
205 /***
206 * TODO Missing Method Documentation
207 */
208 public static void forceUpdate() {
209 updated = true;
210 }
211
212 /***
213 * TODO Missing Method Documentation
214 *
215 * @return TODO Missing Return Method Documentation
216 */
217 private static ISpielplan getDivisionMatches() {
218 ISpielplan league = Commons.getModel().getSpielplan(Commons.getModel().getXtraDaten()
219 .getLeagueLevelUnitID(),
220 Commons.getModel().getBasics()
221 .getSeason());
222
223 return league;
224 }
225
226 /***
227 * TODO Missing Method Documentation
228 *
229 * @return TODO Missing Return Method Documentation
230 */
231 private static Team getNextQualificationOpponent() {
232 Team team = new Team();
233 int teamId = Commons.getModel().getBasics().getTeamId();
234 IMatchKurzInfo[] qualificationMatches = Commons.getModel().getMatchesKurzInfo(teamId,
235 ISpielePanel.NUR_EIGENE_PFLICHTSPIELE,
236 false);
237 List l = new ArrayList();
238
239 l.addAll(Arrays.asList(qualificationMatches));
240
241 Object[] matches = l.toArray();
242
243 for (int i = 0; i < matches.length; i++) {
244 IMatchKurzInfo match = (IMatchKurzInfo) matches[i];
245
246 if ((match.getMatchStatus() != IMatchKurzInfo.FINISHED)
247 && (match.getMatchTyp() == IMatchLineup.QUALISPIEL)) {
248 if (match.getHeimID() == teamId) {
249 team.setName(match.getGastName());
250 team.setTeamId(match.getGastID());
251 } else {
252 team.setName(match.getHeimName());
253 team.setTeamId(match.getHeimID());
254 }
255
256 return team;
257 }
258 }
259
260 return team;
261 }
262
263 /***
264 * TODO Missing Method Documentation
265 *
266 * @return TODO Missing Return Method Documentation
267 */
268 private static List loadDivisionTeams() {
269 List loadedTeams = new ArrayList();
270 ISpielplan league = getDivisionMatches();
271
272 if (league != null) {
273 List eintraege = league.getTabelle().getEintraege();
274
275 for (Iterator iter = eintraege.iterator(); iter.hasNext();) {
276 ILigaTabellenEintrag element = (ILigaTabellenEintrag) iter.next();
277 Team t = new Team();
278
279 t.setName(element.getTeamName());
280 t.setTeamId(element.getTeamId());
281 loadedTeams.add(t);
282 }
283 }
284
285 return loadedTeams;
286 }
287 }