protected Way parseWay() throws XMLStreamException { WayData wd = new WayData(); readCommon(wd); Way w = new Way(wd.getId(), wd.getVersion()); w.setVisible(wd.isVisible()); w.load(wd); externalIdMap.put(wd.getPrimitiveId(), w); Collection<Long> nodeIds = new ArrayList<Long>(); while (true) { int event = parser.next(); if (event == XMLStreamConstants.START_ELEMENT) { if (parser.getLocalName().equals("nd")) { nodeIds.add(parseWayNode(w)); } else if (parser.getLocalName().equals("tag")) { parseTag(w); } else { parseUnknown(); } } else if (event == XMLStreamConstants.END_ELEMENT) { break; } } if (w.isDeleted() && nodeIds.size() > 0) { System.out.println(tr("Deleted way {0} contains nodes", w.getUniqueId())); nodeIds = new ArrayList<Long>(); } ways.put(wd.getUniqueId(), nodeIds); return w; }
/** * their way is not visible anymore. * * <p>=> conflict */ @Test public void waySimple_TheirVersionNotVisibleMyIsModified() { Node mn1 = new Node(new LatLon(0, 0)); mn1.setOsmId(1, 1); my.addPrimitive(mn1); Node mn2 = new Node(new LatLon(1, 1)); mn2.setOsmId(2, 1); my.addPrimitive(mn2); Way myWay = new Way(); myWay.setOsmId(3, 1); myWay.addNode(mn1); myWay.addNode(mn2); myWay.setModified(true); my.addPrimitive(myWay); Way theirWay = new Way(); theirWay.setOsmId(3, 2); theirWay.setVisible(false); /* Invisible objects fetched from the server should be marked as "deleted". * Otherwise it's an error. */ theirWay.setDeleted(true); their.addPrimitive(theirWay); DataSetMerger visitor = new DataSetMerger(my, their); visitor.merge(); Way merged = (Way) my.getPrimitiveById(3, OsmPrimitiveType.WAY); assertEquals(1, visitor.getConflicts().size()); assertTrue(visitor.getConflicts().hasConflictForMy(myWay)); assertTrue(visitor.getConflicts().hasConflictForTheir(theirWay)); assertEquals(myWay, merged); }