]> git.mxchange.org Git - jphone-core.git/blob - src/org/mxchange/jphone/phonenumbers/landline/LandLineNumber.java
c567c4ca4a17708dad843bb0b8b9a09565739ed2
[jphone-core.git] / src / org / mxchange / jphone / phonenumbers / landline / LandLineNumber.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.jphone.phonenumbers.landline;
18
19 import java.util.Calendar;
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.data.Country;
37 import org.mxchange.jcountry.data.CountryData;
38
39 /**
40  * A POJO for dialable phone numbers
41  * <p>
42  * @author Roland Haeder<roland@mxchange.org>
43  */
44 @Entity (name = "phone_numbers")
45 @Table (name = "phone_numbers")
46 @NamedQueries (
47                 {
48                         @NamedQuery (name = "AllLandLineNumbers", query = "SELECT p FROM phone_numbers AS p ORDER BY p.phoneId ASC"),
49                         @NamedQuery (name = "SearchLandLineId", query = "SELECT p FROM phone_numbers AS p WHERE p.phoneId = :phoneId")
50                 }
51 )
52 @SuppressWarnings ("PersistenceUnitPresent")
53 public class LandLineNumber implements DialableLandLineNumber {
54
55         /**
56          * Serial number
57          */
58         @Transient
59         private static final long serialVersionUID = 18_563_748_781_956L;
60
61         /**
62          * Area code (example: 2151 for Krefeld)
63          */
64         @Basic (optional = false)
65         @Column (name = "phone_area_code", length = 10, nullable = false)
66         private Integer phoneAreaCode;
67
68         /**
69          * Connection to table "country_data"
70          */
71         @JoinColumn (name = "phone_country_id", nullable = false, updatable = false)
72         @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false)
73         private Country phoneCountry;
74
75         /**
76          * Timestamp when this entry has been created
77          */
78         @Basic (optional = false)
79         @Temporal (TemporalType.TIMESTAMP)
80         @Column (name = "phone_entry_created", nullable = false, updatable = false)
81         private Calendar 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 Calendar phoneEntryUpdated;
89
90         /**
91          * Id number
92          */
93         @Id
94         @GeneratedValue (strategy = GenerationType.IDENTITY)
95         @Column (name = "phone_id", length = 10, nullable = false, updatable = false)
96         private Long phoneId;
97
98         /**
99          * Phone number with out dial prefix
100          */
101         @Basic (optional = false)
102         @Column (name = "phone_number", nullable = false)
103         private Long phoneNumber;
104
105         /**
106          * Default constructor
107          */
108         public LandLineNumber () {
109         }
110
111         /**
112          * Constructor with country instance, area code and number
113          * <p>
114          * @param phoneCountry Country instance
115          * @param phoneAreaCode Phone area code
116          * @param phoneNumber Phone number
117          */
118         public LandLineNumber (final Country phoneCountry, final Integer phoneAreaCode, final Long phoneNumber) {
119                 // Call default constructor
120                 this();
121
122                 // Set all values
123                 this.phoneCountry = phoneCountry;
124                 this.phoneAreaCode = phoneAreaCode;
125                 this.phoneNumber = phoneNumber;
126         }
127
128         @Override
129         public void copyAll (final DialableLandLineNumber sourceNumber) {
130                 // Copy all
131                 this.setPhoneAreaCode(sourceNumber.getPhoneAreaCode());
132                 this.setPhoneCountry(sourceNumber.getPhoneCountry());
133                 this.setPhoneEntryCreated(sourceNumber.getPhoneEntryCreated());
134                 this.setPhoneId(sourceNumber.getPhoneId());
135                 this.setPhoneNumber(sourceNumber.getPhoneNumber());
136         }
137
138         @Override
139         public boolean equals (final Object object) {
140                 if (null == object) {
141                         return false;
142                 } else if (this.getClass() != object.getClass()) {
143                         return false;
144                 }
145
146                 final DialableLandLineNumber other = (DialableLandLineNumber) object;
147
148                 if (!Objects.equals(this.getPhoneNumber(), other.getPhoneNumber())) {
149                         return false;
150                 } else if (!Objects.equals(this.getPhoneAreaCode(), other.getPhoneAreaCode())) {
151                         return false;
152                 } else if (!Objects.equals(this.getPhoneCountry(), other.getPhoneCountry())) {
153                         return false;
154                 }
155
156                 return true;
157         }
158
159         @Override
160         public Integer getPhoneAreaCode () {
161                 return this.phoneAreaCode;
162         }
163
164         @Override
165         public void setPhoneAreaCode (final Integer phoneAreaCode) {
166                 this.phoneAreaCode = phoneAreaCode;
167         }
168
169         @Override
170         public Country getPhoneCountry () {
171                 return this.phoneCountry;
172         }
173
174         @Override
175         public void setPhoneCountry (final Country phoneCountry) {
176                 this.phoneCountry = phoneCountry;
177         }
178
179         @Override
180         @SuppressWarnings ("ReturnOfDateField")
181         public Calendar getPhoneEntryCreated () {
182                 return this.phoneEntryCreated;
183         }
184
185         @Override
186         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
187         public void setPhoneEntryCreated (final Calendar phoneEntryCreated) {
188                 this.phoneEntryCreated = phoneEntryCreated;
189         }
190
191         @Override
192         @SuppressWarnings ("ReturnOfDateField")
193         public Calendar getPhoneEntryUpdated () {
194                 return this.phoneEntryUpdated;
195         }
196
197         @Override
198         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
199         public void setPhoneEntryUpdated (final Calendar phoneEntryUpdated) {
200                 this.phoneEntryUpdated = phoneEntryUpdated;
201         }
202
203         @Override
204         public Long getPhoneId () {
205                 return this.phoneId;
206         }
207
208         @Override
209         public void setPhoneId (final Long phoneId) {
210                 this.phoneId = phoneId;
211         }
212
213         @Override
214         public Long getPhoneNumber () {
215                 return this.phoneNumber;
216         }
217
218         @Override
219         public void setPhoneNumber (final Long phoneNumber) {
220                 this.phoneNumber = phoneNumber;
221         }
222
223         @Override
224         public int hashCode () {
225                 int hash = 7;
226
227                 hash = 47 * hash + Objects.hashCode(this.getPhoneNumber());
228                 hash = 47 * hash + Objects.hashCode(this.getPhoneAreaCode());
229                 hash = 47 * hash + Objects.hashCode(this.getPhoneCountry());
230
231                 return hash;
232         }
233
234 }