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