Changeset 11175 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/APIDataSet.java
r10647 r11175 12 12 import java.util.Set; 13 13 import java.util.Stack; 14 import java.util.stream.Collectors; 15 import java.util.stream.Stream; 14 16 15 17 import org.openstreetmap.josm.actions.upload.CyclicUploadDependencyException; … … 57 59 } 58 60 61 /** 62 * Initializes the API data set with the modified primitives, ignores unmodified primitives. 63 * 64 * @param primitives the primitives 65 */ 59 66 public final void init(Collection<OsmPrimitive> primitives) { 60 67 toAdd.clear(); … … 89 96 /** 90 97 * Replies true if one of the primitives to be updated or to be deleted 91 * participates in the conflict <code>conflict</code>92 *93 * @param conflict the conflict94 * @return true if one of the primitives to be updated or to be deleted95 * participates in the conflict <code>conflict</code>96 */97 public boolean participatesInConflict(Conflict<?> conflict) {98 if (conflict == null) return false;99 for (OsmPrimitive p: toUpdate) {100 if (conflict.isParticipating(p)) return true;101 }102 for (OsmPrimitive p: toDelete) {103 if (conflict.isParticipating(p)) return true;104 }105 return false;106 }107 108 /**109 * Replies true if one of the primitives to be updated or to be deleted110 98 * participates in at least one conflict in <code>conflicts</code> 111 99 * … … 116 104 public boolean participatesInConflict(ConflictCollection conflicts) { 117 105 if (conflicts == null || conflicts.isEmpty()) return false; 118 Set<PrimitiveId> idsParticipatingInConflicts = new HashSet<>(); 119 for (OsmPrimitive p: conflicts.getMyConflictParties()) { 120 idsParticipatingInConflicts.add(p.getPrimitiveId()); 121 } 122 for (OsmPrimitive p: conflicts.getTheirConflictParties()) { 123 idsParticipatingInConflicts.add(p.getPrimitiveId()); 124 } 125 for (OsmPrimitive p: toUpdate) { 126 if (idsParticipatingInConflicts.contains(p.getPrimitiveId())) return true; 127 } 128 for (OsmPrimitive p: toDelete) { 129 if (idsParticipatingInConflicts.contains(p.getPrimitiveId())) return true; 130 } 131 return false; 106 Set<PrimitiveId> idsParticipatingInConflicts = conflicts.get().stream() 107 .flatMap(c -> Stream.of(c.getMy(), c.getTheir())) 108 .map(OsmPrimitive::getPrimitiveId) 109 .collect(Collectors.toSet()); 110 return Stream.of(toUpdate, toDelete) 111 .flatMap(Collection::stream) 112 .map(OsmPrimitive::getPrimitiveId) 113 .anyMatch(idsParticipatingInConflicts::contains); 132 114 } 133 115 -
trunk/test/unit/org/openstreetmap/josm/data/osm/APIDataSetTest.java
r10945 r11175 3 3 4 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertFalse; 5 6 import static org.junit.Assert.assertTrue; 6 7 import static org.junit.Assert.fail; … … 12 13 import org.openstreetmap.josm.actions.upload.CyclicUploadDependencyException; 13 14 import org.openstreetmap.josm.data.APIDataSet; 15 import org.openstreetmap.josm.data.conflict.ConflictCollection; 14 16 import org.openstreetmap.josm.testutils.JOSMTestRules; 15 17 … … 104 106 assertEquals(1, toUpdate.size()); 105 107 assertEquals(r4, toUpdate.get(0)); 108 109 final ConflictCollection cc4 = new ConflictCollection(); 110 cc4.add(r4, r4); 111 assertTrue(apiDataSet.participatesInConflict(cc4)); 112 final ConflictCollection cc1 = new ConflictCollection(); 113 cc1.add(r1, r1); 114 assertFalse(apiDataSet.participatesInConflict(cc1)); 106 115 } 107 116
Note:
See TracChangeset
for help on using the changeset viewer.