001: /*
002: * (c) Copyright 2007 by Volker Bergmann. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, is permitted under the terms of the
006: * GNU General Public License.
007: *
008: * For redistributing this software or a derivative work under a license other
009: * than the GPL-compatible Free Software License as defined by the Free
010: * Software Foundation or approved by OSI, you must first obtain a commercial
011: * license to this software product from Volker Bergmann.
012: *
013: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
014: * WITHOUT A WARRANTY OF ANY KIND. ALL EXPRESS OR IMPLIED CONDITIONS,
015: * REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF
016: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE
017: * HEREBY EXCLUDED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
018: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
019: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
020: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
021: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
022: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
023: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
024: * POSSIBILITY OF SUCH DAMAGE.
025: */
026:
027: package org.databene.region;
028:
029: import org.databene.commons.Escalator;
030: import org.databene.commons.LoggerEscalator;
031:
032: /**
033: * Represents a phone number.<br/>
034: * <br/>
035: * Created: 13.06.2006 07:19:26
036: * @author Volker Bergmann
037: */
038: public class PhoneNumber {
039:
040: private static final Escalator escalator = new LoggerEscalator();
041:
042: private String countryCode;
043: private String areaCode;
044: private String localNumber;
045:
046: private boolean mobile;
047:
048: // constructors ----------------------------------------------------------------------------------------------------
049:
050: public PhoneNumber() {
051: this ("", "", "");
052: }
053:
054: public PhoneNumber(String countryCode, String cityCode,
055: String localNumber) {
056: this (countryCode, cityCode, localNumber, false);
057: }
058:
059: public PhoneNumber(String countryCode, String cityCode,
060: String localNumber, boolean mobile) {
061: this .countryCode = countryCode;
062: this .areaCode = cityCode;
063: this .localNumber = localNumber;
064: this .mobile = mobile;
065: }
066:
067: // properties ------------------------------------------------------------------------------------------------------
068:
069: public String getCountryCode() {
070: return countryCode;
071: }
072:
073: public void setCountryCode(String countryCode) {
074: this .countryCode = countryCode;
075: }
076:
077: public String getAreaCode() {
078: return areaCode;
079: }
080:
081: public void setAreaCode(String cityCode) {
082: this .areaCode = cityCode;
083: }
084:
085: /**
086: * @return
087: * @deprecated replaced with {@link #getAreaCode()}
088: */
089: public String getCityCode() {
090: escalator.escalate(getClass().getSimpleName()
091: + ".getCityCode() is deprecated. "
092: + "Use getAreaCode() instead", getClass(), null);
093: return areaCode;
094: }
095:
096: /**
097: * @param areaCode
098: * @deprecated replaced with {@link #setAreaCode(String)}
099: */
100: public void setCityCode(String areaCode) {
101: escalator.escalate(getClass().getSimpleName()
102: + ".setCityCode(String) is deprecated. "
103: + "Use setAreaCode(String) instead", getClass(), null);
104: this .areaCode = areaCode;
105: }
106:
107: public String getLocalNumber() {
108: return localNumber;
109: }
110:
111: public void setLocalNumber(String localNumber) {
112: this .localNumber = localNumber;
113: }
114:
115: /**
116: * @return
117: * @deprecated replaced with {@link #getLocalNumber()}
118: */
119: public String getLocalCode() {
120: escalator.escalate(getClass().getSimpleName()
121: + ".getLocalCode() is deprecated. "
122: + "Use getLocalNumber() instead", getClass(), null);
123: return localNumber;
124: }
125:
126: /**
127: * @param localCode
128: * @deprecated replaced with {@link #setLocalCode(String)}
129: */
130: public void setLocalCode(String localCode) {
131: escalator.escalate(getClass().getSimpleName()
132: + ".setLocalCode() is deprecated. "
133: + "Use setLocalNumber() instead", getClass(), null);
134: this .localNumber = localCode;
135: }
136:
137: public boolean isMobile() {
138: return mobile;
139: }
140:
141: public void setMobile(boolean mobile) {
142: this .mobile = mobile;
143: }
144:
145: // java.lang.Object overrides --------------------------------------------------------------------------------------
146:
147: public String toString() {
148: return "+" + countryCode + '-' + areaCode + '-' + localNumber;
149: }
150:
151: @Override
152: public int hashCode() {
153: final int prime = 31;
154: int result = 1;
155: result = prime * result
156: + ((areaCode == null) ? 0 : areaCode.hashCode());
157: result = prime * result
158: + ((countryCode == null) ? 0 : countryCode.hashCode());
159: result = prime * result
160: + ((localNumber == null) ? 0 : localNumber.hashCode());
161: return result;
162: }
163:
164: @Override
165: public boolean equals(Object obj) {
166: if (this == obj)
167: return true;
168: if (obj == null)
169: return false;
170: if (getClass() != obj.getClass())
171: return false;
172: final PhoneNumber other = (PhoneNumber) obj;
173: if (areaCode == null) {
174: if (other.areaCode != null)
175: return false;
176: } else if (!areaCode.equals(other.areaCode))
177: return false;
178: if (countryCode == null) {
179: if (other.countryCode != null)
180: return false;
181: } else if (!countryCode.equals(other.countryCode))
182: return false;
183: if (localNumber == null) {
184: if (other.localNumber != null)
185: return false;
186: } else if (!localNumber.equals(other.localNumber))
187: return false;
188: return true;
189: }
190:
191: }
|