Changeset 2363 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2009-10-31T19:56:25+01:00 (15 years ago)
Author:
jttt
Message:

Better toString() for OsmPrimitive

Location:
trunk/src/org/openstreetmap/josm/data/osm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/Node.java

    r2284 r2363  
    112112
    113113    @Override public String toString() {
    114         if (coor == null) return "{Node id="+getId()+"}";
    115         return "{Node id="+getId()+",version="+getVersion()+",lat="+coor.lat()+",lon="+coor.lon()+"}";
     114        String coorDesc = coor == null?"":"lat="+coor.lat()+",lon="+coor.lon();
     115        return "{Node id=" + getUniqueId() + " version=" + getVersion() + " " + getFlagsAsString() + " "  + coorDesc+"}";
    116116    }
    117117
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r2341 r2363  
    490490     */
    491491    @Override public boolean equals(Object obj) {
    492         if (isNew()) return obj == this;
    493492        if (obj instanceof OsmPrimitive)
    494493            return ((OsmPrimitive)obj).id == id && obj.getClass() == getClass();
     
    502501     */
    503502    @Override public final int hashCode() {
    504         if (id == 0)
    505             return super.hashCode();
    506503        final int[] ret = new int[1];
    507504        Visitor v = new Visitor(){
     
    512509        };
    513510        visit(v);
    514         return id == 0 ? super.hashCode() : (int)(id<<2)+ret[0];
     511        return (int)(id<<2)+ret[0];
    515512    }
    516513
     
    832829    }
    833830
     831    protected String getFlagsAsString() {
     832
     833        StringBuilder builder = new StringBuilder();
     834
     835        if (isModified()) {
     836            builder.append("M");
     837        }
     838        if (isVisible()) {
     839            builder.append("V");
     840        }
     841        if (isDeleted()) {
     842            builder.append("D");
     843        }
     844        if (isFiltered()) {
     845            builder.append("f");
     846        }
     847
     848        if (isDeleted()) {
     849            builder.append("d");
     850        }
     851
     852        return builder.toString();
     853    }
     854
    834855}
    835856
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r2308 r2363  
    171171        for (RelationMemberData member:relationData.getMembers()) {
    172172            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;
     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;
    182182            }
    183183        }
     
    203203            OsmPrimitive foundMember = null;
    204204            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;
     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;
    220220            }
    221221            newMembers.add(new RelationMember(member.getRole(), foundMember));
     
    234234
    235235    @Override public String toString() {
    236         // return "{Relation id="+id+" version="+version+" members="+Arrays.toString(members.toArray())+"}";
    237         // adding members in string increases memory usage a lot and overflows for looped relations
    238         return "{Relation id="+getId()+" version="+getVersion()+"}";
     236        StringBuilder result = new StringBuilder();
     237        result.append("{Relation id=");
     238        result.append(getUniqueId());
     239        result.append(" version=");
     240        result.append(getVersion());
     241        result.append(" [");
     242        for (RelationMember rm:getMembers()) {
     243            result.append(OsmPrimitiveType.from(rm.getMember()));
     244            result.append(" ");
     245            result.append(rm.getMember().getUniqueId());
     246            result.append(", ");
     247        }
     248        result.delete(result.length()-2, result.length());
     249        result.append("]");
     250        result.append("}");
     251        return result.toString();
    239252    }
    240253
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r2305 r2363  
    173173     * @param dataSet Dataset this way is part of. This parameter will be removed in future
    174174     */
     175    @Override
    175176    public void load(PrimitiveData data, DataSet dataSet) {
    176177        super.load(data, dataSet);
     
    195196            if (node != marker) {
    196197                newNodes.add(foundNodes.get(nodeId));
    197             } else {
     198            } else
    198199                throw new AssertionError("Data consistency problem - way with missing node detected");
    199             }
    200200        }
    201201        setNodes(newNodes);
     
    219219
    220220    @Override public String toString() {
    221         if (incomplete) return "{Way id="+getId()+" version="+getVersion()+" (incomplete)}";
    222         return "{Way id="+getId()+" version="+getVersion()+" nodes="+Arrays.toString(nodes)+"}";
     221        String nodesDesc = incomplete?"(incomplete)":"nodes=" + Arrays.toString(nodes);
     222        return "{Way id=" + getUniqueId() + " version=" + getVersion()+ " " + getFlagsAsString()  + " " + nodesDesc + "}";
    223223    }
    224224
Note: See TracChangeset for help on using the changeset viewer.