@@ -17,6 +17,25 @@ public class PhoneNumber {
17
17
/** Static variable to support the getPhoneNumber method. */
18
18
private final static String [] numbers = new String []{"0" ,"1" ,"2" ,"3" ,"4" ,"5" ,"6" ,"7" ,"8" ,"9" };
19
19
20
+ private final static String [] types = new String []{
21
+
22
+ //Personal Phone
23
+ "HomePhone" ,"MobilePhone" ,"HomeFax" ,"HomePhone2" ,
24
+
25
+ //Work Phone
26
+ "BusinessPhone" ,"BusinessPhone2" ,"BusinessFax" ,
27
+ "CompanyMainPhone" ,"AssistantPhone" ,
28
+
29
+ //Primary/Callback
30
+ "PrimaryPhone" ,"Callback" ,
31
+
32
+ //Other
33
+ "OtherFax" ,"OtherTelephone" ,
34
+
35
+ //Legacy
36
+ "CarPhone" ,"Pager" ,"Isdn" ,"RadioPhone" ,"Telex" ,"TtyTddPhone"
37
+ };
38
+
20
39
21
40
//**************************************************************************
22
41
//** Constructor
@@ -85,6 +104,23 @@ public String getType(){
85
104
}
86
105
87
106
107
+ //**************************************************************************
108
+ //** getTypes
109
+ //**************************************************************************
110
+ /** Returns a static list of phone number types:
111
+ * <ul>
112
+ * <li>AssistantPhone</li><li>BusinessFax</li><li>BusinessPhone</li>
113
+ * <li>BusinessPhone2</li><li>Callback</li><li>CarPhone</li>
114
+ * <li>CompanyMainPhone</li><li>HomeFax</li><li>HomePhone</li>
115
+ * <li>HomePhone2</li><li>Isdn</li><li>MobilePhone</li><li>OtherFax</li>
116
+ * <li>OtherTelephone</li><li>Pager</li><li>PrimaryPhone</li>
117
+ * <li>RadioPhone</li><li>Telex</li><li>TtyTddPhone</li>
118
+ * </ul>
119
+ */
120
+ public static String [] getTypes (){
121
+ return types ;
122
+ }
123
+
88
124
public String toString (){
89
125
return type + ": " + number ;
90
126
}
@@ -102,7 +138,7 @@ public boolean equals(Object obj){
102
138
103
139
104
140
//**************************************************************************
105
- //** getPhoneNumber
141
+ //** getNumber
106
142
//**************************************************************************
107
143
/** Used to normalize a phone number into a common format. For example, if
108
144
* you pass in "(555) 555-5555" or "555.555.5555" or "5555555555", the
@@ -140,36 +176,37 @@ private String getNumber(String phoneNumber){
140
176
}
141
177
142
178
143
-
144
179
//**************************************************************************
145
- //** getPhoneType
180
+ //** getType
146
181
//**************************************************************************
147
- /** Used to normalize a phone number type.
182
+ /** Returns a phone number type that most closely matches the given string .
148
183
*/
149
184
private String getType (String type ){
150
- type = type .toUpperCase ();
151
- if (type .contains ("ASSISTANT" )) return "AssistantPhone" ;
152
- if (type .contains ("BUSINESSFAX" ) || type .contains ("WORKFAX" )) return "BusinessFax" ;
153
- if (type .contains ("BUSINESS" ) || type .contains ("WORK" ) || type .contains ("OFFICE" )) return "BusinessPhone" ;
154
- //else if (type.contains("BUSINESS2")) return "BusinessPhone2";
155
- if (type .contains ("CALLBACK" )) return "Callback" ;
156
- if (type .contains ("CAR" )) return "CarPhone" ;
157
- //else if (type.contains("COMPANYMAIN")) return "CompanyMainPhone";
158
- if (type .equals ("HOMEFAX" )) return "HomeFax" ;
185
+ type = type .toUpperCase ().replace (" " , "" );
186
+ for (String t : types ){
187
+ if (t .toUpperCase ().equals (type )) return t ;
188
+ }
189
+
190
+
159
191
if (type .contains ("HOME" )) return "HomePhone" ;
160
- //else if (type.contains("HOME2")) return "HomePhone2";
161
- if (type .contains ("ISDN" )) return "Isdn" ;
162
192
if (type .contains ("MOBILE" )) return "MobilePhone" ;
163
- if (type .equals ("OTHERFAX" )) return "OtherFax" ;
164
- if (type .contains ("PAGER" )) return "Pager" ;
165
- if (type .contains ("PRIMARY" )) return "PrimaryPhone" ;
166
- if (type .contains ("RADIO" )) return "RadioPhone" ;
167
- if (type .contains ("TELEX" )) return "Telex" ;
168
- if (type .contains ("TTYTDD" )) return "TtyTddPhone" ;
169
- return "OtherTelephone" ;
170
- }
193
+
194
+ if (type .equals ("FAX" ) || type .equals ("COMPANYFAX" ) || type .equals ("WORKFAX" )) return "BusinessFax" ;
195
+ if (type .equals ("PERSONALFAX" )) return "HomeFax" ;
196
+ if (type .contains ("FAX" )) return "OtherFax" ;
171
197
198
+ if (type .contains ("BUSINESS" ) || type .contains ("WORK" ) || type .contains ("OFFICE" )) return "BusinessPhone" ;
199
+ if (type .contains ("ASSISTANT" )) return "AssistantPhone" ;
172
200
173
201
202
+ if (type .contains ("PRIMARY" )) return "PrimaryPhone" ;
203
+ if (type .contains ("CALLBACK" )) return "Callback" ;
204
+
205
+
206
+ if (type .contains ("CAR" )) return "CarPhone" ;
207
+ if (type .contains ("RADIO" )) return "RadioPhone" ;
208
+ if (type .contains ("TTY" ) || type .contains ("TDD" )) return "TtyTddPhone" ;
174
209
210
+ return "OtherTelephone" ;
211
+ }
175
212
}
0 commit comments