]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/opening_times/BusinessOpeningTimes.java
let's make sure that serial numbers of objects are never persisted (being ignored...
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / opening_times / BusinessOpeningTimes.java
1 /*
2  * Copyright (C) 2016 Roland Haeder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jcontactsbusiness.opening_times;
18
19 import java.time.DayOfWeek;
20 import java.util.Calendar;
21 import java.util.Objects;
22 import javax.persistence.Basic;
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
25 import javax.persistence.EnumType;
26 import javax.persistence.Enumerated;
27 import javax.persistence.GeneratedValue;
28 import javax.persistence.GenerationType;
29 import javax.persistence.Id;
30 import javax.persistence.Table;
31 import javax.persistence.Temporal;
32 import javax.persistence.TemporalType;
33 import javax.persistence.Transient;
34
35 /**
36  * A POJO for business opening hours
37  * <p>
38  * @author Roland Haeder<roland@mxchange.org>
39  */
40 @Entity (name = "company_opening_times")
41 @Table (name = "company_opening_times")
42 @SuppressWarnings ("PersistenceUnitPresent")
43 public class BusinessOpeningTimes implements OpeningTimes {
44
45         /**
46          * Serial number
47          */
48         @Transient
49         private static final long serialVersionUID = 19_578_871_756_871L;
50
51         /**
52          * Ending day of opening hours (if applyable)
53          */
54         @Column (name = "opening_times_end_day")
55         @Enumerated (EnumType.STRING)
56         private DayOfWeek endDay;
57
58         /**
59          * Ending time (hh:mm)
60          */
61         @Basic (optional = false)
62         @Column (name = "opening_times_end_time", nullable = false)
63         @Temporal (TemporalType.TIME)
64         private Calendar endTime;
65
66         /**
67          * Id number
68          */
69         @Id
70         @Column (name = "opening_times_id", nullable = false, updatable = false)
71         @GeneratedValue (strategy = GenerationType.IDENTITY)
72         private Long id;
73
74         /**
75          * Starting day of opening times
76          */
77         @Basic (optional = false)
78         @Column (name = "opening_times_start_day", nullable = false)
79         @Enumerated (EnumType.STRING)
80         private DayOfWeek startDay;
81
82         /**
83          * Starting time (hh:mm)
84          */
85         @Basic (optional = false)
86         @Column (name = "opening_times_start_time", nullable = false)
87         @Temporal (TemporalType.TIME)
88         private Calendar startTime;
89
90         /**
91          * Default constructor
92          */
93         public BusinessOpeningTimes () {
94         }
95
96         /**
97          * Constructor with all field
98          * <p>
99          * @param endDay    End day
100          * @param endTime   End time
101          * @param id        Id number
102          * @param startDay  Start day
103          * @param startTime Start time
104          */
105         public BusinessOpeningTimes (final DayOfWeek endDay, final Calendar endTime, final Long id, final DayOfWeek startDay, final Calendar startTime) {
106                 // Call other constructor
107                 this(endDay, endTime, startDay, startTime);
108
109                 // Set id number
110                 this.id = id;
111         }
112
113         /**
114          * Constructor with all fields except id number
115          * <p>
116          * @param endDay    End day
117          * @param endTime   End time
118          * @param startDay  Start day
119          * @param startTime Start time
120          */
121         public BusinessOpeningTimes (final DayOfWeek endDay, final Calendar endTime, final DayOfWeek startDay, final Calendar startTime) {
122                 // Set all fields
123                 this.endDay = endDay;
124                 this.endTime = endTime;
125                 this.startDay = startDay;
126                 this.startTime = startTime;
127         }
128
129         @Override
130         public boolean equals (final Object obj) {
131                 if (this == obj) {
132                         return true;
133                 } else if (obj == null) {
134                         return false;
135                 } else if (this.getClass() != obj.getClass()) {
136                         return false;
137                 }
138
139                 final OpeningTimes openingTimes = (OpeningTimes) obj;
140
141                 if (!Objects.equals(this.getId(), openingTimes.getId())) {
142                         return false;
143                 } else if (this.getStartDay() != openingTimes.getStartDay()) {
144                         return false;
145                 } else if (this.getEndDay() != openingTimes.getEndDay()) {
146                         return false;
147                 } else if (!Objects.equals(this.getStartTime(), openingTimes.getStartTime())) {
148                         return false;
149                 } else if (!Objects.equals(this.getEndTime(), openingTimes.getEndTime())) {
150                         return false;
151                 }
152
153                 return true;
154         }
155
156         @Override
157         public int hashCode () {
158                 int hash = 7;
159
160                 hash = 97 * hash + Objects.hashCode(this.getId());
161                 hash = 97 * hash + Objects.hashCode(this.getStartDay());
162                 hash = 97 * hash + Objects.hashCode(this.getEndDay());
163                 hash = 97 * hash + Objects.hashCode(this.getStartTime());
164                 hash = 97 * hash + Objects.hashCode(this.getEndTime());
165
166                 return hash;
167         }
168
169         @Override
170         public DayOfWeek getEndDay () {
171                 return this.endDay;
172         }
173
174         @Override
175         public void setEndDay (final DayOfWeek endDay) {
176                 this.endDay = endDay;
177         }
178
179         @Override
180         @SuppressWarnings ("ReturnOfDateField")
181         public Calendar getEndTime () {
182                 return this.endTime;
183         }
184
185         @Override
186         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
187         public void setEndTime (final Calendar endTime) {
188                 this.endTime = endTime;
189         }
190
191         @Override
192         public Long getId () {
193                 return this.id;
194         }
195
196         @Override
197         public void setId (Long id) {
198                 this.id = id;
199         }
200
201         @Override
202         public DayOfWeek getStartDay () {
203                 return this.startDay;
204         }
205
206         @Override
207         public void setStartDay (final DayOfWeek startDay) {
208                 this.startDay = startDay;
209         }
210
211         @Override
212         @SuppressWarnings ("ReturnOfDateField")
213         public Calendar getStartTime () {
214                 return this.startTime;
215         }
216
217         @Override
218         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
219         public void setStartTime (final Calendar startTime) {
220                 this.startTime = startTime;
221         }
222
223 }