2 * Copyright (C) 2016 - 2020 Free Software Foundation
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.model.phonenumbers.mobileprovider;
19 import java.text.MessageFormat;
20 import java.util.Date;
21 import java.util.Objects;
22 import javax.persistence.Basic;
23 import javax.persistence.CascadeType;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.GeneratedValue;
27 import javax.persistence.GenerationType;
28 import javax.persistence.Id;
29 import javax.persistence.JoinColumn;
30 import javax.persistence.NamedQueries;
31 import javax.persistence.NamedQuery;
32 import javax.persistence.OneToOne;
33 import javax.persistence.Table;
34 import javax.persistence.Temporal;
35 import javax.persistence.TemporalType;
36 import javax.persistence.Transient;
37 import org.apache.commons.lang3.StringUtils;
38 import org.mxchange.jcoreutils.Comparables;
39 import org.mxchange.jcountry.model.data.Country;
40 import org.mxchange.jcountry.model.data.CountryData;
43 * A POJO for mobile providers
45 * @author Roland Häder<roland@mxchange.org>
47 @Entity (name = "mobile_provider")
48 @Table (name = "mobile_provider")
50 @NamedQuery (name = "AllMobileProvider", query = "SELECT p FROM mobile_provider AS p ORDER BY p.providerId ASC")
52 @SuppressWarnings ("PersistenceUnitPresent")
53 public class CellphoneProvider implements MobileProvider {
59 private static final long serialVersionUID = 185_878_567_810_590L;
62 * Country instance ('s dial data)
64 @JoinColumn (name = "provider_country_id", nullable = false)
65 @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false)
66 private Country providerCountry;
69 * Provider dial prefix (example: 0177 for German E+)
71 @Basic (optional = false)
72 @Column (name = "provider_dial_prefix", length = 10, nullable = false)
73 private Long providerDialPrefix;
76 * Timestamp when this entry has been created
78 @Basic (optional = false)
79 @Temporal (TemporalType.TIMESTAMP)
80 @Column (name = "provider_entry_created", nullable = false, updatable = false)
81 private Date providerEntryCreated;
87 @GeneratedValue (strategy = GenerationType.IDENTITY)
88 @Column (name = "provider_id", nullable = false, updatable = false)
89 private Long providerId;
92 * Pattern for mail gateway
94 @Column (name = "provider_mail_pattern", length = 30)
95 private String providerMailPattern;
98 * Name of the provider
100 @Basic (optional = false)
101 @Column (name = "provider_name", length = 30, nullable = false)
102 private String providerName;
105 * Default constructor
107 public CellphoneProvider () {
111 * Constructor with all required data
113 * @param providerDialPrefix Dial prefix
114 * @param providerName Name
115 * @param providerCountry An instance of a Country class
116 * @param providerMailPattern Pattern for email
118 public CellphoneProvider (final Long providerDialPrefix, final String providerName, final Country providerCountry, final String providerMailPattern) {
119 // Invoke default constructor
122 // Are all parameter set?
123 if (null == providerDialPrefix) {
125 throw new NullPointerException("providerDialPrefix is null"); //NOI18N
126 } else if (providerDialPrefix < 1) {
128 throw new IllegalArgumentException(MessageFormat.format("providerDialPrefix={0} is not valid.", providerDialPrefix)); //NOI18N
129 } else if (null == providerName) {
131 throw new NullPointerException("providerName is null"); //NOI18N
132 } else if (providerName.isEmpty()) {
134 throw new IllegalArgumentException("providerName is empty"); //NOI18N
135 } else if (null == providerCountry) {
137 throw new NullPointerException("providerCountry is null"); //NOI18N
138 } else if (null == providerCountry.getCountryId()) {
140 throw new NullPointerException("providerCountry.countryId is null"); //NOI18N
141 } else if (providerCountry.getCountryId() < 1) {
143 throw new IllegalArgumentException(MessageFormat.format("providerCountry.countryId={0} is not valid", providerCountry.getCountryId())); //NOI18N
144 } else if (null == providerMailPattern) {
146 throw new NullPointerException("providerMailPattern is null"); //NOI18N
147 } else if (providerMailPattern.isEmpty()) {
149 throw new IllegalArgumentException("providerMailPattern is empty"); //NOI18N
153 this.providerDialPrefix = providerDialPrefix;
154 this.providerName = providerName;
155 this.providerCountry = providerCountry;
156 this.providerMailPattern = providerMailPattern;
160 public int compareTo (final MobileProvider otherProvider) {
161 // Is the parameter given?
162 if (null == otherProvider) {
164 throw new NullPointerException("otherProvider is null"); //NOI18N
165 } else if (otherProvider.equals(this)) {
171 final int[] comparators = {
173 this.getProviderCountry().compareTo(otherProvider.getProviderCountry()),
175 StringUtils.compare(this.getProviderName(), otherProvider.getProviderName()),
176 // Last is dial prefix
177 this.getProviderDialPrefix().compareTo(otherProvider.getProviderDialPrefix())
181 final int comparison = Comparables.checkAll(comparators);
188 public boolean equals (final Object object) {
189 if (null == object) {
191 } else if (this.getClass() != object.getClass()) {
195 final MobileProvider mobileProvider = (MobileProvider) object;
197 if (!Objects.equals(this.getProviderDialPrefix(), mobileProvider.getProviderDialPrefix())) {
199 } else if (!Objects.equals(this.getProviderName(), mobileProvider.getProviderName())) {
201 } else if (!Objects.equals(this.getProviderCountry(), mobileProvider.getProviderCountry())) {
209 public Country getProviderCountry () {
210 return this.providerCountry;
214 public void setProviderCountry (final Country providerCountry) {
215 this.providerCountry = providerCountry;
219 public Long getProviderDialPrefix () {
220 return this.providerDialPrefix;
224 public void setProviderDialPrefix (final Long providerDialPrefix) {
225 this.providerDialPrefix = providerDialPrefix;
229 @SuppressWarnings ("ReturnOfDateField")
230 public Date getProviderEntryCreated () {
231 return this.providerEntryCreated;
235 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
236 public void setProviderEntryCreated (final Date providerEntryCreated) {
237 this.providerEntryCreated = providerEntryCreated;
241 public Long getProviderId () {
242 return this.providerId;
246 public void setProviderId (final Long providerId) {
247 this.providerId = providerId;
251 public String getProviderMailPattern () {
252 return this.providerMailPattern;
256 public void setProviderMailPattern (final String providerMailPattern) {
257 this.providerMailPattern = providerMailPattern;
261 public String getProviderName () {
262 return this.providerName;
266 public void setProviderName (final String providerName) {
267 this.providerName = providerName;
271 public int hashCode () {
274 hash = 19 * hash + Objects.hashCode(this.getProviderDialPrefix());
275 hash = 19 * hash + Objects.hashCode(this.getProviderName());
276 hash = 19 * hash + Objects.hashCode(this.getProviderCountry());