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

new: rewrite of CombineWay action
new: conflict resolution dialog for CombineWay, including conflicts for different relation memberships
cleanup: cleanup in OsmReader, reduces memory footprint and reduces parsing time
cleanup: made most of the public fields in OsmPrimitive @deprecated, added accessors and changed the code
cleanup: replaced usages of @deprecated constructors for ExtendedDialog
fixed #3208: Combine ways brokes relation order

WARNING: this changeset touches a lot of code all over the code base. "latest" might become slightly unstable in the next days. Also experience incompatibility issues with plugins in the next few days.

File:
1 edited

Legend:

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

    r2067 r2070  
    1010import java.util.Date;
    1111import java.util.HashMap;
     12import java.util.HashSet;
     13import java.util.LinkedList;
     14import java.util.List;
    1215import java.util.Locale;
    1316import java.util.Map;
     17import java.util.Set;
    1418import java.util.Map.Entry;
    1519
     
    3135abstract public class OsmPrimitive implements Comparable<OsmPrimitive> {
    3236
     37    static public <T extends OsmPrimitive>  List<T> getFilteredList(Collection<OsmPrimitive> list, Class<T> type) {
     38        if (list == null) return null;
     39        List<T> ret = new LinkedList<T>();
     40        for(OsmPrimitive p: list) {
     41            if (type.isInstance(p)) {
     42                ret.add(type.cast(p));
     43            }
     44        }
     45        return ret;
     46    }
     47
     48    static public <T extends OsmPrimitive>  Set<T> getFilteredSet(Collection<OsmPrimitive> set, Class<T> type) {
     49        if (set == null) return null;
     50        HashSet<T> ret = new HashSet<T>();
     51        for(OsmPrimitive p: set) {
     52            if (type.isInstance(p)) {
     53                ret.add(type.cast(p));
     54            }
     55        }
     56        return ret;
     57    }
     58
     59
    3360    /* mappaint data */
    3461    public ElemStyle mappaintStyle = null;
     
    7097     * the respective class.
    7198     *
    72      * @deprecated use {@see #getId()}. Don't assign an id, create a primitive with
     99     * @deprecated use {@see #getId()} and {@see #setId()}. Don't assign an id, create a primitive with
    73100     * the respective constructors.
    74101     */
     
    120147
    121148    /**
     149     * If set to true, this object is incomplete, which means only the id
     150     * and type is known (type is the objects instance class)
     151     */
     152    public boolean incomplete = false;
     153
     154    /**
     155     * Contains the version number as returned by the API. Needed to
     156     * ensure update consistency
     157     * @deprecated use {@see #getVersion()} and {@see #setVersion(long)}
     158     */
     159    @Deprecated
     160    public int version = 0;
     161
     162
     163    /**
     164     * Creates a new primitive with id 0.
     165     *
     166     */
     167    public OsmPrimitive() {
     168        this(0);
     169    }
     170
     171    /**
     172     * Creates a new primitive for the given id. If the id > 0, the primitive is marked
     173     * as incomplete.
     174     *
     175     * @param id the id. > 0 required
     176     * @throws IllegalArgumentException thrown if id < 0
     177     */
     178    public OsmPrimitive(long id) throws IllegalArgumentException {
     179        if (id < 0)
     180            throw new IllegalArgumentException(tr("expected id >= 0. Got {0}", id));
     181        this.id = id;
     182        this.version = 0;
     183        this.incomplete = id >0;
     184    }
     185
     186    /* ------------------------------------------------------------------------------------ */
     187    /* accessors                                                                            */
     188    /* ------------------------------------------------------------------------------------ */
     189
     190    /**
    122191     * Sets whether this primitive is selected or not.
    123192     *
     
    162231     *
    163232     * @return <code>true</code>, if the object has been deleted.
    164      * @see #delete(boolean)
     233     * @see #setDeleted(boolean)
    165234     */
    166235    public boolean isDeleted() {
     
    205274
    206275    /**
     276     * Replies the version number as returned by the API. The version is 0 if the id is 0 or
     277     * if this primitive is incomplete.
     278     *
     279     * @see #setVersion(int)
     280     */
     281    public long getVersion() {
     282        return version;
     283    }
     284
     285    /**
    207286     * Replies the id of this primitive.
    208287     *
     
    214293
    215294    /**
    216      * If set to true, this object is highlighted. Currently this is only used to
    217      * show which ways/nodes will connect
    218      */
    219     public volatile boolean highlighted = false;
    220 
    221     private int timestamp;
     295     * Sets the id and the version of this primitive if it is known to the OSM API.
     296     *
     297     * Since we know the id and its version it can't be incomplete anymore. incomplete
     298     * is set to false.
     299     *
     300     * @param id the id. > 0 required
     301     * @param version the version > 0 required
     302     * @throws IllegalArgumentException thrown if id <= 0
     303     * @throws IllegalArgumentException thrown if version <= 0
     304     */
     305    public void setOsmId(long id, int version) {
     306        if (id <= 0)
     307            throw new IllegalArgumentException(tr("id > 0 expected. Got {0}", id));
     308        if (version <= 0)
     309            throw new IllegalArgumentException(tr("version > 0 expected. Got {0}", version));
     310        this.id = id;
     311        this.version = version;
     312        this.incomplete = false;
     313    }
     314
     315    /**
     316     * Clears the id and version known to the OSM API. The id and the version is set to 0.
     317     * incomplete is set to false.
     318     *
     319     * <strong>Caution</strong>: Do not use this method on primitives which are already added to a {@see DataSet}.
     320     * Ways and relations might already refer to the primitive and clearing the OSM ID
     321     * result in corrupt data.
     322     *
     323     * Here's an example use case:
     324     * <pre>
     325     *     // create a clone of an already existing node
     326     *     Node copy = new Node(otherExistingNode);
     327     *
     328     *     // reset the clones OSM id
     329     *     copy.clearOsmId();
     330     * </pre>
     331     *
     332     */
     333    public void clearOsmId() {
     334        this.id = 0;
     335        this.version = 0;
     336        this.incomplete = false;
     337    }
    222338
    223339    public void setTimestamp(Date timestamp) {
     
    240356
    241357    /**
    242      * If set to true, this object is incomplete, which means only the id
    243      * and type is known (type is the objects instance class)
    244      */
    245     public boolean incomplete = false;
    246 
    247     /**
    248      * Contains the version number as returned by the API. Needed to
    249      * ensure update consistency
    250      */
    251     public int version = -1;
     358     * If set to true, this object is highlighted. Currently this is only used to
     359     * show which ways/nodes will connect
     360     */
     361    public volatile boolean highlighted = false;
     362
     363    private int timestamp;
    252364
    253365    private static Collection<String> uninteresting = null;
     
    288400    abstract public void visit(Visitor visitor);
    289401
    290     public final void delete(boolean deleted) {
     402    /**
     403     * Sets whether this primitive is deleted or not.
     404     *
     405     * Also marks this primitive as modified if deleted is true and sets selected to false.
     406     *
     407     * @param deleted  true, if this primitive is deleted; false, otherwise
     408     */
     409    public void setDeleted(boolean deleted) {
     410        this.modified = deleted;
    291411        this.deleted = deleted;
    292         setSelected(false);
    293         modified = true;
     412        this.selected = false;
    294413    }
    295414
Note: See TracChangeset for help on using the changeset viewer.