- Timestamp:
- 2020-03-28T18:22:51+01:00 (5 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r16187 r16212 211 211 } 212 212 for (Way w : copyFrom.getWays()) { 213 Way newWay = new Way(w );213 Way newWay = new Way(w, false, false); 214 214 primMap.put(w, newWay); 215 215 List<Node> newNodes = new ArrayList<>(); … … 224 224 Collection<Relation> relations = copyFrom.getRelations(); 225 225 for (Relation r : relations) { 226 Relation newRelation = new Relation(r); 227 newRelation.setMembers(null); 226 Relation newRelation = new Relation(r, false, false); 228 227 primMap.put(r, newRelation); 229 228 addPrimitive(newRelation); 230 229 } 231 230 for (Relation r : relations) { 232 Relation newRelation = (Relation) primMap.get(r); 233 newRelation.setMembers(r.getMembers().stream() 231 ((Relation) primMap.get(r)).setMembers(r.getMembers().stream() 234 232 .map(rm -> new RelationMember(rm.getRole(), primMap.get(rm.getMember()))) 235 233 .collect(Collectors.toList())); -
trunk/src/org/openstreetmap/josm/data/osm/Node.java
r16077 r16212 221 221 222 222 @Override 223 public void cloneFrom(OsmPrimitive osm ) {223 public void cloneFrom(OsmPrimitive osm, boolean copyChildren) { 224 224 if (!(osm instanceof Node)) 225 225 throw new IllegalArgumentException("Not a node: " + osm); 226 226 boolean locked = writeLock(); 227 227 try { 228 super.cloneFrom(osm );228 super.cloneFrom(osm, copyChildren); 229 229 setCoor(((Node) osm).getCoor()); 230 230 } finally { -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r16077 r16212 883 883 * @param other other primitive 884 884 */ 885 public void cloneFrom(OsmPrimitive other) { 885 public final void cloneFrom(OsmPrimitive other) { 886 cloneFrom(other, true); 887 } 888 889 /** 890 * Get and write all attributes from the parameter. Does not fire any listener, so 891 * use this only in the data initializing phase 892 * @param other other primitive 893 * @param copyChildren whether to copy child primitives too 894 * @since 16212 895 */ 896 protected void cloneFrom(OsmPrimitive other, boolean copyChildren) { 886 897 // write lock is provided by subclasses 887 898 if (id != other.id && dataSet != null) -
trunk/src/org/openstreetmap/josm/data/osm/Relation.java
r15820 r16212 199 199 * @param clearMetadata If {@code true}, clears the OSM id and other metadata as defined by {@link #clearOsmMetadata}. 200 200 * If {@code false}, does nothing 201 */ 202 public Relation(Relation clone, boolean clearMetadata) { 201 * @param copyMembers whether to copy relation members too 202 * @since 16212 203 */ 204 public Relation(Relation clone, boolean clearMetadata, boolean copyMembers) { 203 205 super(clone.getUniqueId(), true); 204 cloneFrom(clone );206 cloneFrom(clone, copyMembers); 205 207 if (clearMetadata) { 206 208 clearOsmMetadata(); 207 209 } 210 } 211 212 /** 213 * Constructs an identical clone of the argument. 214 * @param clone The relation to clone 215 * @param clearMetadata If {@code true}, clears the OSM id and other metadata as defined by {@link #clearOsmMetadata}. 216 * If {@code false}, does nothing 217 */ 218 public Relation(Relation clone, boolean clearMetadata) { 219 this(clone, clearMetadata, true); 208 220 } 209 221 … … 237 249 238 250 @Override 239 public void cloneFrom(OsmPrimitive osm ) {251 public void cloneFrom(OsmPrimitive osm, boolean copyMembers) { 240 252 if (!(osm instanceof Relation)) 241 253 throw new IllegalArgumentException("Not a relation: " + osm); 242 254 boolean locked = writeLock(); 243 255 try { 244 super.cloneFrom(osm); 245 // It's not necessary to clone members as RelationMember class is immutable 246 setMembers(((Relation) osm).getMembers()); 256 super.cloneFrom(osm, copyMembers); 257 if (copyMembers) { 258 // It's not necessary to clone members as RelationMember class is immutable 259 setMembers(((Relation) osm).getMembers()); 260 } 247 261 } finally { 248 262 writeUnlock(locked); -
trunk/src/org/openstreetmap/josm/data/osm/Way.java
r15820 r16212 204 204 * @param clearMetadata If {@code true}, clears the OSM id and other metadata as defined by {@link #clearOsmMetadata}. 205 205 * If {@code false}, does nothing 206 * @since 2410 207 */ 208 public Way(Way original, boolean clearMetadata) { 206 * @param copyNodes whether to copy nodes too 207 * @since 16212 208 */ 209 public Way(Way original, boolean clearMetadata, boolean copyNodes) { 209 210 super(original.getUniqueId(), true); 210 cloneFrom(original );211 cloneFrom(original, copyNodes); 211 212 if (clearMetadata) { 212 213 clearOsmMetadata(); 213 214 } 215 } 216 217 /** 218 * Constructs a new {@code Way} from an existing {@code Way}. 219 * @param original The original {@code Way} to be identically cloned. Must not be null 220 * @param clearMetadata If {@code true}, clears the OSM id and other metadata as defined by {@link #clearOsmMetadata}. 221 * If {@code false}, does nothing 222 * @since 2410 223 */ 224 public Way(Way original, boolean clearMetadata) { 225 this(original, clearMetadata, true); 214 226 } 215 227 … … 286 298 287 299 @Override 288 public void cloneFrom(OsmPrimitive osm ) {300 public void cloneFrom(OsmPrimitive osm, boolean copyNodes) { 289 301 if (!(osm instanceof Way)) 290 302 throw new IllegalArgumentException("Not a way: " + osm); 291 303 boolean locked = writeLock(); 292 304 try { 293 super.cloneFrom(osm); 294 Way otherWay = (Way) osm; 295 setNodes(otherWay.getNodes()); 305 super.cloneFrom(osm, copyNodes); 306 if (copyNodes) { 307 setNodes(((Way) osm).getNodes()); 308 } 296 309 } finally { 297 310 writeUnlock(locked); -
trunk/test/unit/org/openstreetmap/josm/data/osm/DataSetTest.java
r15891 r16212 316 316 new DataSet().mergeFrom(ds); 317 317 } 318 319 /** 320 * Checks that a read-only dataset can be cloned. 321 */ 322 @Test 323 public void testCloneReadOnly() { 324 DataSet ds = new DataSet(); 325 Node n1 = new Node(LatLon.SOUTH_POLE); 326 Node n2 = new Node(LatLon.NORTH_POLE); 327 ds.addPrimitive(n1); 328 ds.addPrimitive(n2); 329 Way w = new Way(); 330 w.setNodes(Arrays.asList(n1, n2)); 331 ds.addPrimitive(w); 332 Relation r = new Relation(); 333 r.setMembers(Arrays.asList(new RelationMember(null, w))); 334 ds.addPrimitive(r); 335 ds.lock(); 336 337 DataSet copy = new DataSet(ds); 338 339 assertEquals(4, copy.allPrimitives().size()); 340 assertTrue(copy.isLocked()); 341 } 318 342 }
Note:
See TracChangeset
for help on using the changeset viewer.