Changeset 97 in josm for src


Ignore:
Timestamp:
2006-04-23T23:20:33+02:00 (18 years ago)
Author:
imi
Message:
  • fixed merge import of incomplete line segments
Location:
src/org/openstreetmap/josm
Files:
4 edited

Legend:

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

    r94 r97  
    8080
    8181        @Override public boolean realEqual(OsmPrimitive osm) {
    82                 return osm instanceof Segment ?
    83                                 super.realEqual(osm) &&
    84                                 from.equals(((Segment)osm).from) &&
    85                                 to.equals(((Segment)osm).to) : false;
     82                if (!(osm instanceof Segment))
     83                        return super.realEqual(osm);
     84                if (incomplete)
     85                        return ((Segment)osm).incomplete;
     86                return from.equals(((Segment)osm).from) && to.equals(((Segment)osm).to);
    8687        }
    8788
  • src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java

    r86 r97  
    8282         */
    8383        public void visit(Segment other) {
     84                if (other.incomplete)
     85                        return; // won't merge in an incomplete line segment!
     86               
    8487                if (mergeAfterId(mergedSegments, ds.segments, other))
    8588                        return;
     
    252255        }
    253256
     257        /**
     258         * @return <code>true</code>, if no merge is needed.
     259         */
    254260        private <P extends OsmPrimitive> boolean mergeAfterId(Map<P,P> merged, Collection<P> primitives, P other) {
    255261                for (P my : primitives) {
     
    257263                                return true; // no merge needed.
    258264                        if (my.id == other.id) {
     265                                if (my instanceof Segment && ((Segment)my).incomplete)
     266                                        return false; // merge always over an incomplete
    259267                                Date d1 = my.timestamp == null ? new Date(0) : my.timestamp;
    260268                                Date d2 = other.timestamp == null ? new Date(0) : other.timestamp;
  • src/org/openstreetmap/josm/io/OsmServerReader.java

    r95 r97  
    2828        private final double lat2;
    2929        private final double lon2;
    30        
     30
    3131        /**
    3232         * Construct the reader and store the information for attaching
     
    5151                        Collection<Collection<GpsPoint>> data = new LinkedList<Collection<GpsPoint>>();
    5252                        Collection<GpsPoint> list = new LinkedList<GpsPoint>();
    53                        
     53
    5454                        for (int i = 0;;++i) {
     55                                currentAction.setText("Downloading points "+(i*5000)+" to "+((i+1)*5000)+"...");
    5556                                Reader r = getReader(url+i);
    5657                                if (r == null)
     
    7071                                activeConnection = null;
    7172                        }
    72        
     73
    7374                        data.add(list);
    7475                        return data;
  • src/org/openstreetmap/josm/test/MergeVisitorTest.java

    r86 r97  
    1616public class MergeVisitorTest extends TestCase {
    1717
    18        
     18
    1919        private DataSet ds;
    2020        private Node dsNode;
     
    2727                v = new MergeVisitor(ds);
    2828                n = DataSetTestCaseHelper.createNode(null);
    29     }
     29        }
    3030
    3131
     
    101101                ds.segments.add(sold);
    102102                // have a conflicting segment point to the new node
    103                 Segment s = new Segment(n,n);
     103                Segment s = new Segment(n,DataSetTestCaseHelper.createNode(null));
    104104                s.id = 23;
    105105                s.modified = true;
     
    108108                assertEquals(n.timestamp, dsNode.timestamp);
    109109                v.visit(s);
     110                assertEquals(1, v.conflicts.size());
    110111                v.fixReferences();
    111112                assertSame(s.from, dsNode);
    112                 assertSame(s.to, dsNode);
    113113        }
    114        
     114
    115115        public void testNoConflictForSame() {
    116116                dsNode.id = 1;
     
    136136                assertEquals("segment should have been merged.", 1, ds.segments.size());
    137137        }
    138        
     138
     139        /**
     140         * Incomplete segments should always loose.
     141         */
     142        public void testImportIncomplete() throws Exception {
     143                Segment s1 = DataSetTestCaseHelper.createSegment(ds, dsNode, dsNode);
     144                s1.id = 1;
     145                Segment s2 = new Segment(s1);
     146                s1.incomplete = true;
     147                v.visit(s2);
     148                assertTrue(s1.realEqual(s2));
     149        }
     150
     151
    139152        /**
    140153         * Nodes beeing merged are equal but should be the same.
     
    163176                assertSame(ls1.from, ls2.from);
    164177        }
    165        
    166        
     178
     179
    167180        /**
    168181         * Create that amount of nodes and add them to the dataset. The id will be 1,2,3,4...
Note: See TracChangeset for help on using the changeset viewer.