Changeset 15013 in josm
- Timestamp:
- 2019-04-22T15:00:55+02:00 (6 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UnJoinNodeWayAction.java
r14654 r15013 10 10 import java.util.ArrayList; 11 11 import java.util.Collection; 12 import java.util.HashSet; 12 13 import java.util.LinkedList; 13 14 import java.util.List; … … 89 90 90 91 // I'm sure there's a better way to handle this 91 UndoRedoHandler.getInstance().add(new RemoveNodesCommand(selectedWay, selectedNodes)); 92 UndoRedoHandler.getInstance().add( 93 new RemoveNodesCommand(selectedWay, new HashSet<>(selectedNodes))); 92 94 } 93 95 -
trunk/src/org/openstreetmap/josm/command/ChangeNodesCommand.java
r12726 r15013 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.util.Collection;7 6 import java.util.List; 8 import java.util.Objects;9 10 import javax.swing.Icon;11 7 12 8 import org.openstreetmap.josm.data.osm.DataSet; 13 9 import org.openstreetmap.josm.data.osm.DefaultNameFormatter; 14 10 import org.openstreetmap.josm.data.osm.Node; 15 import org.openstreetmap.josm.data.osm.OsmPrimitive;16 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;17 11 import org.openstreetmap.josm.data.osm.Way; 18 import org.openstreetmap.josm.tools.ImageProvider;19 12 20 13 /** … … 22 15 * The same can be done with ChangeCommand, but this is more 23 16 * efficient. (Needed for the duplicate node fixing 24 * tool of the validator plugin, when processing large data sets.)17 * tool of the validator, when processing large data sets.) 25 18 * 26 19 * @author Imi 27 20 */ 28 public class ChangeNodesCommand extends Command { 29 30 private final Way way; 31 private final List<Node> newNodes; 21 public class ChangeNodesCommand extends AbstractNodesCommand<List<Node>> { 32 22 33 23 /** … … 37 27 */ 38 28 public ChangeNodesCommand(Way way, List<Node> newNodes) { 39 this(way.getDataSet(), way, newNodes);29 super(way.getDataSet(), way, newNodes); 40 30 } 41 31 … … 48 38 */ 49 39 public ChangeNodesCommand(DataSet ds, Way way, List<Node> newNodes) { 50 super(ds); 51 this.way = way; 52 this.newNodes = newNodes; 53 if (newNodes.isEmpty()) { 54 throw new IllegalArgumentException("Cannot set nodes to be an empty list."); 55 } 40 super(ds, way, newNodes); 56 41 } 57 42 58 43 @Override 59 public boolean executeCommand() { 60 super.executeCommand(); 61 way.setNodes(newNodes); 62 way.setModified(true); 63 return true; 64 } 65 66 @Override 67 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 68 modified.add(way); 44 public void modifyWay() { 45 way.setNodes(cmdNodes); 69 46 } 70 47 … … 73 50 return tr("Change nodes of {0}", way.getDisplayName(DefaultNameFormatter.getInstance())); 74 51 } 75 76 @Override77 public Icon getDescriptionIcon() {78 return ImageProvider.get(OsmPrimitiveType.WAY);79 }80 81 @Override82 public int hashCode() {83 return Objects.hash(super.hashCode(), way, newNodes);84 }85 86 @Override87 public boolean equals(Object obj) {88 if (this == obj) return true;89 if (obj == null || getClass() != obj.getClass()) return false;90 if (!super.equals(obj)) return false;91 ChangeNodesCommand that = (ChangeNodesCommand) obj;92 return Objects.equals(way, that.way) &&93 Objects.equals(newNodes, that.newNodes);94 }95 52 } -
trunk/src/org/openstreetmap/josm/command/RemoveNodesCommand.java
r12726 r15013 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.util.Collection;7 6 import java.util.HashSet; 8 7 import java.util.List; 9 import java.util.Objects;10 8 import java.util.Set; 11 9 12 import javax.swing.Icon; 13 10 import org.openstreetmap.josm.data.osm.DataSet; 14 11 import org.openstreetmap.josm.data.osm.DefaultNameFormatter; 15 12 import org.openstreetmap.josm.data.osm.Node; 16 import org.openstreetmap.josm.data.osm.OsmPrimitive;17 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;18 13 import org.openstreetmap.josm.data.osm.Way; 19 import org.openstreetmap.josm.tools.ImageProvider;20 14 21 15 /** … … 26 20 * @author Giuseppe Bilotta 27 21 */ 28 public class RemoveNodesCommand extends Command { 29 30 private final Way way; 31 private final Set<Node> rmNodes; 22 public class RemoveNodesCommand extends AbstractNodesCommand<Set<Node>> { 32 23 33 24 /** … … 35 26 * @param way The way to modify. Must not be null, and belong to a data set 36 27 * @param rmNodes The list of nodes to remove 28 * @deprecated Use {@link #RemoveNodesCommand(Way, Set)} 37 29 */ 30 @Deprecated 38 31 public RemoveNodesCommand(Way way, List<Node> rmNodes) { 39 super(way.getDataSet()); 40 this.way = way; 41 this.rmNodes = new HashSet<>(rmNodes); 32 super(way.getDataSet(), way, new HashSet<>(rmNodes)); 33 } 34 35 /** 36 * Constructs a new {@code RemoveNodesCommand}. 37 * @param way The way to modify. Must not be null, and belong to a data set 38 * @param rmNodes The set of nodes to remove 39 * @since xxx 40 */ 41 public RemoveNodesCommand(Way way, Set<Node> rmNodes) { 42 super(way.getDataSet(), way, rmNodes); 43 } 44 45 /** 46 * Constructs a new {@code RemoveNodesCommand}. 47 * @param ds The target data set. Must not be {@code null} 48 * @param way The way to modify. Must not be null, and belong to a data set 49 * @param rmNodes The list of nodes to remove 50 * @since 15013 51 */ 52 public RemoveNodesCommand(DataSet ds, Way way, Set<Node> rmNodes) { 53 super(ds, way, rmNodes); 42 54 } 43 55 44 56 @Override 45 public boolean executeCommand() { 46 super.executeCommand(); 47 way.removeNodes(rmNodes); 48 way.setModified(true); 49 return true; 50 } 51 52 @Override 53 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 54 modified.add(way); 57 protected void modifyWay() { 58 way.removeNodes(cmdNodes); 55 59 } 56 60 … … 59 63 return tr("Removed nodes from {0}", way.getDisplayName(DefaultNameFormatter.getInstance())); 60 64 } 61 62 @Override63 public Icon getDescriptionIcon() {64 return ImageProvider.get(OsmPrimitiveType.WAY);65 }66 67 @Override68 public int hashCode() {69 return Objects.hash(super.hashCode(), way, rmNodes);70 }71 72 @Override73 public boolean equals(Object obj) {74 if (this == obj) return true;75 if (obj == null || getClass() != obj.getClass()) return false;76 if (!super.equals(obj)) return false;77 RemoveNodesCommand that = (RemoveNodesCommand) obj;78 return Objects.equals(way, that.way) &&79 Objects.equals(rmNodes, that.rmNodes);80 }81 65 } -
trunk/test/unit/org/openstreetmap/josm/command/RemoveNodesCommandTest.java
r13079 r15013 52 52 public void testExecute() { 53 53 RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay, 54 Collections.singleton List(testData.existingNode));54 Collections.singleton(testData.existingNode)); 55 55 56 56 command.executeCommand(); … … 67 67 public void testUndo() { 68 68 RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay, 69 Collections.singleton List(testData.existingNode));69 Collections.singleton(testData.existingNode)); 70 70 71 71 command.executeCommand(); … … 92 92 ArrayList<OsmPrimitive> added = new ArrayList<>(); 93 93 RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay, 94 Collections.singleton List(testData.existingNode));94 Collections.singleton(testData.existingNode)); 95 95 command.fillModifiedData(modified, deleted, added); 96 96 assertArrayEquals(new Object[] {testData.existingWay }, modified.toArray()); … … 105 105 public void testGetParticipatingPrimitives() { 106 106 RemoveNodesCommand command = new RemoveNodesCommand(testData.existingWay, 107 Collections.singleton List(testData.existingNode));107 Collections.singleton(testData.existingNode)); 108 108 command.executeCommand(); 109 109 assertArrayEquals(new Object[] {testData.existingWay }, command.getParticipatingPrimitives().toArray()); … … 115 115 @Test 116 116 public void testDescription() { 117 assertTrue(new RemoveNodesCommand(testData.existingWay, Collections.singleton List(testData.existingNode))117 assertTrue(new RemoveNodesCommand(testData.existingWay, Collections.singleton(testData.existingNode)) 118 118 .getDescriptionText().matches("Removed nodes from .*")); 119 119 } -
trunk/test/unit/org/openstreetmap/josm/gui/io/UploadDialogTest.java
r15010 r15013 280 280 */ 281 281 @Test 282 public void test validateUploadTag() {282 public void testValidateUploadTag() { 283 283 doTestValidateUploadTag("upload.comment"); 284 284 doTestValidateUploadTag("upload.source");
Note:
See TracChangeset
for help on using the changeset viewer.