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