KickJava   Java API By Example, From Geeks To Geeks.

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


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 AddressModel {
21
22     public static final String JavaDoc[] NAMES = new String JavaDoc[] { "work", "home", "other" };
23
24     public static final int TYPE_WORK = 0;
25
26     public static final int TYPE_HOME = 1;
27
28     public static final int TYPE_OTHER = 2;
29
30     private String JavaDoc poBox;
31
32     private String JavaDoc street;
33
34     private String JavaDoc city;
35
36     private String JavaDoc zipPostalCode;
37
38     private String JavaDoc stateProvinceCounty;
39
40     private String JavaDoc country;
41     
42     private String JavaDoc label;
43
44     int type;
45
46     public AddressModel(String JavaDoc poBox, String JavaDoc street, String JavaDoc city,
47             String JavaDoc zipPostalCode, String JavaDoc stateProvinceCounty, String JavaDoc country, String JavaDoc label,
48             String JavaDoc type) {
49
50         // TODO: throw IllegalArgumentException in case a variable == null
51
boolean foundMatch = false;
52         for (int i = 0; i < NAMES.length; i++) {
53             if (type.equals(NAMES[i])) {
54                 foundMatch = true;
55                 this.type = i;
56             }
57         }
58
59         if (!foundMatch)
60             throw new IllegalArgumentException JavaDoc("unsupported type ="+type);
61
62         this.poBox = poBox;
63         this.street = street;
64         this.city = city;
65         this.zipPostalCode = zipPostalCode;
66         this.stateProvinceCounty = stateProvinceCounty;
67         this.country = country;
68         this.label = label;
69     }
70
71     public AddressModel(String JavaDoc poBox, String JavaDoc street, String JavaDoc city,
72             String JavaDoc zipPostalCode, String JavaDoc stateProvinceCounty, String JavaDoc country, String JavaDoc label,
73             int type) {
74         
75         // TODO: throw IllegalArgumentException in case a variable == null
76

77         if (type < 0 || type > 2)
78             throw new IllegalArgumentException JavaDoc("unsupported type =" + type);
79
80         this.poBox = poBox;
81         this.street = street;
82         this.city = city;
83         this.zipPostalCode = zipPostalCode;
84         this.stateProvinceCounty = stateProvinceCounty;
85         this.country = country;
86         this.type = type;
87         this.label = label;
88     }
89
90     public String JavaDoc getTypeString() {
91         if (type == 0)
92             return "work";
93         if (type == 1)
94             return "home";
95         if (type == 2)
96             return "other";
97         else
98             throw new IllegalArgumentException JavaDoc("type not supported");
99     }
100
101     /**
102      * @return Returns the city.
103      */

104     public String JavaDoc getCity() {
105         return city;
106     }
107
108     /**
109      * @return Returns the country.
110      */

111     public String JavaDoc getCountry() {
112         return country;
113     }
114
115     /**
116      * @return Returns the poBox.
117      */

118     public String JavaDoc getPoBox() {
119         return poBox;
120     }
121
122     /**
123      * @return Returns the stateProvinceCounty.
124      */

125     public String JavaDoc getStateProvinceCounty() {
126         return stateProvinceCounty;
127     }
128
129     /**
130      * @return Returns the zipPostalCode.
131      */

132     public String JavaDoc getZipPostalCode() {
133         return zipPostalCode;
134     }
135
136     /**
137      * @return Returns the type.
138      */

139     public int getType() {
140         return type;
141     }
142
143     /**
144      * @return Returns the street.
145      */

146     public String JavaDoc getStreet() {
147         return street;
148     }
149     
150     /**
151      * @return Returns the label.
152      */

153     public String JavaDoc getLabel() {
154         return label;
155     }
156 }
157
Popular Tags