Changeset 2070 in josm for trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
- Timestamp:
- 2009-09-06T23:07:33+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r2067 r2070 10 10 import java.util.Date; 11 11 import java.util.HashMap; 12 import java.util.HashSet; 13 import java.util.LinkedList; 14 import java.util.List; 12 15 import java.util.Locale; 13 16 import java.util.Map; 17 import java.util.Set; 14 18 import java.util.Map.Entry; 15 19 … … 31 35 abstract public class OsmPrimitive implements Comparable<OsmPrimitive> { 32 36 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 33 60 /* mappaint data */ 34 61 public ElemStyle mappaintStyle = null; … … 70 97 * the respective class. 71 98 * 72 * @deprecated use {@see #getId()} . Don't assign an id, create a primitive with99 * @deprecated use {@see #getId()} and {@see #setId()}. Don't assign an id, create a primitive with 73 100 * the respective constructors. 74 101 */ … … 120 147 121 148 /** 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 /** 122 191 * Sets whether this primitive is selected or not. 123 192 * … … 162 231 * 163 232 * @return <code>true</code>, if the object has been deleted. 164 * @see # delete(boolean)233 * @see #setDeleted(boolean) 165 234 */ 166 235 public boolean isDeleted() { … … 205 274 206 275 /** 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 /** 207 286 * Replies the id of this primitive. 208 287 * … … 214 293 215 294 /** 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 } 222 338 223 339 public void setTimestamp(Date timestamp) { … … 240 356 241 357 /** 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; 252 364 253 365 private static Collection<String> uninteresting = null; … … 288 400 abstract public void visit(Visitor visitor); 289 401 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; 291 411 this.deleted = deleted; 292 setSelected(false); 293 modified = true; 412 this.selected = false; 294 413 } 295 414
Note:
See TracChangeset
for help on using the changeset viewer.