Ignore:
Timestamp:
2017-04-15T01:38:46+02:00 (3 years ago)
Author:
Don-vip
Message:

sonar - squid:S1192 - String literals should not be duplicated

Location:
trunk/src/org/openstreetmap/josm/data/validation/tests
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/CrossingWays.java

    r11893 r11913  
    3232    protected static final int CROSSING_WAYS = 601;
    3333
    34     private static final String HIGHWAY = "highway";
    35     private static final String RAILWAY = "railway";
    36     private static final String WATERWAY = "waterway";
     34    static final String HIGHWAY = "highway";
     35    static final String RAILWAY = "railway";
     36    static final String WATERWAY = "waterway";
    3737
    3838    /** All way segments, grouped by cells */
  • trunk/src/org/openstreetmap/josm/data/validation/tests/DuplicateNode.java

    r11893 r11913  
    22package org.openstreetmap.josm.data.validation.tests;
    33
     4import static org.openstreetmap.josm.data.validation.tests.CrossingWays.HIGHWAY;
     5import static org.openstreetmap.josm.data.validation.tests.CrossingWays.RAILWAY;
     6import static org.openstreetmap.josm.data.validation.tests.CrossingWays.WATERWAY;
    47import static org.openstreetmap.josm.tools.I18n.tr;
    58
     
    99102
    100103    private static final String[] TYPES = {
    101             "none", "highway", "railway", "waterway", "boundary", "power", "natural", "landuse", "building"};
     104            "none", HIGHWAY, RAILWAY, WATERWAY, "boundary", "power", "natural", "landuse", "building"};
    102105
    103106    /** The map of potential duplicates.
     
    210213                            .primitives(primitives)
    211214                            .build());
    212                 } else if (typeMap.get("highway")) {
     215                } else if (typeMap.get(HIGHWAY)) {
    213216                    errors.add(TestError.builder(parentTest, Severity.ERROR, DUPLICATE_NODE_HIGHWAY)
    214217                            .message(tr("Highway duplicated nodes"))
    215218                            .primitives(primitives)
    216219                            .build());
    217                 } else if (typeMap.get("railway")) {
     220                } else if (typeMap.get(RAILWAY)) {
    218221                    errors.add(TestError.builder(parentTest, Severity.ERROR, DUPLICATE_NODE_RAILWAY)
    219222                            .message(tr("Railway duplicated nodes"))
    220223                            .primitives(primitives)
    221224                            .build());
    222                 } else if (typeMap.get("waterway")) {
     225                } else if (typeMap.get(WATERWAY)) {
    223226                    errors.add(TestError.builder(parentTest, Severity.ERROR, DUPLICATE_NODE_WATERWAY)
    224227                            .message(tr("Waterway duplicated nodes"))
  • trunk/src/org/openstreetmap/josm/data/validation/tests/Highways.java

    r11807 r11913  
    22package org.openstreetmap.josm.data.validation.tests;
    33
     4import static org.openstreetmap.josm.data.validation.tests.CrossingWays.HIGHWAY;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    56
     
    7778        if (n.isUsable()) {
    7879            if (!n.hasTag("crossing", "no")
    79              && !(n.hasKey("crossing") && (n.hasTag("highway", "crossing") || n.hasTag("highway", "traffic_signals")))
     80             && !(n.hasKey("crossing") && (n.hasTag(HIGHWAY, "crossing")
     81                                        || n.hasTag(HIGHWAY, "traffic_signals")))
    8082             && n.isReferredByWays(2)) {
    8183                testMissingPedestrianCrossing(n);
     
    9294    public void visit(Way w) {
    9395        if (w.isUsable()) {
    94             if (w.isClosed() && w.hasTag("highway", CLASSIFIED_HIGHWAYS) && w.hasTag("junction", "roundabout")) {
     96            if (w.isClosed() && w.hasTag(HIGHWAY, CLASSIFIED_HIGHWAYS) && w.hasTag("junction", "roundabout")) {
    9597                // TODO: find out how to handle splitted roundabouts (see #12841)
    9698                testWrongRoundabout(w);
     
    110112        for (Node n : new HashSet<>(w.getNodes())) {
    111113            for (Way h : Utils.filteredCollection(n.getReferrers(), Way.class)) {
    112                 String value = h.get("highway");
     114                String value = h.get(HIGHWAY);
    113115                if (h != w && value != null && !value.endsWith("_link")) {
    114116                    List<Way> list = map.get(value);
     
    130132                if (list.size() > 2 || oneway1 == null || oneway2 == null || !oneway1 || !oneway2) {
    131133                    // Error when the highway tags do not match
    132                     String value = w.get("highway");
     134                    String value = w.get(HIGHWAY);
    133135                    if (!value.equals(s)) {
    134136                        errors.add(TestError.builder(this, Severity.WARNING, WRONG_ROUNDABOUT_HIGHWAY)
    135137                                .message(tr("Incorrect roundabout (highway: {0} instead of {1})", value, s))
    136138                                .primitives(w)
    137                                 .fix(() -> new ChangePropertyCommand(w, "highway", s))
     139                                .fix(() -> new ChangePropertyCommand(w, HIGHWAY, s))
    138140                                .build());
    139141                    }
     
    145147
    146148    public static boolean isHighwayLinkOkay(final Way way) {
    147         final String highway = way.get("highway");
     149        final String highway = way.get(HIGHWAY);
    148150        if (highway == null || !highway.endsWith("_link")
    149151                || !IN_DOWNLOADED_AREA.test(way.getNode(0)) || !IN_DOWNLOADED_AREA.test(way.getNode(way.getNodesCount()-1))) {
     
    164166
    165167        return Utils.filteredCollection(referrers, Way.class).stream().anyMatch(
    166                 otherWay -> !way.equals(otherWay) && otherWay.hasTag("highway", highway, highway.replaceAll("_link$", "")));
     168                otherWay -> !way.equals(otherWay) && otherWay.hasTag(HIGHWAY, highway, highway.replaceAll("_link$", "")));
    167169    }
    168170
     
    185187
    186188        for (Way w : OsmPrimitive.getFilteredList(n.getReferrers(), Way.class)) {
    187             String highway = w.get("highway");
     189            String highway = w.get(HIGHWAY);
    188190            if (highway != null) {
    189191                if ("footway".equals(highway) || "path".equals(highway)) {
  • trunk/src/org/openstreetmap/josm/data/validation/tests/OverlappingWays.java

    r11608 r11913  
    22package org.openstreetmap.josm.data.validation.tests;
    33
     4import static org.openstreetmap.josm.data.validation.tests.CrossingWays.HIGHWAY;
     5import static org.openstreetmap.josm.data.validation.tests.CrossingWays.RAILWAY;
    46import static org.openstreetmap.josm.tools.I18n.tr;
    57
     
    9092
    9193                for (WaySegment ws : duplicated) {
    92                     if (ws.way.hasKey("highway")) {
     94                    if (ws.way.hasKey(HIGHWAY)) {
    9395                        highway++;
    94                     } else if (ws.way.hasKey("railway")) {
     96                    } else if (ws.way.hasKey(RAILWAY)) {
    9597                        railway++;
    9698                    }
  • trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java

    r11621 r11913  
    22package org.openstreetmap.josm.data.validation.tests;
    33
     4import static org.openstreetmap.josm.data.validation.tests.CrossingWays.HIGHWAY;
     5import static org.openstreetmap.josm.data.validation.tests.CrossingWays.RAILWAY;
    46import static org.openstreetmap.josm.tools.I18n.tr;
    57
     
    5759        @Override
    5860        public boolean isPrimitiveUsable(OsmPrimitive p) {
    59             return super.isPrimitiveUsable(p) && p.hasKey("highway");
     61            return super.isPrimitiveUsable(p) && p.hasKey(HIGHWAY);
    6062        }
    6163    }
     
    181183                        continue;
    182184                    }
    183                     if (en.hasTag("highway", "turning_circle", "bus_stop")
     185                    if (en.hasTag(HIGHWAY, "turning_circle", "bus_stop")
    184186                            || en.hasTag("amenity", "parking_entrance")
    185                             || en.hasTag("railway", "buffer_stop")
     187                            || en.hasTag(RAILWAY, "buffer_stop")
    186188                            || en.isKeyTrue("noexit")
    187189                            || en.hasKey("entrance", "barrier")) {
     
    302304        MyWaySegment(Way w, Node n1, Node n2) {
    303305            this.w = w;
    304             String railway = w.get("railway");
    305             String highway = w.get("highway");
     306            String railway = w.get(RAILWAY);
     307            String highway = w.get(HIGHWAY);
    306308            this.isAbandoned = "abandoned".equals(railway) || w.isKeyTrue("disused");
    307309            this.highway = (highway != null || railway != null) && !isAbandoned;
     
    449451                && !w.hasKey("addr:interpolation")
    450452                // similarly for public transport platforms
    451                 && !w.hasTag("highway", "platform") && !w.hasTag("railway", "platform")
     453                && !w.hasTag(HIGHWAY, "platform") && !w.hasTag(RAILWAY, "platform")
    452454                ) {
    453455            ways.addAll(getWaySegments(w));
    454456            QuadBuckets<Node> set = endnodes;
    455             if (w.hasKey("highway", "railway")) {
     457            if (w.hasKey(HIGHWAY, RAILWAY)) {
    456458                set = endnodesHighway;
    457459            }
  • trunk/src/org/openstreetmap/josm/data/validation/tests/UntaggedWay.java

    r11384 r11913  
    22package org.openstreetmap.josm.data.validation.tests;
    33
     4import static org.openstreetmap.josm.data.validation.tests.CrossingWays.HIGHWAY;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    56
     
    8182        Map<String, String> tags = w.getKeys();
    8283        if (!tags.isEmpty()) {
    83             String highway = tags.get("highway");
     84            String highway = tags.get(HIGHWAY);
    8485            if (highway != null && NAMED_WAYS.contains(highway) && !tags.containsKey("name") && !tags.containsKey("ref")
    8586                    && !"yes".equals(tags.get("noname"))) {
  • trunk/src/org/openstreetmap/josm/data/validation/tests/WayConnectedToArea.java

    r11587 r11913  
    22package org.openstreetmap.josm.data.validation.tests;
    33
     4import static org.openstreetmap.josm.data.validation.tests.CrossingWays.HIGHWAY;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    56
     
    3031    @Override
    3132    public void visit(Way w) {
    32         if (!w.isUsable() || w.isClosed() || !w.hasKey("highway")) {
     33        if (!w.isUsable() || w.isClosed() || !w.hasKey(HIGHWAY)) {
    3334            return;
    3435        }
     
    3738        List<OsmPrimitive> r = w.firstNode().getReferrers();
    3839        for (OsmPrimitive p : r) {
    39             if (p != w && p.hasKey("highway")) {
     40            if (p != w && p.hasKey(HIGHWAY)) {
    4041                hasway = true;
    4142                break;
     
    5051        r = w.lastNode().getReferrers();
    5152        for (OsmPrimitive p : r) {
    52             if (p != w && p.hasKey("highway")) {
     53            if (p != w && p.hasKey(HIGHWAY)) {
    5354                hasway = true;
    5455                break;
     
    8687    private void addPossibleError(Way w, Node wayNode, OsmPrimitive p, OsmPrimitive area) {
    8788        // Avoid "legal" cases (see #10655)
    88         if (w.hasKey("highway") && wayNode.hasTag("leisure", "slipway") && area.hasTag("natural", "water")) {
     89        if (w.hasKey(HIGHWAY) && wayNode.hasTag("leisure", "slipway") && area.hasTag("natural", "water")) {
    8990            return;
    9091        }
Note: See TracChangeset for help on using the changeset viewer.