View Javadoc
1   /*******************************************************************************
2    *   Gisgraphy Project 
3    * 
4    *   This library is free software; you can redistribute it and/or
5    *   modify it under the terms of the GNU Lesser General Public
6    *   License as published by the Free Software Foundation; either
7    *   version 2.1 of the License, or (at your option) any later version.
8    * 
9    *   This library is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   *   Lesser General Public License for more details.
13   * 
14   *   You should have received a copy of the GNU Lesser General Public
15   *   License along with this library; if not, write to the Free Software
16   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
17   * 
18   *  Copyright 2008  Gisgraphy project 
19   *  David Masclet <davidmasclet@gisgraphy.com>
20   *  
21   *  
22   *******************************************************************************/
23  package com.gisgraphy.model;
24  
25  import java.io.Serializable;
26  
27  import javax.persistence.Column;
28  import javax.persistence.Embeddable;
29  
30  import org.apache.commons.lang.builder.ToStringBuilder;
31  import org.apache.commons.lang.builder.ToStringStyle;
32  
33  /**
34   * This class is used to represent an address with address, city, province and
35   * postal-code information.
36   * 
37   * !!!!THIS CLASS IS AN OLD CLASS TO STORE USER INFORMATION, DO NOT USE FOR GEOCODING OR GIS!!!!
38   * 
39   * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
40   */
41  @Embeddable
42  public class Address extends BaseObject implements Serializable {
43      private static final long serialVersionUID = 3617859655330969141L;
44  
45      private String address;
46  
47      private String city;
48  
49      private String province;
50  
51      private String country;
52  
53      private String postalCode;
54  
55      @Column(length = 150)
56      public String getAddress() {
57  	return address;
58      }
59  
60      @Column(nullable = false, length = 50)
61      public String getCity() {
62  	return city;
63      }
64  
65      @Column(length = 100)
66      public String getProvince() {
67  	return province;
68      }
69  
70      @Column(length = 100)
71      public String getCountry() {
72  	return country;
73      }
74  
75      @Column(name = "postal_code", nullable = false, length = 15)
76      public String getPostalCode() {
77  	return postalCode;
78      }
79  
80      public void setAddress(String address) {
81  	this.address = address;
82      }
83  
84      public void setCity(String city) {
85  	this.city = city;
86      }
87  
88      public void setCountry(String country) {
89  	this.country = country;
90      }
91  
92      public void setPostalCode(String postalCode) {
93  	this.postalCode = postalCode;
94      }
95  
96      public void setProvince(String province) {
97  	this.province = province;
98      }
99  
100     /**
101      * Overridden equals method for object comparison. Compares based on
102      * hashCode.
103      * 
104      * @param o
105      *                Object to compare
106      * @return true/false based on hashCode
107      */
108     @Override
109     public boolean equals(Object o) {
110 	if (this == o) {
111 	    return true;
112 	}
113 	if (!(o instanceof Address)) {
114 	    return false;
115 	}
116 
117 	final Address address1 = (Address) o;
118 
119 	return this.hashCode() == address1.hashCode();
120     }
121 
122     /**
123      * Overridden hashCode method - compares on address, city, province, country
124      * and postal code.
125      * 
126      * @return hashCode
127      */
128     @Override
129     public int hashCode() {
130 	int result;
131 	result = (address != null ? address.hashCode() : 0);
132 	result = 29 * result + (city != null ? city.hashCode() : 0);
133 	result = 29 * result + (province != null ? province.hashCode() : 0);
134 	result = 29 * result + (country != null ? country.hashCode() : 0);
135 	result = 29 * result + (postalCode != null ? postalCode.hashCode() : 0);
136 	return result;
137     }
138 
139     /**
140      * Returns a multi-line String with key=value pairs.
141      * 
142      * @return a String representation of this class.
143      */
144     @Override
145     public String toString() {
146 	return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
147 		.append("country", this.country)
148 		.append("address", this.address).append("province",
149 			this.province).append("postalCode", this.postalCode)
150 		.append("city", this.city).toString();
151     }
152 }