Changeset 14882 in josm


Ignore:
Timestamp:
2019-03-12T21:59:50+01:00 (5 years ago)
Author:
GerdP
Message:

code cleanup: move duplicated code to check ignore list and set ignored flag into new method in class TestError

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/ValidateAction.java

    r14838 r14882  
    177177                for (TestError error : errors) {
    178178                    if (canceled) return;
    179                     List<String> s = new ArrayList<>();
    180                     s.add(error.getIgnoreState());
    181                     s.add(error.getIgnoreGroup());
    182                     s.add(error.getIgnoreSubGroup());
    183                     for (String state : s) {
    184                         if (state != null && OsmValidator.hasIgnoredError(state)) {
    185                             error.setIgnored(true);
    186                         }
    187                     }
     179                    error.updateIgnored();
    188180                }
    189181            }
  • trunk/src/org/openstreetmap/josm/actions/upload/ValidateUploadHook.java

    r14672 r14882  
    4444    /**
    4545     * Validate the modified data before uploading
     46     * @param apiDataSet contains primitives to be uploaded
     47     * @return true if upload should continue, else false
    4648     */
    4749    @Override
     
    7779
    7880        if (ValidatorPrefHelper.PREF_USE_IGNORE.get()) {
    79             int nume = 0;
     81            boolean allIgnored = true;
    8082            for (TestError error : errors) {
    81                 List<String> s = new ArrayList<>();
    82                 s.add(error.getIgnoreState());
    83                 s.add(error.getIgnoreGroup());
    84                 s.add(error.getIgnoreSubGroup());
    85                 for (String state : s) {
    86                     if (state != null && OsmValidator.hasIgnoredError(state)) {
    87                         error.setIgnored(true);
    88                     }
    89                 }
    90                 if (!error.isIgnored()) {
    91                     ++nume;
     83                if (!error.updateIgnored()) {
     84                    allIgnored = false;
    9285                }
    9386            }
    94             if (nume == 0)
     87            if (allIgnored)
    9588                return true;
    9689        }
  • trunk/src/org/openstreetmap/josm/data/validation/TestError.java

    r14768 r14882  
    279279    public String getIgnoreState() {
    280280        Collection<String> strings = new TreeSet<>();
    281         StringBuilder ignorestring = new StringBuilder(getIgnoreSubGroup());
    282281        for (OsmPrimitive o : primitives) {
    283282            // ignore data not yet uploaded
     
    294293            strings.add(type + '_' + o.getId());
    295294        }
     295        StringBuilder ignorestring = new StringBuilder(getIgnoreSubGroup());
    296296        for (String o : strings) {
    297297            ignorestring.append(':').append(o);
    298298        }
    299299        return ignorestring.toString();
     300    }
     301
     302    /**
     303     * Check if this error matches an entry in the ignore list and
     304     * set the ignored flag if it is.
     305     * @return the new ignored state
     306     */
     307    public boolean updateIgnored() {
     308        setIgnored(calcIgnored());
     309        return isIgnored();
     310    }
     311
     312    private boolean calcIgnored() {
     313        String state = getIgnoreGroup();
     314        if (state != null && OsmValidator.hasIgnoredError(state))
     315            return true;
     316        state = getIgnoreSubGroup();
     317        if (state != null && OsmValidator.hasIgnoredError(state))
     318            return true;
     319        state = getIgnoreState();
     320        return state != null && OsmValidator.hasIgnoredError(state);
    300321    }
    301322
Note: See TracChangeset for help on using the changeset viewer.