Changeset 1843 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2009-07-25T18:37:45+02:00 (15 years ago)
Author:
jttt
Message:

Use OsmPrimitive methods instead of direct access to keys field when possible

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/ApiPreconditionChecker.java

    r1814 r1843  
    7474    private boolean checkMaxNodes(Collection<OsmPrimitive> add, long maxNodes) {
    7575        for (OsmPrimitive osmPrimitive : add) {
    76             if (osmPrimitive.keys == null) {
    77                 continue;
    78             }
    79             for (Entry<String,String> e : osmPrimitive.keys.entrySet()) {
     76            for (Entry<String,String> e : osmPrimitive.entrySet()) {
    8077                if(e.getValue().length() > 255) {
    8178                    if (osmPrimitive.deleted) {
  • trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java

    r1820 r1843  
    4545
    4646            for (String key : m.keySet()) {
    47                 clist.add(new ChangePropertyCommand(selectionSubset, key, osm.keys.get(key)));
     47                clist.add(new ChangePropertyCommand(selectionSubset, key, osm.get(key)));
    4848            }
    4949        }
     
    8383    private boolean containsSameKeysWithDifferentValues(Collection<? extends OsmPrimitive> osms) {
    8484        Map<String,String> kvSeen = new HashMap<String,String>();
    85         for (Iterator<? extends OsmPrimitive> it = osms.iterator(); it.hasNext();) {
    86             OsmPrimitive osm = it.next();
    87             if (osm.keys == null || osm.keys.isEmpty()) {
    88                 continue;
    89             }
    90             for (String key : osm.keys.keySet()) {
    91                 String value = osm.keys.get(key);
     85        for (OsmPrimitive osm:osms) {
     86            for (String key : osm.keySet()) {
     87                String value = osm.get(key);
    9288                if (! kvSeen.containsKey(key)) {
    9389                    kvSeen.put(key, value);
  • trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java

    r1820 r1843  
    2424import org.openstreetmap.josm.command.Command;
    2525import org.openstreetmap.josm.command.SequenceCommand;
    26 import org.openstreetmap.josm.data.SelectionChangedListener;
    27 import org.openstreetmap.josm.data.osm.DataSet;
    2826import org.openstreetmap.josm.data.osm.Node;
    2927import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    3432import org.openstreetmap.josm.data.osm.visitor.Visitor;
    3533import org.openstreetmap.josm.gui.PrimitiveNameFormatter;
    36 import org.openstreetmap.josm.gui.layer.Layer;
    37 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
    3834import org.openstreetmap.josm.tools.Shortcut;
    3935
     
    279275            }
    280276            Relation c = null;
    281             String type = "";
     277            String type = r.get("type");
     278            if (type == null) {
     279                type = "";
     280            }
    282281            int i = 0;
    283 
    284             if(r.keys != null) {
    285                 type = r.keys.get("type");
    286             }
    287282
    288283            for (RelationMember rm : r.members) {
  • trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r1814 r1843  
    9494
    9595            if (regexSearch) {
    96                 if (osm.keys == null)
     96                if (!osm.hasKeys())
    9797                    return false;
    9898
     
    115115                }
    116116
    117                 for (Entry<String, String> e : osm.keys.entrySet()) {
     117                for (Entry<String, String> e : osm.entrySet()) {
    118118                    String k = e.getKey();
    119119                    String v = e.getValue();
     
    223223        public boolean match(OsmPrimitive osm) throws ParseError {
    224224
    225             if (osm.keys == null || osm.keys.isEmpty())
     225            if (!osm.hasKeys())
    226226                return mode == Mode.NONE;
    227227
     
    251251            case ANY_VALUE_REGEXP:
    252252            case EXACT_REGEXP:
    253                 for (Entry<String, String> entry:osm.keys.entrySet()) {
     253                for (Entry<String, String> entry:osm.entrySet()) {
    254254                    if (keyPattern.matcher(entry.getKey()).matches()) {
    255255                        if (mode == Mode.ANY_VALUE_REGEXP
     
    260260                return false;
    261261            case MISSING_KEY_REGEXP:
    262                 for (String k:osm.keys.keySet()) {
     262                for (String k:osm.keySet()) {
    263263                    if (keyPattern.matcher(k).matches())
    264264                        return false;
     
    280280        public Any(String s) {this.s = s;}
    281281        @Override public boolean match(OsmPrimitive osm) throws ParseError {
    282             if (osm.keys == null)
     282            if (!osm.hasKeys())
    283283                return s.equals("");
    284284
     
    301301            // is not Java 1.5
    302302            //search = java.text.Normalizer.normalize(search, java.text.Normalizer.Form.NFC);
    303             for (Entry<String, String> e : osm.keys.entrySet()) {
     303            for (Entry<String, String> e : osm.entrySet()) {
    304304                if (regexSearch) {
    305305                    String key = e.getKey();
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r1762 r1843  
    2929 */
    3030abstract public class OsmPrimitive implements Comparable<OsmPrimitive> {
    31 
    32     /**
    33      * The key/value list for this primitive.
    34      */
    35     public Map<String, String> keys;
    3631
    3732    /* mappaint data */
     
    219214    }
    220215
     216    /*------------
     217     * Keys handling
     218     ------------*/
     219
     220    /**
     221     * The key/value list for this primitive.
     222     */
     223    public Map<String, String> keys;
     224
    221225    /**
    222226     * Set the given value to the given key
     
    248252    }
    249253
    250     public String getName() {
    251         return null;
     254    /**
     255     * Added in revision 1843
     256     * Please do not use in plug-ins until this version becomes JOSM tested
     257     */
     258    public final void removeAll() {
     259        keys = null;
     260        mappaintStyle = null;
    252261    }
    253262
     
    266275            return Collections.emptyList();
    267276        return keys.keySet();
     277    }
     278
     279    /**
     280     * Added in revision 1843
     281     * Please do not use in plug-ins until this version becomes JOSM tested
     282     */
     283    public final boolean hasKeys() {
     284        return keys != null && !keys.isEmpty();
     285    }
     286
     287
     288
     289
     290
     291
     292    public String getName() {
     293        return null;
    268294    }
    269295
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java

    r1755 r1843  
    495495            return;
    496496        }
    497         else if (drawMultipolygon && r.keys != null && "multipolygon".equals(r.keys.get("type")))
     497        else if (drawMultipolygon && "multipolygon".equals(r.get("type")))
    498498        {
    499499            if(drawMultipolygon(r))
    500500              return;
    501501        }
    502         else if (drawRestriction && r.keys != null && "restriction".equals(r.keys.get("type")))
     502        else if (drawRestriction && "restriction".equals(r.get("type")))
    503503        {
    504504            drawRestriction(r);
     
    751751
    752752        if (nodeStyle == null) {
    753             r.putError(tr("Style for restriction {0} not found.", r.keys.get("restriction")), true);
     753            r.putError(tr("Style for restriction {0} not found.", r.get("restriction")), true);
    754754            return;
    755755        }
     
    11121112    protected String getNodeName(Node n) {
    11131113        String name = null;
    1114         if (n.keys != null) {
     1114        if (n.hasKeys()) {
    11151115            for (String rn : regionalNameOrder) {
    1116                 name = n.keys.get(rn);
     1116                name = n.get(rn);
    11171117                if (name != null) break;
    11181118            }
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/TagMergeItem.java

    r1655 r1843  
    33
    44import static org.openstreetmap.josm.tools.I18n.tr;
    5 
    6 import java.util.HashMap;
    75
    86import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    5654        if (their == null) throw new IllegalArgumentException(tr("parameter '{0}' must not be null", "their"));
    5755        this.key = key;
    58         myTagValue = null;
    59         if (my.keys != null && my.keys.containsKey(key)) {
    60             myTagValue = my.keys.get(key);
    61         }
    62         theirTagValue = null;
    63         if (their.keys != null && their.keys.containsKey(key)) {
    64             theirTagValue = their.keys.get(key);
    65         }
     56        myTagValue = my.get(key);
     57        theirTagValue = their.get(key);
    6658    }
    6759
     
    108100            throw new IllegalStateException(tr("cannot apply undecided tag merge item"));
    109101        } else if (mergeDecision == MergeDecisionType.KEEP_THEIR) {
    110             if (theirTagValue == null && primitive.keys != null) {
    111                 primitive.keys.remove(key);
     102            if (theirTagValue == null) {
     103                primitive.remove(key);
    112104            } else if (theirTagValue != null) {
    113                 if (primitive.keys == null) {
    114                     primitive.keys = new HashMap<String, String>();
    115                 }
    116                 primitive.keys.put(key, theirTagValue);
     105                primitive.put(key, theirTagValue);
    117106            }
    118107        } else if (mergeDecision == MergeDecisionType.KEEP_MINE) {
    119             if (myTagValue == null && primitive.keys != null) {
    120                 primitive.keys.remove(key);
     108            if (myTagValue == null) {
     109                primitive.remove(key);
    121110            } else if (myTagValue != null) {
    122                 if (primitive.keys == null) {
    123                     primitive.keys = new HashMap<String, String>();
    124                 }
    125                 primitive.keys.put(key, myTagValue);
     111                primitive.put(key, myTagValue);
    126112            }
    127113        } else {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java

    r1815 r1843  
    240240                HashMap<String, Vector<OsmPrimitive>> map=new HashMap<String, Vector<OsmPrimitive>>();
    241241                for (OsmPrimitive osm: sel) {
    242                     if(osm.keys != null)
     242                    String val=osm.get(key);
     243                    if(val != null)
    243244                    {
    244                         String val=osm.keys.get(key);
    245                         if(val != null)
    246                         {
    247                             if (map.containsKey(val)) {
    248                                 map.get(val).add(osm);
    249                             } else {
    250                                 Vector<OsmPrimitive> v = new Vector<OsmPrimitive>();
    251                                 v.add(osm);
    252                                 map.put(val, v);
    253                             }
     245                        if (map.containsKey(val)) {
     246                            map.get(val).add(osm);
     247                        } else {
     248                            Vector<OsmPrimitive> v = new Vector<OsmPrimitive>();
     249                            v.add(osm);
     250                            map.put(val, v);
    254251                        }
    255252                    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/TagEditorModel.java

    r1814 r1843  
    99import java.util.Collection;
    1010import java.util.Comparator;
    11 import java.util.HashMap;
    1211import java.util.List;
    1312import java.util.logging.Logger;
     
    1514import javax.swing.table.AbstractTableModel;
    1615
    17 import org.openstreetmap.josm.Main;
    1816import org.openstreetmap.josm.command.ChangePropertyCommand;
    1917import org.openstreetmap.josm.command.Command;
     
    2422/**
    2523 * TagEditorModel is a table model.
    26  * 
    27  * 
     24 *
     25 *
    2826 * @author gubaer
    2927 *
     
    104102    /**
    105103     * adds a tag to the model
    106      * 
     104     *
    107105     * @param tag the tag. Must not be null.
    108      * 
     106     *
    109107     * @exception IllegalArgumentException thrown, if tag is null
    110108     */
     
    129127    /**
    130128     * adds a tag given by a name/value pair to the tag editor model.
    131      * 
     129     *
    132130     * If there is no tag with name <code>name</name> yet, a new {@link TagModel} is created
    133131     * and append to this model.
    134      * 
     132     *
    135133     * If there is a tag with name <code>name</name>, <code>value</code> is merged to the list
    136134     * of values for this tag.
    137      * 
     135     *
    138136     * @param name the name; converted to "" if null
    139137     * @param value the value; converted to "" if null
     
    183181    /**
    184182     * deletes the names of the tags given by tagIndices
    185      * 
     183     *
    186184     * @param tagIndices a list of tag indices
    187185     */
     
    201199    /**
    202200     * deletes the values of the tags given by tagIndices
    203      * 
     201     *
    204202     * @param tagIndices the lit of tag indices
    205203     */
     
    219217    /**
    220218     * deletes the tags given by tagIndices
    221      * 
     219     *
    222220     * @param tagIndices the list of tag indices
    223221     */
     
    261259    /**
    262260     * initializes the model with the tags of an OSM primitive
    263      * 
     261     *
    264262     * @param primitive the OSM primitive
    265263     */
     
    278276    /**
    279277     * applies the current state of the tag editor model to a primitive
    280      * 
     278     *
    281279     * @param primitive the primitive
    282      * 
     280     *
    283281     */
    284282    public void applyToPrimitive(OsmPrimitive primitive) {
    285         if (primitive.keys == null) {
    286             primitive.keys = new HashMap<String, String>();
    287         } else {
    288             primitive.keys.clear();
    289         }
     283        primitive.removeAll();
    290284        for (TagModel tag: tags) {
    291285            // tag still holds an unchanged list of different values for the same key.
     
    306300    /**
    307301     * checks whether the tag model includes a tag with a given key
    308      * 
     302     *
    309303     * @param key  the key
    310304     * @return true, if the tag model includes the tag; false, otherwise
     
    345339
    346340        for (OsmPrimitive primitive : primitives) {
    347             if (primitive.keys == null) {
    348                 continue;
    349             }
    350             for (String oldkey : primitive.keys.keySet()) {
     341            for (String oldkey : primitive.keySet()) {
    351342                if (!currentkeys.contains(oldkey)) {
    352343                    ChangePropertyCommand deleteCommand =
     
    367358    /**
    368359     * replies the list of keys of the tags managed by this model
    369      * 
     360     *
    370361     * @return the list of keys managed by this model
    371362     */
     
    397388     * updates the name of a tag and sets the dirty state to  true if
    398389     * the new name is different from the old name.
    399      * 
     390     *
    400391     * @param tag   the tag
    401392     * @param newName  the new name
     
    412403     * updates the value value of a tag and sets the dirty state to true if the
    413404     * new name is different from the old name
    414      * 
     405     *
    415406     * @param tag  the tag
    416407     * @param newValue  the new value
     
    426417    /**
    427418     * replies true, if this model has been updated
    428      * 
     419     *
    429420     * @return true, if this model has been updated
    430421     */
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r1823 r1843  
    1818import java.awt.TexturePaint;
    1919import java.awt.event.ActionEvent;
    20 import java.awt.event.KeyEvent;
    2120import java.awt.geom.Area;
    2221import java.awt.image.BufferedImage;
     
    3837
    3938import org.openstreetmap.josm.Main;
    40 import org.openstreetmap.josm.actions.GpxExportAction;
    4139import org.openstreetmap.josm.actions.RenameLayerAction;
    42 import org.openstreetmap.josm.actions.SaveAction;
    43 import org.openstreetmap.josm.actions.SaveAsAction;
    4440import org.openstreetmap.josm.data.conflict.Conflict;
    4541import org.openstreetmap.josm.data.conflict.ConflictCollection;
     
    6763import org.openstreetmap.josm.tools.GBC;
    6864import org.openstreetmap.josm.tools.ImageProvider;
    69 import org.openstreetmap.josm.tools.Shortcut;
    7065
    7166/**
     
    8277    /**
    8378     * Replies a new unique name for a data layer
    84      * 
     79     *
    8580     * @return a new unique name for a data layer
    8681     */
     
    497492                wpt.setTime();
    498493            }
    499             if (n.keys != null && n.keys.containsKey("name")) {
    500                 wpt.attr.put("name", n.keys.get("name"));
     494            String name = n.get("name");
     495            if (name != null) {
     496                wpt.attr.put("name", name);
    501497            }
    502498        }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r1747 r1843  
    44import java.util.Collections;
    55import java.util.HashMap;
     6import java.util.Iterator;
    67import java.util.LinkedList;
    78import java.util.List;
    89import java.util.Map;
    9 import java.util.Iterator;
    10 
     10
     11import org.openstreetmap.josm.Main;
    1112import org.openstreetmap.josm.data.osm.Node;
    1213import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1314import org.openstreetmap.josm.data.osm.OsmUtils;
    1415import org.openstreetmap.josm.data.osm.Way;
    15 import org.openstreetmap.josm.Main;
    1616
    1717public class ElemStyles
     
    185185            {
    186186                boolean noclosed = o instanceof Way && !((Way)o).isClosed();
    187                 Iterator<String> iterator = o.keys.keySet().iterator();
     187                Iterator<String> iterator = o.keySet().iterator();
    188188                while(iterator.hasNext())
    189189                {
    190190                    String key = iterator.next();
    191                     String val = o.keys.get(key);
     191                    String val = o.get(key);
    192192                    AreaElemStyle s = areas.get("n" + key + "=" + val);
    193193                    if(s == null || (s.closed && noclosed))
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

    r1814 r1843  
    106106                returnValue.hadEmpty = true;
    107107            }
    108             if(s.keys != null && s.keys.size() > 0) {
    109                 returnValue.hadKeys = true;
    110             }
     108            returnValue.hadKeys = returnValue.hadKeys | s.hasKeys();
    111109        }
    112110        return returnValue;
     
    220218                {
    221219                    for (OsmPrimitive s : sel)
    222                         if(s.keys != null && s.keys.size() > 0) {
     220                        if(s.hasKeys()) {
    223221                            def = false;
    224222                        }
     
    381379
    382380            // no change if same as before
    383             if (value.equals(originalValue) || (originalValue == null && (value == null || value.length() == 0))) return;
    384 
    385             if (delete_if_empty && value != null && value.length() == 0) {
     381            if (value.equals(originalValue) || (originalValue == null &&  value.length() == 0)) return;
     382
     383            if (delete_if_empty && value.length() == 0) {
    386384                value = null;
    387385            }
  • trunk/src/org/openstreetmap/josm/io/OsmWriter.java

    r1735 r1843  
    164164
    165165    private void addTags(OsmPrimitive osm, String tagname, boolean tagOpen) {
    166         if (osm.keys != null) {
     166        if (osm.hasKeys()) {
    167167            if (tagOpen) {
    168168                out.println(">");
    169169            }
    170             for (Entry<String, String> e : osm.keys.entrySet()) {
     170            for (Entry<String, String> e : osm.entrySet()) {
    171171                if ((osm instanceof Changeset) || !("created_by".equals(e.getKey())))
    172172                    out.println("    <tag k='"+ XmlWriter.encode(e.getKey()) +
Note: See TracChangeset for help on using the changeset viewer.