- Timestamp:
- 2020-02-10T20:46:11+01:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/conflict/ConflictCollection.java
r15295 r15832 6 6 import java.util.ArrayList; 7 7 import java.util.Collection; 8 import java.util.HashSet;9 8 import java.util.Iterator; 10 9 import java.util.List; … … 12 11 import java.util.Set; 13 12 import java.util.concurrent.CopyOnWriteArrayList; 13 import java.util.stream.Collectors; 14 14 15 15 import org.openstreetmap.josm.data.osm.Node; … … 69 69 70 70 protected void fireConflictAdded() { 71 for (IConflictListener listener : listeners) { 72 listener.onConflictsAdded(this); 73 } 71 listeners.forEach(listener -> listener.onConflictsAdded(this)); 74 72 } 75 73 76 74 protected void fireConflictRemoved() { 77 for (IConflictListener listener : listeners) { 78 listener.onConflictsRemoved(this); 79 } 75 listeners.forEach(listener -> listener.onConflictsRemoved(this)); 80 76 } 81 77 … … 114 110 public void add(Collection<Conflict<?>> otherConflicts) { 115 111 if (otherConflicts == null) return; 116 for (Conflict<?> c : otherConflicts) { 117 addConflict(c); 118 } 112 otherConflicts.forEach(this::addConflict); 119 113 fireConflictAdded(); 120 114 } … … 146 140 * 147 141 * @param my the primitive 148 */ 142 * @deprecated use {@link #removeForMy(OsmPrimitive)} 143 */ 144 @Deprecated 149 145 public void remove(OsmPrimitive my) { 150 Iterator<Conflict<?>> it = iterator(); 151 while (it.hasNext()) { 152 if (it.next().isMatchingMy(my)) { 153 it.remove(); 154 } 155 } 156 fireConflictRemoved(); 146 removeForMy(my); 157 147 } 158 148 … … 166 156 */ 167 157 public Conflict<?> getConflictForMy(OsmPrimitive my) { 168 for (Conflict<?> c : conflicts) { 169 if (c.isMatchingMy(my)) 170 return c; 171 } 172 return null; 158 return conflicts.stream() 159 .filter(c -> c.isMatchingMy(my)) 160 .findFirst() 161 .orElse(null); 173 162 } 174 163 … … 182 171 */ 183 172 public Conflict<?> getConflictForTheir(OsmPrimitive their) { 184 for (Conflict<?> c : conflicts) { 185 if (c.isMatchingTheir(their)) 186 return c; 187 } 188 return null; 173 return conflicts.stream() 174 .filter(c -> c.isMatchingTheir(their)) 175 .findFirst() 176 .orElse(null); 189 177 } 190 178 … … 225 213 */ 226 214 public void removeForMy(OsmPrimitive my) { 227 Iterator<Conflict<?>> it = iterator(); 228 while (it.hasNext()) { 229 if (it.next().isMatchingMy(my)) { 230 it.remove(); 231 } 215 if (conflicts.removeIf(c -> c.isMatchingMy(my))) { 216 fireConflictRemoved(); 232 217 } 233 218 } … … 239 224 */ 240 225 public void removeForTheir(OsmPrimitive their) { 241 Iterator<Conflict<?>> it = iterator(); 242 while (it.hasNext()) { 243 if (it.next().isMatchingTheir(their)) { 244 it.remove(); 245 } 226 if (conflicts.removeIf(c -> c.isMatchingTheir(their))) { 227 fireConflictRemoved(); 246 228 } 247 229 } … … 290 272 */ 291 273 public void add(ConflictCollection other) { 292 for (Conflict<?> c : other) { 293 if (!hasConflict(c)) { 294 add(c); 295 } 296 } 274 other.conflicts.stream() 275 .filter(c -> !hasConflict(c)) 276 .forEach(this::add); 297 277 } 298 278 … … 305 285 */ 306 286 public Set<OsmPrimitive> getMyConflictParties() { 307 Set<OsmPrimitive> ret = new HashSet<>(); 308 for (Conflict<?> c: conflicts) { 309 ret.add(c.getMy()); 310 } 311 return ret; 287 return conflicts.stream() 288 .map(Conflict::getMy) 289 .collect(Collectors.toSet()); 312 290 } 313 291 … … 320 298 */ 321 299 public Set<OsmPrimitive> getTheirConflictParties() { 322 Set<OsmPrimitive> ret = new HashSet<>(); 323 for (Conflict<?> c: conflicts) { 324 ret.add(c.getTheir()); 325 } 326 return ret; 300 return conflicts.stream() 301 .map(Conflict::getTheir) 302 .collect(Collectors.toSet()); 327 303 } 328 304
Note:
See TracChangeset
for help on using the changeset viewer.