1
2 package hoplugins.teamAnalyzer.manager;
3
4 import hoplugins.Commons;
5
6 import hoplugins.commons.utils.ListUtil;
7
8 import hoplugins.teamAnalyzer.SystemManager;
9 import hoplugins.teamAnalyzer.comparator.MatchComparator;
10 import hoplugins.teamAnalyzer.vo.Match;
11
12 import plugins.IMatchKurzInfo;
13 import plugins.ISpielePanel;
14
15 import java.util.ArrayList;
16 import java.util.Collection;
17 import java.util.HashMap;
18 import java.util.Iterator;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.SortedSet;
22
23
24 /***
25 * TODO Missing Class Documentation
26 *
27 * @author TODO Author Name
28 */
29 public class MatchManager {
30
31
32 private static MatchList matches = null;
33
34
35
36 /***
37 * TODO Missing Method Documentation
38 *
39 * @return TODO Missing Return Method Documentation
40 */
41 public static List getAllMatches() {
42 return matches.getMatches();
43 }
44
45 /***
46 * TODO Missing Method Documentation
47 *
48 * @return TODO Missing Return Method Documentation
49 */
50 public static List getMatchDetails() {
51 List filteredMatches = getSelectedMatches();
52 MatchPopulator matchPopulator = new MatchPopulator();
53
54 return matchPopulator.populate(filteredMatches);
55 }
56
57 /***
58 * TODO Missing Method Documentation
59 *
60 * @return TODO Missing Return Method Documentation
61 */
62 public static List getSelectedMatches() {
63 if (matches == null) {
64 loadActiveTeamMatchList();
65 }
66
67 return matches.filterMatches(SystemManager.getFilter());
68 }
69
70 /***
71 * TODO Missing Method Documentation
72 */
73 public static void clean() {
74 loadActiveTeamMatchList();
75 }
76
77 /***
78 * TODO Missing Method Documentation
79 */
80 public static void loadActiveTeamMatchList() {
81 matches = new MatchList();
82
83 SortedSet sortedMatches = loadMatchList();
84
85 for (Iterator iter = sortedMatches.iterator(); iter.hasNext();) {
86 Match element = (Match) iter.next();
87
88 matches.addMatch(element);
89 }
90 }
91
92 /***
93 * TODO Missing Method Documentation
94 *
95 * @return TODO Missing Return Method Documentation
96 */
97 private static List getTeamMatch() {
98 List teamMatches = new ArrayList();
99 String oldName = SystemManager.getActiveTeamName();
100
101 IMatchKurzInfo[] matchKurtzInfo = Commons.getModel().getMatchesKurzInfo(SystemManager
102 .getActiveTeamId(),
103 ISpielePanel.NUR_EIGENE_SPIELE,
104 false);
105
106 for (int i = 0; i < matchKurtzInfo.length; i++) {
107 IMatchKurzInfo matchInfo = matchKurtzInfo[i];
108
109 if (matchInfo.getMatchStatus() != IMatchKurzInfo.FINISHED) {
110 continue;
111 }
112
113 Match match = new Match(matchInfo);
114
115 String temp;
116
117 if (match.getHomeId() == SystemManager.getActiveTeamId()) {
118 temp = match.getHomeTeam();
119 } else {
120 temp = match.getAwayTeam();
121 }
122
123 if (SystemManager.getConfig().isCheckTeamName()) {
124
125 String oldShort = oldName.substring(0, oldName.length() - 1);
126
127 if (oldShort.equalsIgnoreCase(temp)) {
128 temp = oldName;
129 }
130
131 if (!temp.equalsIgnoreCase(oldName)) {
132 if (match.getWeek() > 14) {
133 oldName = temp;
134 } else {
135 return teamMatches;
136 }
137 }
138 }
139
140 teamMatches.add(match);
141 }
142
143 return teamMatches;
144 }
145
146 /***
147 * TODO Missing Method Documentation
148 *
149 * @return TODO Missing Return Method Documentation
150 */
151 private static SortedSet loadMatchList() {
152 Map matchIds = new HashMap();
153
154 for (Iterator iter = getTeamMatch().iterator(); iter.hasNext();) {
155 Match match = (Match) iter.next();
156
157 if (!matchIds.containsKey(match.getMatchId() + "")) {
158 matchIds.put(match.getMatchId() + "", match);
159 }
160 }
161
162 Collection matchList = matchIds.values();
163 SortedSet sorted = ListUtil.getSortedSet(matchList, new MatchComparator());
164
165 return sorted;
166 }
167 }