1
2 package hoplugins.commons.utils;
3
4 import plugins.IHOMiniModel;
5
6 import java.util.Calendar;
7 import java.util.Date;
8
9 /***
10 * Factory for creating HTCalendar instances.
11 *
12 * @author <a href=mailto:nethyperon@users.sourceforge.net>Boy van der Werf</a>
13 */
14 public final class HTCalendarFactory {
15 /***
16 * Constructs a HTCalendar.
17 */
18 private HTCalendarFactory() {
19 }
20
21 /***
22 * Creates a HTCalendar to calculate local values for a league, using the economy date to flip
23 * over to the next week.
24 *
25 * @param model HO data model
26 *
27 * @return a HTCalendar.
28 */
29 public static HTCalendar createEconomyCalendar(IHOMiniModel model) {
30 final Calendar calMark = Calendar.getInstance();
31
32 calMark.setTimeInMillis(model.getXtraDaten().getEconomyDate().getTime());
33
34 final HTCalendar calendar = new HTCalendar();
35
36 calendar.initialize(calMark);
37 calendar.setTime(model.getBasics().getDatum());
38
39 final int correction = calendar.getHTSeason()
40 - model.getBasics().getSeason();
41
42 calendar.setSeasonCorrection(correction);
43
44 return calendar;
45 }
46
47 /***
48 * Creates a HTCalendar to calculate local values for a league, using the economy date to flip
49 * over to the next week.
50 *
51 * @param model HO data model
52 * @param date Date to set the calendar
53 *
54 * @return a HTCalendar.
55 */
56 public static HTCalendar createEconomyCalendar(IHOMiniModel model, Date date) {
57 final HTCalendar calendar = createEconomyCalendar(model);
58
59 calendar.setTime(date);
60
61 return calendar;
62 }
63
64 /***
65 * Creates a HTCalendar to calculate global (Swedish) values.
66 *
67 * @return a HTCalendar.
68 */
69 public static HTCalendar createGlobalCalendar() {
70 return new HTCalendar();
71 }
72
73 /***
74 * Creates a HTCalendar to calculate global (Swedish) values and presets it with he specified
75 * date a date.
76 *
77 * @param date Date to set the calendar
78 *
79 * @return a HTCalendar.
80 */
81 public static HTCalendar createGlobalCalendar(Date date) {
82 final HTCalendar calendar = createGlobalCalendar();
83
84 calendar.setTime(date);
85
86 return calendar;
87 }
88
89 /***
90 * Creates a HTCalendar to calculate local values for a league, using the training date to
91 * flip over to the next week.
92 *
93 * @param model HO data model
94 *
95 * @return a HTCalendar.
96 */
97 public static HTCalendar createTrainingCalendar(IHOMiniModel model) {
98 final Calendar calMark = Calendar.getInstance();
99
100 calMark.setTimeInMillis(model.getXtraDaten().getTrainingDate().getTime());
101
102 final HTCalendar calendar = new HTCalendar();
103
104 calendar.initialize(calMark);
105 calendar.setTime(model.getBasics().getDatum());
106
107 final int correction = calendar.getHTSeason()
108 - model.getBasics().getSeason();
109
110 calendar.setSeasonCorrection(correction);
111
112 return calendar;
113 }
114
115 /***
116 * Creates a HTCalendar to calculate local values for a league, using the training date to
117 * flip over to the next week.
118 *
119 * @param model HO data model
120 * @param date Date to set the calendar
121 *
122 * @return a HTCalendar.
123 */
124 public static HTCalendar createTrainingCalendar(IHOMiniModel model,
125 Date date) {
126 final HTCalendar calendar = createTrainingCalendar(model);
127
128 calendar.setTime(date);
129
130 return calendar;
131 }
132 }