Changeset 11608 in josm for trunk/src/org/openstreetmap/josm/data
- Timestamp:
- 2017-02-25T03:14:20+01:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java
r11587 r11608 706 706 * Replies true, if the map of key/value pairs of this primitive is not empty. 707 707 * 708 * @return true, if the map of key/value pairs of this primitive is not empty; false 709 * otherwise 708 * @return true, if the map of key/value pairs of this primitive is not empty; false otherwise 710 709 */ 711 710 @Override … … 718 717 * 719 718 * @param key the key 720 * @return true, if his primitive has a tag with key <code>key</code> 721 */ 719 * @return true, if this primitive has a tag with key <code>key</code> 720 */ 721 @Override 722 722 public boolean hasKey(String key) { 723 723 return key != null && indexOfKey(keys, key) >= 0; … … 728 728 * 729 729 * @param keys the keys 730 * @return true, if his primitive has a tag with any of the <code>keys</code>730 * @return true, if this primitive has a tag with any of the <code>keys</code> 731 731 * @since 11587 732 732 */ … … 758 758 759 759 /** 760 * Tests whether this primitive contains a tag consisting of {@code key} and {@code value s}.760 * Tests whether this primitive contains a tag consisting of {@code key} and {@code value}. 761 761 * @param key the key forming the tag. 762 762 * @param value value forming the tag. 763 * @return true if fprimitive contains a tag consisting of {@code key} and {@code value}.763 * @return true if primitive contains a tag consisting of {@code key} and {@code value}. 764 764 */ 765 765 public boolean hasTag(String key, String value) { … … 781 781 * @param key the key forming the tag. 782 782 * @param values one or many values forming the tag. 783 * @return true if fprimitive contains a tag consisting of {@code key} and any of {@code values}.783 * @return true if primitive contains a tag consisting of {@code key} and any of {@code values}. 784 784 */ 785 785 public boolean hasTag(String key, Collection<String> values) { 786 786 return values.contains(get(key)); 787 787 } 788 789 /** 790 * Tests whether this primitive contains a tag consisting of {@code key} and a value different from {@code value}. 791 * @param key the key forming the tag. 792 * @param value value not forming the tag. 793 * @return true if primitive contains a tag consisting of {@code key} and a value different from {@code value}. 794 * @since 11608 795 */ 796 public boolean hasTagDifferent(String key, String value) { 797 String v = get(key); 798 return v != null && !v.equals(value); 799 } 800 801 /** 802 * Tests whether this primitive contains a tag consisting of {@code key} and none of {@code values}. 803 * @param key the key forming the tag. 804 * @param values one or many values forming the tag. 805 * @return true if primitive contains a tag consisting of {@code key} and none of {@code values}. 806 * @since 11608 807 */ 808 public boolean hasTagDifferent(String key, String... values) { 809 return hasTagDifferent(key, Arrays.asList(values)); 810 } 811 812 /** 813 * Tests whether this primitive contains a tag consisting of {@code key} and none of {@code values}. 814 * @param key the key forming the tag. 815 * @param values one or many values forming the tag. 816 * @return true if primitive contains a tag consisting of {@code key} and none of {@code values}. 817 * @since 11608 818 */ 819 public boolean hasTagDifferent(String key, Collection<String> values) { 820 String v = get(key); 821 return v != null && !values.contains(v); 822 } 788 823 } -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r11600 r11608 1353 1353 */ 1354 1354 public final boolean hasAreaTags() { 1355 return hasKey("landuse", "amenity", "leisure", "building", "building:part") 1356 || "yes".equals(get("area")) 1357 || "riverbank".equals(get("waterway")) 1355 return hasKey("landuse", "amenity", "building", "building:part") 1356 || hasTag("area", "yes") 1357 || hasTag("waterway", "riverbank") 1358 || hasTagDifferent("leisure", "picnic_table", "slipway", "firepit") 1358 1359 || hasTag("natural", "water", "wood", "scrub", "wetland", "grassland", "heath", "rock", "bare_rock", 1359 1360 "sand", "beach", "scree", "bay", "glacier", "shingle", "fell", "reef", "stone", -
trunk/src/org/openstreetmap/josm/data/osm/Tagged.java
r10736 r11608 4 4 import java.util.Collection; 5 5 import java.util.Map; 6 6 7 /** 7 8 * Objects implement Tagged if they provide a map of key/value pairs. 8 9 * 9 * 10 * @since 2115 10 11 */ 11 12 // FIXME: better naming? setTags(), getTags(), getKeys() instead of keySet() ? … … 67 68 68 69 /** 70 * Replies true if there is a tag with key <code>key</code>. 71 * 72 * @param key the key 73 * @return true, if there is a tag with key <code>key</code> 74 * @since 11608 75 */ 76 default boolean hasKey(String key) { 77 return get(key) != null; 78 } 79 80 /** 69 81 * Replies the set of keys 70 82 * -
trunk/src/org/openstreetmap/josm/data/osm/history/HistoryNode.java
r8509 r11608 10 10 11 11 /** 12 * Represents an immutable OSM node in the context of a historical view on 13 * OSM data. 14 * 12 * Represents an immutable OSM node in the context of a historical view on OSM data. 13 * @since 1670 15 14 */ 16 15 public class HistoryNode extends HistoryOsmPrimitive { -
trunk/src/org/openstreetmap/josm/data/osm/history/HistoryOsmPrimitive.java
r11553 r11608 5 5 6 6 import java.text.MessageFormat; 7 import java.util.Collection; 7 8 import java.util.Collections; 8 9 import java.util.Date; … … 19 20 import org.openstreetmap.josm.data.osm.Relation; 20 21 import org.openstreetmap.josm.data.osm.SimplePrimitiveId; 22 import org.openstreetmap.josm.data.osm.Tagged; 21 23 import org.openstreetmap.josm.data.osm.User; 22 24 import org.openstreetmap.josm.data.osm.Way; … … 24 26 25 27 /** 26 * Represents an immutable OSM primitive in the context of a historical view on 27 * OSM data. 28 * 28 * Represents an immutable OSM primitive in the context of a historical view on OSM data. 29 * @since 1670 29 30 */ 30 public abstract class HistoryOsmPrimitive implements Comparable<HistoryOsmPrimitive> {31 public abstract class HistoryOsmPrimitive implements Tagged, Comparable<HistoryOsmPrimitive> { 31 32 32 33 private long id; … … 38 39 private long version; 39 40 private Map<String, String> tags; 40 41 protected final void ensurePositiveLong(long value, String name) {42 if (value <= 0) {43 throw new IllegalArgumentException(MessageFormat.format("Parameter ''{0}'' > 0 expected. Got ''{1}''.", name, value));44 }45 }46 41 47 42 /** … … 119 114 } 120 115 116 /** 117 * Returns the id. 118 * @return the id 119 */ 121 120 public long getId() { 122 121 return id; 123 122 } 124 123 124 /** 125 * Returns the primitive id. 126 * @return the primitive id 127 */ 125 128 public PrimitiveId getPrimitiveId() { 126 129 return new SimplePrimitiveId(id, getType()); 127 130 } 128 131 132 /** 133 * Determines if the primitive is still visible. 134 * @return {@code true} if the primitive is still visible 135 */ 129 136 public boolean isVisible() { 130 137 return visible; 131 138 } 132 139 140 /** 141 * Returns the user. 142 * @return the user 143 */ 133 144 public User getUser() { 134 145 return user; 135 146 } 136 147 148 /** 149 * Returns the changeset id. 150 * @return the changeset id 151 */ 137 152 public long getChangesetId() { 138 153 return changesetId; 139 154 } 140 155 156 /** 157 * Returns the timestamp. 158 * @return the timestamp 159 */ 141 160 public Date getTimestamp() { 142 161 return timestamp; 143 162 } 144 163 164 /** 165 * Returns the version. 166 * @return the version 167 */ 145 168 public long getVersion() { 146 169 return version; 147 170 } 148 171 172 protected final void ensurePositiveLong(long value, String name) { 173 if (value <= 0) { 174 throw new IllegalArgumentException(MessageFormat.format("Parameter ''{0}'' > 0 expected. Got ''{1}''.", name, value)); 175 } 176 } 177 149 178 public boolean matches(long id, long version) { 150 179 return this.id == id && this.version == version; … … 155 184 } 156 185 186 /** 187 * Returns the primitive type. 188 * @return the primitive type 189 */ 157 190 public abstract OsmPrimitiveType getType(); 158 191 … … 164 197 } 165 198 166 public void put(String key, String value) { 199 @Override 200 public final void put(String key, String value) { 167 201 tags.put(key, value); 168 202 } 169 203 170 public String get(String key) { 204 @Override 205 public final String get(String key) { 171 206 return tags.get(key); 172 207 } 173 208 174 public boolean hasTag(String key) { 175 return tags.get(key) != null; 176 } 177 209 @Override 210 public final boolean hasKey(String key) { 211 return tags.containsKey(key); 212 } 213 214 @Override 215 public final Map<String, String> getKeys() { 216 return getTags(); 217 } 218 219 @Override 220 public final void setKeys(Map<String, String> keys) { 221 throw new UnsupportedOperationException(); 222 } 223 224 @Override 225 public final void remove(String key) { 226 throw new UnsupportedOperationException(); 227 } 228 229 @Override 230 public final void removeAll() { 231 throw new UnsupportedOperationException(); 232 } 233 234 @Override 235 public final boolean hasKeys() { 236 return !tags.isEmpty(); 237 } 238 239 @Override 240 public final Collection<String> keySet() { 241 return Collections.unmodifiableSet(tags.keySet()); 242 } 243 244 /** 245 * Replies the key/value map. 246 * @return the key/value map 247 */ 178 248 public Map<String, String> getTags() { 179 249 return Collections.unmodifiableMap(tags); … … 272 342 public String toString() { 273 343 return getClass().getSimpleName() + " [version=" + version + ", id=" + id + ", visible=" + visible + ", " 274 + (timestamp != null ? "timestamp=" + timestamp: "") + ", "275 + (user != null ? "user=" + user + ", ": "") + "changesetId="344 + (timestamp != null ? ("timestamp=" + timestamp) : "") + ", " 345 + (user != null ? ("user=" + user + ", ") : "") + "changesetId=" 276 346 + changesetId 277 347 + ']'; -
trunk/src/org/openstreetmap/josm/data/osm/history/HistoryRelation.java
r10632 r11608 15 15 16 16 /** 17 * Represents an immutable OSM relation in the context of a historical view on 18 * OSM data. 19 * 17 * Represents an immutable OSM relation in the context of a historical view on OSM data. 18 * @since 1670 20 19 */ 21 20 public class HistoryRelation extends HistoryOsmPrimitive { -
trunk/src/org/openstreetmap/josm/data/osm/history/HistoryWay.java
r10662 r11608 15 15 16 16 /** 17 * Represents an immutable OSM way in the context of a historical view on 18 * OSM data. 19 * 17 * Represents an immutable OSM way in the context of a historical view on OSM data. 18 * @since 1670 20 19 */ 21 20 public class HistoryWay extends HistoryOsmPrimitive { -
trunk/src/org/openstreetmap/josm/data/validation/Test.java
r11553 r11608 342 342 */ 343 343 protected static final boolean isBuilding(OsmPrimitive p) { 344 String v = p.get("building"); 345 return v != null && !"no".equals(v) && !"entrance".equals(v); 344 return p.hasTagDifferent("building", "no", "entrance"); 346 345 } 347 346 … … 357 356 Test test = (Test) obj; 358 357 return Objects.equals(name, test.name) && 359 358 Objects.equals(description, test.description); 360 359 } 361 360 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/Addresses.java
r11339 r11608 63 63 // warning level only if several relations have different names, see #10945 64 64 final String name = list.get(0).get("name"); 65 if (name == null || SubclassFilteredCollection.filter(list, r -> name.equals(r.get("name"))).size() < list.size()) {65 if (name == null || SubclassFilteredCollection.filter(list, r -> r.hasTag("name", name)).size() < list.size()) { 66 66 level = Severity.WARNING; 67 67 } else { … … 147 147 street.add((Way) p); 148 148 } 149 if (relationName != null && p.has Key("name") && !relationName.equals(p.get("name"))) {149 if (relationName != null && p.hasTagDifferent("name", relationName)) { 150 150 if (wrongStreetNames.isEmpty()) { 151 151 wrongStreetNames.add(r); -
trunk/src/org/openstreetmap/josm/data/validation/tests/Coastlines.java
r11129 r11608 251 251 252 252 private static boolean isCoastline(OsmPrimitive osm) { 253 return osm instanceof Way && "coastline".equals(osm.get("natural"));253 return osm instanceof Way && osm.hasTag("natural", "coastline"); 254 254 } 255 255 -
trunk/src/org/openstreetmap/josm/data/validation/tests/CrossingWays.java
r11587 r11608 241 241 242 242 static boolean isHighway(OsmPrimitive w) { 243 return w.has Key(HIGHWAY) && !w.hasTag(HIGHWAY, "rest_area", "services");243 return w.hasTagDifferent(HIGHWAY, "rest_area", "services"); 244 244 } 245 245 -
trunk/src/org/openstreetmap/josm/data/validation/tests/Highways.java
r11129 r11608 92 92 public void visit(Way w) { 93 93 if (w.isUsable()) { 94 if (w.isClosed() && w.hasKey("highway") && CLASSIFIED_HIGHWAYS.contains(w.get("highway")) 95 && w.hasKey("junction") && "roundabout".equals(w.get("junction"))) { 94 if (w.isClosed() && w.hasTag("highway", CLASSIFIED_HIGHWAYS) && w.hasTag("junction", "roundabout")) { 96 95 // TODO: find out how to handle splitted roundabouts (see #12841) 97 96 testWrongRoundabout(w); … … 131 130 if (list.size() > 2 || oneway1 == null || oneway2 == null || !oneway1 || !oneway2) { 132 131 // Error when the highway tags do not match 133 if (!w.get("highway").equals(s)) { 132 String value = w.get("highway"); 133 if (!value.equals(s)) { 134 134 errors.add(TestError.builder(this, Severity.WARNING, WRONG_ROUNDABOUT_HIGHWAY) 135 .message(tr("Incorrect roundabout (highway: {0} instead of {1})", w.get("highway"), s))135 .message(tr("Incorrect roundabout (highway: {0} instead of {1})", value, s)) 136 136 .primitives(w) 137 137 .fix(() -> new ChangePropertyCommand(w, "highway", s)) -
trunk/src/org/openstreetmap/josm/data/validation/tests/LongSegment.java
r11129 r11608 35 35 @Override 36 36 public void visit(Way w) { 37 if ( "ferry".equals(w.get("route"))) {37 if (w.hasTag("route", "ferry")) { 38 38 return; 39 39 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/MultipolygonTest.java
r11590 r11608 175 175 private void checkStyleConsistency(Relation r, Multipolygon polygon) { 176 176 ElemStyles styles = MapPaintStyles.getStyles(); 177 if (styles != null && ! "boundary".equals(r.get("type"))) {177 if (styles != null && !r.hasTag("type", "boundary")) { 178 178 AreaElement area = ElemStyles.getAreaElemStyle(r, false); 179 179 boolean areaStyle = area != null; -
trunk/src/org/openstreetmap/josm/data/validation/tests/OverlappingWays.java
r11129 r11608 90 90 91 91 for (WaySegment ws : duplicated) { 92 if (ws.way. get("highway") != null) {92 if (ws.way.hasKey("highway")) { 93 93 highway++; 94 } else if (ws.way. get("railway") != null) {94 } else if (ws.way.hasKey("railway")) { 95 95 railway++; 96 96 } … … 107 107 currentWays.add(ws.way); 108 108 } 109 /* These ways not seen before 110 * If two or more of the overlapping ways are 111 * highways or railways mark a separate error 112 */ 109 // These ways not seen before 110 // If two or more of the overlapping ways are highways or railways mark a separate error 113 111 if ((highlight = seenWays.get(currentWays)) == null) { 114 112 String errortype; -
trunk/src/org/openstreetmap/josm/data/validation/tests/PowerLines.java
r11432 r11608 165 165 */ 166 166 private static boolean isPowerIn(OsmPrimitive p, Collection<String> values) { 167 String v = p.get("power"); 168 return v != null && values != null && values.contains(v); 167 return p.hasTag("power", values); 169 168 } 170 169 … … 176 175 */ 177 176 private static boolean isBuildingIn(OsmPrimitive p, Collection<String> values) { 178 String v = p.get("building"); 179 return v != null && values != null && values.contains(v); 177 return p.hasTag("building", values); 180 178 } 181 179 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/TurnrestrictionTest.java
r11129 r11608 48 48 @Override 49 49 public void visit(Relation r) { 50 if (! "restriction".equals(r.get("type")))50 if (!r.hasTag("type", "restriction")) 51 51 return; 52 52 … … 224 224 225 225 private static boolean isFullOneway(Way w) { 226 return w.isOneway() != 0 && ! "no".equals(w.get("oneway:bicycle"));226 return w.isOneway() != 0 && !w.hasTag("oneway:bicycle", "no"); 227 227 } 228 228 -
trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java
r11587 r11608 306 306 this.isAbandoned = "abandoned".equals(railway) || w.isKeyTrue("disused"); 307 307 this.highway = (highway != null || railway != null) && !isAbandoned; 308 this.isBoundary = !this.highway && "administrative".equals(w.get("boundary"));308 this.isBoundary = !this.highway && w.hasTag("boundary", "administrative"); 309 309 line = new Line2D.Double(n1.getEastNorth().east(), n1.getEastNorth().north(), 310 310 n2.getEastNorth().east(), n2.getEastNorth().north());
Note:
See TracChangeset
for help on using the changeset viewer.