View Javadoc

1   // %2614020934:hoplugins.teamAnalyzer.report%
2   package hoplugins.teamAnalyzer.report;
3   
4   import hoplugins.teamAnalyzer.vo.PlayerAppearance;
5   import hoplugins.teamAnalyzer.vo.PlayerPerformance;
6   
7   import java.util.Collection;
8   import java.util.HashMap;
9   import java.util.Map;
10  
11  
12  /***
13   * Report of all players played in a certain spot on the field
14   *
15   * @author <a href=mailto:draghetto@users.sourceforge.net>Massimiliano Amato</a>
16   */
17  public class SpotReport extends Report {
18      //~ Instance fields ----------------------------------------------------------------------------
19  
20      /*** Map of players that played in this spot */
21      private Map players = new HashMap();
22  
23      /*** Map of PositionReport based on the effective position on the field */
24      private Map positionReports = new HashMap();
25  
26      //~ Constructors -------------------------------------------------------------------------------
27  
28      /***
29       * Creates a new SpotReport object.
30       *
31       * @param pp
32       */
33      public SpotReport(PlayerPerformance pp) {
34          super(pp);
35      }
36  
37      //~ Methods ------------------------------------------------------------------------------------
38  
39      /***
40       * Document me!
41       *
42       * @return
43       */
44      public Collection getPlayerAppearance() {
45          return players.values();
46      }
47  
48      /***
49       * Document me!
50       *
51       * @return
52       */
53      public Collection getPositionReports() {
54          return positionReports.values();
55      }
56  
57      /***
58       * Add a performance to the spot and updates the position based map
59       *
60       * @param pp
61       */
62      public void addPerformance(PlayerPerformance pp) {
63          super.addPerformance(pp);
64          updatePositionDetails(pp);
65          updatePlayerAppearance(pp);
66      }
67  
68      /***
69       * Update player appearance of 1
70       *
71       * @param pp
72       */
73      private void updatePlayerAppearance(PlayerPerformance pp) {
74          String name = "" + pp.getSpielerName();
75  
76          name = name.replaceAll(" ", "");
77  
78          PlayerAppearance playerApperance = (PlayerAppearance) players.get(name);
79  
80          if (playerApperance == null) {
81              playerApperance = new PlayerAppearance();
82              playerApperance.setPlayerId(pp.getSpielerId());
83              playerApperance.setName(pp.getSpielerName());
84  
85              playerApperance.setStatus(pp.getStatus());
86              players.put(name, playerApperance);
87          }
88  
89          playerApperance.addApperarence();
90      }
91  
92      /***
93       * Update positionReport based on the new player performance
94       *
95       * @param pp
96       */
97      private void updatePositionDetails(PlayerPerformance pp) {
98          PositionReport report = (PositionReport) positionReports.get("" + pp.getPositionCode());
99  
100         if (report == null) {
101             report = new PositionReport(pp);
102             positionReports.put("" + pp.getPositionCode(), report);
103         }
104 
105         report.addPerformance(pp);
106     }
107 }