Changeset 2077 in josm for trunk/src/org/openstreetmap/josm/data
- Timestamp:
- 2009-09-07T23:06:19+02:00 (17 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/osm
- Files:
-
- 4 edited
-
DataSet.java (modified) (2 diffs)
-
OsmPrimitiveType.java (modified) (1 diff)
-
Relation.java (modified) (1 diff)
-
Way.java (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r2070 r2077 313 313 * 314 314 * @param id the id, > 0 required 315 * @param type the type of the primitive. Must not be null. 315 316 * @return the primitive 316 317 * @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) { 319 322 if (id <= 0) 320 323 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) { 328 334 if (primitive.getId() == id) return primitive; 329 335 } … … 341 347 for (OsmPrimitive primitive : relations) { 342 348 ret.add(primitive.getId()); 343 }344 return ret;345 }346 347 /**348 * Replies the set of ids of all complete primitives (i.e. those with349 * ! primitive.incomplete)350 *351 * @return the set of ids of all complete primitives352 */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 }369 349 } 370 350 return ret; -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitiveType.java
r1989 r2077 39 39 } 40 40 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 41 50 } -
trunk/src/org/openstreetmap/josm/data/osm/Relation.java
r2070 r2077 112 112 */ 113 113 public Relation() { 114 114 super(0); 115 115 } 116 116 -
trunk/src/org/openstreetmap/josm/data/osm/Way.java
r2070 r2077 3 3 4 4 import java.util.ArrayList; 5 5 6 import java.util.Arrays; 6 7 import java.util.Collection; … … 10 11 import org.openstreetmap.josm.tools.CopyList; 11 12 import org.openstreetmap.josm.tools.Pair; 13 import static org.openstreetmap.josm.tools.I18n.tr; 12 14 13 15 /** … … 123 125 */ 124 126 public Way(){ 127 super(0); 125 128 } 126 129 … … 197 200 } 198 201 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())); 200 213 if (incomplete) return; 201 214 clearCached(); … … 203 216 } 204 217 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())); 207 231 clearCached(); 208 232 nodes.add(offs, n);
Note:
See TracChangeset
for help on using the changeset viewer.
