Changeset 18885 in josm for trunk/src/org


Ignore:
Timestamp:
2023-10-30T20:12:12+01:00 (13 months ago)
Author:
taylor.smock
Message:

Fix #23252: Ignore line_management=transition|termination in UnconnectedPowerTest (patch by gaben, modified)

Modifications are as follows:

  • Lint fixes
  • Performance enhancements (profiling done with validator and an overpass download of Mesa County, Colorado)
    • Iterating over an array is much more efficient than using streams. For methods that may be frequently called, using Arrays.stream is currently not a good idea.
      • hasTagDifferent: 2.09 MB -> 0
      • hasTag: 125MB -> 0
      • hasKey: 879MB -> 0
Location:
trunk/src/org/openstreetmap/josm/data
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java

    r18881 r18885  
    7777     * Then it indicates, whether it is completely hidden or
    7878     * just shown in gray color.
    79      *
     79     * <p>
    8080     * When the primitive is not disabled, this flag should be
    8181     * unset as well (for efficient access).
     
    521521    @Override
    522522    public void visitKeys(KeyValueVisitor visitor) {
    523         String[] keys = this.keys;
    524         if (keys != null) {
    525             for (int i = 0; i < keys.length; i += 2) {
    526                 visitor.visitKeyValue(this, keys[i], keys[i + 1]);
     523        String[] tKeys = this.keys;
     524        if (tKeys != null) {
     525            for (int i = 0; i < tKeys.length; i += 2) {
     526                visitor.visitKeyValue(this, tKeys[i], tKeys[i + 1]);
    527527            }
    528528        }
     
    754754    @Override
    755755    public final Collection<String> keySet() {
    756         String[] keys = this.keys;
    757         if (keys == null) {
     756        String[] tKeys = this.keys;
     757        if (tKeys == null) {
    758758            return Collections.emptySet();
    759759        }
    760         if (keys.length == 2) {
    761             return Collections.singleton(keys[0]);
    762         }
    763 
    764         final Set<String> result = new HashSet<>(Utils.hashMapInitialCapacity(keys.length / 2));
    765         for (int i = 0; i < keys.length; i += 2) {
    766             result.add(keys[i]);
     760        if (tKeys.length == 2) {
     761            return Collections.singleton(tKeys[0]);
     762        }
     763
     764        final Set<String> result = new HashSet<>(Utils.hashMapInitialCapacity(tKeys.length / 2));
     765        for (int i = 0; i < tKeys.length; i += 2) {
     766            result.add(tKeys[i]);
    767767        }
    768768        return result;
     
    810810     */
    811811    public boolean hasKey(String... keys) {
    812         return keys != null && Arrays.stream(keys).anyMatch(this::hasKey);
     812        if (keys != null) {
     813            for (String key : keys) {
     814                if (this.hasKey(key)) {
     815                    return true;
     816                }
     817            }
     818        }
     819        return false;
    813820    }
    814821
  • trunk/src/org/openstreetmap/josm/data/osm/Tagged.java

    r18474 r18885  
    22package org.openstreetmap.josm.data.osm;
    33
    4 import java.util.Arrays;
    54import java.util.Collection;
    65import java.util.Map;
     
    147146     */
    148147    default boolean hasTag(String key, String... values) {
    149         return hasTag(key, Arrays.asList(values));
     148        final String actualValue = get(key);
     149        for (String value : values) {
     150            if (Objects.equals(value, actualValue)) {
     151                return true;
     152            }
     153        }
     154        return false;
    150155    }
    151156
     
    182187     */
    183188    default boolean hasTagDifferent(String key, String... values) {
    184         return hasTagDifferent(key, Arrays.asList(values));
     189        final String actual = get(key);
     190        for (String value : values) {
     191            if (Objects.equals(actual, value)) {
     192                return false;
     193            }
     194        }
     195        return true;
    185196    }
    186197
  • trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java

    r18871 r18885  
    5353 */
    5454public abstract class UnconnectedWays extends Test {
     55    private static final String POWER = "power";
     56    private static final String PLATFORM = "platform";
     57    private static final String PLATFORM_EDGE = "platform_edge";
     58    private static final String CONSTRUCTION = "construction";
    5559    private final int code;
    5660    private final boolean isHighwayTest;
     
    102106                    || n.isKeyTrue("noexit")
    103107                    || n.hasKey("entrance", "barrier")
    104                     || n.getParentWays().stream().anyMatch(p -> isBuilding(p) || p.hasTag(RAILWAY, "platform", "platform_edge"));
     108                    || n.getParentWays().stream().anyMatch(p -> isBuilding(p) || p.hasTag(RAILWAY, PLATFORM, PLATFORM_EDGE));
    105109        }
    106110    }
     
    120124        @Override
    121125        protected boolean isCandidate(OsmPrimitive p) {
    122             if (p.hasTag(RAILWAY, "construction") && p.hasKey("construction"))
    123                 return p.hasTagDifferent("construction", "platform", "platform_edge", "service_station", "station");
     126            if (p.hasTag(RAILWAY, CONSTRUCTION) && p.hasKey(CONSTRUCTION))
     127                return p.hasTagDifferent(CONSTRUCTION, PLATFORM, PLATFORM_EDGE, "service_station", "station");
    124128            return p.hasTagDifferent(RAILWAY, "proposed", "planned", "abandoned", "razed", "disused", "no",
    125                     "platform", "platform_edge", "service_station", "station");
     129                    PLATFORM, PLATFORM_EDGE, "service_station", "station");
    126130        }
    127131
     
    197201        @Override
    198202        protected boolean isCandidate(OsmPrimitive p) {
    199             return p.hasTag("power", "line", "minor_line", "cable");
     203            return p.hasTag(POWER, "line", "minor_line", "cable");
    200204        }
    201205
    202206        @Override
    203207        protected boolean ignoreUnconnectedEndNode(Node n) {
    204             return n.hasTag("power", "terminal") || n.hasTag("location:transition", "yes");
     208            return n.hasTag(POWER, "terminal") || n.hasTag("location:transition", "yes")
     209                    || n.hasTag("line_management", "transition", "termination");
    205210        }
    206211    }
     
    270275                return map;
    271276            }
    272             if (s.w.hasTag(HIGHWAY, "platform"))
     277            if (s.w.hasTag(HIGHWAY, PLATFORM))
    273278                continue;
    274279            for (Node endnode : s.nearbyNodes(mindist)) {
    275280                Way parentWay = getWantedParentWay(endnode);
    276                 if (parentWay != null && !parentWay.hasTag(HIGHWAY, "platform")
     281                if (parentWay != null && !parentWay.hasTag(HIGHWAY, PLATFORM)
    277282                        && Objects.equals(OsmUtils.getLayer(s.w), OsmUtils.getLayer(parentWay))
    278283                        // to handle intersections of 't' shapes and similar
     
    296301                for (Node endnode : s.nearbyNodes(mindist)) {
    297302                    if (!s.isConnectedTo(endnode)) {
    298                         if (s.w.hasTag("power")) {
     303                        if (s.w.hasTag(POWER)) {
    299304                            boolean badConnection = false;
    300305                            Way otherWay = getWantedParentWay(endnode);
Note: See TracChangeset for help on using the changeset viewer.