Changeset 5401 in josm for trunk/src/org/openstreetmap/josm/actions
- Timestamp:
- 2012-08-06T20:15:36+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java
r5266 r5401 44 44 public class SplitWayAction extends JosmAction { 45 45 46 46 /** 47 * Represents the result of a {@link SplitWayAction} 48 * @see SplitWayAction#splitWay 49 * @see SplitWayAction#split 50 */ 47 51 public static class SplitWayResult { 48 52 private final Command command; … … 51 55 private List<Way> newWays; 52 56 57 /** 58 * @param command The command to be performed to split the way (which is saved for later retrieval by the {@link #getCommand} method) 59 * @param newSelection The new list of selected primitives ids (which is saved for later retrieval by the {@link #getNewSelection} method) 60 * @param originalWay The original way being split (which is saved for later retrieval by the {@link #getOriginalWay} method) 61 * @param newWays The resulting new ways (which is saved for later retrieval by the {@link #getOriginalWay} method) 62 */ 53 63 public SplitWayResult(Command command, List<? extends PrimitiveId> newSelection, Way originalWay, List<Way> newWays) { 54 64 this.command = command; … … 58 68 } 59 69 70 /** 71 * Replies the command to be performed to split the way 72 * @return The command to be performed to split the way 73 */ 60 74 public Command getCommand() { 61 75 return command; 62 76 } 63 77 78 /** 79 * Replies the new list of selected primitives ids 80 * @return The new list of selected primitives ids 81 */ 64 82 public List<? extends PrimitiveId> getNewSelection() { 65 83 return newSelection; 66 84 } 67 85 86 /** 87 * Replies the original way being split 88 * @return The original way being split 89 */ 68 90 public Way getOriginalWay() { 69 91 return originalWay; 70 92 } 71 93 94 /** 95 * Replies the resulting new ways 96 * @return The resulting new ways 97 */ 72 98 public List<Way> getNewWays() { 73 99 return newWays; … … 114 140 } 115 141 116 { // Remove ways that doesn't have selected node in the middle117 Iterator<Way> it =applicableWays.iterator();142 // If several ways have been found, remove ways that doesn't have selected node in the middle 143 if (applicableWays.size() > 1) { 118 144 WAY_LOOP: 119 while (it.hasNext()) {145 for (Iterator<Way> it = applicableWays.iterator(); it.hasNext();) { 120 146 Way w = it.next(); 121 147 for (Node n : selectedNodes) { 122 if(!w.isInnerNode(n)) { 148 if (!w.isInnerNode(n)) { 123 149 it.remove(); 124 150 continue WAY_LOOP; … … 167 193 List<Way> result = new ArrayList<Way>(OsmPrimitive.getFilteredList(selectedNodes.get(0).getReferrers(), Way.class)); 168 194 for (int i=1; i<selectedNodes.size(); i++) { 169 Iterator<Way> it = result.iterator();170 195 List<OsmPrimitive> ref = selectedNodes.get(i).getReferrers(); 171 while (it.hasNext()) {196 for (Iterator<Way> it = result.iterator(); it.hasNext(); ) { 172 197 if (!ref.contains(it.next())) { 173 198 it.remove(); … … 176 201 } 177 202 178 { // Remove broken ways 179 Iterator<Way> it = result.iterator(); 180 while (it.hasNext()) { 181 if (it.next().getNodesCount() <= 2) { 182 it.remove(); 183 } 203 // Remove broken ways 204 for (Iterator<Way> it = result.iterator(); it.hasNext(); ) { 205 if (it.next().getNodesCount() <= 2) { 206 it.remove(); 184 207 } 185 208 } … … 189 212 else { 190 213 // Return only selected ways 191 Iterator<Way> it = result.iterator(); 192 while (it.hasNext()) { 214 for (Iterator<Way> it = result.iterator(); it.hasNext(); ) { 193 215 if (!selectedWays.contains(it.next())) { 194 216 it.remove(); … … 197 219 return result; 198 220 } 199 200 221 } 201 222 … … 277 298 278 299 /** 279 * Splits a way 280 * @param layer 281 * @param way 282 * @param wayChunks 283 * @return 300 * Splits the way {@code way} into chunks of {@code wayChunks} and replies 301 * the result of this process in an instance of {@link SplitWayResult}. 302 * 303 * Note that changes are not applied to the data yet. You have to 304 * submit the command in {@link SplitWayResult#getCommand()} first, 305 * i.e. {@code Main.main.undoredo.add(result.getCommand())}. 306 * 307 * @param layer the layer which the way belongs to. Must not be null. 308 * @param way the way to split. Must not be null. 309 * @param wayChunks the list of way chunks into the way is split. Must not be null. 310 * @param selection The list of currently selected primitives 311 * @return the result from the split operation 284 312 */ 285 313 public static SplitWayResult splitWay(OsmDataLayer layer, Way way, List<List<Node>> wayChunks, Collection<? extends OsmPrimitive> selection) { … … 479 507 * @param way the way to split. Must not be null. 480 508 * @param atNodes the list of nodes where the way is split. Must not be null. 509 * @param selection The list of currently selected primitives 481 510 * @return the result from the split operation 482 511 */ 483 static public SplitWayResult split(OsmDataLayer layer, Way way, List<Node> atNodes, Collection<? extends OsmPrimitive> selection){ 512 static public SplitWayResult split(OsmDataLayer layer, Way way, List<Node> atNodes, Collection<? extends OsmPrimitive> selection) { 484 513 List<List<Node>> chunks = buildSplitChunks(way, atNodes); 485 514 if (chunks == null) return null;
Note:
See TracChangeset
for help on using the changeset viewer.