2 * Copyright (C) 2016 Roland Haeder
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.
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.
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/>.
17 package org.mxchange.jphone.phonenumbers.fax;
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;
39 * A POJO for dialable fax numbers
41 * @author Roland Haeder<roland@mxchange.org>
43 @Entity (name = "fax_numbers")
44 @Table (name = "fax_numbers")
46 @NamedQuery (name = "SearchFaxId", query = "SELECT f FROM fax_numbers AS f WHERE f.phoneId = :faxId")
48 public class FaxNumber implements DialableFaxNumber {
53 private static final long serialVersionUID = 17_687_687_191_375L;
56 * Area code (example: 2151 for Krefeld)
58 @Basic (optional = false)
59 @Column (name = "fax_area_code", length = 10, nullable = false)
60 private Integer faxAreaCode;
63 * Country instance ('s dial data)
65 @JoinColumn (name = "fax_country_id", nullable = false)
66 @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false)
67 private Country faxCountry;
70 * Timestamp when this entry has been created
72 @Basic (optional = false)
73 @Temporal (TemporalType.TIMESTAMP)
74 @Column (name = "fax_entry_created", nullable = false, updatable = false)
75 private Calendar phoneEntryCreated;
81 @GeneratedValue (strategy = GenerationType.IDENTITY)
82 @Column (name = "fax_id", nullable = false, updatable = false)
86 * Fax number without prefix
88 @Basic (optional = false)
89 @Column (name = "fax_number", nullable = false)
90 private Long phoneNumber;
99 * Constructor with country, area code and number
101 * @param faxCountry Country instance
102 * @param faxAreaCode Area code (without leading zeros)
103 * @param faxNumber Fax number (without area code and leading zero)
105 public FaxNumber (final Country faxCountry, final Integer faxAreaCode, final Long faxNumber) {
106 // Call default constructor
110 this.faxCountry = faxCountry;
111 this.faxAreaCode = faxAreaCode;
112 this.phoneNumber = faxNumber;
116 public void copyAll (final DialableFaxNumber sourceNumber) {
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());
126 public boolean equals (final Object object) {
127 if (null == object) {
129 } else if (this.getClass() != object.getClass()) {
133 final DialableFaxNumber other = (DialableFaxNumber) object;
135 if (!Objects.equals(this.getPhoneNumber(), other.getPhoneNumber())) {
137 } else if (!Objects.equals(this.getPhoneAreaCode(), other.getPhoneAreaCode())) {
139 } else if (!Objects.equals(this.getPhoneCountry(), other.getPhoneCountry())) {
147 public int hashCode () {
149 hash = 23 * hash + Objects.hashCode(this.getPhoneNumber());
150 hash = 23 * hash + Objects.hashCode(this.getPhoneAreaCode());
151 hash = 23 * hash + Objects.hashCode(this.getPhoneCountry());
156 public Integer getPhoneAreaCode () {
157 return this.faxAreaCode;
161 public void setPhoneAreaCode (final Integer faxAreaCode) {
162 this.faxAreaCode = faxAreaCode;
166 public Country getPhoneCountry () {
167 return this.faxCountry;
171 public void setPhoneCountry (final Country faxCountry) {
172 this.faxCountry = faxCountry;
176 public Calendar getPhoneEntryCreated () {
177 return this.phoneEntryCreated;
181 public void setPhoneEntryCreated (final Calendar phoneEntryCreated) {
182 this.phoneEntryCreated = phoneEntryCreated;
186 public Long getPhoneId () {
191 public void setPhoneId (final Long phoneId) {
192 this.phoneId = phoneId;
196 public Long getPhoneNumber () {
197 return this.phoneNumber;
201 public void setPhoneNumber (final Long phoneNumber) {
202 this.phoneNumber = phoneNumber;