Changeset 2404 in josm for trunk/src/org
- Timestamp:
- 2009-11-07T20:01:37+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/osm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/PrimitiveData.java
r2399 r2404 40 40 private final Map<String, String> keys = new HashMap<String, String>(); 41 41 private boolean modified; 42 private boolean visible ;42 private boolean visible = true; 43 43 private boolean deleted; 44 44 private long id; -
trunk/src/org/openstreetmap/josm/data/osm/Relation.java
r2399 r2404 3 3 import java.util.ArrayList; 4 4 import java.util.Collection; 5 import java.util.HashMap;6 5 import java.util.HashSet; 7 6 import java.util.List; 8 import java.util.Map;9 7 import java.util.Set; 10 8 … … 160 158 RelationData relationData = (RelationData) data; 161 159 162 // TODO Make this faster163 164 Node nodeMarker = new Node();165 Way wayMarker = new Way();166 Relation relationMarker = new Relation();167 Map<Long, Node> nodes = new HashMap<Long, Node>();168 Map<Long, Way> ways = new HashMap<Long, Way>();169 Map<Long, Relation> relations = new HashMap<Long, Relation>();170 171 for (RelationMemberData member : relationData.getMembers()) {172 switch (member.getMemberType()) {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 }183 }184 185 for (Node node : dataSet.getNodes()) {186 if (nodes.get(node.getUniqueId()) == nodeMarker) {187 nodes.put(node.getUniqueId(), node);188 }189 }190 for (Way way : dataSet.getWays()) {191 if (ways.get(way.getUniqueId()) == wayMarker) {192 ways.put(way.getUniqueId(), way);193 }194 }195 for (Relation relation : dataSet.getRelations()) {196 if (relations.get(relation.getUniqueId()) == relationMarker) {197 relations.put(relation.getUniqueId(), relation);198 }199 }200 201 160 List<RelationMember> newMembers = new ArrayList<RelationMember>(); 202 161 for (RelationMemberData member : relationData.getMembers()) { 203 OsmPrimitive foundMember = null; 204 switch (member.getMemberType()) { 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 } 221 newMembers.add(new RelationMember(member.getRole(), foundMember)); 162 OsmPrimitive primitive = dataSet.getPrimitiveById(member); 163 if (primitive == null) 164 throw new AssertionError("Data consistency problem - relation with missing member detected"); 165 newMembers.add(new RelationMember(member.getRole(), primitive)); 222 166 } 223 167 setMembers(newMembers); -
trunk/src/org/openstreetmap/josm/data/osm/RelationMemberData.java
r2399 r2404 9 9 10 10 public RelationMemberData(String role, OsmPrimitiveType type, long id) { 11 this.role = role ;11 this.role = role == null?"":role; 12 12 this.memberType = type; 13 13 this.memberId = id; 14 14 } 15 15 16 public RelationMemberData(String role, OsmPrimitiveprimitive) {17 this(role, OsmPrimitiveType.from(primitive), primitive.getUniqueId());16 public RelationMemberData(String role, PrimitiveId primitive) { 17 this(role, primitive.getType(), primitive.getUniqueId()); 18 18 } 19 19 … … 26 26 public OsmPrimitiveType getMemberType() { 27 27 return memberType; 28 } 29 30 public boolean hasRole() { 31 return !"".equals(role); 28 32 } 29 33 -
trunk/src/org/openstreetmap/josm/data/osm/Way.java
r2399 r2404 7 7 import java.util.Arrays; 8 8 import java.util.Collection; 9 import java.util.HashMap;10 9 import java.util.List; 11 import java.util.Map;12 10 13 11 import org.openstreetmap.josm.data.osm.visitor.Visitor; … … 179 177 WayData wayData = (WayData) data; 180 178 181 // TODO We should have some lookup by id mechanism in future to speed this up182 Node marker = new Node(0);183 Map<Long, Node> foundNodes = new HashMap<Long, Node>();184 for (Long nodeId : wayData.getNodes()) {185 foundNodes.put(nodeId, marker);186 }187 for (Node node : dataSet.getNodes()) {188 if (foundNodes.get(node.getUniqueId()) == marker) {189 foundNodes.put(node.getUniqueId(), node);190 }191 }192 193 179 List<Node> newNodes = new ArrayList<Node>(wayData.getNodes().size()); 194 180 for (Long nodeId : wayData.getNodes()) { 195 Node node = foundNodes.get(nodeId);196 if (node != marker) {197 newNodes.add( foundNodes.get(nodeId));181 Node node = (Node)dataSet.getPrimitiveById(nodeId, OsmPrimitiveType.NODE); 182 if (node != null) { 183 newNodes.add(node); 198 184 } else 199 185 throw new AssertionError("Data consistency problem - way with missing node detected");
Note:
See TracChangeset
for help on using the changeset viewer.