Ticket #2803: validator2.patch

File validator2.patch, 4.3 KB (added by delta_foxtrot2, 17 years ago)

validator2.patch

  • src/org/openstreetmap/josm/plugins/validator/tests/TagChecker.java

    old new  
    7878    protected static ArrayList<String> ignoreDataEquals = new ArrayList<String>();
    7979    protected static ArrayList<String> ignoreDataEndsWith = new ArrayList<String>();
    8080    protected static ArrayList<IgnoreKeyPair> ignoreDataKeyPair = new ArrayList<IgnoreKeyPair>();
     81    protected static ArrayList<IgnoreTwoKeyPair> ignoreDataTwoKeyPair = new ArrayList<IgnoreTwoKeyPair>();
    8182
    8283    /** The preferences prefix */
    8384    protected static final String PREFIX = PreferenceEditor.PREFIX + "." + TagChecker.class.getSimpleName();
     
    252253                            tmp.value = line.substring(mid+1);
    253254                            ignoreDataKeyPair.add(tmp);
    254255                        }
     256                        else if(key.equals("T:"))
     257                        {
     258                            IgnoreTwoKeyPair tmp = new IgnoreTwoKeyPair();
     259                            int mid = line.indexOf("=");
     260                            int split = line.indexOf("|");
     261                            tmp.key1 = line.substring(0, mid);
     262                            tmp.value1 = line.substring(mid+1, split);
     263                            line = line.substring(split+1);
     264                            mid = line.indexOf("=");
     265                            tmp.key2 = line.substring(0, mid);
     266                            tmp.value2 = line.substring(mid+1);
     267                            ignoreDataTwoKeyPair.add(tmp);
     268                        }
    255269                        continue;
    256270                    }
    257271                    else if(tagcheckerfile)
     
    374388
    375389        if(checkComplex)
    376390        {
     391            Map<String, String> props = (p.keys == null) ? Collections.<String, String>emptyMap() : p.keys;
     392            for(Entry<String, String> prop: props.entrySet() )
     393            {
     394                boolean ignore = true;
     395                String key1 = prop.getKey();
     396                String value1 = prop.getValue();
     397
     398                for(IgnoreTwoKeyPair a : ignoreDataTwoKeyPair)
     399                {
     400                    if(key1.equals(a.key1) && value1.equals(a.value1))
     401                    {
     402                        ignore = false;
     403                        for(Entry<String, String> prop2: props.entrySet() )
     404                        {
     405                            String key2 = prop2.getKey();
     406                            String value2 = prop2.getValue();
     407                            for(IgnoreTwoKeyPair b : ignoreDataTwoKeyPair)
     408                            {
     409                                if(key2.equals(b.key2) && value2.equals(b.value2))
     410                                {
     411                                    ignore = true;
     412                                    break;
     413                                }
     414                            }
     415                            if(ignore)
     416                                break;
     417                        }
     418                    }
     419                    if(ignore)
     420                        break;
     421                }
     422
     423                if(!ignore)
     424                {
     425                    errors.add( new TestError(this, Severity.ERROR, tr("Illegal tag/value combinations"),
     426                    tr("Illegal tag/value combinations"), tr("Illegal tag/value combinations"), 1272, p) );
     427                    withErrors.add(p, "TC");
     428                }
     429            }
     430
    377431            for(CheckerData d : checkerData)
    378432            {
    379433                if(d.match(p))
     
    471525                            ignore = true;
    472526                    }
    473527
     528                    for(IgnoreTwoKeyPair a : ignoreDataTwoKeyPair)
     529                    {
     530                        if(key.equals(a.key2) && value.equals(a.value2))
     531                            ignore = true;
     532                    }
     533
    474534                    if(!ignore)
    475535                    {
    476536                        String i = marktr("Value ''{0}'' for key ''{1}'' not in presets.");
     
    777837        return false;
    778838    }
    779839
     840    private static class IgnoreTwoKeyPair {
     841        public String key1;
     842        public String value1;
     843        public String key2;
     844        public String value2;
     845    }
     846
    780847    private static class IgnoreKeyPair {
    781848        public String key;
    782849        public String value;