Changeset 2399 in josm for trunk/src/org
- Timestamp:
- 2009-11-07T14:41:34+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UploadSelectionAction.java
r2381 r2399 2 2 package org.openstreetmap.josm.actions; 3 3 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 … … 21 22 import org.openstreetmap.josm.data.osm.Node; 22 23 import org.openstreetmap.josm.data.osm.OsmPrimitive; 23 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;24 24 import org.openstreetmap.josm.data.osm.Relation; 25 25 import org.openstreetmap.josm.data.osm.Way; … … 33 33 import org.openstreetmap.josm.tools.ExceptionUtil; 34 34 import org.xml.sax.SAXException; 35 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;36 35 37 36 /** … … 326 325 for (OsmPrimitive p: ds.allPrimitives()) { 327 326 if (canceled) return; 328 OsmPrimitive myDeletedParent = layer.data.getPrimitiveById(p .getId(), OsmPrimitiveType.from(p));327 OsmPrimitive myDeletedParent = layer.data.getPrimitiveById(p); 329 328 // our local dataset includes a deleted parent of a primitive we want 330 329 // to delete. Include this parent in the collection of uploaded primitives -
trunk/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java
r2349 r2399 13 13 14 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;16 15 import org.openstreetmap.josm.data.osm.PrimitiveData; 17 16 … … 29 28 30 29 for (PrimitiveData pd:data) { 31 createdPrimitives.add(getLayer().data.getPrimitiveById(pd .getId(), OsmPrimitiveType.fromData(pd), true));30 createdPrimitives.add(getLayer().data.getPrimitiveById(pd, true)); 32 31 } 33 32 … … 41 40 @Override public void undoCommand() { 42 41 for (PrimitiveData p:data) { 43 getLayer().data.removePrimitive(p .getId(), OsmPrimitiveType.fromData(p));42 getLayer().data.removePrimitive(p); 44 43 } 45 44 } … … 47 46 @Override 48 47 public MutableTreeNode description() { 49 48 return new DefaultMutableTreeNode( 50 49 new JLabel(tr("Added {0} objects", data.size()), null, 51 50 JLabel.HORIZONTAL -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r2396 r2399 1 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 2 2 package org.openstreetmap.josm.data.osm; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import java.awt.geom.Area; … … 14 16 import java.util.LinkedList; 15 17 import java.util.List; 18 import java.util.Map; 16 19 import java.util.Set; 17 20 … … 30 33 public class DataSet implements Cloneable { 31 34 35 private static class IdHash implements Hash<PrimitiveId,OsmPrimitive> { 36 37 public int getHashCode(PrimitiveId k) { 38 return (int)k.getUniqueId() ^ k.getType().hashCode(); 39 } 40 41 public boolean equals(PrimitiveId key, OsmPrimitive value) { 42 if (key == null || value == null) return false; 43 return key.getUniqueId() == value.getUniqueId() && key.getType() == value.getType(); 44 } 45 } 46 32 47 /** 33 48 * A list of listeners to selection changed events. The list is static, as listeners register … … 48 63 } 49 64 } 65 66 private Storage<OsmPrimitive> allPrimitives = new Storage<OsmPrimitive>(new IdHash()); 67 private Map<PrimitiveId, OsmPrimitive> primitivesMap = allPrimitives.foreignKey(new IdHash()); 50 68 51 69 /** … … 179 197 */ 180 198 public void addPrimitive(OsmPrimitive primitive) { 199 if (getPrimitiveById(primitive) != null) 200 throw new DataIntegrityProblemException( 201 tr("Unable to add primitive {0} to the dataset because it's already included", primitive.toString())); 202 181 203 if (primitive instanceof Node) { 182 204 nodes.add((Node) primitive); … … 186 208 relations.add((Relation) primitive); 187 209 } 210 allPrimitives.add(primitive); 188 211 } 189 212 190 213 public OsmPrimitive addPrimitive(PrimitiveData data) { 214 OsmPrimitive result; 191 215 if (data instanceof NodeData) { 192 Node node = new Node((NodeData)data, this); 193 nodes.add(node); 194 return node; 216 result = new Node((NodeData)data, this); 195 217 } else if (data instanceof WayData) { 196 Way way = new Way((WayData)data, this); 197 ways.add(way); 198 return way; 218 result = new Way((WayData)data, this); 199 219 } else if (data instanceof RelationData) { 200 Relation relation = new Relation((RelationData)data, this); 201 relations.add(relation); 202 return relation; 220 result = new Relation((RelationData)data, this); 203 221 } else 204 222 throw new AssertionError(); 223 addPrimitive(result); 224 return result; 205 225 } 206 226 … … 214 234 * @param primitive the primitive. Ignored if null. 215 235 */ 216 public void removePrimitive(OsmPrimitive primitive) { 217 if (primitive == null) 236 public void removePrimitive(PrimitiveId primitiveId) { 237 OsmPrimitive primitive = getPrimitiveById(primitiveId); 238 if (primitive == null) { 239 System.out.println("Warning: somebody is trying to remove nonexisting primitive from the Dataset. Action will be ignored. You can report this problem on http://josm.openstreetmap.de"); 240 new Exception().printStackTrace(); 218 241 return; 242 } 219 243 if (primitive instanceof Node) { 220 244 nodes.remove(primitive); … … 225 249 } 226 250 selectedPrimitives.remove(primitive); 227 } 228 229 public void removePrimitive(long id, OsmPrimitiveType type) { 230 removePrimitive(getPrimitiveById(id, type)); 251 allPrimitives.remove(primitive); 231 252 } 232 253 … … 542 563 */ 543 564 public OsmPrimitive getPrimitiveById(long id, OsmPrimitiveType type) { 544 return getPrimitiveById(id, type, false); 545 } 546 547 public OsmPrimitive getPrimitiveById(long id, OsmPrimitiveType type, boolean createNew) { 548 Collection<? extends OsmPrimitive> primitives = null; 549 switch(type) { 550 case NODE: primitives = nodes; break; 551 case WAY: primitives = ways; break; 552 case RELATION: primitives = relations; break; 553 } 554 for (OsmPrimitive primitive : primitives) { 555 if (primitive.getUniqueId() == id) return primitive; 556 } 557 558 if (createNew) { 559 OsmPrimitive result = null; 560 switch (type) { 561 case NODE: result = new Node(id, true); break; 562 case WAY: result = new Way(id, true); break; 563 case RELATION: result = new Relation(id, true); break; 565 return getPrimitiveById(new SimplePrimitiveId(id, type), false); 566 } 567 568 public OsmPrimitive getPrimitiveById(PrimitiveId primitiveId) { 569 return getPrimitiveById(primitiveId, false); 570 } 571 572 public OsmPrimitive getPrimitiveById(PrimitiveId primitiveId, boolean createNew) { 573 OsmPrimitive result = primitivesMap.get(primitiveId); 574 575 if (result == null && createNew) { 576 switch (primitiveId.getType()) { 577 case NODE: result = new Node(primitiveId.getUniqueId(), true); break; 578 case WAY: result = new Way(primitiveId.getUniqueId(), true); break; 579 case RELATION: result = new Relation(primitiveId.getUniqueId(), true); break; 564 580 } 565 581 addPrimitive(result); 566 return result;567 } else 568 return null;582 } 583 584 return result; 569 585 } 570 586 -
trunk/src/org/openstreetmap/josm/data/osm/Node.java
r2363 r2399 139 139 return formatter.format(this); 140 140 } 141 142 public OsmPrimitiveType getType() { 143 return OsmPrimitiveType.NODE; 144 } 141 145 } -
trunk/src/org/openstreetmap/josm/data/osm/NodeData.java
r2305 r2399 59 59 } 60 60 61 public OsmPrimitiveType getType() { 62 return OsmPrimitiveType.NODE; 63 } 64 61 65 } -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r2363 r2399 10 10 import java.util.Date; 11 11 import java.util.HashMap; 12 import java.util.HashSet;13 12 import java.util.LinkedHashSet; 14 13 import java.util.LinkedList; … … 16 15 import java.util.Locale; 17 16 import java.util.Map; 18 import java.util.Set;19 17 import java.util.Map.Entry; 20 18 import java.util.concurrent.atomic.AtomicLong; … … 35 33 * @author imi 36 34 */ 37 abstract public class OsmPrimitive implements Comparable<OsmPrimitive>, Tagged {35 abstract public class OsmPrimitive implements Comparable<OsmPrimitive>, Tagged, PrimitiveId { 38 36 39 37 private static final AtomicLong idCounter = new AtomicLong(0); -
trunk/src/org/openstreetmap/josm/data/osm/PrimitiveData.java
r2305 r2399 15 15 * 16 16 */ 17 public abstract class PrimitiveData implements Tagged {17 public abstract class PrimitiveData implements Tagged, PrimitiveId { 18 18 19 19 // Useful? … … 169 169 } 170 170 171 /** 172 * PrimitiveId implementation. Returns the same value as getId() 173 */ 174 public long getUniqueId() { 175 return id; 176 } 177 171 178 172 179 -
trunk/src/org/openstreetmap/josm/data/osm/Relation.java
r2381 r2399 171 171 for (RelationMemberData member : relationData.getMembers()) { 172 172 switch (member.getMemberType()) { 173 174 175 176 177 178 179 180 181 173 case NODE: 174 nodes.put(member.getMemberId(), nodeMarker); 175 break; 176 case WAY: 177 ways.put(member.getMemberId(), wayMarker); 178 break; 179 case RELATION: 180 relations.put(member.getMemberId(), relationMarker); 181 break; 182 182 } 183 183 } … … 203 203 OsmPrimitive foundMember = null; 204 204 switch (member.getMemberType()) { 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 205 case NODE: 206 foundMember = nodes.get(member.getMemberId()); 207 if (foundMember == nodeMarker) 208 throw new AssertionError("Data consistency problem - relation with missing member detected"); 209 break; 210 case WAY: 211 foundMember = ways.get(member.getMemberId()); 212 if (foundMember == wayMarker) 213 throw new AssertionError("Data consistency problem - relation with missing member detected"); 214 break; 215 case RELATION: 216 foundMember = relations.get(member.getMemberId()); 217 if (foundMember == relationMarker) 218 throw new AssertionError("Data consistency problem - relation with missing member detected"); 219 break; 220 220 } 221 221 newMembers.add(new RelationMember(member.getRole(), foundMember)); … … 340 340 return ret; 341 341 } 342 343 public OsmPrimitiveType getType() { 344 return OsmPrimitiveType.RELATION; 345 } 342 346 } -
trunk/src/org/openstreetmap/josm/data/osm/RelationData.java
r2305 r2399 37 37 } 38 38 39 public OsmPrimitiveType getType() { 40 return OsmPrimitiveType.RELATION; 41 } 42 39 43 } -
trunk/src/org/openstreetmap/josm/data/osm/RelationMember.java
r2285 r2399 7 7 * 8 8 */ 9 public class RelationMember {9 public class RelationMember implements PrimitiveId { 10 10 11 11 /** … … 157 157 return false; 158 158 } 159 160 /** 161 * PrimitiveId implementation. Returns the same value as getMember().getType() 162 */ 163 public OsmPrimitiveType getType() { 164 return member.getType(); 165 } 166 167 /** 168 * PrimitiveId implementation. Returns the same value as getMemberType().getUniqueId() 169 */ 170 public long getUniqueId() { 171 return member.getUniqueId(); 172 } 159 173 } -
trunk/src/org/openstreetmap/josm/data/osm/RelationMemberData.java
r2305 r2399 2 2 package org.openstreetmap.josm.data.osm; 3 3 4 public class RelationMemberData {4 public class RelationMemberData implements PrimitiveId { 5 5 6 6 private final String role; … … 33 33 } 34 34 35 /** 36 * PrimitiveId implementation. Returns the same value as {@link #getMemberType()} 37 */ 38 public OsmPrimitiveType getType() { 39 return memberType; 40 } 41 42 /** 43 * PrimitiveId implementation. Returns the same value as {@link #getMemberId()()} 44 */ 45 public long getUniqueId() { 46 return memberId; 47 } 48 35 49 } -
trunk/src/org/openstreetmap/josm/data/osm/Way.java
r2381 r2399 328 328 return formatter.format(this); 329 329 } 330 331 public OsmPrimitiveType getType() { 332 return OsmPrimitiveType.WAY; 333 } 330 334 } -
trunk/src/org/openstreetmap/josm/data/osm/WayData.java
r2305 r2399 37 37 } 38 38 39 public OsmPrimitiveType getType() { 40 return OsmPrimitiveType.WAY; 41 } 42 39 43 }
Note:
See TracChangeset
for help on using the changeset viewer.