001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.addressbook.model;
019:
020: public class AddressModel {
021:
022: public static final String[] NAMES = new String[] { "work", "home",
023: "other" };
024:
025: public static final int TYPE_WORK = 0;
026:
027: public static final int TYPE_HOME = 1;
028:
029: public static final int TYPE_OTHER = 2;
030:
031: private String poBox;
032:
033: private String street;
034:
035: private String city;
036:
037: private String zipPostalCode;
038:
039: private String stateProvinceCounty;
040:
041: private String country;
042:
043: private String label;
044:
045: int type;
046:
047: public AddressModel(String poBox, String street, String city,
048: String zipPostalCode, String stateProvinceCounty,
049: String country, String label, String type) {
050:
051: // TODO: throw IllegalArgumentException in case a variable == null
052: boolean foundMatch = false;
053: for (int i = 0; i < NAMES.length; i++) {
054: if (type.equals(NAMES[i])) {
055: foundMatch = true;
056: this .type = i;
057: }
058: }
059:
060: if (!foundMatch)
061: throw new IllegalArgumentException("unsupported type ="
062: + type);
063:
064: this .poBox = poBox;
065: this .street = street;
066: this .city = city;
067: this .zipPostalCode = zipPostalCode;
068: this .stateProvinceCounty = stateProvinceCounty;
069: this .country = country;
070: this .label = label;
071: }
072:
073: public AddressModel(String poBox, String street, String city,
074: String zipPostalCode, String stateProvinceCounty,
075: String country, String label, int type) {
076:
077: // TODO: throw IllegalArgumentException in case a variable == null
078:
079: if (type < 0 || type > 2)
080: throw new IllegalArgumentException("unsupported type ="
081: + type);
082:
083: this .poBox = poBox;
084: this .street = street;
085: this .city = city;
086: this .zipPostalCode = zipPostalCode;
087: this .stateProvinceCounty = stateProvinceCounty;
088: this .country = country;
089: this .type = type;
090: this .label = label;
091: }
092:
093: public String getTypeString() {
094: if (type == 0)
095: return "work";
096: if (type == 1)
097: return "home";
098: if (type == 2)
099: return "other";
100: else
101: throw new IllegalArgumentException("type not supported");
102: }
103:
104: /**
105: * @return Returns the city.
106: */
107: public String getCity() {
108: return city;
109: }
110:
111: /**
112: * @return Returns the country.
113: */
114: public String getCountry() {
115: return country;
116: }
117:
118: /**
119: * @return Returns the poBox.
120: */
121: public String getPoBox() {
122: return poBox;
123: }
124:
125: /**
126: * @return Returns the stateProvinceCounty.
127: */
128: public String getStateProvinceCounty() {
129: return stateProvinceCounty;
130: }
131:
132: /**
133: * @return Returns the zipPostalCode.
134: */
135: public String getZipPostalCode() {
136: return zipPostalCode;
137: }
138:
139: /**
140: * @return Returns the type.
141: */
142: public int getType() {
143: return type;
144: }
145:
146: /**
147: * @return Returns the street.
148: */
149: public String getStreet() {
150: return street;
151: }
152:
153: /**
154: * @return Returns the label.
155: */
156: public String getLabel() {
157: return label;
158: }
159: }
|