Changeset 24115 in osm for applications
- Timestamp:
- 2010-11-07T17:21:51+01:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/OSMAddress.java
r24093 r24115 41 41 super.setOsmObject(osmObject); 42 42 43 OsmUtils.getValuesFromAddressInterpolation(this); 44 43 45 String streetNameViaRel = OsmUtils.getAssociatedStreet(this.osmObject); 44 46 if (!StringUtils.isNullOrEmpty(streetNameViaRel)) { … … 99 101 */ 100 102 public boolean hasStreetName() { 101 return TagUtils.hasAddrStreetTag(osmObject) ;103 return TagUtils.hasAddrStreetTag(osmObject) || hasDerivedValue(TagUtils.ADDR_STREET_TAG); 102 104 } 103 105 … … 187 189 String val = guessedValues.get(tag); 188 190 if (!StringUtils.isNullOrEmpty(val)) { 189 setOSMTag(tag, val); 191 setOSMTag(tag, val); 190 192 } 191 193 } 194 guessedValues.clear(); 192 195 } 193 196 … … 206 209 */ 207 210 public boolean hasPostCode() { 208 return TagUtils.hasAddrPostcodeTag(osmObject);211 return hasTag(TagUtils.ADDR_POSTCODE_TAG); 209 212 } 210 213 … … 231 234 * Checks for city tag. 232 235 * 233 * @return true, if successful236 * @return true, if a city tag is present or available via referrer. 234 237 */ 235 238 public boolean hasCity() { 236 return TagUtils.hasAddrCityTag(osmObject);239 return hasTag(TagUtils.ADDR_CITY_TAG); 237 240 } 238 241 … … 242 245 */ 243 246 public String getState() { 244 if (!TagUtils.hasAddrStateTag(osmObject)) { 245 return MISSING_TAG; 246 } 247 return TagUtils.getAddrStateValue(osmObject); 248 } 249 250 /** 251 * Gets the name of the state associated with this address. 247 return getTagValueWithGuess(TagUtils.ADDR_STATE_TAG); 248 } 249 250 /** 251 * Checks for state tag. 252 * 253 * @return true, if a state tag is present or available via referrer. 254 */ 255 public boolean hasState() { 256 return hasTag(TagUtils.ADDR_STATE_TAG); 257 } 258 259 /** 260 * Gets the name of the country associated with this address. 252 261 * @return 253 262 */ 254 263 public String getCountry() { 255 if (!TagUtils.hasAddrCountryTag(osmObject)) { 256 return MISSING_TAG; 257 } 258 return TagUtils.getAddrCountryValue(osmObject); 259 } 260 261 /** 262 * Removes all addresss related tags from the node or way. 264 return getTagValueWithGuess(TagUtils.ADDR_COUNTRY_TAG); 265 } 266 267 /** 268 * Checks for country tag. 269 * 270 * @return true, if a country tag is present or available via referrer. 271 */ 272 public boolean hasCountry() { 273 return hasTag(TagUtils.ADDR_COUNTRY_TAG); 274 } 275 276 /** 277 * Removes all address-related tags from the node or way. 263 278 */ 264 279 public void removeAllAddressTags() { … … 269 284 removeOSMTag(TagUtils.ADDR_STATE_TAG); 270 285 removeOSMTag(TagUtils.ADDR_STREET_TAG); 286 } 287 288 /** 289 * Checks if the associated OSM object has the given tag or if the tag is available via a referrer. 290 * 291 * @param tag the tag to look for. 292 * @return true, if there is a value for the given tag. 293 */ 294 public boolean hasTag(String tag) { 295 if (StringUtils.isNullOrEmpty(tag)) return false; 296 297 return TagUtils.hasTag(osmObject, tag) || hasDerivedValue(tag); 271 298 } 272 299 … … 403 430 404 431 /** 432 * Returns true, if this instance has derived values from any referrer. 433 * @return 434 */ 435 public boolean hasDerivedValues() { 436 return derivedValues.size() > 0; 437 } 438 439 /** 405 440 * Gets the derived value for the given tag. 406 441 * @param tag The tag to get the derived value for. -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/OSMEntityBase.java
r24090 r24115 26 26 import org.openstreetmap.josm.data.osm.OsmPrimitive; 27 27 import org.openstreetmap.josm.data.osm.Way; 28 import org.openstreetmap.josm.tools.CheckParameterUtil; 28 29 29 30 /** … … 56 57 */ 57 58 protected void setOsmObject(OsmPrimitive osmObject) { 59 CheckParameterUtil.ensureParameterNotNull(osmObject, "osmObject"); 58 60 this.osmObject = osmObject; 59 61 } … … 64 66 */ 65 67 public static void addChangedListener(IAddressEditContainerListener listener) { 68 CheckParameterUtil.ensureParameterNotNull(listener, "listener"); 66 69 containerListeners.add(listener); 67 70 } … … 72 75 */ 73 76 public static void removeChangedListener(IAddressEditContainerListener listener) { 77 CheckParameterUtil.ensureParameterNotNull(listener, "listener"); 74 78 containerListeners.remove(listener); 75 79 } … … 79 83 */ 80 84 protected static void fireEntityChanged(IOSMEntity entity) { 85 CheckParameterUtil.ensureParameterNotNull(entity, "entity"); 81 86 for (IAddressEditContainerListener listener : containerListeners) { 82 87 listener.entityChanged(entity); … … 89 94 */ 90 95 public void addCommandListener(ICommandListener listener) { 96 CheckParameterUtil.ensureParameterNotNull(listener, "listener"); 91 97 cmdListeners.add(listener); 92 98 } … … 97 103 */ 98 104 public void removeCommandListener(ICommandListener listener) { 105 CheckParameterUtil.ensureParameterNotNull(listener, "listener"); 99 106 cmdListeners.remove(listener); 100 107 } … … 104 111 * 105 112 * @param source the entity that issued the command. 106 * @param cmd the command to execute. 107 */ 108 protected void fireCommandIssued(Command cmd) { 113 * @param command the command to execute. 114 */ 115 protected void fireCommandIssued(Command command) { 116 CheckParameterUtil.ensureParameterNotNull(command, "command"); 109 117 if (cmdListeners.size() == 0) { 110 118 throw new RuntimeException("Object has no TX context: " + this); … … 112 120 113 121 for (ICommandListener l : cmdListeners) { 114 l.commandIssued(this, c md);122 l.commandIssued(this, command); 115 123 } 116 124 } … … 154 162 */ 155 163 protected void setOSMTag(String tag, String newValue) { 164 CheckParameterUtil.ensureParameterNotNull(tag, "tag"); 156 165 if (StringUtils.isNullOrEmpty(tag)) return; 157 166 … … 170 179 */ 171 180 protected void removeOSMTag(String tag) { 181 CheckParameterUtil.ensureParameterNotNull(tag, "tag"); 172 182 setOSMTag(tag, null); // a value of null removes the tag 173 183 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/OsmUtils.java
r24028 r24115 118 118 return null; 119 119 } 120 121 /** 122 * Gets the tag values from an address interpolation ref, if present. 123 * 124 * @param address the address 125 * @return the values from address interpolation 126 */ 127 public static boolean getValuesFromAddressInterpolation(OSMAddress address) { 128 if (address == null) return false; 129 130 OsmPrimitive osmAddr = address.getOsmObject(); 131 132 for (OsmPrimitive osm : osmAddr.getReferrers()) { 133 if (osm instanceof Way) { 134 Way w = (Way) osm; 135 if (TagUtils.hasAddrInterpolationTag(w)) { 136 applyDerivedValue(address, w, TagUtils.ADDR_POSTCODE_TAG); 137 applyDerivedValue(address, w, TagUtils.ADDR_CITY_TAG); 138 applyDerivedValue(address, w, TagUtils.ADDR_COUNTRY_TAG); 139 applyDerivedValue(address, w, TagUtils.ADDR_STREET_TAG); 140 return true; 141 } 142 } 143 } 144 145 return false; 146 } 147 148 private static void applyDerivedValue(OSMAddress address, Way w, String tag) { 149 if (!address.hasTag(tag) && TagUtils.hasTag(w, tag)) { 150 address.setDerivedValue(tag, w.get(tag)); 151 } 152 } 120 153 } -
applications/editors/josm/plugins/FixAddresses/src/org/openstreetmap/josm/plugins/fixAddresses/TagUtils.java
r24104 r24115 27 27 */ 28 28 public final class TagUtils { 29 30 /** 31 * Checks if the given OSM object has a (non-empty) value for the given tag. 32 * 33 * @param osm the osm object to inspect. 34 * @param tag the tag to look for. 35 * @return true, if osm object has a non-empty value for this tag 36 */ 37 public static boolean hasTag(OsmPrimitive osm, String tag) { 38 return osm != null && !StringUtils.isNullOrEmpty(osm.get(tag)); 39 } 29 40 30 41 /**
Note:
See TracChangeset
for help on using the changeset viewer.