]> git.mxchange.org Git - jphone-core.git/blob - src/org/mxchange/jphone/model/phonenumbers/fax/FaxNumber.java
5dd3752f27303f943aa7354019eaca57f4184629
[jphone-core.git] / src / org / mxchange / jphone / model / phonenumbers / fax / FaxNumber.java
1 /*
2  * Copyright (C) 2016, 2017 Roland Häder
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.jphone.model.phonenumbers.fax;
18
19 import java.util.Date;
20 import java.util.Objects;
21 import javax.persistence.Basic;
22 import javax.persistence.CascadeType;
23 import javax.persistence.Column;
24 import javax.persistence.Entity;
25 import javax.persistence.GeneratedValue;
26 import javax.persistence.GenerationType;
27 import javax.persistence.Id;
28 import javax.persistence.JoinColumn;
29 import javax.persistence.NamedQueries;
30 import javax.persistence.NamedQuery;
31 import javax.persistence.OneToOne;
32 import javax.persistence.Table;
33 import javax.persistence.Temporal;
34 import javax.persistence.TemporalType;
35 import javax.persistence.Transient;
36 import org.mxchange.jcountry.model.data.Country;
37 import org.mxchange.jcountry.model.data.CountryData;
38
39 /**
40  * A POJO for dialable fax numbers
41  * <p>
42  * @author Roland Häder<roland@mxchange.org>
43  */
44 @Entity (name = "fax_numbers")
45 @Table (name = "fax_numbers")
46 @NamedQueries (
47                 {
48                         @NamedQuery (name = "AllFaxNumbers", query = "SELECT f FROM fax_numbers AS f ORDER BY f.phoneId ASC"),
49                         @NamedQuery (name = "SearchFaxNumberId", query = "SELECT f FROM fax_numbers AS f WHERE f.phoneId = :faxNumberId")
50                 }
51 )
52 @SuppressWarnings ("PersistenceUnitPresent")
53 public class FaxNumber implements DialableFaxNumber {
54
55         /**
56          * Serial number
57          */
58         @Transient
59         private static final long serialVersionUID = 17_687_687_191_375L;
60
61         /**
62          * Area code (example: 2151 for Krefeld)
63          */
64         @Basic (optional = false)
65         @Column (name = "fax_area_code", length = 10, nullable = false)
66         private Integer faxAreaCode;
67
68         /**
69          * Country instance ('s dial data)
70          */
71         @JoinColumn (name = "fax_country_id", nullable = false)
72         @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false)
73         private Country faxCountry;
74
75         /**
76          * Timestamp when this entry has been created
77          */
78         @Basic (optional = false)
79         @Temporal (TemporalType.TIMESTAMP)
80         @Column (name = "fax_entry_created", nullable = false, updatable = false)
81         private Date phoneEntryCreated;
82
83         /**
84          * Timestamp when this entry has been created
85          */
86         @Temporal (TemporalType.TIMESTAMP)
87         @Column (name = "phone_entry_updated", updatable = false)
88         private Date phoneEntryUpdated;
89
90         /**
91          * Id number
92          */
93         @Id
94         @GeneratedValue (strategy = GenerationType.IDENTITY)
95         @Column (name = "fax_id", nullable = false, updatable = false)
96         private Long phoneId;
97
98         /**
99          * Fax number without prefix
100          */
101         @Basic (optional = false)
102         @Column (name = "fax_number", nullable = false)
103         private Long phoneNumber;
104
105         /**
106          * Default constructor
107          */
108         public FaxNumber () {
109         }
110
111         /**
112          * Constructor with country, area code and number
113          * <p>
114          * @param faxCountry Country instance
115          * @param faxAreaCode Area code (without leading zeros)
116          * @param faxNumber Fax number (without area code and leading zero)
117          */
118         public FaxNumber (final Country faxCountry, final Integer faxAreaCode, final Long faxNumber) {
119                 // Call default constructor
120                 this();
121
122                 // Set all values
123                 this.faxCountry = faxCountry;
124                 this.faxAreaCode = faxAreaCode;
125                 this.phoneNumber = faxNumber;
126         }
127
128         @Override
129         public boolean equals (final Object object) {
130                 if (null == object) {
131                         return false;
132                 } else if (this.getClass() != object.getClass()) {
133                         return false;
134                 }
135
136                 final DialableFaxNumber other = (DialableFaxNumber) object;
137
138                 if (!Objects.equals(this.getPhoneNumber(), other.getPhoneNumber())) {
139                         return false;
140                 } else if (!Objects.equals(this.getPhoneId(), other.getPhoneId())) {
141                         return false;
142                 } else if (!Objects.equals(this.getPhoneAreaCode(), other.getPhoneAreaCode())) {
143                         return false;
144                 } else if (!Objects.equals(this.getPhoneCountry(), other.getPhoneCountry())) {
145                         return false;
146                 }
147
148                 return true;
149         }
150
151         @Override
152         public Integer getPhoneAreaCode () {
153                 return this.faxAreaCode;
154         }
155
156         @Override
157         public void setPhoneAreaCode (final Integer faxAreaCode) {
158                 this.faxAreaCode = faxAreaCode;
159         }
160
161         @Override
162         public Country getPhoneCountry () {
163                 return this.faxCountry;
164         }
165
166         @Override
167         public void setPhoneCountry (final Country faxCountry) {
168                 this.faxCountry = faxCountry;
169         }
170
171         @Override
172         @SuppressWarnings ("ReturnOfDateField")
173         public Date getPhoneEntryCreated () {
174                 return this.phoneEntryCreated;
175         }
176
177         @Override
178         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
179         public void setPhoneEntryCreated (final Date phoneEntryCreated) {
180                 this.phoneEntryCreated = phoneEntryCreated;
181         }
182
183         @Override
184         @SuppressWarnings ("ReturnOfDateField")
185         public Date getPhoneEntryUpdated () {
186                 return this.phoneEntryUpdated;
187         }
188
189         @Override
190         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
191         public void setPhoneEntryUpdated (final Date phoneEntryUpdated) {
192                 this.phoneEntryUpdated = phoneEntryUpdated;
193         }
194
195         @Override
196         public Long getPhoneId () {
197                 return this.phoneId;
198         }
199
200         @Override
201         public void setPhoneId (final Long phoneId) {
202                 this.phoneId = phoneId;
203         }
204
205         @Override
206         public Long getPhoneNumber () {
207                 return this.phoneNumber;
208         }
209
210         @Override
211         public void setPhoneNumber (final Long phoneNumber) {
212                 this.phoneNumber = phoneNumber;
213         }
214
215         @Override
216         public int hashCode () {
217                 int hash = 3;
218
219                 hash = 23 * hash + Objects.hashCode(this.getPhoneId());
220                 hash = 23 * hash + Objects.hashCode(this.getPhoneNumber());
221                 hash = 23 * hash + Objects.hashCode(this.getPhoneAreaCode());
222                 hash = 23 * hash + Objects.hashCode(this.getPhoneCountry());
223
224                 return hash;
225         }
226
227 }