Modify

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#12885 closed enhancement (fixed)

[patch] Modify OsmValidator class to add new tests

Reported by: darya Owned by: team
Priority: normal Milestone: 16.05
Component: Core validator Version:
Keywords: OsmValidator, GSoC Cc: darya

Description (last modified by Don-vip)

I'm creating a JOSM plugin to validate public transport routes. I want the results to appear in the existing Validator window. To do that, I need the possibility to add additional Test classes to the org.openstreetmap.josm.data.validation.OsmValidator class.

A possible fix for my needs would be:

1) Change the class attribute private static final allAvailableTests to private static allAvailableTests

2) Add method:

public static void addTest(Class newTestClass) {
        Class<Test>[] newTestArray = new Class[allAvailableTests.length+1];
        for (int i=0; i<allAvailableTests.length; i++) {
            newTestArray[i] = allAvailableTests[i];
        }
        newTestArray[newTestArray.length-1] = newTestClass;
        allAvailableTests = newTestArray;
        try {
            allTestsMap.put(newTestClass.getName(), (Test)newTestClass.getConstructor().newInstance());
        } catch(ReflectiveOperationException e) {
            Main.error(e);
        }
    }

An alternative solution would be to change the method OsmValidator.getAllTestsMap()

from

    public static SortedMap<String, Test> getAllTestsMap() {
        applyPrefs(allTestsMap, false);
        return new TreeMap<>(allTestsMap);
  }

to

    public static SortedMap<String, Test> getAllTestsMap() {
        applyPrefs(allTestsMap, false);
        TreeMap<String, Test> sortedMap = new TreeMap<>(allTestsMap);
        allTestsMap = sortedMap;
        return sortedMap;
    }

Thank you in advance!

Attachments (0)

Change History (8)

comment:1 by Don-vip, 9 years ago

Description: modified (diff)

comment:2 by Klumbumbus, 9 years ago

Summary: Modify OsmValidator class to add new tests[patch] Modify OsmValidator class to add new tests

comment:3 by Don-vip, 9 years ago

Does your plugin only add validator tests? If so, you can simply write a new test in JOSM core and propose it as a patch. There are already too many plugins for public transport.

comment:4 by bastiK, 9 years ago

Resolution: fixed
Status: newclosed

In 10297/josm:

fixed #12885 - new method to add validator test from plugin (based on patch by by darya)

in reply to:  3 comment:5 by bastiK, 9 years ago

Keywords: GSoC added

Replying to Don-vip:

Does your plugin only add validator tests?

This part of the GSoC project, so there is probably more.

In general, I think this is (was) a valid request.

comment:6 by darya, 9 years ago

No, the plugin will also have the functionality to fix problems, e.g. if the public transport route has a gap. Yes, it is within the GSoC, summary here: https://summerofcode.withgoogle.com/projects/#4678354603081728

I think it would imply too many modifications to the core if I were to put it there. Besides, not every JOSM user will need to validate public transport routes, so it belongs into a plugin.

comment:7 by Don-vip, 9 years ago

Milestone: 16.05

Ok thanks !

comment:8 by darya, 9 years ago

I can not add my tests, thank you very much for the change.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.