Changeset 20155 in osm for applications/editors


Ignore:
Timestamp:
2010-02-25T22:40:01+01:00 (14 years ago)
Author:
jttt
Message:

Speed optimizations

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

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/tests/TagChecker.java

    r19611 r20155  
    55
    66import java.awt.Dimension;
     7import java.awt.GridBagConstraints;
    78import java.awt.GridBagLayout;
    89import java.awt.event.ActionEvent;
     
    4142import org.openstreetmap.josm.data.osm.Node;
    4243import org.openstreetmap.josm.data.osm.OsmPrimitive;
     44import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    4345import org.openstreetmap.josm.data.osm.OsmUtils;
    4446import org.openstreetmap.josm.data.osm.Relation;
     
    149151    {
    150152        super(tr("Properties checker :"),
    151               tr("This plugin checks for errors in property keys and values."));
     153                tr("This plugin checks for errors in property keys and values."));
    152154    }
    153155
     
    327329            /*  for(String a : OsmPrimitive.getDirectionKeys())
    328330                presetsValueData.add(a);
    329             */
     331             */
    330332            for(String a : Main.pref.getCollection(PreferenceEditor.PREFIX + ".knownkeys",
    331             Arrays.asList(new String[]{"is_in", "int_ref", "fixme", "population"})))
     333                    Arrays.asList(new String[]{"is_in", "int_ref", "fixme", "population"})))
    332334                presetsValueData.add(a);
    333335            for(TaggingPreset p : presets)
     
    431433                {
    432434                    errors.add( new TestError(this, Severity.ERROR, tr("Illegal tag/value combinations"),
    433                     tr("Illegal tag/value combinations"), tr("Illegal tag/value combinations"), 1272, p) );
     435                            tr("Illegal tag/value combinations"), tr("Illegal tag/value combinations"), 1272, p) );
    434436                    withErrors.add(p, "TC");
    435437                }
    436438            }
    437439
     440            Map<String, String> keys = p.getKeys();
    438441            for(CheckerData d : checkerData)
    439442            {
    440                 if(d.match(p))
     443                if(d.match(p, keys))
    441444                {
    442445                    errors.add( new TestError(this, d.getSeverity(), tr("Illegal tag/value combinations"),
    443                     d.getDescription(), d.getDescriptionOrig(), d.getCode(), p) );
     446                            d.getDescription(), d.getDescriptionOrig(), d.getCode(), p) );
    444447                    withErrors.add(p, "TC");
    445448                }
     
    456459                    translated the stuff before. Makes the ignore file language dependend. */
    457460                    errors.add( new TestError(this, Severity.WARNING, tr("Painting problem"),
    458                     s, s, PAINT, p) );
     461                            s, s, PAINT, p) );
    459462                    withErrors.add(p, "P");
    460463                }
     
    471474            {
    472475                errors.add( new TestError(this, Severity.WARNING, tr("Tags with empty values"),
    473                 tr(s, key), MessageFormat.format(s, key), EMPTY_VALUES, p) );
     476                        tr(s, key), MessageFormat.format(s, key), EMPTY_VALUES, p) );
    474477                withErrors.add(p, "EV");
    475478            }
     
    477480            {
    478481                errors.add( new TestError(this, Severity.WARNING, tr("Invalid property key"),
    479                 tr(s, key), MessageFormat.format(s, key), INVALID_KEY, p) );
     482                        tr(s, key), MessageFormat.format(s, key), INVALID_KEY, p) );
    480483                withErrors.add(p, "IPK");
    481484            }
     
    483486            {
    484487                errors.add( new TestError(this, Severity.WARNING, tr("Invalid white space in property key"),
    485                 tr(s, key), MessageFormat.format(s, key), INVALID_KEY_SPACE, p) );
     488                        tr(s, key), MessageFormat.format(s, key), INVALID_KEY_SPACE, p) );
    486489                withErrors.add(p, "IPK");
    487490            }
     
    489492            {
    490493                errors.add( new TestError(this, Severity.OTHER, tr("Property values start or end with white space"),
    491                 tr(s, key), MessageFormat.format(s, key), INVALID_SPACE, p) );
     494                        tr(s, key), MessageFormat.format(s, key), INVALID_SPACE, p) );
    492495                withErrors.add(p, "SPACE");
    493496            }
     
    495498            {
    496499                errors.add( new TestError(this, Severity.OTHER, tr("Property values contain HTML entity"),
    497                 tr(s, key), MessageFormat.format(s, key), INVALID_HTML, p) );
     500                        tr(s, key), MessageFormat.format(s, key), INVALID_HTML, p) );
    498501                withErrors.add(p, "HTML");
    499502            }
     
    523526                        String i = marktr("Key ''{0}'' not in presets.");
    524527                        errors.add( new TestError(this, Severity.OTHER, tr("Presets do not contain property key"),
    525                         tr(i, key), MessageFormat.format(i, key), INVALID_VALUE, p) );
     528                                tr(i, key), MessageFormat.format(i, key), INVALID_VALUE, p) );
    526529                        withErrors.add(p, "UPK");
    527530                    }
     
    546549                        String i = marktr("Value ''{0}'' for key ''{1}'' not in presets.");
    547550                        errors.add( new TestError(this, Severity.OTHER, tr("Presets do not contain property value"),
    548                         tr(i, prop.getValue(), key), MessageFormat.format(i, prop.getValue(), key), INVALID_VALUE, p) );
     551                                tr(i, prop.getValue(), key), MessageFormat.format(i, prop.getValue(), key), INVALID_VALUE, p) );
    549552                        withErrors.add(p, "UPV");
    550553                    }
    551554                }
    552555            }
    553                         if (checkFixmes && value != null && value.length() > 0) {
    554                                 if ((value.toLowerCase().contains("FIXME")
    555                                                 || value.contains("check and delete")
    556                                                 || key.contains("todo") || key.toLowerCase().contains("fixme"))
    557                                                 && !withErrors.contains(p, "FIXME")) {
    558                                         errors.add(new TestError(this, Severity.OTHER,
    559                                                         tr("FIXMES"), FIXME, p));
    560                                         withErrors.add(p, "FIXME");
    561                                 }
    562                         }
     556            if (checkFixmes && value != null && value.length() > 0) {
     557                if ((value.toLowerCase().contains("FIXME")
     558                        || value.contains("check and delete")
     559                        || key.contains("todo") || key.toLowerCase().contains("fixme"))
     560                        && !withErrors.contains(p, "FIXME")) {
     561                    errors.add(new TestError(this, Severity.OTHER,
     562                            tr("FIXMES"), FIXME, p));
     563                    withErrors.add(p, "FIXME");
     564                }
     565            }
    563566        }
    564567    }
     
    600603    {
    601604        GBC a = GBC.eol();
    602         a.anchor = GBC.EAST;
     605        a.anchor = GridBagConstraints.EAST;
    603606
    604607        testPanel.add( new JLabel(name), GBC.eol().insets(3,0,0,0) );
     
    637640                        tr("TagChecker source"),
    638641                        JOptionPane.QUESTION_MESSAGE
    639                         );
     642                );
    640643                if (source != null)
    641644                    ((DefaultListModel)Sources.getModel()).addElement(source);
     
    668671                                tr("Information"),
    669672                                JOptionPane.INFORMATION_MESSAGE
    670                                 );
     673                        );
    671674                    }
    672675                }
     
    703706
    704707        testPanel.add(new JLabel(tr("Data sources")), GBC.eol().insets(23,0,0,0));
    705         testPanel.add(new JScrollPane(Sources), GBC.eol().insets(23,0,0,0).fill(GBC.HORIZONTAL));
     708        testPanel.add(new JScrollPane(Sources), GBC.eol().insets(23,0,0,0).fill(GridBagConstraints.HORIZONTAL));
    706709        final JPanel buttonPanel = new JPanel(new GridBagLayout());
    707         testPanel.add(buttonPanel, GBC.eol().fill(GBC.HORIZONTAL));
     710        testPanel.add(buttonPanel, GBC.eol().fill(GridBagConstraints.HORIZONTAL));
    708711        buttonPanel.add(addSrcButton, GBC.std().insets(0,5,0,0));
    709712        buttonPanel.add(editSrcButton, GBC.std().insets(5,5,5,0));
     
    837840                        {
    838841                            commands.add( new ChangePropertyKeyCommand(Collections.singleton(primitives.get(i)),
    839                             key, replacementKey) );
     842                                    key, replacementKey) );
    840843                        }
    841844                    }
     
    879882        private String description;
    880883        private List<CheckerElement> data = new ArrayList<CheckerElement>();
    881         private Integer type = 0;
    882         private Integer code;
     884        private OsmPrimitiveType type;
     885        private int code;
    883886        protected Severity severity;
    884         protected static int NODE = 1;
    885         protected static int WAY = 2;
    886         protected static int RELATION = 3;
    887         protected static int ALL = 4;
    888887        protected static int TAG_CHECK_ERROR  = 1250;
    889888        protected static int TAG_CHECK_WARN   = 1260;
     
    915914                else
    916915                    tag = n.startsWith("/") ? getPattern(n) : n;
    917                 noMatch = m.group(2).equals("!=");
    918                 n = m.group(3).trim();
    919                 if(n.equals("*"))
    920                     valueAll = true;
    921                 else if(n.equals("BOOLEAN_TRUE"))
    922                 {
    923                     valueBool = true;
    924                     value = OsmUtils.trueval;
    925                 }
    926                 else if(n.equals("BOOLEAN_FALSE"))
    927                 {
    928                     valueBool = true;
    929                     value = OsmUtils.falseval;
    930                 }
    931                 else
    932                     value = n.startsWith("/") ? getPattern(n) : n;
    933             }
    934             public boolean match(OsmPrimitive osm)
    935             {
    936                 for(Entry<String, String> prop: osm.getKeys().entrySet())
    937                 {
     916                    noMatch = m.group(2).equals("!=");
     917                    n = m.group(3).trim();
     918                    if(n.equals("*"))
     919                        valueAll = true;
     920                    else if(n.equals("BOOLEAN_TRUE"))
     921                    {
     922                        valueBool = true;
     923                        value = OsmUtils.trueval;
     924                    }
     925                    else if(n.equals("BOOLEAN_FALSE"))
     926                    {
     927                        valueBool = true;
     928                        value = OsmUtils.falseval;
     929                    }
     930                    else
     931                        value = n.startsWith("/") ? getPattern(n) : n;
     932            }
     933            public boolean match(OsmPrimitive osm, Map<String, String> keys) {
     934                for(Entry<String, String> prop: keys.entrySet()) {
    938935                    String key = prop.getKey();
    939936                    String val = valueBool ? OsmUtils.getNamedOsmBoolean(prop.getValue()) : prop.getValue();
    940937                    if((tagAll || (tag instanceof Pattern ? ((Pattern)tag).matcher(key).matches() : key.equals(tag)))
    941                     && (valueAll || (value instanceof Pattern ? ((Pattern)value).matcher(val).matches() : val.equals(value))))
     938                            && (valueAll || (value instanceof Pattern ? ((Pattern)value).matcher(val).matches() : val.equals(value))))
    942939                        return !noMatch;
    943940                }
     
    962959            String[] n = str.split(" *: *", 3);
    963960            if(n[0].equals("way"))
    964                 type = WAY;
     961                type = OsmPrimitiveType.WAY;
    965962            else if(n[0].equals("node"))
    966                 type = NODE;
     963                type = OsmPrimitiveType.NODE;
    967964            else if(n[0].equals("relation"))
    968                 type = RELATION;
     965                type = OsmPrimitiveType.RELATION;
    969966            else if(n[0].equals("*"))
    970                 type = ALL;
    971             if(type == 0 || n.length != 3)
     967                type = null;
     968            else
    972969                return tr("Could not find element type");
     970            if (n.length != 3)
     971                return tr("Incorrect number of parameters");
     972
    973973            if(n[1].equals("W"))
    974974            {
     
    10051005            return null;
    10061006        }
    1007         public boolean match(OsmPrimitive osm)
    1008         {
    1009             if(osm.getKeys() == null || (type == NODE && !(osm instanceof Node))
    1010             || (type == RELATION && !(osm instanceof Relation)) || (type == WAY && !(osm instanceof Way)))
     1007        public boolean match(OsmPrimitive osm, Map<String, String> keys)
     1008        {
     1009            if (type != null && OsmPrimitiveType.from(osm) != type)
    10111010                return false;
    1012             for(CheckerElement ce : data)
    1013             {
    1014                 if(!ce.match(osm))
     1011
     1012            for(CheckerElement ce : data) {
     1013                if(!ce.match(osm, keys))
    10151014                    return false;
    10161015            }
     
    10291028            return severity;
    10301029        }
    1031         public int getCode()
    1032         {
    1033             return code + type;
     1030
     1031        public int getCode() {
     1032            if (type == null) {
     1033                return code;
     1034            } else {
     1035                return code + type.ordinal() + 1;
     1036            }
    10341037        }
    10351038    }
  • applications/editors/josm/plugins/validator/src/org/openstreetmap/josm/plugins/validator/util/AgregatePrimitivesVisitor.java

    r17540 r20155  
    22
    33import java.util.Collection;
    4 import java.util.LinkedList;
     4import java.util.HashSet;
    55
    66import org.openstreetmap.josm.data.osm.Node;
     
    2121{
    2222    /** Aggregated data */
    23     Collection<OsmPrimitive> aggregatedData;
    24 
    25     /**
    26      * Constructor
    27      */
    28     public AgregatePrimitivesVisitor()
    29     {
    30         aggregatedData = new LinkedList<OsmPrimitive>();
    31     }
     23    final Collection<OsmPrimitive> aggregatedData = new HashSet<OsmPrimitive>();
    3224
    3325    /**
Note: See TracChangeset for help on using the changeset viewer.