1 package org.columba.addressbook.model; 19 20 public class AddressModel { 21 22 public static final String [] NAMES = new String [] { "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 poBox; 31 32 private String street; 33 34 private String city; 35 36 private String zipPostalCode; 37 38 private String stateProvinceCounty; 39 40 private String country; 41 42 private String label; 43 44 int type; 45 46 public AddressModel(String poBox, String street, String city, 47 String zipPostalCode, String stateProvinceCounty, String country, String label, 48 String type) { 49 50 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 ("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 poBox, String street, String city, 72 String zipPostalCode, String stateProvinceCounty, String country, String label, 73 int type) { 74 75 77 if (type < 0 || type > 2) 78 throw new IllegalArgumentException ("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 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 ("type not supported"); 99 } 100 101 104 public String getCity() { 105 return city; 106 } 107 108 111 public String getCountry() { 112 return country; 113 } 114 115 118 public String getPoBox() { 119 return poBox; 120 } 121 122 125 public String getStateProvinceCounty() { 126 return stateProvinceCounty; 127 } 128 129 132 public String getZipPostalCode() { 133 return zipPostalCode; 134 } 135 136 139 public int getType() { 140 return type; 141 } 142 143 146 public String getStreet() { 147 return street; 148 } 149 150 153 public String getLabel() { 154 return label; 155 } 156 } 157
| Popular Tags
|