Changeset 6821 in josm


Ignore:
Timestamp:
2014-02-07T00:18:58+01:00 (10 years ago)
Author:
bastiK
Message:

see #8902 - Small performance enhancements / coding style (patch by shinigami)

primitives.diff: few optimizations around osm primitives

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java

    r6629 r6821  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.osm;
     3
     4import org.openstreetmap.josm.tools.Utils;
    35
    46import static org.openstreetmap.josm.tools.I18n.tr;
     
    701703    @Override
    702704    public String getLocalName() {
    703         String key = "name:" + Locale.getDefault().toString();
    704         if (get(key) != null)
    705             return get(key);
    706         key = "name:" + Locale.getDefault().getLanguage() + "_" + Locale.getDefault().getCountry();
    707         if (get(key) != null)
    708             return get(key);
    709         key = "name:" + Locale.getDefault().getLanguage();
    710         if (get(key) != null)
    711             return get(key);
     705        final Locale locale = Locale.getDefault();
     706        String key = "name:" + locale.toString();
     707        String val = get(key);
     708        if (val != null)
     709            return val;
     710
     711        final String language = locale.getLanguage();
     712        key = "name:" + language + "_" + locale.getCountry();
     713        val = get(key);
     714        if (val != null)
     715            return val;
     716
     717        key = "name:" + language;
     718        val = get(key);
     719        if (val != null)
     720            return val;
     721
    712722        return getName();
     723    }
     724
     725    /**
     726     * Tests whether this primitive contains a tag consisting of {@code key} and {@code values}.
     727     * @param key the key forming the tag.
     728     * @param value value forming the tag.
     729     * @return true iff primitive contains a tag consisting of {@code key} and {@code value}.
     730     */
     731    public boolean hasTag(String key, String value) {
     732        return Utils.equal(value, get(key));
    713733    }
    714734
  • trunk/src/org/openstreetmap/josm/gui/mappaint/xml/Prototype.java

    r3836 r6821  
    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        }
     
    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        }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlCondition.java

    r3805 r6821  
    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}
Note: See TracChangeset for help on using the changeset viewer.