Changeset 2404 in josm for trunk/src/org


Ignore:
Timestamp:
2009-11-07T20:01:37+01:00 (15 years ago)
Author:
jttt
Message:

Use Dataset.getPrimitiveById() instead of custom looking for primitive in Way.load() and Relation.load()

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  
    4040    private final Map<String, String> keys = new HashMap<String, String>();
    4141    private boolean modified;
    42     private boolean visible;
     42    private boolean visible = true;
    4343    private boolean deleted;
    4444    private long id;
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r2399 r2404  
    33import java.util.ArrayList;
    44import java.util.Collection;
    5 import java.util.HashMap;
    65import java.util.HashSet;
    76import java.util.List;
    8 import java.util.Map;
    97import java.util.Set;
    108
     
    160158        RelationData relationData = (RelationData) data;
    161159
    162         // TODO Make this faster
    163 
    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 
    201160        List<RelationMember> newMembers = new ArrayList<RelationMember>();
    202161        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));
    222166        }
    223167        setMembers(newMembers);
  • trunk/src/org/openstreetmap/josm/data/osm/RelationMemberData.java

    r2399 r2404  
    99
    1010    public RelationMemberData(String role, OsmPrimitiveType type, long id) {
    11         this.role = role;
     11        this.role = role == null?"":role;
    1212        this.memberType = type;
    1313        this.memberId = id;
    1414    }
    1515
    16     public RelationMemberData(String role, OsmPrimitive primitive) {
    17         this(role, OsmPrimitiveType.from(primitive), primitive.getUniqueId());
     16    public RelationMemberData(String role, PrimitiveId primitive) {
     17        this(role, primitive.getType(), primitive.getUniqueId());
    1818    }
    1919
     
    2626    public OsmPrimitiveType getMemberType() {
    2727        return memberType;
     28    }
     29
     30    public boolean hasRole() {
     31        return !"".equals(role);
    2832    }
    2933
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r2399 r2404  
    77import java.util.Arrays;
    88import java.util.Collection;
    9 import java.util.HashMap;
    109import java.util.List;
    11 import java.util.Map;
    1210
    1311import org.openstreetmap.josm.data.osm.visitor.Visitor;
     
    179177        WayData wayData = (WayData) data;
    180178
    181         // TODO We should have some lookup by id mechanism in future to speed this up
    182         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 
    193179        List<Node> newNodes = new ArrayList<Node>(wayData.getNodes().size());
    194180        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);
    198184            } else
    199185                throw new AssertionError("Data consistency problem - way with missing node detected");
Note: See TracChangeset for help on using the changeset viewer.