View Javadoc
1   /*
2    * (c) Copyright 2006-2020 by rapiddweller GmbH & Volker Bergmann. All rights reserved.
3    *
4    * Redistribution and use in source and binary forms, with or without
5    * modification, is permitted under the terms of the
6    * GNU General Public License.
7    *
8    * For redistributing this software or a derivative work under a license other
9    * than the GPL-compatible Free Software License as defined by the Free
10   * Software Foundation or approved by OSI, you must first obtain a commercial
11   * license to this software product from rapiddweller GmbH & Volker Bergmann.
12   *
13   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14   * WITHOUT A WARRANTY OF ANY KIND. ALL EXPRESS OR IMPLIED CONDITIONS,
15   * REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF
16   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE
17   * HEREBY EXCLUDED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24   * POSSIBILITY OF SUCH DAMAGE.
25   */
26  
27  package com.rapiddweller.domain.address;
28  
29  import com.rapiddweller.common.NullSafeComparator;
30  
31  /**
32   * Represents a phone number.<br/>
33   * <br/>
34   * Created: 13.06.2006 07:19:26
35   *
36   * @author Volker Bergmann
37   * @since 0.1
38   */
39  public class PhoneNumber {
40  
41    private String countryCode;
42    private String areaCode;
43    private String localNumber;
44  
45    private boolean mobile;
46  
47    // constructors ----------------------------------------------------------------------------------------------------
48  
49    /**
50     * Instantiates a new Phone number.
51     */
52    public PhoneNumber() {
53      this("", "", "");
54    }
55  
56    /**
57     * Instantiates a new Phone number.
58     *
59     * @param countryCode the country code
60     * @param cityCode    the city code
61     * @param localNumber the local number
62     */
63    public PhoneNumber(String countryCode, String cityCode,
64                       String localNumber) {
65      this(countryCode, cityCode, localNumber, false);
66    }
67  
68    /**
69     * Instantiates a new Phone number.
70     *
71     * @param countryCode the country code
72     * @param cityCode    the city code
73     * @param localNumber the local number
74     * @param mobile      the mobile
75     */
76    public PhoneNumber(String countryCode, String cityCode, String localNumber,
77                       boolean mobile) {
78      this.countryCode = countryCode;
79      this.areaCode = cityCode;
80      this.localNumber = localNumber;
81      this.mobile = mobile;
82    }
83  
84    // properties ------------------------------------------------------------------------------------------------------
85  
86    /**
87     * Gets country code.
88     *
89     * @return the country code
90     */
91    public String getCountryCode() {
92      return countryCode;
93    }
94  
95    /**
96     * Sets country code.
97     *
98     * @param countryCode the country code
99     */
100   public void setCountryCode(String countryCode) {
101     this.countryCode = countryCode;
102   }
103 
104   /**
105    * Gets area code.
106    *
107    * @return the area code
108    */
109   public String getAreaCode() {
110     return areaCode;
111   }
112 
113   /**
114    * Sets area code.
115    *
116    * @param cityCode the city code
117    */
118   public void setAreaCode(String cityCode) {
119     this.areaCode = cityCode;
120   }
121 
122   /**
123    * Gets local number.
124    *
125    * @return the local number
126    */
127   public String getLocalNumber() {
128     return localNumber;
129   }
130 
131   /**
132    * Sets local number.
133    *
134    * @param localNumber the local number
135    */
136   public void setLocalNumber(String localNumber) {
137     this.localNumber = localNumber;
138   }
139 
140   /**
141    * Is mobile boolean.
142    *
143    * @return the boolean
144    */
145   public boolean isMobile() {
146     return mobile;
147   }
148 
149   /**
150    * Sets mobile.
151    *
152    * @param mobile the mobile
153    */
154   public void setMobile(boolean mobile) {
155     this.mobile = mobile;
156   }
157 
158   // java.lang.Object overrides --------------------------------------------------------------------------------------
159 
160   @Override
161   public String toString() {
162     return "+" + countryCode + '-' + areaCode + '-' + localNumber;
163   }
164 
165   @Override
166   public int hashCode() {
167     final int prime = 31;
168     int result = 1;
169     result = prime * result
170         + ((areaCode == null) ? 0 : areaCode.hashCode());
171     result = prime * result
172         + ((countryCode == null) ? 0 : countryCode.hashCode());
173     result = prime * result
174         + ((localNumber == null) ? 0 : localNumber.hashCode());
175     return result;
176   }
177 
178   @Override
179   public boolean equals(Object obj) {
180     if (this == obj) {
181       return true;
182     }
183     if (obj == null) {
184       return false;
185     }
186     if (getClass() != obj.getClass()) {
187       return false;
188     }
189     final PhoneNumber../../../com/rapiddweller/domain/address/PhoneNumber.html#PhoneNumber">PhoneNumber that = (PhoneNumber) obj;
190     if (!this.areaCode.equals(that.areaCode)) {
191       return false;
192     }
193     if (!NullSafeComparator.equals(this.countryCode, that.countryCode)) {
194       return false;
195     }
196     return (this.localNumber.equals(that.localNumber));
197   }
198 
199 }