View Javadoc
1   /*
2    * Copyright (c) 2002-2018, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.appointment.modules.resource.business.calendar;
35  
36  import java.io.Serializable;
37  
38  /**
39   * DTO to display appointments of resources in a calendar
40   */
41  public class CalendarAppointmentResourceDTO implements Serializable, Comparable<CalendarAppointmentResourceDTO>
42  {
43      private static final long serialVersionUID = 8142423630911536264L;
44      private int _nIdApppointment;
45      private int _nStartingHour;
46      private int _nStartingMinute;
47      private int _nEndingHour;
48      private int _nEndingMinute;
49      private int _nDuration;
50      private String _appointmentDescription;
51      private int _nIdForm;
52  
53      /**
54       * Creates a new calendar appointment resource DTO
55       * 
56       * @param nIdApppointment
57       *            The id of the appointment
58       * @param nStartingHour
59       *            The starting hour
60       * @param nStartingMinute
61       *            The starting minute
62       * @param nEndingHour
63       *            The ending hour
64       * @param nEndingMinute
65       *            The ending minute
66       * @param appointmentDescription
67       *            The description of the appointment
68       * @param nIdForm
69       *            The id of the form
70       */
71      public CalendarAppointmentResourceDTO( int nIdApppointment, int nStartingHour, int nStartingMinute, int nEndingHour, int nEndingMinute,
72              String appointmentDescription, int nIdForm )
73      {
74          this._nIdApppointment = nIdApppointment;
75          this._nStartingHour = nStartingHour;
76          this._nStartingMinute = nStartingMinute;
77          this._nEndingHour = nEndingHour;
78          this._nEndingMinute = nEndingMinute;
79          this._appointmentDescription = appointmentDescription;
80          this._nIdForm = nIdForm;
81      }
82  
83      /**
84       * Get the id of the associated appointment
85       * 
86       * @return The id of the associated appointment
87       */
88      public int getIdApppointment( )
89      {
90          return _nIdApppointment;
91      }
92  
93      /**
94       * Set the id of the associated appointment
95       * 
96       * @param nIdApppointment
97       *            The id of the associated appointment
98       */
99      public void setIdApppointment( int nIdApppointment )
100     {
101         this._nIdApppointment = nIdApppointment;
102     }
103 
104     /**
105      * Get the starting hour of the appointment
106      * 
107      * @return The starting hour of the appointment
108      */
109     public int getStartingHour( )
110     {
111         return _nStartingHour;
112     }
113 
114     /**
115      * Set the starting hour of the appointment
116      * 
117      * @param nStartingHour
118      *            The starting hour of the appointment
119      */
120     public void setStartingHour( int nStartingHour )
121     {
122         this._nStartingHour = nStartingHour;
123     }
124 
125     /**
126      * Get the starting minute of the appointment
127      * 
128      * @return The starting minute of the appointment
129      */
130     public int getStartingMinute( )
131     {
132         return _nStartingMinute;
133     }
134 
135     /**
136      * Get the starting minute of the appointment
137      * 
138      * @param nStartingMinute
139      *            The starting minute of the appointment
140      */
141     public void setStartingMinute( int nStartingMinute )
142     {
143         this._nStartingMinute = nStartingMinute;
144     }
145 
146     /**
147      * Get the ending hour of the appointment
148      * 
149      * @return The ending hour of the appointment
150      */
151     public int getEndingHour( )
152     {
153         return _nEndingHour;
154     }
155 
156     /**
157      * Set the ending hour of the appointment
158      * 
159      * @param nEndingHour
160      *            The ending hour of the appointment
161      */
162     public void setEndingHour( int nEndingHour )
163     {
164         this._nEndingHour = nEndingHour;
165     }
166 
167     /**
168      * Get the ending minute of the appointment
169      * 
170      * @return The ending minute of the appointment
171      */
172     public int getEndingMinute( )
173     {
174         return _nEndingMinute;
175     }
176 
177     /**
178      * Set the ending minute of the appointment
179      * 
180      * @param nEndingMinute
181      *            The ending minute of the appointment
182      */
183     public void setEndingMinute( int nEndingMinute )
184     {
185         this._nEndingMinute = nEndingMinute;
186     }
187 
188     /**
189      * Get the duration of the appointment in minutes
190      * 
191      * @return The duration of the appointment in minutes
192      */
193     public int getDuration( )
194     {
195         if ( _nDuration == 0 )
196         {
197             _nDuration = ( ( ( getEndingHour( ) - getStartingHour( ) ) * 60 ) + getEndingMinute( ) ) - getStartingMinute( );
198         }
199 
200         return _nDuration;
201     }
202 
203     /**
204      * Get the description of the appointment
205      * 
206      * @return The description of the appointment
207      */
208     public String getAppointmentDescription( )
209     {
210         return _appointmentDescription;
211     }
212 
213     /**
214      * Set the description of the appointment
215      * 
216      * @param appointmentDescription
217      *            The description of the appointment
218      */
219     public void setAppointmentDescription( String appointmentDescription )
220     {
221         this._appointmentDescription = appointmentDescription;
222     }
223 
224     /**
225      * Get the id of the associated formulaire
226      * 
227      * @return The id of the associated formulaire
228      */
229     public int getIdForm( )
230     {
231         return _nIdForm;
232     }
233 
234     /**
235      * Set the id of the associated form
236      * 
237      * @param nIdApppointment
238      *            The id of the associated form
239      */
240     public void setIdForm( int nIdForm )
241     {
242         this._nIdForm = nIdForm;
243     }
244 
245     /**
246      * {@inheritDoc}
247      */
248     @Override
249     public int compareTo( CalendarAppointmentResourceDTO o )
250     {
251         return ( ( getStartingHour( ) * 60 ) + getStartingMinute( ) ) - ( ( o.getStartingHour( ) * 60 ) + o.getStartingMinute( ) );
252     }
253 
254     /**
255      * {@inheritDoc}
256      */
257     @Override
258     public boolean equals( Object o )
259     {
260         if ( o instanceof CalendarAppointmentResourceDTO )
261         {
262             return compareTo( (CalendarAppointmentResourceDTO) o ) == 0;
263         }
264 
265         return false;
266     }
267 
268     /**
269      * {@inheritDoc}
270      */
271     @Override
272     public int hashCode( )
273     {
274         return super.hashCode( );
275     }
276 }