Ignore:
Timestamp:
2009-10-24T21:22:49+02:00 (17 years ago)
Author:
jttt
Message:

Use PrimitiveData for Copy, Paste and Paste tags actions

Location:
trunk/src/org/openstreetmap/josm/data/osm
Files:
1 added
14 edited

Legend:

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

    r2115 r2305  
    5050    /**
    5151     * Creates a changeset with id <code>id</code>. If id > 0, sets incomplete to true.
    52      * 
     52     *
    5353     * @param id the id
    5454     */
    … …  
    6161    /**
    6262     * Creates a clone of <code>other</code>
    63      * 
     63     *
    6464     * @param other the other changeset. If null, creates a new changeset with id 0.
    6565     */
    … …  
    192192        this.tags.remove(key);
    193193    }
     194
     195    public void removeAll() {
     196        this.tags.clear();
     197    }
     198
    194199
    195200    public boolean hasEqualSemanticAttributes(Changeset other) {
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r2282 r2305  
    11// License: GPL. Copyright 2007 by Immanuel Scholz and others
    22package org.openstreetmap.josm.data.osm;
    3 import static org.openstreetmap.josm.tools.I18n.tr;
    4 
    53import java.awt.geom.Area;
    64import java.util.ArrayList;
    … …  
    1614
    1715import org.openstreetmap.josm.data.SelectionChangedListener;
    18 import org.openstreetmap.josm.data.osm.QuadBuckets;
    1916
    2017/**
    … …  
    113110     */
    114111    public void addPrimitive(OsmPrimitive primitive) {
    115         if (primitive == null)
    116             return;
    117112        if (primitive instanceof Node) {
    118113            nodes.add((Node) primitive);
    … …  
    121116        } else if (primitive instanceof Relation) {
    122117            relations.add((Relation) primitive);
     118        }
     119    }
     120
     121    public OsmPrimitive addPrimitive(PrimitiveData data) {
     122        if (data instanceof NodeData) {
     123            Node node = new Node((NodeData)data, this);
     124            nodes.add(node);
     125            return node;
     126        } else if (data instanceof WayData) {
     127            Way way = new Way((WayData)data, this);
     128            ways.add(way);
     129            return way;
     130        } else if (data instanceof RelationData) {
     131            Relation relation = new Relation((RelationData)data, this);
     132            relations.add(relation);
     133            return relation;
     134        } else {
     135            throw new AssertionError();
    123136        }
    124137    }
    … …  
    145158    }
    146159
     160    public void removePrimitive(long id, OsmPrimitiveType type) {
     161        removePrimitive(getPrimitiveById(id, type));
     162    }
     163
    147164    public Collection<OsmPrimitive> getSelectedNodesAndWays() {
    148165        Collection<OsmPrimitive> sel = getSelected(nodes);
    … …  
    246263     * Sets the current selection to the primitives in <code>selection</code>.
    247264     * Notifies all {@see SelectionChangedListener} if <code>fireSelectionChangeEvent</code> is true.
    248      * 
     265     *
    249266     * @param selection the selection
    250267     * @param fireSelectionChangeEvent true, if the selection change listeners are to be notified; false, otherwise
    … …  
    265282     * Sets the current selection to the primitives in <code>selection</code>
    266283     * and notifies all {@see SelectionChangedListener}.
    267      * 
     284     *
    268285     * @param selection the selection
    269286     */
    … …  
    275292     * Adds   the primitives in <code>selection</code> to the current selection
    276293     * and notifies all {@see SelectionChangedListener}.
    277      * 
     294     *
    278295     * @param selection the selection
    279296     */
    … …  
    285302     * Adds the primitives in <code>selection</code> to the current selection.
    286303     * Notifies all {@see SelectionChangedListener} if <code>fireSelectionChangeEvent</code> is true.
    287      * 
     304     *
    288305     * @param selection the selection
    289306     * @param fireSelectionChangeEvent true, if the selection change listeners are to be notified; false, otherwise
    … …  
    443460     * exists
    444461     *
    445      * @param id  the id, > 0 required
     462     * @param id  uniqueId of the primitive. Might be < 0 for newly created primitives
    446463     * @param type the type of  the primitive. Must not be null.
    447464     * @return the primitive
    448      * @exception IllegalArgumentException thrown, if id <= 0
    449      * @exception IllegalArgumentException thrown, if type is null
    450      * @exception IllegalArgumentException thrown, if type is neither NODE, or WAY or RELATION
     465     * @exception NullPointerException thrown, if type is null
    451466     */
    452467    public OsmPrimitive getPrimitiveById(long id, OsmPrimitiveType type) {
    453         if (id <= 0)
    454             throw new IllegalArgumentException(tr("Parameter ''{0}'' > 0 expected. Got ''{1}''.", "id", id));
    455         if (id <= 0)
    456             throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "type"));
     468        return getPrimitiveById(id, type, false);
     469    }
     470
     471    public OsmPrimitive getPrimitiveById(long id, OsmPrimitiveType type, boolean createNew) {
    457472        Collection<? extends OsmPrimitive> primitives = null;
    458473        switch(type) {
    … …  
    462477        }
    463478        for (OsmPrimitive primitive : primitives) {
    464             if (primitive.getId() == id) return primitive;
    465         }
    466         return null;
     479            if (primitive.getUniqueId() == id) return primitive;
     480        }
     481
     482        if (createNew) {
     483            OsmPrimitive result = null;
     484            switch (type) {
     485            case NODE: result = new Node(id, true); break;
     486            case WAY: result = new Way(id, true); break;
     487            case RELATION: result = new Relation(id, true); break;
     488            }
     489            addPrimitive(result);
     490            return result;
     491        } else {
     492            return null;
     493        }
    467494    }
    468495
    … …  
    565592     * Replies true if there is at least one primitive in this dataset with
    566593     * {@see OsmPrimitive#isModified()} == <code>true</code>.
    567      * 
     594     *
    568595     * @return true if there is at least one primitive in this dataset with
    569596     * {@see OsmPrimitive#isModified()} == <code>true</code>.
  • trunk/src/org/openstreetmap/josm/data/osm/NodeData.java

    r2299 r2305  
    22package org.openstreetmap.josm.data.osm;
    33
     4import org.openstreetmap.josm.data.coor.CachedLatLon;
     5import org.openstreetmap.josm.data.coor.EastNorth;
    46import org.openstreetmap.josm.data.coor.LatLon;
    57
    68public class NodeData extends PrimitiveData {
    79
    8     private LatLon coor;
     10    private final CachedLatLon coor = new CachedLatLon(0, 0);
     11
     12    public NodeData() {
     13
     14    }
     15
     16    public NodeData(double lat, double lon, String... keys) {
     17        setCoor(new LatLon(lat, lon));
     18        setKeysAsList(keys);
     19    }
     20
     21    public NodeData(String... keys) {
     22        setKeysAsList(keys);
     23    }
     24
     25    public NodeData(NodeData data) {
     26        super(data);
     27        setCoor(data.getCoor());
     28    }
    929
    1030    public LatLon getCoor() {
    … …  
    1333
    1434    public void setCoor(LatLon coor) {
    15         this.coor = coor;
     35        this.coor.setCoor(coor);
     36    }
     37
     38    public EastNorth getEastNorth() {
     39        return this.coor.getEastNorth();
     40    }
     41
     42    public void setEastNorth(EastNorth eastNorth) {
     43        this.coor.setEastNorth(eastNorth);
     44    }
     45
     46    @Override
     47    public NodeData makeCopy() {
     48        return new NodeData(this);
     49    }
     50
     51    @Override
     52    public Node makePrimitive(DataSet dataSet) {
     53        return new Node(this, dataSet);
    1654    }
    1755
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r2300 r2305  
    3636abstract public class OsmPrimitive implements Comparable<OsmPrimitive>, Tagged {
    3737
    38     static final AtomicLong idCounter = new AtomicLong(0);
     38    private static final AtomicLong idCounter = new AtomicLong(0);
     39
     40    static long generateUniqueId() {
     41        return idCounter.decrementAndGet();
     42    }
    3943
    4044    private static final int FLAG_MODIFIED = 1 << 0;
    … …  
    164168                throw new IllegalArgumentException(tr("Expected ID >= 0. Got {0}.", id));
    165169            else if (id == 0) {
    166                 this.id = idCounter.decrementAndGet();
     170                this.id = generateUniqueId();
    167171            } else {
    168172                this.id = id;
    … …  
    400404     */
    401405    public void clearOsmId() {
    402         this.id = idCounter.decrementAndGet();
     406        this.id = generateUniqueId();
    403407        this.version = 0;
    404408        this.incomplete = false;
    … …  
    456460        if(directionKeys == null) {
    457461            directionKeys = Main.pref.getCollection("tags.direction",
    458                     Arrays.asList(new String[]{"oneway","incline","incline_steep","aerialway"}));
     462                    Arrays.asList("oneway","incline","incline_steep","aerialway"));
    459463        }
    460464        return directionKeys;
    … …  
    841845
    842846    protected void saveCommonAttributes(PrimitiveData data) {
    843         data.setId(data.getId());
     847        data.setId(id);
    844848        data.getKeys().clear();
    845849        data.getKeys().putAll(getKeys());
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitiveType.java

    r2181 r2305  
    55public enum OsmPrimitiveType {
    66
    7     NODE ("node"),
    8     WAY  ("way"),
    9     RELATION ("relation");
     7    NODE ("node", Node.class, NodeData.class),
     8    WAY  ("way", Way.class, WayData.class),
     9    RELATION ("relation", Relation.class, RelationData.class);
    1010
    11     private String apiTypeName;
     11    private final String apiTypeName;
     12    private final Class<? extends OsmPrimitive> osmClass;
     13    private final Class<? extends PrimitiveData> dataClass;
    1214
    13     OsmPrimitiveType(String apiTypeName) {
     15    OsmPrimitiveType(String apiTypeName, Class<? extends OsmPrimitive> osmClass, Class<? extends PrimitiveData> dataClass) {
    1416        this.apiTypeName = apiTypeName;
     17        this.osmClass = osmClass;
     18        this.dataClass = dataClass;
    1519    }
    1620
    1721    public String getAPIName() {
    1822        return apiTypeName;
     23    }
     24
     25    public Class<? extends OsmPrimitive> getOsmClass() {
     26        return osmClass;
     27    }
     28
     29    public Class<? extends PrimitiveData> getDataClass() {
     30        return dataClass;
    1931    }
    2032
    … …  
    3042    }
    3143
    32     public static OsmPrimitiveType from(Class cls) {
     44    public static OsmPrimitiveType from(Class<? extends OsmPrimitive> cls) {
    3345        if (cls.equals(Node.class)) return NODE;
    3446        if (cls.equals(Way.class)) return WAY;
    3547        if (cls.equals(Relation.class)) return RELATION;
    3648        throw new IllegalArgumentException(tr("Parameter ''{0}'' is not an acceptable class. Got ''{1}''.", "cls", cls.toString()));
     49    }
     50
     51    public static OsmPrimitiveType fromData(Class<? extends PrimitiveData> cls) {
     52        if (cls.equals(NodeData.class)) return NODE;
     53        if (cls.equals(WayData.class)) return WAY;
     54        if (cls.equals(RelationData.class)) return RELATION;
     55        throw new IllegalArgumentException(tr("Parameter ''{0}'' is not an acceptable class. Got ''{1}''.", "cls", cls.toString()));
     56    }
     57
     58    public static OsmPrimitiveType fromData(PrimitiveData data) {
     59        return fromData(data.getClass());
    3760    }
    3861
  • trunk/src/org/openstreetmap/josm/data/osm/PrimitiveData.java

    r2299 r2305  
    22package org.openstreetmap.josm.data.osm;
    33
     4import java.util.ArrayList;
     5import java.util.Collection;
    46import java.util.HashMap;
     7import java.util.List;
    58import java.util.Map;
    69
    … …  
    1215 *
    1316 */
    14 public abstract class PrimitiveData {
     17public abstract class PrimitiveData implements Tagged {
    1518
    1619    // Useful?
    … …  
    1922    //private boolean selected;
    2023    //private boolean highlighted;
     24
     25    public PrimitiveData() {
     26        id = OsmPrimitive.generateUniqueId();
     27    }
     28
     29    public PrimitiveData(PrimitiveData data) {
     30        this.keys.putAll(data.keys);
     31        this.modified = data.modified;
     32        this.visible = data.visible;
     33        this.deleted = data.deleted;
     34        this.id = data.id;
     35        this.user = data.user;
     36        this.version = data.version;
     37        this.timestamp = data.timestamp;
     38    }
    2139
    2240    private final Map<String, String> keys = new HashMap<String, String>();
    … …  
    7593    }
    7694
     95    public void clearOsmId() {
     96        id = OsmPrimitive.generateUniqueId();
     97    }
     98
     99    public abstract PrimitiveData makeCopy();
     100
     101    public abstract OsmPrimitive makePrimitive(DataSet dataSet);
    77102
    78103    @Override
    … …  
    94119    }
    95120
     121    // Tagged implementation
     122
     123    public String get(String key) {
     124        return keys.get(key);
     125    }
     126
     127    public boolean hasKeys() {
     128        return !keys.isEmpty();
     129    }
     130
     131    public Collection<String> keySet() {
     132        return keys.keySet();
     133    }
     134
     135    public void put(String key, String value) {
     136        keys.put(key, value);
     137    }
     138
     139    public void remove(String key) {
     140        keys.remove(key);
     141    }
     142
     143    public void removeAll() {
     144        keys.clear();
     145    }
     146
     147    public void setKeys(Map<String, String> keys) {
     148        this.keys.clear();
     149        this.keys.putAll(keys);
     150    }
     151
     152
     153    @SuppressWarnings("unchecked")
     154    static public <T extends PrimitiveData>  List<T> getFilteredList(Collection<T> list, OsmPrimitiveType type) {
     155        List<T> ret = new ArrayList<T>();
     156        for(PrimitiveData p: list) {
     157            if (type.getDataClass().isInstance(p)) {
     158                ret.add((T)p);
     159            }
     160        }
     161        return ret;
     162    }
     163
     164    protected void setKeysAsList(String... keys) {
     165        assert keys.length % 2 == 0;
     166        for (int i=0; i<keys.length/2; i++) {
     167            this.keys.put(keys[i * 2], keys[i * 2 + 1]);
     168        }
     169    }
     170
     171
    96172
    97173}
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r2284 r2305  
    205205                foundMember = nodes.get(member.getMemberId());
    206206                if (foundMember == nodeMarker) {
    207                     foundMember = new Node(member.getMemberId(), true);
     207                    throw new AssertionError("Data consistency problem - relation with missing member detected");
    208208                }
    209209                break;
    … …  
    211211                foundMember = ways.get(member.getMemberId());
    212212                if (foundMember == wayMarker) {
    213                     foundMember = new Way(member.getMemberId(), true);
     213                    throw new AssertionError("Data consistency problem - relation with missing member detected");
    214214                }
    215215                break;
    … …  
    217217                foundMember = relations.get(member.getMemberId());
    218218                if (foundMember == relationMarker) {
    219                     foundMember = new Relation(member.getMemberId(), true);
     219                    throw new AssertionError("Data consistency problem - relation with missing member detected");
    220220                }
    221221                break;
  • trunk/src/org/openstreetmap/josm/data/osm/RelationData.java

    r2299 r2305  
    99    private final List<RelationMemberData> members = new ArrayList<RelationMemberData>();
    1010
     11    public RelationData() {
     12
     13    }
     14
     15    public RelationData(RelationData data) {
     16        super(data);
     17        members.addAll(data.members);
     18    }
     19
    1120    public List<RelationMemberData> getMembers() {
    1221        return members;
     22    }
     23
     24    @Override
     25    public RelationData makeCopy() {
     26        return new RelationData(this);
     27    }
     28
     29    @Override
     30    public Relation makePrimitive(DataSet dataSet) {
     31        return new Relation(this, dataSet);
    1332    }
    1433
  • trunk/src/org/openstreetmap/josm/data/osm/RelationMemberData.java

    r2299 r2305  
    44public class RelationMemberData {
    55
    6     private String role;
    7     private long memberId;
    8     private OsmPrimitiveType memberType;
     6    private final String role;
     7    private final long memberId;
     8    private final OsmPrimitiveType memberType;
    99
    10     public RelationMemberData() {
    11 
     10    public RelationMemberData(String role, OsmPrimitiveType type, long id) {
     11        this.role = role;
     12        this.memberType = type;
     13        this.memberId = id;
    1214    }
    1315
    1416    public RelationMemberData(String role, OsmPrimitive primitive) {
    15         this.role = role;
    16         this.memberId = primitive.getUniqueId();
    17         this.memberType = OsmPrimitiveType.from(primitive);
     17        this(role, OsmPrimitiveType.from(primitive), primitive.getUniqueId());
    1818    }
    1919
    … …  
    2121        return memberId;
    2222    }
    23     public void setMemberId(long memberId) {
    24         this.memberId = memberId;
    25     }
    2623    public String getRole() {
    2724        return role;
    2825    }
    29     public void setRole(String role) {
    30         this.role = role;
    31     }
    3226    public OsmPrimitiveType getMemberType() {
    3327        return memberType;
    34     }
    35     public void setMemberType(OsmPrimitiveType memberType) {
    36         this.memberType = memberType;
    3728    }
    3829
  • trunk/src/org/openstreetmap/josm/data/osm/Tag.java

    r2070 r2305  
    22package org.openstreetmap.josm.data.osm;
    33
    4 import java.util.ArrayList;
    5 import java.util.Collections;
    6 import java.util.Iterator;
    7 import java.util.List;
    84
    95/**
    … …  
    2117     */
    2218    public Tag(){
    23         this.key = "";
    24         this.value = "";
     19        this("", "");
    2520    }
    2621
    … …  
    2823     * Create a tag whose key is <code>key</code> and whose value is
    2924     * empty.
    30      * 
     25     *
    3126     * @param key the key. If null, it is set to the empty key.
    3227     */
    3328    public Tag(String key) {
    34         this();
    35         this.key = key == null ? "" : key;
     29        this(key, "");
    3630    }
    3731
    … …  
    3933     * Creates a tag for a key and a value. If key and/or value are null,
    4034     * the empty value "" is assumed.
    41      * 
     35     *
    4236     * @param key the key
    4337     * @param value  the value
    … …  
    5044    /**
    5145     * Creates clone of the tag <code>tag</code>.
    52      * 
    53      * @param tag the tag. If null, creates an empty tag.
     46     *
     47     * @param tag the tag.
    5448     */
    5549    public Tag(Tag tag) {
    56         if (tag != null) {
    57             key = tag.getKey();
    58             value = tag.getValue();
    59         }
     50        this(tag.getKey(), tag.getValue());
    6051    }
    6152
    6253    /**
    6354     * Replies the key of the tag. This is never null.
    64      * 
     55     *
    6556     * @return the key of the tag
    6657     */
    … …  
    7162    /**
    7263     * Replies the value of the tag. This is never null.
    73      * 
     64     *
    7465     * @return the value of the tag
    7566     */
    … …  
    8677     * Replies true if the key of this tag is equal to <code>key</code>.
    8778     * If <code>key</code> is null, assumes the empty key.
    88      * 
     79     *
    8980     * @param key the key
    9081     * @return true if the key of this tag is equal to <code>key</code>
    9182     */
    9283    public boolean matchesKey(String key) {
    93         if (key == null) {
    94             key = "";
    95         }
    9684        return this.key.equals(key);
    9785    }
    … …  
    10290     *   <li>removing leading and trailing white space</li>
    10391     * <ul>
    104      * 
     92     *
    10593     */
    10694    public void normalize() {
    … …  
    113101        final int prime = 31;
    114102        int result = 1;
    115         result = prime * result + ((key == null) ? 0 : key.hashCode());
    116         result = prime * result + ((value == null) ? 0 : value.hashCode());
     103        result = prime * result + key.hashCode();
     104        result = prime * result + value.hashCode();
    117105        return result;
    118106    }
    … …  
    120108    @Override
    121109    public boolean equals(Object obj) {
    122         if (this == obj)
    123             return true;
    124         if (obj == null)
     110        if (obj instanceof Tag) {
     111            Tag other = (Tag) obj;
     112            return key.equals(other.getKey()) && value.equals(other.getValue());
     113        } else {
    125114            return false;
    126         if (getClass() != obj.getClass())
    127             return false;
    128         Tag other = (Tag) obj;
    129         if (key == null) {
    130             if (other.key != null)
    131                 return false;
    132         } else if (!key.equals(other.key))
    133             return false;
    134         if (value == null) {
    135             if (other.value != null)
    136                 return false;
    137         } else if (!value.equals(other.value))
    138             return false;
    139         return true;
     115        }
     116    }
     117
     118    @Override
     119    public String toString() {
     120        return key + "=" + value;
    140121    }
    141122}
  • trunk/src/org/openstreetmap/josm/data/osm/TagCollection.java

    r2181 r2305  
    1717 * TagCollection is a collection of tags which can be used to manipulate
    1818 * tags managed by {@see OsmPrimitive}s.
    19  * 
     19 *
    2020 * A TagCollection can be created:
    2121 * <ul>
    … …  
    2525 *  <li>from the intersection of all tags managed by a collection of primitives with {@see #commonToAllPrimitives(Collection)}</li>
    2626 * </ul>
    27  * 
     27 *
    2828 * It  provides methods to query the collection, like {@see #size()}, {@see #hasTagsFor(String)}, etc.
    29  * 
     29 *
    3030 * Basic set operations allow to create the union, the intersection and  the difference
    3131 * of tag collections, see {@see #union(TagCollection)}, {@see #intersect(TagCollection)},
    3232 * and {@see #minus(TagCollection)}.
    33  * 
     33 *
    3434 *
    3535 */
    … …  
    4040     * {@see OsmPrimitive}. If <code>primitive</code> is null, replies
    4141     * an empty tag collection.
    42      * 
     42     *
    4343     * @param primitive  the primitive
    4444     * @return a tag collection with the tags managed by a specific
    4545     * {@see OsmPrimitive}
    4646     */
    47     public static TagCollection from(OsmPrimitive primitive) {
     47    public static TagCollection from(Tagged primitive) {
    4848        TagCollection tags = new TagCollection();
    4949        for (String key: primitive.keySet()) {
    … …  
    6262     * a collection of primitives
    6363     */
    64     public static TagCollection unionOfAllPrimitives(Collection<? extends OsmPrimitive> primitives) {
     64    public static TagCollection unionOfAllPrimitives(Collection<? extends Tagged> primitives) {
    6565        TagCollection tags = new TagCollection();
    6666        if (primitives == null) return tags;
    67         for (OsmPrimitive primitive: primitives) {
     67        for (Tagged primitive: primitives) {
    6868            if (primitive == null) {
    6969                continue;
    … …  
    7878     * <code>primitives</code>. Replies an empty tag collection of <code>primitives</code>
    7979     * is null.
    80      * 
     80     *
    8181     * @param primitives the primitives
    8282     * @return  a tag collection with the tags which are common to all primitives
    8383     */
    84     public static TagCollection commonToAllPrimitives(Collection<? extends OsmPrimitive> primitives) {
     84    public static TagCollection commonToAllPrimitives(Collection<? extends Tagged> primitives) {
    8585        TagCollection tags = new TagCollection();
    8686        if (primitives == null || primitives.isEmpty()) return tags;
    … …  
    9191        // intersect with the others
    9292        //
    93         for (OsmPrimitive primitive: primitives) {
     93        for (Tagged primitive: primitives) {
    9494            if (primitive == null) {
    9595                continue;
    … …  
    103103     * Replies a tag collection with the union of the tags which are common to all primitives in
    104104     * the dataset <code>ds</code>. Returns an empty tag collection of <code>ds</code> is null.
    105      * 
     105     *
    106106     * @param ds the dataset
    107107     * @return a tag collection with the union of the tags which are common to all primitives in
    … …  
    129129     * Creates a clone of the tag collection <code>other</code>. Creats an empty
    130130     * tag collection if <code>other</code> is null.
    131      * 
     131     *
    132132     * @param other the other collection
    133133     */
    … …  
    141141    /**
    142142     * Replies the number of tags in this tag collection
    143      * 
     143     *
    144144     * @return the number of tags in this tag collection
    145145     */
    … …  
    150150    /**
    151151     * Replies true if this tag collection is empty
    152      * 
     152     *
    153153     * @return true if this tag collection is empty; false, otherwise
    154154     */
    … …  
    159159    /**
    160160     * Adds a tag to the tag collection. If <code>tag</code> is null, nothing is added.
    161      * 
     161     *
    162162     * @param tag the tag to add
    163163     */
    … …  
    171171     * Adds a collection of tags to the tag collection. If <code>tags</code> is null, nothing
    172172     * is added. null values in the collection are ignored.
    173      * 
     173     *
    174174     * @param tags the collection of tags
    175175     */
    … …  
    184184     * Adds the tags of another tag collection to this collection. Adds nothing, if
    185185     * <code>tags</code> is null.
    186      * 
     186     *
    187187     * @param tags the other tag collection
    188188     */
    … …  
    195195     * Removes a specific tag from the tag collection. Does nothing if <code>tag</code> is
    196196     * null.
    197      * 
     197     *
    198198     * @param tag the tag to be removed
    199199     */
    … …  
    206206     * Removes a collection of tags from the tag collection. Does nothing if <code>tags</code> is
    207207     * null.
    208      * 
     208     *
    209209     * @param tags the tags to be removed
    210210     */
    … …  
    217217     * Removes all tags in the tag collection <code>tags</code> from the current tag collection.
    218218     * Does nothing if <code>tags</code> is null.
    219      * 
     219     *
    220220     * @param tags the tag collection to be removed.
    221221     */
    … …  
    228228     * Removes all tags whose keys are equal to  <code>key</code>. Does nothing if <code>key</code>
    229229     * is null.
    230      * 
     230     *
    231231     * @param key the key to be removed
    232232     */
    … …  
    244244     * Removes all tags whose key is in the collection <code>keys</code>. Does nothing if
    245245     * <code>keys</code> is null.
    246      * 
     246     *
    247247     * @param keys the collection of keys to be removed
    248248     */
    … …  
    256256    /**
    257257     * Replies true if the this tag collection contains <code>tag</code>.
    258      * 
     258     *
    259259     * @param tag the tag to look up
    260260     * @return true if the this tag collection contains <code>tag</code>; false, otherwise
    … …  
    266266    /**
    267267     * Replies true if this tag collection contains at least one tag with key <code>key</code>.
    268      * 
     268     *
    269269     * @param key the key to look up
    270270     * @return true if this tag collection contains at least one tag with key <code>key</code>; false, otherwise
    … …  
    281281     * Replies true if this tag collection contains all tags in <code>tags</code>. Replies
    282282     * false, if tags is null.
    283      * 
     283     *
    284284     * @param tags the tags to look up
    285285     * @return true if this tag collection contains all tags in <code>tags</code>. Replies
    … …  
    288288    public boolean containsAll(Collection<Tag> tags) {
    289289        if (tags == null) return false;
    290         return tags.containsAll(tags);
     290        return this.tags.containsAll(tags);
    291291    }
    292292
    … …  
    294294     * Replies true if this tag collection at least one tag for every key in <code>keys</code>.
    295295     * Replies false, if <code>keys</code> is null. null values in <code>keys</code> are ignored.
    296      * 
     296     *
    297297     * @param keys the keys to lookup
    298298     * @return true if this tag collection at least one tag for every key in <code>keys</code>.
    … …  
    311311    /**
    312312     * Replies the number of tags with key <code>key</code>
    313      * 
     313     *
    314314     * @param key the key to look up
    315315     * @return the number of tags with key <code>key</code>. 0, if key is null.
    … …  
    328328    /**
    329329     * Replies true if there is at least one tag for the given key.
    330      * 
     330     *
    331331     * @param key the key to look up
    332332     * @return true if there is at least one tag for the given key. false, if key is null.
    … …  
    339339     * Replies true it there is at least one tag with a non empty value for key.
    340340     * Replies false if key is null.
    341      * 
     341     *
    342342     * @param key the key
    343343     * @return true it there is at least one tag with a non empty value for key.
    … …  
    354354     * if the value of this tag is not empty. Replies false if key is
    355355     * null.
    356      * 
     356     *
    357357     * @param key the key
    358358     * @return true if there is exactly one tag for <code>key</code> and
    … …  
    368368     * Replies true if there is a tag with an empty value for <code>key</code>.
    369369     * Replies false, if key is null.
    370      * 
     370     *
    371371     * @param key the key
    372372     * @return true if there is a tag with an empty value for <code>key</code>
    … …  
    381381     * Replies true if there is exactly one tag for <code>key</code> and if
    382382     * the value for this tag is empty. Replies false if key is null.
    383      * 
     383     *
    384384     * @param key the key
    385385     * @return  true if there is exactly one tag for <code>key</code> and if
    … …  
    395395     * Replies a tag collection with the tags for a given key. Replies an empty collection
    396396     * if key is null.
    397      * 
     397     *
    398398     * @param key the key to look up
    399399     * @return a tag collection with the tags for a given key. Replies an empty collection
    … …  
    415415     * Replies a tag collection with all tags whose key is equal to one of the keys in
    416416     * <code>keys</code>. Replies an empty collection if keys is null.
    417      * 
     417     *
    418418     * @param keys the keys to look up
    419419     * @return a tag collection with all tags whose key is equal to one of the keys in
    … …  
    434434    /**
    435435     * Replies the tags of this tag collection as set
    436      * 
     436     *
    437437     * @return the tags of this tag collection as set
    438438     */
    … …  
    444444     * Replies the tags of this tag collection as list.
    445445     * Note that the order of the list is not preserved between method invocations.
    446      * 
     446     *
    447447     * @return the tags of this tag collection as list.
    448448     */
    … …  
    453453    /**
    454454     * Replies an iterator to iterate over the tags in this collection
    455      * 
     455     *
    456456     * @return the iterator
    457457     */
    … …  
    462462    /**
    463463     * Replies the set of keys of this tag collection.
    464      * 
     464     *
    465465     * @return the set of keys of this tag collection
    466466     */
    … …  
    475475    /**
    476476     * Replies the set of keys which have at least 2 matching tags.
    477      * 
     477     *
    478478     * @return the set of keys which have at least 2 matching tags.
    479479     */
    … …  
    496496     * Sets a unique tag for the key of this tag. All other tags with the same key are
    497497     * removed from the collection. Does nothing if tag is null.
    498      * 
     498     *
    499499     * @param tag the tag to set
    500500     */
    … …  
    509509     * removed from the collection. Assume the empty string for key and value if either
    510510     * key or value is null.
    511      * 
     511     *
    512512     * @param key the key
    513513     * @param value the value
    … …  
    520520    /**
    521521     * Replies the set of values in this tag collection
    522      * 
     522     *
    523523     * @return the set of values
    524524     */
    … …  
    534534     * Replies the set of values for a given key. Replies an empty collection if there
    535535     * are no values for the given key.
    536      * 
     536     *
    537537     * @param key the key to look up
    538538     * @return the set of values for a given key. Replies an empty collection if there
    … …  
    552552    /**
    553553     * Replies true if for every key there is one tag only, i.e. exactly one value.
    554      * 
     554     *
    555555     * @return
    556556     */
    … …  
    562562     * Applies this tag collection to an {@see OsmPrimitive}. Does nothing if
    563563     * primitive is null
    564      * 
     564     *
    565565     * @param primitive  the primitive
    566566     * @throws IllegalStateException thrown if this tag collection can't be applied
    567567     * because there are keys with multiple values
    568568     */
    569     public void applyTo(OsmPrimitive primitive) throws IllegalStateException {
     569    public void applyTo(Tagged primitive) throws IllegalStateException {
    570570        if (primitive == null) return;
    571571        if (! isApplicableToPrimitive())
    … …  
    583583     * Applies this tag collection to a collection of {@see OsmPrimitive}s. Does nothing if
    584584     * primitives is null
    585      * 
     585     *
    586586     * @param primitives  the collection of primitives
    587587     * @throws IllegalStateException thrown if this tag collection can't be applied
    588588     * because there are keys with multiple values
    589589     */
    590     public void applyTo(Collection<? extends OsmPrimitive> primitives) throws IllegalStateException{
     590    public void applyTo(Collection<? extends Tagged> primitives) throws IllegalStateException{
    591591        if (primitives == null) return;
    592592        if (! isApplicableToPrimitive())
    593593            throw new IllegalStateException(tr("Tag collection can't be applied to a primitive because there are keys with multiple values."));
    594         for (OsmPrimitive primitive: primitives) {
     594        for (Tagged primitive: primitives) {
    595595            applyTo(primitive);
    596596        }
    … …  
    600600     * Replaces the tags of an {@see OsmPrimitive} by the tags in this collection . Does nothing if
    601601     * primitive is null
    602      * 
     602     *
    603603     * @param primitive  the primitive
    604604     * @throws IllegalStateException thrown if this tag collection can't be applied
    605605     * because there are keys with multiple values
    606606     */
    607     public void replaceTagsOf(OsmPrimitive primitive) throws IllegalStateException {
     607    public void replaceTagsOf(Tagged primitive) throws IllegalStateException {
    608608        if (primitive == null) return;
    609609        if (! isApplicableToPrimitive())
    … …  
    618618     * Replaces the tags of a collection of{@see OsmPrimitive}s by the tags in this collection.
    619619     * Does nothing if primitives is null
    620      * 
     620     *
    621621     * @param primitive  the collection of primitives
    622622     * @throws IllegalStateException thrown if this tag collection can't be applied
    623623     * because there are keys with multiple values
    624624     */
    625     public void replaceTagsOf(Collection<? extends OsmPrimitive> primitives) throws IllegalStateException {
     625    public void replaceTagsOf(Collection<? extends Tagged> primitives) throws IllegalStateException {
    626626        if (primitives == null) return;
    627627        if (! isApplicableToPrimitive())
    628628            throw new IllegalStateException(tr("Tag collection can't be applied to a primitive because there are keys with multiple values."));
    629         for (OsmPrimitive primitive: primitives) {
     629        for (Tagged primitive: primitives) {
    630630            replaceTagsOf(primitive);
    631631        }
    … …  
    634634    /**
    635635     * Builds the intersection of this tag collection and another tag collection
    636      * 
     636     *
    637637     * @param other the other tag collection. If null, replies an empty tag collection.
    638638     * @return the intersection of this tag collection and another tag collection
    … …  
    653653    /**
    654654     * Replies the difference of this tag collection and another tag collection
    655      * 
     655     *
    656656     * @param other the other tag collection. May be null.
    657657     * @return the difference of this tag collection and another tag collection
    … …  
    667667    /**
    668668     * Replies the union of this tag collection and another tag collection
    669      * 
     669     *
    670670     * @param other the other tag collection. May be null.
    671671     * @return the union of this tag collection and another tag collection
    … …  
    690690    /**
    691691     * Replies the concatenation of all tag values (concatenated by a semicolon)
    692      * 
     692     *
    693693     * @return the concatenation of all tag values
    694694     */
    … …  
    707707        return buffer.toString();
    708708    }
     709
     710    @Override
     711    public String toString() {
     712        return tags.toString();
     713    }
    709714}
  • trunk/src/org/openstreetmap/josm/data/osm/Tagged.java

    r2115 r2305  
    66/**
    77 * Objects implement Tagged if they provide a map of key/value pairs.
    8  * 
    9  * 
     8 *
     9 *
    1010 */
    1111// FIXME: better naming? setTags(), getTags(), getKeys() instead of keySet() ?
    … …  
    1414    /**
    1515     * Sets the map of key/value pairs
    16      * 
     16     *
    1717     * @param keys the map of key value pairs. If null, reset to the empty map.
    1818     */
    … …  
    2121    /**
    2222     * Replies the map of key/value pairs. Never null, but may be the empty map.
    23      * 
     23     *
    2424     * @return the map of key/value pairs
    2525     */
    … …  
    2828    /**
    2929     * Sets a key/value pairs
    30      * 
     30     *
    3131     * @param key the key
    3232     * @param value the value. If null, removes the key/value pair.
    … …  
    3636    /**
    3737     * Replies the value of the given key; null, if there is no value for this key
    38      * 
     38     *
    3939     * @param key the key
    4040     * @return the value
    … …  
    4444    /**
    4545     * Removes a given key/value pair
    46      * 
     46     *
    4747     * @param key the key
    4848     */
    … …  
    5151    /**
    5252     * Replies true, if there is at least one key/value pair; false, otherwise
    53      * 
     53     *
    5454     * @return true, if there is at least one key/value pair; false, otherwise
    5555     */
    … …  
    5858    /**
    5959     * Replies the set of keys
    60      * 
     60     *
    6161     * @return the set of keys
    6262     */
    6363    Collection<String> keySet();
     64
     65    /**
     66     * Removes all tags
     67     */
     68    void removeAll();
    6469}
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r2284 r2305  
    196196                newNodes.add(foundNodes.get(nodeId));
    197197            } else {
    198                 newNodes.add(new Node(nodeId, true));
     198                throw new AssertionError("Data consistency problem - way with missing node detected");
    199199            }
    200200        }
  • trunk/src/org/openstreetmap/josm/data/osm/WayData.java

    r2299 r2305  
    99    private final List<Long> nodes = new ArrayList<Long>();
    1010
     11    public WayData() {
     12
     13    }
     14
     15    public WayData(WayData data) {
     16        super(data);
     17        nodes.addAll(data.getNodes());
     18    }
     19
    1120    public List<Long> getNodes() {
    1221        return nodes;
     22    }
     23
     24    @Override
     25    public WayData makeCopy() {
     26        return new WayData(this);
     27    }
     28
     29    @Override
     30    public OsmPrimitive makePrimitive(DataSet dataSet) {
     31        return new Way(this, dataSet);
    1332    }
    1433
Note: See TracChangeset for help on using the changeset viewer.