]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/opening_times/BusinessOpeningTimes.java
added constructors and made endTime/startTime not nullable
[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
34 /**
35  * A POJO for business opening hours
36  * <p>
37  * @author Roland Haeder<roland@mxchange.org>
38  */
39 @Entity (name = "company_opening_times")
40 @Table (name = "company_opening_times")
41 public class BusinessOpeningTimes implements OpeningTimes {
42
43         /**
44          * Serial number
45          */
46         private static final long serialVersionUID = 19_578_871_756_871L;
47
48         /**
49          * Ending day of opening hours (if applyable)
50          */
51         @Column (name = "opening_times_end_day")
52         @Enumerated (EnumType.STRING)
53         private DayOfWeek endDay;
54
55         /**
56          * Ending time (hh:mm)
57          */
58         @Basic (optional = false)
59         @Column (name = "opening_times_end_time", nullable = false)
60         @Temporal (TemporalType.TIME)
61         private Calendar endTime;
62
63         /**
64          * Id number
65          */
66         @Id
67         @Column (name = "opening_times_id", nullable = false, updatable = false)
68         @GeneratedValue (strategy = GenerationType.IDENTITY)
69         private Long id;
70
71         /**
72          * Starting day of opening times
73          */
74         @Basic (optional = false)
75         @Column (name = "opening_times_start_day", nullable = false)
76         @Enumerated (EnumType.STRING)
77         private DayOfWeek startDay;
78
79         /**
80          * Starting time (hh:mm)
81          */
82         @Basic (optional = false)
83         @Column (name = "opening_times_start_time", nullable = false)
84         @Temporal (TemporalType.TIME)
85         private Calendar startTime;
86
87         /**
88          * Default constructor
89          */
90         public BusinessOpeningTimes () {
91         }
92
93         /**
94          * Constructor with all field
95          * <p>
96          * @param endDay    End day
97          * @param endTime   End time
98          * @param id        Id number
99          * @param startDay  Start day
100          * @param startTime Start time
101          */
102         public BusinessOpeningTimes (final DayOfWeek endDay, final Calendar endTime, final Long id, final DayOfWeek startDay, final Calendar startTime) {
103                 // Call other constructor
104                 this(endDay, endTime, startDay, startTime);
105
106                 // Set id number
107                 this.id = id;
108         }
109
110         /**
111          * Constructor with all fields except id number
112          * <p>
113          * @param endDay    End day
114          * @param endTime   End time
115          * @param startDay  Start day
116          * @param startTime Start time
117          */
118         public BusinessOpeningTimes (final DayOfWeek endDay, final Calendar endTime, final DayOfWeek startDay, final Calendar startTime) {
119                 // Set all fields
120                 this.endDay = endDay;
121                 this.endTime = endTime;
122                 this.startDay = startDay;
123                 this.startTime = startTime;
124         }
125
126         @Override
127         public boolean equals (final Object obj) {
128                 if (this == obj) {
129                         return true;
130                 } else if (obj == null) {
131                         return false;
132                 } else if (this.getClass() != obj.getClass()) {
133                         return false;
134                 }
135
136                 final OpeningTimes openingTimes = (OpeningTimes) obj;
137
138                 if (!Objects.equals(this.getId(), openingTimes.getId())) {
139                         return false;
140                 } else if (this.getStartDay() != openingTimes.getStartDay()) {
141                         return false;
142                 } else if (this.getEndDay() != openingTimes.getEndDay()) {
143                         return false;
144                 } else if (!Objects.equals(this.getStartTime(), openingTimes.getStartTime())) {
145                         return false;
146                 } else if (!Objects.equals(this.getEndTime(), openingTimes.getEndTime())) {
147                         return false;
148                 }
149
150                 return true;
151         }
152
153         @Override
154         public int hashCode () {
155                 int hash = 7;
156
157                 hash = 97 * hash + Objects.hashCode(this.getId());
158                 hash = 97 * hash + Objects.hashCode(this.getStartDay());
159                 hash = 97 * hash + Objects.hashCode(this.getEndDay());
160                 hash = 97 * hash + Objects.hashCode(this.getStartTime());
161                 hash = 97 * hash + Objects.hashCode(this.getEndTime());
162
163                 return hash;
164         }
165
166         @Override
167         public DayOfWeek getEndDay () {
168                 return this.endDay;
169         }
170
171         @Override
172         public void setEndDay (final DayOfWeek endDay) {
173                 this.endDay = endDay;
174         }
175
176         @Override
177         public Calendar getEndTime () {
178                 return this.endTime;
179         }
180
181         @Override
182         public void setEndTime (final Calendar endTime) {
183                 this.endTime = endTime;
184         }
185
186         @Override
187         public Long getId () {
188                 return this.id;
189         }
190
191         @Override
192         public void setId (Long id) {
193                 this.id = id;
194         }
195
196         @Override
197         public DayOfWeek getStartDay () {
198                 return this.startDay;
199         }
200
201         @Override
202         public void setStartDay (final DayOfWeek startDay) {
203                 this.startDay = startDay;
204         }
205
206         @Override
207         public Calendar getStartTime () {
208                 return this.startTime;
209         }
210
211         @Override
212         public void setStartTime (final Calendar startTime) {
213                 this.startTime = startTime;
214         }
215
216 }