View Javadoc

1   package geo.google.datamodel;
2   
3   
4   import java.io.Serializable;
5   
6   import org.apache.commons.lang.StringUtils;
7   import org.apache.commons.lang.builder.EqualsBuilder;
8   import org.apache.commons.lang.builder.HashCodeBuilder;
9   import org.apache.commons.lang.builder.ToStringBuilder;
10  import org.apache.commons.lang.builder.ToStringStyle;
11  /***
12   * A simple data class for US address info.
13   * @see GeoAddress
14   * 
15   * @author jliang
16   *
17   */
18  public class GeoUsAddress implements Serializable{
19    private static final long serialVersionUID = 2701695885973529100L;
20    private String _addressLine1 = StringUtils.EMPTY;
21    private String _addressLine2 = StringUtils.EMPTY;
22    private String _city = StringUtils.EMPTY;
23    private String _county = StringUtils.EMPTY;
24    private String _state = StringUtils.EMPTY;
25    private String _postalCode = StringUtils.EMPTY;
26    private String _country = StringUtils.EMPTY;
27    private GeoCoordinate _coordinate = new GeoCoordinate();
28    private GeoAddressAccuracy _accuracy = GeoAddressAccuracy.UNKNOWN_LOCATION;
29    
30    public GeoUsAddress() {
31    }
32  
33    public GeoUsAddress(String addressLine1, String addressLine2, String city, 
34            String county, String state, String postalCode, String country, 
35            GeoCoordinate coordinate, GeoAddressAccuracy accuracy) {
36      _addressLine1 = addressLine1;
37      _addressLine2 = addressLine2;
38      _city = city;
39      _county = county;
40      _state = state;
41      _postalCode = postalCode;
42      _country = country;
43      _coordinate = coordinate;
44    }
45  
46    public String getAddressLine1() {
47      return _addressLine1;
48    }
49  
50    public void setAddressLine1(String addressLine1) {
51      _addressLine1 = addressLine1;
52    }
53  
54    public String getAddressLine2() {
55      return _addressLine2;
56    }
57  
58    public void setAddressLine2(String addressLine2) {
59      _addressLine2 = addressLine2;
60    }
61  
62    public String getCity() {
63      return _city;
64    }
65  
66    public void setCity(String city) {
67      _city = city;
68    }
69  
70    public String getCounty() {
71      return _county;
72    }
73  
74    public void setCounty(String county) {
75      _county = county;
76    }
77  
78    public String getPostalCode() {
79      return _postalCode;
80    }
81  
82    public void setPostalCode(String postalCode) {
83      _postalCode = postalCode;
84    }
85  
86    public String getState() {
87      return _state;
88    }
89  
90    public void setState(String state) {
91      _state = state;
92    }
93    public String getCountry() {
94      return _country;
95    }
96  
97    public void setCountry(String country) {
98      _country = country;
99    }
100 
101   public GeoCoordinate getCoordinate() {
102     return _coordinate;
103   }
104 
105   public void setCoordinate(GeoCoordinate coordinate) {
106     _coordinate = coordinate;
107   }
108 
109   public GeoAddressAccuracy getAccuracy() {
110     return _accuracy;
111   }
112 
113   public void setAccuracy(GeoAddressAccuracy accuracy) {
114     _accuracy = accuracy;
115   }
116 
117   @Override
118   public boolean equals(Object o) {
119     return EqualsBuilder.reflectionEquals(this, o);
120   }
121   
122   @Override
123   public int hashCode() {
124     return HashCodeBuilder.reflectionHashCode(this);
125   }
126   
127   @Override
128   public String toString() {
129     return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
130   }
131   
132   /***
133    * Return a single line representation of this address in the format of:
134    * <pre>
135    * &lt;addressLine1&gt;, &lt;city&gt;, &lt;state&gt; &lt;postalCode&gt;
136    * </pre>
137    * The standardizer will send this address line string to google's geocode service. 
138    * Extend this class and override this method if it needs to be encoded differently. 
139    */
140   public String toAddressLine(){
141     StringBuilder sb = new StringBuilder();
142     sb.append(_addressLine1)
143       .append(", ")
144       .append(_city)
145       .append(", ")
146       .append(_state)
147       .append(" ")
148       .append(_postalCode);
149     return sb.toString();
150   }
151   
152 }