Ticket #8902: primitives.diff

File primitives.diff, 4.3 KB (added by shinigami, 13 years ago)

few optimizations around osm primitives

  • src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java

     
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.osm;
    33
     4import org.openstreetmap.josm.tools.Utils;
     5
    46import static org.openstreetmap.josm.tools.I18n.tr;
    57
    68import java.text.MessageFormat;
     
    694696     */
    695697    @Override
    696698    public String getLocalName() {
    697         String key = "name:" + Locale.getDefault().toString();
    698         if (get(key) != null)
    699             return get(key);
    700         key = "name:" + Locale.getDefault().getLanguage() + "_" + Locale.getDefault().getCountry();
    701         if (get(key) != null)
    702             return get(key);
    703         key = "name:" + Locale.getDefault().getLanguage();
    704         if (get(key) != null)
    705             return get(key);
     699        final Locale locale = Locale.getDefault();
     700        String key = "name:" + locale.toString();
     701        String val = get(key);
     702        if (val != null)
     703            return val;
     704
     705        final String language = locale.getLanguage();
     706        key = "name:" + language + "_" + locale.getCountry();
     707        val = get(key);
     708        if (val != null)
     709            return val;
     710
     711        key = "name:" + language;
     712        val = get(key);
     713        if (val != null)
     714            return val;
     715
    706716        return getName();
    707717    }
    708718
    709719    /**
     720     * Tests whether this primitive contains a tag consisting of {@code key} and {@code values}.
     721     * @param key the key forming the tag.
     722     * @param value value forming the tag.
     723     * @return true iff primitive contains a tag consisting of {@code key} and {@code value}.
     724     */
     725    public boolean hasTag(String key, String value) {
     726        return Utils.equal(value, get(key));
     727    }
     728
     729    /**
    710730     * Tests whether this primitive contains a tag consisting of {@code key} and any of {@code values}.
    711731     * @param key the key forming the tag.
    712732     * @param values one or many values forming the tag.
  • src/org/openstreetmap/josm/gui/mappaint/xml/Prototype.java

     
    2424
    2525    public String getCode() {
    2626        if(code == null) {
    27             code = "";
    28             if (conditions != null) {
     27            if (conditions == null || conditions.isEmpty()) {
     28                code = "";
     29            } else {
     30                final StringBuilder sb = new StringBuilder();
    2931                for(XmlCondition r: conditions) {
    30                     code += r.toCode();
     32                    r.appendCode(sb);
    3133                }
     34                code = sb.toString();
    3235            }
    3336        }
    3437        return code;
     
    4144        for(XmlCondition r : conditions)
    4245        {
    4346            String k = primitive.get(r.key);
     47
     48            if (k == null || (r.value != null && !k.equals(r.value)))
     49                return false;
     50
    4451            String bv = OsmUtils.getNamedOsmBoolean(r.boolValue);
    45             if(k == null || (r.value != null && !k.equals(r.value))
    46                     || (bv != null && !bv.equals(OsmUtils.getNamedOsmBoolean(k))))
     52
     53            if (bv != null && !bv.equals(OsmUtils.getNamedOsmBoolean(k)))
    4754                return false;
    4855        }
    4956        return true;
  • src/org/openstreetmap/josm/gui/mappaint/xml/XmlCondition.java

     
    3737    {
    3838      return "Rule["+key+","+(boolValue != null ? "b="+boolValue:"v="+value)+"]";
    3939    }
    40     public String toCode()
     40
     41    public void appendCode(StringBuilder sb)
    4142    {
    42       return "[k="+key+(boolValue != null ? ",b="+boolValue:",v="+value)+"]";
     43        sb.append("[k=").append(key);
     44
     45        if (boolValue != null)
     46            sb.append(",b=").append(boolValue);
     47        else
     48            sb.append(",v=").append(value);
     49
     50        sb.append("]");
    4351    }
    4452}