View Javadoc

1   // %3190202247:hoplugins.trainingExperience%
2   package hoplugins.trainingExperience;
3   
4   import hoplugins.Commons;
5   
6   import hoplugins.commons.utils.HTCalendar;
7   import hoplugins.commons.utils.HTCalendarFactory;
8   
9   import hoplugins.trainingExperience.constants.Skills;
10  import hoplugins.trainingExperience.vo.PastSkillup;
11  
12  import plugins.ISkillup;
13  import plugins.ISpieler;
14  
15  import java.text.ParseException;
16  
17  import java.util.ArrayList;
18  import java.util.Collections;
19  import java.util.Comparator;
20  import java.util.Date;
21  import java.util.Iterator;
22  import java.util.List;
23  import java.util.Vector;
24  
25  
26  /***
27   * Class that keeps track of the past skillup for the active user
28   */
29  public class OldTrainingManager {
30      //~ Instance fields ----------------------------------------------------------------------------
31  
32      /*** List of all skill up */
33      private List allSkillups = new ArrayList();
34  
35      /*** List of trained skill up */
36      private List trainSkillups = new ArrayList();
37  
38      //~ Constructors -------------------------------------------------------------------------------
39  
40      /***
41       * Calculates data for the player
42       *
43       * @param player
44       */
45      public OldTrainingManager(ISpieler player) {
46          if (player == null) {
47              return;
48          }
49  
50          //TreeMap mapTrained = new TreeMap();
51          //TreeMap mapAll = new TreeMap();
52          allSkillups = new ArrayList();
53          trainSkillups = new ArrayList();
54  
55          for (int i = 0; i < 10; i++) {
56              if (i == 7) {
57                  i = 8;
58              }
59  
60              Vector v = player.getAllLevelUp(i);
61              int count = 0;
62  
63              for (Iterator iter = v.iterator(); iter.hasNext();) {
64                  Object[] element = (Object[]) iter.next();
65                  PastSkillup su = null;
66  
67                  try {
68                      Date htDate = Commons.getModel().getHelper().getHattrickDate("" //$NON-NLS-1$
69                                                                                   + element[0]);
70                      Date trainingDate = Commons.getModel().getHelper()
71                                                 .getLastTrainingDate(htDate,
72                                                                      Commons.getModel().getXtraDaten()
73                                                                             .getTrainingDate())
74                                                 .getTime();
75  
76                      su = getSkillup(trainingDate);
77                      su.setValue(Skills.getSkillValue(player, i) - count);
78                      su.setType(i);
79                      su.setTrainType(ISkillup.SKILLUP_REAL);
80                      allSkillups.add(su);
81  
82                      if (i < 8) {
83                          trainSkillups.add(su);
84                      }
85                  } catch (ParseException e) {
86                      e.printStackTrace();
87                  }
88  
89                  count++;
90              }
91          }
92  
93          SkillupComperator comp = new SkillupComperator();
94  
95          Collections.sort(allSkillups, comp);
96          Collections.sort(trainSkillups, comp);
97      }
98  
99      //~ Methods ------------------------------------------------------------------------------------
100 
101     /***
102      * Returns the list of all calculated Skillups for the active player.
103      *
104      * @return list of all skillups
105      */
106     public List getAllSkillups() {
107         return allSkillups;
108     }
109 
110     /***
111      * Returns the list of calculated Skillups for the active player as a result of training.
112      *
113      * @return list of trained skillups
114      */
115     public List getTrainedSkillups() {
116         return trainSkillups;
117     }
118 
119     /***
120      * Calculates the HT Week and Season from the SkillupDate and initialize the Skillup Object
121      *
122      * @param skillupDate Skillup Date
123      *
124      * @return a skillup object with season and week value
125      */
126     private PastSkillup getSkillup(Date skillupDate) {
127         HTCalendar calendar = HTCalendarFactory.createEconomyCalendar(Commons.getModel(),
128                                                                       skillupDate);
129 
130         PastSkillup skillup = new PastSkillup();
131 
132         skillup.setHtSeason(calendar.getHTSeason());
133         skillup.setHtWeek(calendar.getHTWeek());
134         skillup.setDate(skillupDate);
135 
136         return skillup;
137     }
138 
139     //~ Inner Classes ------------------------------------------------------------------------------
140 
141     /***
142      * TODO Missing Class Documentation
143      *
144      * @author TODO Author Name
145      */
146     private class SkillupComperator implements Comparator {
147         //~ Methods --------------------------------------------------------------------------------
148 
149         /***
150          * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
151          */
152         public int compare(Object o1, Object o2) {
153             ISkillup skillup1 = (ISkillup) o1;
154             ISkillup skillup2 = (ISkillup) o2;
155 
156             if (skillup1.getDate().before(skillup2.getDate())) {
157                 return -1;
158             } else if (skillup1.getDate().after(skillup2.getDate())) {
159                 return 1;
160             } else {
161                 if (skillup1.getType() == skillup2.getType()) {
162                     if (skillup1.getValue() > skillup2.getValue()) {
163                         return 1;
164                     } else {
165                         return -1;
166                     }
167                 }
168 
169                 return 0;
170             }
171         }
172     }
173 }