Ignore:
Timestamp:
2017-07-04T23:09:33+02:00 (7 years ago)
Author:
giackserva
Message:

[pt_assistant] #josm14990

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

    r33417 r33425  
    329329
    330330    /**
    331      * Carries out the second stage of the testing: sorting
     331     * Carries out the second stage of the testing: sorting and segments
    332332     *
    333333     * @param r
     
    341341        List<TestError> routeCheckerErrors = routeChecker.getErrors();
    342342
    343         /*- At this point, there are 3 variants:
    344          *
    345          * 1) There are no errors => route is correct
    346          * 2) There is only a sorting error (can only be 1), but otherwise
    347          * correct.
    348          * 3) There are some other errors/gaps that cannot be fixed by
    349          * sorting => start further test (stop-by-stop)
    350          *
    351          * */
    352 
    353         if (!routeCheckerErrors.isEmpty()) {
    354             // Variant 2
    355             // If there is only the sorting error, add it
    356             this.errors.addAll(routeChecker.getErrors());
    357         }
    358 
    359         // if (!routeChecker.getHasGap()) {
    360         // // Variant 1
    361         // storeCorrectRouteSegments(r);
    362         // }
    363 
    364         // Variant 3:
    365         proceedAfterSorting(r);
    366 
    367     }
    368 
    369     /**
    370      * Carries out the stop-by-stop testing which includes building the route
    371      * data model.
    372      *
    373      * @param r
    374      *            route relation
    375      */
    376     private void proceedAfterSorting(Relation r) {
    377 
    378343        SegmentChecker segmentChecker = new SegmentChecker(r, this);
    379 
    380         // Check if the creation of the route data model in the segment checker
    381         // worked. If it did not, it means the roles in the route relation do
    382         // not match the tags of the route members.
    383         if (!segmentChecker.getErrors().isEmpty()) {
    384             this.errors.addAll(segmentChecker.getErrors());
    385         }
    386 
    387344        segmentChecker.performFirstStopTest();
    388345        segmentChecker.performLastStopTest();
    389346        segmentChecker.performStopNotServedTest();
    390347
    391         boolean sortingErrorFound = false;
    392         for (TestError error : this.errors) {
    393             if (error.getCode() == ERROR_CODE_SORTING
    394                     || error.getCode() == ERROR_CODE_PARTIAL_SORTING) {
    395                 sortingErrorFound = true;
    396                 break;
    397             }
    398         }
    399         if (!sortingErrorFound) {
    400             segmentChecker.performStopByStopTest();
    401             segmentChecker.findFixes();
    402         }
    403 
    404         for (TestError error : segmentChecker.getErrors()) {
    405             if (error.getCode() != PTAssistantValidatorTest.ERROR_CODE_RELATION_MEMBER_ROLES) {
    406                 this.errors.add(error);
    407             }
     348        //At this point, there are 3 variants:
     349        if(routeCheckerErrors.isEmpty()) {
     350             if (!routeChecker.getHasGap()) {
     351                 //There are no errors => route is correct
     352                 storeCorrectRouteSegments(r, segmentChecker.getManager(),
     353                         segmentChecker.getAssigner());
     354             } else {
     355                 // There are some other errors/gaps that cannot be fixed by
     356                 // sorting => start further test (stop-by-stop)
     357                 segmentChecker.performStopByStopTest();
     358                 segmentChecker.findFixes();
     359             }
     360        } else {
     361            // There is only a sorting error (can only be 1), but otherwise
     362            // correct
     363            this.errors.addAll(routeChecker.getErrors());
     364        }
     365
     366        //add eventual errors found
     367        if (!segmentChecker.getErrors().isEmpty()) {
     368            this.errors.addAll(segmentChecker.getErrors());
    408369        }
    409370    }
     
    445406     *            route relation
    446407     */
    447     @SuppressWarnings("unused")
    448     private void storeCorrectRouteSegments(Relation r) {
    449         PTRouteDataManager manager = new PTRouteDataManager(r);
    450         StopToWayAssigner assigner = new StopToWayAssigner(manager.getPTWays());
     408    private void storeCorrectRouteSegments(Relation r,
     409            PTRouteDataManager manager, StopToWayAssigner assigner) {
    451410        if (manager.getPTStops().size() > 1) {
    452411            for (int i = 1; i < manager.getPTStops().size(); i++) {
    453                 PTStop segmentStartStop = manager.getPTStops().get(i - 1);
    454                 PTStop segmentEndStop = manager.getPTStops().get(i);
    455                 Way segmentStartWay = assigner.get(segmentStartStop);
    456                 Way segmentEndWay = assigner.get(segmentEndStop);
    457                 List<PTWay> waysBetweenStops = manager.getPTWaysBetween(segmentStartWay, segmentEndWay);
    458                 PTRouteSegment routeSegment = new PTRouteSegment(segmentStartStop, segmentEndStop, waysBetweenStops, r);
    459                 SegmentChecker.addCorrectSegment(routeSegment);
     412                PTStop startStop = manager.getPTStops().get(i - 1);
     413                PTStop endStop = manager.getPTStops().get(i);
     414                Way startWay = assigner.get(startStop);
     415                Way endWay = assigner.get(endStop);
     416                List<PTWay> waysBetweenStops = manager.getPTWaysBetween(startWay, endWay);
     417                SegmentChecker.addCorrectSegment(
     418                        new PTRouteSegment(startStop, endStop, waysBetweenStops, r));
    460419            }
    461420        }
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/SegmentChecker.java

    r33417 r33425  
    6666        super(relation, test);
    6767
    68         this.manager = new PTRouteDataManager(relation);
    69 
    70         for (RelationMember rm : manager.getFailedMembers()) {
     68        this.setManager(new PTRouteDataManager(relation));
     69
     70        for (RelationMember rm : getManager().getFailedMembers()) {
    7171            List<Relation> primitives = new ArrayList<>(1);
    7272            primitives.add(relation);
     
    8282        }
    8383
    84         this.assigner = new StopToWayAssigner(manager.getPTWays());
     84        this.setAssigner(new StopToWayAssigner(getManager().getPTWays()));
    8585
    8686    }
     
    100100     * checking its correctness
    101101     *
    102      * @param segment
    103      *            to add to the list of correct segments
     102     * @param segment to add to the list of correct segments
    104103     */
    105104    public static synchronized void addCorrectSegment(PTRouteSegment segment) {
     
    125124    public void performFirstStopTest() {
    126125
    127         performEndStopTest(manager.getFirstStop());
     126        performEndStopTest(getManager().getFirstStop());
    128127
    129128    }
     
    131130    public void performLastStopTest() {
    132131
    133         performEndStopTest(manager.getLastStop());
     132        performEndStopTest(getManager().getLastStop());
    134133
    135134    }
     
    237236        boolean contains = false;
    238237
    239         List<PTWay> ptways = manager.getPTWays();
     238        List<PTWay> ptways = getManager().getPTWays();
    240239        for (PTWay ptway : ptways) {
    241240            List<Way> ways = ptway.getWays();
     
    260259
    261260    public void performStopNotServedTest() {
    262         for (PTStop stop : manager.getPTStops()) {
    263             Way way = assigner.get(stop);
     261        for (PTStop stop : getManager().getPTStops()) {
     262            Way way = getAssigner().get(stop);
    264263            if (way == null) {
    265264                createStopError(stop);
     
    274273    public void performStopByStopTest() {
    275274
    276         if (manager.getPTStopCount() < 2) {
     275        if (getManager().getPTStopCount() < 2) {
    277276            return;
    278277        }
     
    281280
    282281        // Check each route segment:
    283         for (int i = 1; i < manager.getPTStopCount(); i++) {
    284 
    285             PTStop startStop = manager.getPTStops().get(i - 1);
    286             PTStop endStop = manager.getPTStops().get(i);
    287 
    288             Way startWay = assigner.get(startStop);
    289             Way endWay = assigner.get(endStop);
    290             if (startWay == null || endWay == null || (startWay == endWay && startWay == manager.getLastWay())) {
     282        for (int i = 1; i < getManager().getPTStopCount(); i++) {
     283
     284            PTStop startStop = getManager().getPTStops().get(i - 1);
     285            PTStop endStop = getManager().getPTStops().get(i);
     286
     287            Way startWay = getAssigner().get(startStop);
     288            Way endWay = getAssigner().get(endStop);
     289            if (startWay == null || endWay == null || (startWay == endWay && startWay == getManager().getLastWay())) {
    291290                continue;
    292291            }
    293292
    294             List<PTWay> segmentWays = manager.getPTWaysBetween(startWay, endWay);
     293            List<PTWay> segmentWays = getManager().getPTWaysBetween(startWay, endWay);
    295294
    296295            Node firstNode = findFirstNodeOfRouteSegmentInDirectionOfTravel(segmentWays.get(0));
     
    319318            PTWay wronglySortedPtway = existingWaySortingIsWrong(segmentWays.get(0), firstNode,
    320319                    segmentWays.get(segmentWays.size() - 1));
    321             if (wronglySortedPtway == null) { // i.e. if the sorting is correct:
     320            if (wronglySortedPtway != null) {  // i.e. if the sorting is wrong:
    322321                PTRouteSegment routeSegment = new PTRouteSegment(startStop, endStop, segmentWays, relation);
    323                 addCorrectSegment(routeSegment);
    324             } else { // i.e. if the sorting is wrong:
    325                 PTRouteSegment routeSegment = new PTRouteSegment(startStop, endStop, segmentWays, relation);
    326                 // TestError error = this.errors.get(this.errors.size() - 1);
    327                 // wrongSegments.put(error, routeSegment);
    328 
    329322                List<Relation> primitives = new ArrayList<>(1);
    330323                primitives.add(relation);
     
    381374        // 2) failing that, check which node this startWay shares with the
    382375        // following way:
    383         PTWay nextWay = manager.getNextPTWay(startWay);
     376        PTWay nextWay = getManager().getNextPTWay(startWay);
    384377        if (nextWay == null) {
    385378            return null;
    386379        }
    387         PTWay wayAfterNext = manager.getNextPTWay(nextWay);
     380        PTWay wayAfterNext = getManager().getNextPTWay(nextWay);
    388381        Node[] nextWayEndnodes = nextWay.getEndNodes();
    389382        if ((startWayEndnodes[0] == nextWayEndnodes[0] && startWayEndnodes[1] == nextWayEndnodes[1])
     
    412405    private boolean isDeadendNode(Node node) {
    413406        int count = 0;
    414         for (PTWay ptway : manager.getPTWays()) {
     407        for (PTWay ptway : getManager().getPTWays()) {
    415408            List<Way> ways = ptway.getWays();
    416409            for (Way way : ways) {
     
    478471            // matter which of the geometrically equal PTWays it finds
    479472
    480             PTWay nextPTWayAccortingToExistingSorting = manager.getNextPTWay(current);
     473            PTWay nextPTWayAccortingToExistingSorting = getManager().getNextPTWay(current);
    481474
    482475            // if current contains an unsplit roundabout:
    483476            if (current.containsUnsplitRoundabout()) {
    484                 currentNode = manager.getCommonNode(current, nextPTWayAccortingToExistingSorting);
     477                currentNode = getManager().getCommonNode(current, nextPTWayAccortingToExistingSorting);
    485478                if (currentNode == null) {
    486479
     
    578571        List<PTWay> nextPtways = new ArrayList<>();
    579572
    580         List<PTWay> ptways = manager.getPTWays();
     573        List<PTWay> ptways = getManager().getPTWays();
    581574
    582575        for (PTWay ptway : ptways) {
     
    643636
    644637        for (Builder builder : wrongSegmentBuilders.keySet()) {
    645 
    646638            if (wrongSegmentBuilders.get(builder).getRelation() == this.relation) {
    647 
    648639                findFix(builder);
    649 
    650             }
    651         }
    652 
     640            }
     641        }
    653642    }
    654643
     
    11341123    }
    11351124
     1125    public PTRouteDataManager getManager() {
     1126        return manager;
     1127    }
     1128
     1129    public void setManager(PTRouteDataManager manager) {
     1130        this.manager = manager;
     1131    }
     1132
     1133    public StopToWayAssigner getAssigner() {
     1134        return assigner;
     1135    }
     1136
     1137    public void setAssigner(StopToWayAssigner assigner) {
     1138        this.assigner = assigner;
     1139    }
     1140
    11361141}
Note: See TracChangeset for help on using the changeset viewer.