View Javadoc

1   // %2725479759:hoplugins.teamAnalyzer.util%
2   package hoplugins.teamAnalyzer.util;
3   
4   import hoplugins.teamAnalyzer.SystemManager;
5   import hoplugins.teamAnalyzer.vo.Match;
6   
7   import plugins.IMatchDetails;
8   
9   
10  /***
11   * Match Utility Class
12   *
13   * @author <a href=mailto:draghetto@users.sourceforge.net>Massimiliano Amato</a>
14   */
15  public class MatchUtil {
16      //~ Methods ------------------------------------------------------------------------------------
17  
18      /***
19       * Check if the match is an homeMatch for the selected team
20       *
21       * @param match Match to be analyzed
22       *
23       * @return true, if active team playes at home in that match or false if away
24       */
25      public static boolean isHome(Match match) {
26          boolean isHome = false;
27  
28          if (match.getHomeId() == SystemManager.getActiveTeamId()) {
29              isHome = true;
30          }
31  
32          return isHome;
33      }
34  
35      /***
36       * Check if the match is an homeMatch for the selected team
37       *
38       * @param match IMatchDetails to be analyzed
39       *
40       * @return true, if active team playes at home in that match or false if away
41       */
42      public static boolean isHome(IMatchDetails match) {
43          boolean isHome = false;
44  
45          if (match.getHeimId() == SystemManager.getActiveTeamId()) {
46              isHome = true;
47          }
48  
49          return isHome;
50      }
51  
52      /***
53       * Returns the description  code for the match type
54       *
55       * @param type int type of match
56       *
57       * @return A string code
58       */
59      public static String getMatchType(int type) {
60          if (type == 1) {
61              return " ";
62          } else if (type == 2) {
63              return "Q";
64          } else if (type == 3) {
65              return "C";
66          } else {
67              return "F";
68          }
69      }
70  
71      /***
72       * Returns the result type, as 0 for draw, 1 for wins and -1 for defeat
73       *
74       * @param match Match to be analyzed
75       *
76       * @return result code
77       */
78      public static int result(Match match) {
79          boolean isHome = MatchUtil.isHome(match);
80  
81          if (match.getHomeGoals() == match.getAwayGoals()) {
82              return 0;
83          }
84  
85          if ((match.getHomeGoals() > match.getAwayGoals()) && isHome) {
86              return 1;
87          }
88  
89          if ((match.getHomeGoals() < match.getAwayGoals()) && !isHome) {
90              return 1;
91          }
92  
93          return -1;
94      }
95  
96      /***
97       * Returns the result type, as 0 for draw, 1 for wins and -1 for defeat
98       *
99       * @param match IMatchDetails to be analyzed
100      *
101      * @return result code
102      */
103     public static int result(IMatchDetails match) {
104         boolean isHome = MatchUtil.isHome(match);
105 
106         if (match.getHomeGoals() == match.getGuestGoals()) {
107             return 0;
108         }
109 
110         if ((match.getHomeGoals() > match.getGuestGoals()) && isHome) {
111             return 1;
112         }
113 
114         if ((match.getHomeGoals() < match.getGuestGoals()) && !isHome) {
115             return 1;
116         }
117 
118         return -1;
119     }
120 }