KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > addressbook > model > PhoneModel


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.addressbook.model;
19
20 public class PhoneModel {
21
22     public final static int TYPE_BUSINESS_PHONE = 0;
23     public final static int TYPE_ASSISTANT_PHONE = 1;
24     public final static int TYPE_BUSINESS_FAX = 2;
25     public final static int TYPE_CALLBACK_PHONE = 3;
26     public final static int TYPE_CAR_PHONE = 4;
27     public final static int TYPE_COMPANY_PHONE = 5;
28     public final static int TYPE_HOME_PHONE = 6;
29     public final static int TYPE_HOME_FAX = 7;
30     public final static int TYPE_ISDN = 8;
31     public final static int TYPE_MOBILE_PHONE = 9;
32     public final static int TYPE_OTHER_PHONE = 10;
33     public final static int TYPE_OTHER_FAX = 11;
34     public final static int TYPE_PAGER = 12;
35     public final static int TYPE_PRIMARY_PHONE = 13;
36     public final static int TYPE_RADIO = 14;
37     public final static int TYPE_TELEX = 15;
38     public final static int TYPE_TTY = 16;
39     
40     
41     public final static String JavaDoc[] NAMES = new String JavaDoc[] { "BusinessPhone",
42             "AssistantPhone", "BusinessFax", "CallbackPhone", "CarPhone",
43             "CompanyPhone", "HomePhone", "HomeFax", "ISDN", "MobilePhone",
44             "OtherPhone", "OtherFax", "Pager", "PrimaryPhone", "Radio",
45             "Telex", "TTY" };
46
47     private String JavaDoc number;
48
49     private int type;
50
51     public PhoneModel(String JavaDoc number, int type) {
52         this.number = number;
53         this.type = type;
54
55         if (type >= NAMES.length)
56             throw new IllegalArgumentException JavaDoc("unsupported type");
57     }
58
59     public PhoneModel(String JavaDoc number, String JavaDoc type) {
60         this.number = number;
61
62         boolean foundMatch = false;
63         for (int i = 0; i < NAMES.length; i++) {
64             if (type.equals(NAMES[i])) {
65                 foundMatch = true;
66                 this.type = i;
67             }
68         }
69
70         if (!foundMatch)
71             throw new IllegalArgumentException JavaDoc("unsupported type: " + type);
72     }
73
74     /**
75      * @return Returns the number.
76      */

77     public String JavaDoc getNumber() {
78         return number;
79     }
80
81     /**
82      * @return Returns the type.
83      */

84     public int getType() {
85         return type;
86     }
87
88     public String JavaDoc getTypeString() {
89         return NAMES[type];
90     }
91
92 }
93
Popular Tags