Ignore:
Timestamp:
2017-06-21T22:23:11+02:00 (7 years ago)
Author:
giackserva
Message:

[pt_assistant] implemented #josm14957

Location:
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation
Files:
2 edited

Legend:

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

    r33349 r33405  
    4545
    4646        public static final int ERROR_CODE_SORTING = 3711;
     47        public static final int ERROR_CODE_PARTIAL_SORTING = 3712;
    4748        public static final int ERROR_CODE_ROAD_TYPE = 3721;
    4849        public static final int ERROR_CODE_CONSTRUCTION = 3722;
     
    390391                boolean sortingErrorFound = false;
    391392                for (TestError error : this.errors) {
    392                         if (error.getCode() == ERROR_CODE_SORTING) {
     393                        if (error.getCode() == ERROR_CODE_SORTING
     394                                        || error.getCode() == ERROR_CODE_PARTIAL_SORTING) {
    393395                                sortingErrorFound = true;
    394396                                break;
     
    469471                                || testError.getCode() == ERROR_CODE_CONSTRUCTION
    470472                                || testError.getCode() == ERROR_CODE_SORTING
     473                                || testError.getCode() == ERROR_CODE_PARTIAL_SORTING
    471474                                || testError.getCode() == ERROR_CODE_END_STOP
    472475                                || testError.getCode() == ERROR_CODE_PLATFORM_PART_OF_HIGHWAY) {
     
    505508                }
    506509
    507                 if (testError.getCode() == ERROR_CODE_SORTING) {
     510                if (testError.getCode() == ERROR_CODE_SORTING
     511                                || testError.getCode() == ERROR_CODE_PARTIAL_SORTING) {
    508512                        commands.add(RouteChecker.fixSortingError(testError));
    509513                }
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/RouteChecker.java

    r33082 r33405  
    4343    }
    4444
    45     protected void performSortingTest() {
     45   protected void performSortingTest() {
    4646
    4747        final List<RelationMember> waysToCheck = new ArrayList<>();
     
    5757        }
    5858
    59         if (hasGap(waysToCheck)) {
     59        int numOfGaps = countGaps(waysToCheck);
     60
     61        if (numOfGaps > 0) {
    6062
    6163            this.hasGap = true;
     
    6466            sortedMembers = sorter.sortMembers(waysToCheck);
    6567
    66             if (!hasGap(sortedMembers)) {
     68            int numOfGapsAfterSort = countGaps(sortedMembers);
     69
     70            if (numOfGapsAfterSort == 0) {
    6771                Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_SORTING);
    6872                builder.message(tr("PT: Route contains a gap that can be fixed by sorting"));
     
    7074                TestError e = builder.build();
    7175                this.errors.add(e);
    72 
     76            } else if(numOfGapsAfterSort < numOfGaps) {
     77                Builder builder = TestError.builder(this.test, Severity.WARNING, PTAssistantValidatorTest.ERROR_CODE_PARTIAL_SORTING);
     78                builder.message(tr("PT: Route gaps can decrease by sorting members. Further validations will be required"));
     79                builder.primitives(relation);
     80                TestError e = builder.build();
     81                this.errors.add(e);
    7382            }
    74 
    7583        }
    76 
    7784    }
    7885
    7986    /**
    80      * Checks if there is a gap for a given list of ways. It does not check if
     87     * Counts how many gaps there are for a given list of ways. It does not check if
    8188     * the way actually stands for a public transport platform - that should be
    8289     * checked beforehand.
     
    8693     *         Relation Editor), false otherwise
    8794     */
    88     private boolean hasGap(List<RelationMember> waysToCheck) {
    89         WayConnectionTypeCalculator connectionTypeCalculator = new WayConnectionTypeCalculator();
     95    private int countGaps(List<RelationMember> waysToCheck) {
     96        int numberOfGaps = 0;
     97
     98        WayConnectionTypeCalculator connectionTypeCalculator = new WayConnectionTypeCalculator();
    9099        final List<WayConnectionType> links = connectionTypeCalculator.updateLinks(waysToCheck);
    91100        for (int i = 0; i < links.size(); i++) {
    92101            final WayConnectionType link = links.get(i);
    93             final boolean hasError = !(i == 0 || link.linkPrev) || !(i == links.size() - 1 || link.linkNext)
    94                     || link.direction == null || WayConnectionType.Direction.NONE.equals(link.direction);
    95             if (hasError) {
    96                 return true;
    97 
     102            if(!(i == 0 || link.linkPrev) || !(i == links.size() - 1 || link.linkNext)
     103                    || link.direction == null || WayConnectionType.Direction.NONE.equals(link.direction)) {
     104                numberOfGaps++;
     105                i++;
    98106            }
    99107        }
    100108
    101         return false;
     109        return numberOfGaps;
    102110    }
    103111
     
    115123
    116124    protected static Command fixSortingError(TestError testError) {
    117         if (testError.getCode() != PTAssistantValidatorTest.ERROR_CODE_SORTING) {
     125        if (testError.getCode() != PTAssistantValidatorTest.ERROR_CODE_SORTING
     126                        && testError.getCode() != PTAssistantValidatorTest.ERROR_CODE_PARTIAL_SORTING) {
    118127            return null;
    119128        }
     
    129138        for (RelationMember member : members) {
    130139            if (RouteUtils.isPTWay(member)) {
    131                 if (member.getRole().equals("")) {
     140                if ("".equals(member.getRole())) {
    132141                    ways.add(member);
    133142                } else {
     
    135144                    ways.add(modifiedMember);
    136145                }
    137 
    138146            } else { // stops:
    139                 if (member.getRole().equals("stop_positon")) {
     147                if ("stop_positon".equals(member.getRole())) {
    140148                    // it is not expected that stop_positions could
    141149                    // be relations
     
    150158                    stops.add(member);
    151159                }
    152 
    153160            }
    154161        }
     
    169176        sortedRelation.setMembers(sortedRelationMembers);
    170177
    171         ChangeCommand changeCommand = new ChangeCommand(originalRelation, sortedRelation);
    172 
    173         return changeCommand;
    174 
     178        return new ChangeCommand(originalRelation, sortedRelation);
    175179    }
    176 
    177180}
Note: See TracChangeset for help on using the changeset viewer.