1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.calendar.business;
35
36 import fr.paris.lutece.plugins.calendar.service.Utils;
37
38 import java.util.ArrayList;
39 import java.util.Date;
40 import java.util.GregorianCalendar;
41 import java.util.HashMap;
42 import java.util.List;
43 import java.util.Locale;
44 import java.util.Map;
45 import java.util.Set;
46
47
48
49
50
51 public class SimpleAgenda implements Agenda
52 {
53 private static final long serialVersionUID = -798521682637709581L;
54 private String _strName;
55 private String _strKeyName;
56 private Map<String, List<Event>> _mapDays = new HashMap<String, List<Event>>( );
57 private List<Event> _list = new ArrayList<Event>( );
58
59
60
61
62 public SimpleAgenda( )
63 {
64 }
65
66
67
68
69
70 public String getName( )
71 {
72 return _strName;
73 }
74
75
76
77
78
79 public void setName( String strName )
80 {
81 _strName = strName;
82 }
83
84
85
86
87
88
89 public String getKeyName( )
90 {
91 return _strKeyName;
92 }
93
94
95
96
97
98
99 public void setKeyName( String strKeyName )
100 {
101 _strKeyName = strKeyName;
102 }
103
104
105
106
107
108
109 public boolean hasEvents( String strDate )
110 {
111 return _mapDays.containsKey( strDate );
112 }
113
114
115
116
117
118
119 public List<Event> getEventsByDate( String strDate )
120 {
121 List<Event> listEvents = null;
122
123 if ( hasEvents( strDate ) )
124 {
125 listEvents = _mapDays.get( strDate );
126 }
127
128 return listEvents;
129 }
130
131
132
133
134
135 public void addEvent( Event event )
136 {
137 String strDate = Utils.getDate( event.getDate( ) );
138 List<Event> listEvents = null;
139
140 if ( hasEvents( strDate ) )
141 {
142 listEvents = getEventsByDate( strDate );
143 }
144 else
145 {
146 listEvents = new ArrayList<Event>( );
147 _mapDays.put( strDate, listEvents );
148 }
149
150 listEvents.add( event );
151 }
152
153
154
155
156
157 public List<Event> getEvents( )
158 {
159 _list.clear( );
160
161 Set<String> setKey = _mapDays.keySet( );
162
163 for ( String strDate : setKey )
164 {
165 List<Event> listEvents = getEventsByDate( strDate );
166
167 for ( Event event : listEvents )
168 {
169 _list.add( event );
170 }
171 }
172
173 return _list;
174 }
175
176
177
178
179
180
181
182
183 public List<Event> getEventsByDate( Date dateBegin, Date dateEnd, Locale localeEnv )
184 {
185 _list.clear( );
186
187 java.util.Calendar calendar = new GregorianCalendar( localeEnv );
188 calendar.setTime( dateBegin );
189
190 java.util.Calendar calendar1 = new GregorianCalendar( localeEnv );
191 calendar1.setTime( dateEnd );
192
193 while ( !Utils.getDate( calendar ).equals( Utils.getDate( calendar1 ) ) )
194 {
195 List<Event> listEvents = getEventsByDate( Utils.getDate( calendar ) );
196
197 if ( listEvents != null )
198 {
199 for ( Event event : listEvents )
200 {
201 _list.add( event );
202 }
203 }
204
205 calendar.add( java.util.Calendar.DATE, 1 );
206 }
207
208 return _list;
209 }
210 }