Ignore:
Timestamp:
2009-09-07T23:06:19+02:00 (15 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.

File:
1 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;
Note: See TracChangeset for help on using the changeset viewer.