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.domain.geoloc.entity;
24
25 import javax.persistence.Entity;
26
27 import org.hibernate.annotations.Cache;
28 import org.hibernate.annotations.CacheConcurrencyStrategy;
29 import org.hibernate.annotations.Index;
30
31 /**
32 * Represents a city subdivision Object
33 *
34 * @author <a href="mailto:david.masclet@gisgraphy.com">David Masclet</a>
35 */
36 @Entity
37 @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
38 public class CitySubdivision extends GisFeature implements ZipCodeAware {
39 private String zipCode;
40
41 /**
42 * Constructor that populate the {@link CitySubdivision} with the gisFeature
43 * fields<br>
44 *
45 * @param gisFeature
46 * The gisFeature from which we want to populate the
47 * {@linkplain CitySubdivision}
48 */
49 public CitySubdivision(GisFeature gisFeature) {
50 super(gisFeature);
51 }
52
53 /*
54 * (non-Javadoc)
55 *
56 * @see com.gisgraphy.domain.geoloc.entity.ZipCodeAware#setZipCode(java.lang.Integer)
57 */
58 public void setZipCode(String zipCode) {
59 this.zipCode = zipCode;
60 }
61
62 /*
63 * (non-Javadoc)
64 *
65 * @see com.gisgraphy.domain.geoloc.entity.ZipCodeAware#getZipCode()
66 */
67 @Index(name = "citySubdivisionZipCode")
68 public String getZipCode() {
69 return zipCode;
70 }
71
72 /**
73 * Default constructor (Needed by CGLib)
74 */
75 public CitySubdivision() {
76 super();
77 }
78
79 /*
80 * (non-Javadoc)
81 *
82 * @see com.gisgraphy.domain.geoloc.entity.GisFeature#hashCode()
83 */
84 @Override
85 public int hashCode() {
86 final int PRIME = 31;
87 int result = super.hashCode();
88 result = PRIME * result
89 + ((getFeatureId() == null) ? 0 : getFeatureId().hashCode());
90 return result;
91 }
92
93 /*
94 * (non-Javadoc)
95 *
96 * @see com.gisgraphy.domain.geoloc.entity.GisFeature#equals(java.lang.Object)
97 */
98 @Override
99 public boolean equals(Object obj) {
100 if (this == obj) {
101 return true;
102 }
103 if (!super.equals(obj)) {
104 return false;
105 }
106 if (getClass() != obj.getClass()) {
107 return false;
108 }
109 final CitySubdivision other = (CitySubdivision) obj;
110 if (getFeatureId() == null) {
111 if (other.getFeatureId() != null) {
112 return false;
113 }
114 } else if (!getFeatureId().equals(other.getFeatureId())) {
115 return false;
116 }
117 return true;
118 }
119
120 /*
121 * (non-Javadoc)
122 *
123 * @see com.gisgraphy.domain.geoloc.entity.GisFeature#populate(com.gisgraphy.domain.geoloc.entity.GisFeature)
124 */
125 @Override
126 public void populate(GisFeature gisFeature) {
127 super.populate(gisFeature);
128 if (gisFeature instanceof ZipCodeAware) {
129 this.setZipCode(((ZipCodeAware) gisFeature).getZipCode());
130 }
131 }
132
133 }