001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.mappaint.xml;
003
004import java.util.Collection;
005
006import org.openstreetmap.josm.data.osm.OsmPrimitive;
007import org.openstreetmap.josm.data.osm.OsmUtils;
008import org.openstreetmap.josm.gui.mappaint.Range;
009
010abstract public class Prototype {
011    // zoom range to display the feature
012    public Range range;
013
014    public int priority;
015    public String code;
016    public Collection<XmlCondition> conditions = null;
017
018    public Prototype(Range range) {
019        this.range = range;
020    }
021
022    public Prototype() {
023    }
024
025    public String getCode() {
026        if(code == null) {
027            code = "";
028            if (conditions != null) {
029                for(XmlCondition r: conditions) {
030                    code += r.toCode();
031                }
032            }
033        }
034        return code;
035    }
036
037    public boolean check(OsmPrimitive primitive)
038    {
039        if(conditions == null)
040            return true;
041        for(XmlCondition r : conditions)
042        {
043            String k = primitive.get(r.key);
044            String bv = OsmUtils.getNamedOsmBoolean(r.boolValue);
045            if(k == null || (r.value != null && !k.equals(r.value))
046                    || (bv != null && !bv.equals(OsmUtils.getNamedOsmBoolean(k))))
047                return false;
048        }
049        return true;
050    }
051
052}