- Timestamp:
- 2014-10-29T21:28:16+01:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/command/DeleteCommand.java
r7024 r7675 44 44 /** 45 45 * A command to delete a number of primitives from the dataset. 46 * 46 * @since 23 47 47 */ 48 48 public class DeleteCommand extends Command { … … 60 60 */ 61 61 public DeleteCommand(Collection<? extends OsmPrimitive> data) throws IllegalArgumentException { 62 if (data == null) 63 throw new IllegalArgumentException("Parameter 'data' must not be empty"); 62 CheckParameterUtil.ensureParameterNotNull(data, "data"); 64 63 if (data.isEmpty()) 65 64 throw new IllegalArgumentException(tr("At least one object to delete required, got empty collection")); 66 65 this.toDelete = data; 66 checkConsistency(); 67 67 } 68 68 … … 74 74 */ 75 75 public DeleteCommand(OsmPrimitive data) throws IllegalArgumentException { 76 CheckParameterUtil.ensureParameterNotNull(data, "data"); 77 this.toDelete = Collections.singleton(data); 76 this(Collections.singleton(data)); 78 77 } 79 78 … … 88 87 */ 89 88 public DeleteCommand(OsmDataLayer layer, OsmPrimitive data) throws IllegalArgumentException { 90 super(layer); 91 CheckParameterUtil.ensureParameterNotNull(data, "data"); 92 this.toDelete = Collections.singleton(data); 89 this(layer, Collections.singleton(data)); 93 90 } 94 91 … … 104 101 public DeleteCommand(OsmDataLayer layer, Collection<? extends OsmPrimitive> data) throws IllegalArgumentException{ 105 102 super(layer); 106 if (data == null) 107 throw new IllegalArgumentException("Parameter 'data' must not be empty"); 103 CheckParameterUtil.ensureParameterNotNull(data, "data"); 108 104 if (data.isEmpty()) 109 105 throw new IllegalArgumentException(tr("At least one object to delete required, got empty collection")); 110 106 this.toDelete = data; 107 checkConsistency(); 108 } 109 110 private void checkConsistency() { 111 for (OsmPrimitive p : toDelete) { 112 if (p == null) { 113 throw new IllegalArgumentException("Primitive to delete must not be null"); 114 } else if (p.getDataSet() == null) { 115 throw new IllegalArgumentException("Primitive to delete must be in a dataset"); 116 } 117 } 111 118 } 112 119 … … 231 238 * Delete the primitives and everything they reference. 232 239 * 233 * If a node is deleted, the node and all ways and relations the node is part of are deleted as 234 * well. 235 * 240 * If a node is deleted, the node and all ways and relations the node is part of are deleted as well. 236 241 * If a way is deleted, all relations the way is member of are also deleted. 237 *238 242 * If a way is deleted, only the way and no nodes are deleted. 239 243 * … … 257 261 } 258 262 263 /** 264 * Delete the primitives and everything they reference. 265 * 266 * If a node is deleted, the node and all ways and relations the node is part of are deleted as well. 267 * If a way is deleted, all relations the way is member of are also deleted. 268 * If a way is deleted, only the way and no nodes are deleted. 269 * 270 * @param layer the {@link OsmDataLayer} in whose context primitives are deleted. Must not be null. 271 * @param selection The list of all object to be deleted. 272 * @return command A command to perform the deletions, or null of there is nothing to delete. 273 * @throws IllegalArgumentException thrown if layer is null 274 */ 259 275 public static Command deleteWithReferences(OsmDataLayer layer, Collection<? extends OsmPrimitive> selection) { 260 276 return deleteWithReferences(layer, selection, false); 261 277 } 262 278 279 /** 280 * Try to delete all given primitives. 281 * 282 * If a node is used by a way, it's removed from that way. If a node or a way is used by a 283 * relation, inform the user and do not delete. 284 * 285 * If this would cause ways with less than 2 nodes to be created, delete these ways instead. If 286 * they are part of a relation, inform the user and do not delete. 287 * 288 * @param layer the {@link OsmDataLayer} in whose context the primitives are deleted 289 * @param selection the objects to delete. 290 * @return command a command to perform the deletions, or null if there is nothing to delete. 291 */ 263 292 public static Command delete(OsmDataLayer layer, Collection<? extends OsmPrimitive> selection) { 264 293 return delete(layer, selection, true, false); -
trunk/src/org/openstreetmap/josm/data/osm/Way.java
r7587 r7675 285 285 WayData wayData = (WayData) data; 286 286 287 if (!wayData.getNodes().isEmpty() && getDataSet() == null) { 288 throw new AssertionError("Data consistency problem - way without dataset detected"); 289 } 290 287 291 List<Node> newNodes = new ArrayList<>(wayData.getNodes().size()); 288 292 for (Long nodeId : wayData.getNodes()) { … … 290 294 if (node != null) { 291 295 newNodes.add(node); 292 } else 296 } else { 293 297 throw new AssertionError("Data consistency problem - way with missing node detected"); 298 } 294 299 } 295 300 setNodes(newNodes);
Note:
See TracChangeset
for help on using the changeset viewer.