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  
24  package com.gisgraphy.importer.dto;
25  
26  import com.vividsolutions.jts.geom.Point;
27  
28  /**
29   * Represents a house number member in the Karlsruhe schema.
30   * 
31   * @author <a href="mailto:david.masclet@gisgraphy.com">David Masclet</a>
32   */
33  public class AssociatedStreetMember {
34  	
35  	
36  
37  	public AssociatedStreetMember() {
38  		super();
39  	}
40  
41  	public AssociatedStreetMember(String id, Point location, String houseNumber, String name, String type,String role) {
42  		super();
43  		this.id = id;
44  		this.location = location;
45  		this.role = role;
46  		this.type = type;
47  		this.houseNumber = houseNumber;
48  		this.streetName = name;
49  	}
50  
51  	/**
52  	 * the id of the relation
53  	 */
54  	private String id;
55  	/**
56  	 * the gis location of the member (middle point or location )
57  	 */
58  	private Point location;
59  	 /**
60  	 * house or street
61  	 */
62  	private String role;
63  	/**
64  	 * the type of node (way or node), note that house can be way too!
65  	 */
66  	private String type;
67  	
68  	/**
69  	 * the number of the house (if type=house). it is a string because of latin that is can have bis ter or a letter (3c)
70  	 */
71  	private String houseNumber;
72  	
73  	/**
74  	 * the streetName of the street
75  	 */
76  	private String streetName;
77  
78  	/**
79  	 * @return the id
80  	 */
81  	public String getId() {
82  		return id;
83  	}
84  
85  	/**
86  	 * @param id the id to set
87  	 */
88  	public void setId(String id) {
89  		this.id = id;
90  	}
91  
92  	/**
93  	 * @return the location
94  	 */
95  	public Point getLocation() {
96  		return location;
97  	}
98  
99  	/**
100 	 * @param location the location to set
101 	 */
102 	public void setLocation(Point location) {
103 		this.location = location;
104 	}
105 
106 	/**
107 	 * @return the role
108 	 */
109 	public String getRole() {
110 		return role;
111 	}
112 
113 	/**
114 	 * @param role the role to set
115 	 */
116 	public void setRole(String role) {
117 		this.role = role;
118 	}
119 
120 	/**
121 	 * @return the type
122 	 */
123 	public String getType() {
124 		return type;
125 	}
126 
127 	/**
128 	 * @param type the type to set
129 	 */
130 	public void setType(String type) {
131 		this.type = type;
132 	}
133 
134 	/**
135 	 * @return the houseNumber
136 	 */
137 	public String getHouseNumber() {
138 		return houseNumber;
139 	}
140 
141 	/**
142 	 * @param houseNumber the houseNumber to set
143 	 */
144 	public void setHouseNumber(String houseNumber) {
145 		this.houseNumber = houseNumber;
146 	}
147 
148 	/**
149 	 * @return the streetName
150 	 */
151 	public String getStreetName() {
152 		return streetName;
153 	}
154 
155 	/**
156 	 * @param name the name to set
157 	 */
158 	public void setStreetName(String name) {
159 		this.streetName = name;
160 	}
161 
162 	@Override
163 	public String toString() {
164 		return String.format("AssociatedStreetMember [id=%s, location=%s, role=%s, type=%s, houseNumber=%s, streetName=%s]", id, location, role, type, houseNumber, streetName);
165 	}
166 
167 	/* (non-Javadoc)
168 	 * @see java.lang.Object#hashCode()
169 	 */
170 	@Override
171 	public int hashCode() {
172 		final int prime = 31;
173 		int result = 1;
174 		result = prime * result + ((houseNumber == null) ? 0 : houseNumber.hashCode());
175 		result = prime * result + ((id == null) ? 0 : id.hashCode());
176 		result = prime * result + ((location == null) ? 0 : location.hashCode());
177 		result = prime * result + ((streetName == null) ? 0 : streetName.hashCode());
178 		result = prime * result + ((role == null) ? 0 : role.hashCode());
179 		result = prime * result + ((type == null) ? 0 : type.hashCode());
180 		return result;
181 	}
182 
183 	/* (non-Javadoc)
184 	 * @see java.lang.Object#equals(java.lang.Object)
185 	 */
186 	@Override
187 	public boolean equals(Object obj) {
188 		if (this == obj)
189 			return true;
190 		if (obj == null)
191 			return false;
192 		if (getClass() != obj.getClass())
193 			return false;
194 		AssociatedStreetMember other = (AssociatedStreetMember) obj;
195 		if (houseNumber == null) {
196 			if (other.houseNumber != null)
197 				return false;
198 		} else if (!houseNumber.equals(other.houseNumber))
199 			return false;
200 		if (id == null) {
201 			if (other.id != null)
202 				return false;
203 		} else if (!id.equals(other.id))
204 			return false;
205 		if (location == null) {
206 			if (other.location != null)
207 				return false;
208 		} else if (!location.equals(other.location))
209 			return false;
210 		if (streetName == null) {
211 			if (other.streetName != null)
212 				return false;
213 		} else if (!streetName.equals(other.streetName))
214 			return false;
215 		if (role == null) {
216 			if (other.role != null)
217 				return false;
218 		} else if (!role.equals(other.role))
219 			return false;
220 		if (type == null) {
221 			if (other.type != null)
222 				return false;
223 		} else if (!type.equals(other.type))
224 			return false;
225 		return true;
226 	}
227 	
228 	public boolean isStreet(){
229 		if ("street".equalsIgnoreCase(role)||
230 				("way".equalsIgnoreCase(role)) && !isNumeric(houseNumber)||
231 				(streetName!=null && streetName.equalsIgnoreCase(houseNumber))
232 				){
233 			return true;
234 		}
235 		return false;
236 	}
237 	
238 	public boolean isHouse(){
239 		if ("house".equalsIgnoreCase(role)||
240 				("node".equalsIgnoreCase(role)) && isNumeric(houseNumber)||
241 				(houseNumber!=null && !houseNumber.equalsIgnoreCase(streetName))
242 				){
243 			return true;
244 		}
245 		return false;
246 	}
247 	
248 	
249 	private static boolean isNumeric(String houseNumber) {
250 		try {
251 			Integer.parseInt(houseNumber);
252 			return true;
253 		} catch (NumberFormatException e) {
254 			return false;
255 		}
256 	}
257 }