Ignore:
Timestamp:
2009-09-07T23:06:19+02:00 (17 years ago)
Author:
Gubaer
Message:

Had to replace DataSet:getPrimitiveById(id) with DataSet:getPrimitiveById(id,type). Primitive ids are not globally unique, only per type of primitive.
Fixed problems in unit test, available unit tests passing again.

Location:
trunk/src/org/openstreetmap/josm/data/osm
Files:
4 edited

Legend:

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

    r2070 r2077  
    313313     *
    314314     * @param id  the id, > 0 required
     315     * @param type the type of  the primitive. Must not be null.
    315316     * @return the primitive
    316317     * @exception IllegalArgumentException thrown, if id <= 0
    317      */
    318     public OsmPrimitive getPrimitiveById(long id) {
     318     * @exception IllegalArgumentException thrown, if type is null
     319     * @exception IllegalArgumentException thrown, if type is neither NODE, or WAY or RELATION
     320     */
     321    public OsmPrimitive getPrimitiveById(long id, OsmPrimitiveType type) {
    319322        if (id <= 0)
    320323            throw new IllegalArgumentException(tr("parameter {0} > 0 required. Got {1}.", "id", id));
    321         for (OsmPrimitive primitive : nodes) {
    322             if (primitive.getId() == id) return primitive;
    323         }
    324         for (OsmPrimitive primitive : ways) {
    325             if (primitive.getId() == id) return primitive;
    326         }
    327         for (OsmPrimitive primitive : relations) {
     324        if (id <= 0)
     325            throw new IllegalArgumentException(tr("paramete''{0}'' must not be null", "type"));
     326        Collection<? extends OsmPrimitive> primitives = null;
     327        switch(type) {
     328        case NODE: primitives = nodes; break;
     329        case WAY: primitives = ways; break;
     330        case RELATION: primitives = relations; break;
     331        case CHANGESET: throw new IllegalArgumentException(tr("unsupported value ''{0}'' or parameter ''{1}''", type, "type"));
     332        }
     333        for (OsmPrimitive primitive : primitives) {
    328334            if (primitive.getId() == id) return primitive;
    329335        }
     
    341347        for (OsmPrimitive primitive : relations) {
    342348            ret.add(primitive.getId());
    343         }
    344         return ret;
    345     }
    346 
    347     /**
    348      * Replies the set of ids of all complete primitives (i.e. those with
    349      * ! primitive.incomplete)
    350      *
    351      * @return the set of ids of all complete primitives
    352      */
    353     public Set<Long> getCompletePrimitiveIds() {
    354         HashSet<Long> ret = new HashSet<Long>();
    355         for (OsmPrimitive primitive : nodes) {
    356             if (!primitive.incomplete) {
    357                 ret.add(primitive.getId());
    358             }
    359         }
    360         for (OsmPrimitive primitive : ways) {
    361             if (! primitive.incomplete) {
    362                 ret.add(primitive.getId());
    363             }
    364         }
    365         for (OsmPrimitive primitive : relations) {
    366             if (! primitive.incomplete) {
    367                 ret.add(primitive.getId());
    368             }
    369349        }
    370350        return ret;
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitiveType.java

    r1989 r2077  
    3939    }
    4040
     41    public static OsmPrimitiveType from(String value) {
     42        if (value == null) return null;
     43        for (OsmPrimitiveType type: values()){
     44            if (type.getAPIName().equalsIgnoreCase(value))
     45                return type;
     46        }
     47        return null;
     48    }
     49
    4150}
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r2070 r2077  
    112112     */
    113113    public Relation() {
    114 
     114        super(0);
    115115    }
    116116
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r2070 r2077  
    33
    44import java.util.ArrayList;
     5
    56import java.util.Arrays;
    67import java.util.Collection;
     
    1011import org.openstreetmap.josm.tools.CopyList;
    1112import org.openstreetmap.josm.tools.Pair;
     13import static org.openstreetmap.josm.tools.I18n.tr;
    1214
    1315/**
     
    123125     */
    124126    public Way(){
     127        super(0);
    125128    }
    126129
     
    197200    }
    198201
    199     public void addNode(Node n) {
     202    /**
     203     * Adds a node to the end of the list of nodes. Ignored, if n is null.
     204     *
     205     * @param n the node. Ignored, if null.
     206     * @throws IllegalStateException thrown, if this way is marked as incomplete. We can't add a node
     207     * to an incomplete way
     208     */
     209    public void addNode(Node n) throws IllegalStateException {
     210        if (n==null) return;
     211        if (incomplete)
     212            throw new IllegalStateException(tr("can't add node {0} to incomplete way {1}", n.getId(), getId()));
    200213        if (incomplete) return;
    201214        clearCached();
     
    203216    }
    204217
    205     public void addNode(int offs, Node n) {
    206         if (incomplete) return;
     218    /**
     219     * Adds a node at position offs.
     220     *
     221     * @param int offs the offset
     222     * @param n the node. Ignored, if null.
     223     * @throws IllegalStateException thrown, if this way is marked as incomplete. We can't add a node
     224     * to an incomplete way
     225     * @throws IndexOutOfBoundsException thrown if offs is out of bounds
     226     */
     227    public void addNode(int offs, Node n) throws IllegalStateException, IndexOutOfBoundsException {
     228        if (n==null) return;
     229        if (incomplete)
     230            throw new IllegalStateException(tr("can't add node {0} to incomplete way {1}", n.getId(), getId()));
    207231        clearCached();
    208232        nodes.add(offs, n);
Note: See TracChangeset for help on using the changeset viewer.