KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > domain > Address


1 package sellwin.domain;
2
3 import java.util.*;
4 import java.io.*;
5
6 // SellWin http://sourceforge.net/projects/sellwincrm
7
//Contact support@open-app.com for commercial help with SellWin
8
//This software is provided "AS IS", without a warranty of any kind.
9

10 /**
11  * This class represents a 'person', 'contact', or physical mailing
12  * address in the system. Its goal is to capture all info about a user
13  * or person in a consistent way.
14  * This class holds column values found in the 'address' table.
15  */

16 public class Address implements Serializable {
17     public final static String JavaDoc[] STATES = {
18 "AL", "AK", "AZ", "AR",
19 "CA", "CO", "CT", "DE",
20 "DC", "FL", "GA", "HI",
21 "ID", "IL", "IN", "IA",
22 "KS", "KY", "LA", "ME",
23 "MD", "MA", "MI", "MN",
24 "MS", "MO", "MT", "NE",
25 "NV", "NH", "NJ", "NM",
26 "NY", "NC", "ND", "OH",
27 "OK", "OR", "PA", "RI",
28 "SC", "SD", "TN", "TX",
29 "UT", "VT", "VA", "WA",
30 "WV", "WI", "WY"
31     };
32
33     private long pk;
34     private String JavaDoc firstName;
35     private String JavaDoc lastName;
36     private String JavaDoc middleInitial;
37     private String JavaDoc addressLine1;
38     private String JavaDoc addressLine2;
39     private String JavaDoc title;
40     private String JavaDoc phone;
41     private String JavaDoc fax;
42     private String JavaDoc pager;
43     private String JavaDoc cell;
44     private String JavaDoc email;
45     private String JavaDoc city;
46     private String JavaDoc state;
47     private String JavaDoc country;
48     private String JavaDoc zip;
49     private String JavaDoc zip4;
50     private String JavaDoc modifiedBy;
51     private Date modifiedDate;
52     private boolean modified=false;
53
54     public Address() {
55         pk=0;
56         firstName="";
57         lastName="";
58         middleInitial=" ";
59         addressLine1=" ";
60         addressLine2=" ";
61         title=" ";
62         phone=" ";
63         fax=" ";
64         pager=" ";
65         cell=" ";
66         email=" ";
67         city=" ";
68         state=" ";
69         country="USA";
70         zip=" ";
71         zip4=" ";
72         modifiedBy="";
73         modifiedDate = new Date();
74     }
75
76     public final void setPK(long p) { pk = p; }
77     public final void setCity(String JavaDoc s) { city = s; }
78     public final void setState(String JavaDoc s) { state = s; }
79     public final void setCountry(String JavaDoc s) { country = s; }
80     public final void setZip(String JavaDoc s) { zip = s; }
81     public final void setZip4(String JavaDoc s) { zip4 = s; }
82     public final void setAddressLine1(String JavaDoc s) { addressLine1 = s; }
83     public final void setAddressLine2(String JavaDoc s) { addressLine2 = s; }
84     public final void setFirstName(String JavaDoc s) { firstName = s; }
85     public final void setLastName(String JavaDoc s) { lastName = s; }
86     public final void setMiddleInitial(String JavaDoc s) { middleInitial = s; }
87     public final void setTitle(String JavaDoc s) { title = s; }
88     public final void setPhone(String JavaDoc s) { phone = s; }
89     public final void setFax(String JavaDoc s) { fax = s; }
90     public final void setPager(String JavaDoc s) { pager = s; }
91     public final void setCell(String JavaDoc s) { cell = s; }
92     public final void setEmail(String JavaDoc s) { email = s; }
93     public final void setModifiedBy(String JavaDoc s) { modifiedBy = s; }
94     public final void setModifiedDate(Date s) { modifiedDate = s; }
95     public final void setModified(boolean b) { modified = b; }
96
97     public final long getPK() { return pk; }
98     public final String JavaDoc getAddressLine1() { return addressLine1; }
99     public final String JavaDoc getAddressLine2() { return addressLine2; }
100     public final String JavaDoc getCity() { return city; }
101     public final String JavaDoc getState() { return state; }
102     public final String JavaDoc getCountry() { return country; }
103     public final String JavaDoc getZip() { return zip; }
104     public final String JavaDoc getZip4() { return zip4; }
105     public final String JavaDoc getFirstName() { return firstName; }
106     public final String JavaDoc getLastName() { return lastName ; }
107     public final String JavaDoc getMiddleInitial() { return middleInitial; }
108     public final String JavaDoc getTitle() { return title;}
109     public final String JavaDoc getPhone() { return phone; }
110     public final String JavaDoc getFax() { return fax; }
111     public final String JavaDoc getPager() { return pager;}
112     public final String JavaDoc getCell() { return cell; }
113     public final String JavaDoc getEmail() { return email; }
114     public final String JavaDoc getModifiedBy() { return modifiedBy; }
115     public final Date getModifiedDate() { return modifiedDate; }
116     public final boolean isModified() { return modified; }
117
118     public final String JavaDoc getFormattedName() {
119         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
120
121         if (getLastName() == null) {
122             ;
123         } else {
124             str.append(getLastName()).append(", ");
125         }
126
127         if (getFirstName() == null) {
128             ;
129         } else {
130             str.append(getFirstName()).append(" ");
131         }
132
133         if (getMiddleInitial() == null) {
134             ;
135         } else {
136             str.append(getMiddleInitial());
137         }
138
139         return str.toString();
140         //return getLastName() + ", " + getFirstName() + " " + getMiddleInitial();
141
}
142
143     public final void print() {
144         System.out.println(" ADDRESS--->");
145         System.out.println(" pk=" + pk);
146         System.out.println(" fname=["+ firstName + "]");
147         System.out.println(" lname=["+ lastName + "]");
148         System.out.println(" mi=["+ middleInitial + "]");
149         System.out.println(" line1=["+ addressLine1 + "]");
150         System.out.println(" line2=["+ addressLine2 + "]");
151         System.out.println(" title=["+ title + "]");
152         System.out.println(" phone=["+ phone + "]");
153         System.out.println(" fax=["+ fax + "]");
154         System.out.println(" pager=["+ pager + "]");
155         System.out.println(" cell=["+ cell + "]");
156         System.out.println(" email=["+ email + "]");
157         System.out.println(" city=["+ city + "]");
158         System.out.println(" state=["+ state + "]");
159         System.out.println(" country=["+ country + "]");
160         System.out.println(" zip=[" + zip + "]");
161         System.out.println(" zip4=["+ zip4 + "]");
162     }
163
164     public final Address copy() {
165         Address copy = new Address();
166         copy.pk = pk;
167         if (firstName != null)
168             copy.firstName = new String JavaDoc(firstName);
169         if (lastName != null)
170             copy.lastName = new String JavaDoc(lastName);
171         if (middleInitial != null)
172             copy.middleInitial = new String JavaDoc(middleInitial);
173         if (addressLine1 != null)
174             copy.addressLine1 = new String JavaDoc(addressLine1);
175         if (addressLine2 != null)
176             copy.addressLine2 = new String JavaDoc(addressLine2);
177         if (title != null)
178             copy.title = new String JavaDoc(title);
179         if (phone != null)
180             copy.phone = new String JavaDoc(phone);
181         if (fax != null)
182             copy.fax = new String JavaDoc(fax);
183         if (pager != null)
184             copy.pager = new String JavaDoc(pager);
185         if (cell != null)
186             copy.cell = new String JavaDoc(cell);
187         if (email != null)
188             copy.email = new String JavaDoc(email);
189         if (city != null)
190             copy.city = new String JavaDoc(city);
191         if (state != null)
192             copy.state = new String JavaDoc(state);
193         if (country != null)
194             copy.country = new String JavaDoc(country);
195         if (zip != null)
196             copy.zip = new String JavaDoc(zip);
197         if (zip4 != null)
198             copy.zip4 = new String JavaDoc(zip4);
199         copy.modifiedDate = new Date(modifiedDate.getTime());
200         copy.modified = modified;
201         if (modifiedBy != null)
202             copy.modifiedBy = new String JavaDoc(modifiedBy);
203
204         return copy;
205     }
206
207     public static void copyFields(Address to, Address from) {
208         to.setAddressLine1(from.getAddressLine1());
209         to.setAddressLine2(from.getAddressLine2());
210         to.setCity(from.getCity());
211         to.setState(from.getState());
212         to.setCountry(from.getCountry());
213         to.setZip(from.getZip());
214         to.setZip4(from.getZip4());
215         to.setFirstName(from.getFirstName());
216         to.setLastName(from.getLastName());
217         to.setMiddleInitial(from.getMiddleInitial());
218         to.setTitle(from.getTitle());
219         to.setPhone(from.getPhone());
220         to.setFax(from.getFax());
221         to.setPager(from.getPager());
222         to.setCell(from.getCell());
223         to.setEmail(from.getEmail());
224         to.setModified(from.isModified());
225     }
226
227     public final boolean diff(Address from) {
228         if (!getAddressLine1().equals(from.getAddressLine1()))
229             return true;
230         if (!getAddressLine2().equals(from.getAddressLine2()))
231             return true;
232         if (!getCity().equals(from.getCity()))
233             return true;
234         if (!getState().equals(from.getState()))
235             return true;
236         if (!getCountry().equals(from.getCountry()))
237             return true;
238         if (!getZip().equals(from.getZip()))
239             return true;
240         if (!getZip4().equals(from.getZip4()))
241             return true;
242         if (!getFirstName().equals(from.getFirstName()))
243             return true;
244         if (!getLastName().equals(from.getLastName()))
245             return true;
246         if (!getMiddleInitial().equals(from.getMiddleInitial()))
247             return true;
248         if (!getTitle().equals(from.getTitle()))
249             return true;
250         if (!getPhone().equals(from.getPhone()))
251             return true;
252         if (!getFax().equals(from.getFax()))
253             return true;
254         if (!getPager().equals(from.getPager()))
255             return true;
256         if (!getCell().equals(from.getCell()))
257             return true;
258         if (!getEmail().equals(from.getEmail()))
259             return true;
260
261         return false;
262     }
263 }
264
Popular Tags