Ignore:
Timestamp:
2017-08-21T09:59:11+02:00 (7 years ago)
Author:
giackserva
Message:

[pt_assistant] fixed #josm15166

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/RouteChecker.java

    r33503 r33508  
    142142    protected boolean performFromToTagsTest() {
    143143
     144        if (manager.getPTStopCount() == 0) {
     145            return false;
     146        }
     147
     148        boolean foundError = false;
     149
    144150        String from = relation.get("from");
     151        if (from != null) {
     152            from = from.toLowerCase();
     153            PTStop stop = manager.getFirstStop();
     154            OsmPrimitive primitive = checkPTStopName(stop, from);
     155
     156            if (primitive != null) {
     157                Builder builder = TestError.builder(this.test, Severity.WARNING,
     158                        PTAssistantValidatorTest.ERROR_CODE_FROM_TO_ROUTE_TAG);
     159                builder.message(tr("PT: The name of the first stop does not match the \"from\" tag of the route relation"));
     160                builder.primitives(primitive, relation);
     161                TestError e = builder.build();
     162                this.errors.add(e);
     163                foundError = true;
     164            }
     165        }
     166
    145167        String to = relation.get("to");
    146         if (from == null || to == null || manager.getPTStopCount() == 0) {
    147             return false;
    148         }
    149 
    150         from = from.toLowerCase();
    151         to = to.toLowerCase();
    152 
    153         boolean foundError = false;
    154         PTStop stop = manager.getFirstStop();
    155         OsmPrimitive primitive = checkPTStopName(stop, from);
    156 
    157         if (primitive != null) {
    158             Builder builder = TestError.builder(this.test, Severity.WARNING,
    159                     PTAssistantValidatorTest.ERROR_CODE_FROM_TO_ROUTE_TAG);
    160             builder.message(tr("PT: The name of the first stop does not match the \"from\" tag of the route relation"));
    161             builder.primitives(primitive, relation);
    162             TestError e = builder.build();
    163             this.errors.add(e);
    164             foundError = true;
    165         }
    166 
    167         stop = manager.getLastStop();
    168         primitive = checkPTStopName(stop, to);
    169 
    170         if (primitive != null) {
    171             Builder builder = TestError.builder(this.test, Severity.WARNING,
    172                     PTAssistantValidatorTest.ERROR_CODE_FROM_TO_ROUTE_TAG);
    173             builder.message(tr("PT: The name of the last stop does not match the \"to\" tag of the route relation"));
    174             builder.primitives(primitive, relation);
    175             TestError e = builder.build();
    176             this.errors.add(e);
    177             foundError = true;
     168        if (to != null) {
     169            to = to.toLowerCase();
     170            PTStop stop = manager.getLastStop();
     171            OsmPrimitive primitive = checkPTStopName(stop, to);
     172
     173            if (primitive != null) {
     174                Builder builder = TestError.builder(this.test, Severity.WARNING,
     175                        PTAssistantValidatorTest.ERROR_CODE_FROM_TO_ROUTE_TAG);
     176                builder.message(tr("PT: The name of the last stop does not match the \"to\" tag of the route relation"));
     177                builder.primitives(primitive, relation);
     178                TestError e = builder.build();
     179                this.errors.add(e);
     180                foundError = true;
     181            }
    178182        }
    179183
     
    226230    //it returns null if the names match
    227231    private OsmPrimitive checkPTStopName(PTStop stop, String name) {
    228         OsmPrimitive primitive = null;
    229232        List<String> toCheck = new ArrayList<>();
    230         if (stop.getPlatform() != null) {
    231             primitive = stop.getPlatform();
     233        OsmPrimitive primitive = stop.getPlatform();
     234        if (primitive != null) {
    232235            toCheck.addAll(getPrimitiveNameTags(primitive));
    233236        }
    234         if (toCheck.isEmpty() && stop.getStopPosition() != null) {
    235             primitive = stop.getStopPosition();
     237        primitive = stop.getStopPosition();
     238        if (toCheck.isEmpty() && primitive != null) {
    236239            toCheck.addAll(getPrimitiveNameTags(primitive));
    237240        }
     
    239242        for (String value : toCheck) {
    240243            if (value.equals(name)) {
    241                 return primitive;
    242             }
    243         }
    244 
    245         return null;
     244                //if one of the names matches, return null
     245                return null;
     246            }
     247        }
     248
     249        return primitive;
    246250    }
    247251
Note: See TracChangeset for help on using the changeset viewer.