View Javadoc

1   // %2944446152:hoplugins.teamAnalyzer.manager%
2   package hoplugins.teamAnalyzer.manager;
3   
4   import hoplugins.teamAnalyzer.util.MatchUtil;
5   import hoplugins.teamAnalyzer.vo.Filter;
6   import hoplugins.teamAnalyzer.vo.Match;
7   
8   import java.util.ArrayList;
9   import java.util.Iterator;
10  import java.util.List;
11  
12  
13  /***
14   * TODO Missing Class Documentation
15   *
16   * @author TODO Author Name
17   */
18  public class MatchList {
19      //~ Instance fields ----------------------------------------------------------------------------
20  
21      private List matchList;
22  
23      //~ Constructors -------------------------------------------------------------------------------
24  
25      /***
26       * Creates a new MatchList object.
27       */
28      public MatchList() {
29          matchList = new ArrayList();
30      }
31  
32      //~ Methods ------------------------------------------------------------------------------------
33  
34      /***
35       * TODO Missing Method Documentation
36       *
37       * @return TODO Missing Return Method Documentation
38       */
39      public List getMatches() {
40          return matchList;
41      }
42  
43      /***
44       * TODO Missing Method Documentation
45       *
46       * @param match TODO Missing Method Parameter Documentation
47       */
48      public void addMatch(Match match) {
49          matchList.add(match);
50      }
51  
52      /***
53       * TODO Missing Method Documentation
54       *
55       * @param filter TODO Missing Method Parameter Documentation
56       *
57       * @return TODO Missing Return Method Documentation
58       */
59      public List filterMatches(Filter filter) {
60          int counter = 0;
61          List list = new ArrayList();
62  
63          if (filter.isAutomatic()) {
64              for (Iterator iter = matchList.iterator(); iter.hasNext();) {
65                  Match match = (Match) iter.next();
66  
67                  if (isAutomaticIncluded(filter, match)) {
68                      list.add(match);
69                      counter++;
70                  }
71  
72                  if (counter >= filter.getNumber()) {
73                      break;
74                  }
75              }
76          } else {
77              List filterMatches = filter.getMatches();
78  
79              for (Iterator iter = matchList.iterator(); iter.hasNext();) {
80                  Match match = (Match) iter.next();
81  
82                  if (filterMatches.contains("" + match.getMatchId())) {
83                      list.add(match);
84                  }
85              }
86          }
87  
88          return list;
89      }
90  
91      /***
92       * TODO Missing Method Documentation
93       *
94       * @param filter TODO Missing Method Parameter Documentation
95       * @param match TODO Missing Method Parameter Documentation
96       *
97       * @return TODO Missing Return Method Documentation
98       */
99      private boolean isAutomaticIncluded(Filter filter, Match match) {
100         boolean isHome = MatchUtil.isHome(match);
101         int result = MatchUtil.result(match);
102         int matchType = match.getMatchType();
103 
104         if (!filter.isHomeGames() && isHome) {
105             return false;
106         }
107 
108         if (!filter.isAwayGames() && !isHome) {
109             return false;
110         }
111 
112         if (!filter.isDefeat() && (result == -1)) {
113             return false;
114         }
115 
116         if (!filter.isDraw() && (result == 0)) {
117             return false;
118         }
119 
120         if (!filter.isWin() && (result == 1)) {
121             return false;
122         }
123 
124         if (!filter.isLeague() && (matchType == 1)) {
125             return false;
126         }
127 
128         if (!filter.isCup() && (matchType == 3)) {
129             return false;
130         }
131 
132         if (!filter.isQualifier() && (matchType == 2)) {
133             return false;
134         }
135 
136         if (!filter.isFriendly() && (matchType > 3)) {
137             return false;
138         }
139 
140         return true;
141     }
142 }