Changeset 12726 in josm
- Timestamp:
- 2017-09-04T23:45:49+02:00 (7 years ago)
- Location:
- trunk
- Files:
-
- 67 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java
r12641 r12726 12 12 import org.openstreetmap.josm.command.AddCommand; 13 13 import org.openstreetmap.josm.data.coor.LatLon; 14 import org.openstreetmap.josm.data.osm.DataSet; 14 15 import org.openstreetmap.josm.data.osm.Node; 15 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 66 67 67 68 // add the node 68 MainApplication.undoRedo.add(new AddCommand(nnew)); 69 getLayerManager().getEditDataSet().setSelected(nnew); 69 DataSet ds = getLayerManager().getEditDataSet(); 70 MainApplication.undoRedo.add(new AddCommand(ds, nnew)); 71 ds.setSelected(nnew); 70 72 MapView mapView = MainApplication.getMap().mapView; 71 73 if (mapView != null && !mapView.getRealBounds().contains(nnew.getCoor())) { -
trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java
r12641 r12726 25 25 import org.openstreetmap.josm.data.coor.EastNorth; 26 26 import org.openstreetmap.josm.data.coor.LatLon; 27 import org.openstreetmap.josm.data.osm.DataSet; 27 28 import org.openstreetmap.josm.data.osm.Node; 28 29 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 137 138 } 138 139 139 Collection<OsmPrimitive> sel = getLayerManager().getEditDataSet().getSelected(); 140 DataSet ds = getLayerManager().getEditDataSet(); 141 Collection<OsmPrimitive> sel = ds.getSelected(); 140 142 List<Node> nodes = OsmPrimitive.getFilteredList(sel, Node.class); 141 143 List<Way> ways = OsmPrimitive.getFilteredList(sel, Way.class); … … 222 224 Node n = new Node(ll); 223 225 nodesToAdd.add(n); 224 cmds.add(new AddCommand( n));226 cmds.add(new AddCommand(ds, n)); 225 227 } 226 228 } … … 234 236 Way newWay = new Way(); 235 237 newWay.setNodes(nodesToAdd); 236 cmds.add(new AddCommand( newWay));238 cmds.add(new AddCommand(ds, newWay)); 237 239 } else { 238 240 Way newWay = new Way(existingWay); 239 241 newWay.setNodes(nodesToAdd); 240 cmds.add(new ChangeCommand( existingWay, newWay));242 cmds.add(new ChangeCommand(ds, existingWay, newWay)); 241 243 } 242 244 -
trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java
r12641 r12726 248 248 final String commandName; 249 249 if (existingRelation == null) { 250 list.add(new AddCommand( relation));250 list.add(new AddCommand(selectedWays.iterator().next().getDataSet(), relation)); 251 251 commandName = getName(false); 252 252 } else { -
trunk/src/org/openstreetmap/josm/actions/FollowLineAction.java
r12641 r12726 15 15 import org.openstreetmap.josm.command.SelectCommand; 16 16 import org.openstreetmap.josm.command.SequenceCommand; 17 import org.openstreetmap.josm.data.osm.DataSet; 17 18 import org.openstreetmap.josm.data.osm.Node; 18 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 20 21 import org.openstreetmap.josm.gui.MainApplication; 21 22 import org.openstreetmap.josm.gui.MapFrame; 22 import org.openstreetmap.josm.gui.layer.OsmDataLayer;23 23 import org.openstreetmap.josm.tools.Shortcut; 24 24 import org.openstreetmap.josm.tools.Utils; … … 61 61 @Override 62 62 public void actionPerformed(ActionEvent evt) { 63 OsmDataLayer osmLayer = getLayerManager().getEditLayer();64 if ( osmLayer== null)63 DataSet ds = getLayerManager().getEditDataSet(); 64 if (ds == null) 65 65 return; 66 66 MapFrame map = MainApplication.getMap(); 67 67 if (!(map.mapMode instanceof DrawAction)) return; // We are not on draw mode 68 68 69 Collection<Node> selectedPoints = osmLayer.data.getSelectedNodes();70 Collection<Way> selectedLines = osmLayer.data.getSelectedWays();69 Collection<Node> selectedPoints = ds.getSelectedNodes(); 70 Collection<Way> selectedLines = ds.getSelectedWays(); 71 71 if ((selectedPoints.size() > 1) || (selectedLines.size() != 1)) // Unsuitable selection 72 72 return; … … 115 115 } 116 116 MainApplication.undoRedo.add(new SequenceCommand(tr("Follow line"), 117 new ChangeCommand( follower, newFollower),118 new SelectCommand( newFollower.isClosed() // see #10028 - unselect last node when closing a way117 new ChangeCommand(ds, follower, newFollower), 118 new SelectCommand(ds, newFollower.isClosed() // see #10028 - unselect last node when closing a way 119 119 ? Arrays.<OsmPrimitive>asList(follower) 120 120 : Arrays.<OsmPrimitive>asList(follower, newPoint) -
trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java
r12641 r12726 24 24 import org.openstreetmap.josm.command.SequenceCommand; 25 25 import org.openstreetmap.josm.data.coor.EastNorth; 26 import org.openstreetmap.josm.data.osm.DataSet; 26 27 import org.openstreetmap.josm.data.osm.Node; 27 28 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 84 85 if (!isEnabled()) 85 86 return; 86 Collection<Node> selectedNodes = getLayerManager().getEditDataSet().getSelectedNodes(); 87 DataSet ds = getLayerManager().getEditDataSet(); 88 Collection<Node> selectedNodes = ds.getSelectedNodes(); 87 89 Collection<Command> cmds = new LinkedList<>(); 88 90 Map<Way, MultiMap<Integer, Node>> data = new HashMap<>(); 89 91 90 92 // If the user has selected some ways, only join the node to these. 91 boolean restrictToSelectedWays = 92 !getLayerManager().getEditDataSet().getSelectedWays().isEmpty(); 93 boolean restrictToSelectedWays = !ds.getSelectedWays().isEmpty(); 93 94 94 95 // Planning phase: decide where we'll insert the nodes and put it all in "data" … … 155 156 Way wnew = new Way(w); 156 157 wnew.setNodes(wayNodes); 157 cmds.add(new ChangeCommand( w, wnew));158 cmds.add(new ChangeCommand(ds, w, wnew)); 158 159 } 159 160 -
trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java
r12641 r12726 157 157 corrCmds = (new ReverseWayTagCorrector()).execute(w, wnew); 158 158 } 159 return new ReverseWayResult(wnew, corrCmds, new ChangeCommand(w .getDataSet(), w, wnew));159 return new ReverseWayResult(wnew, corrCmds, new ChangeCommand(w, wnew)); 160 160 } 161 161 -
trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java
r12718 r12726 593 593 final Way changedWay = new Way(way); 594 594 changedWay.setNodes(wayToKeep.getNodes()); 595 commandList.add(new ChangeCommand(way .getDataSet(), way, changedWay));595 commandList.add(new ChangeCommand(way, changedWay)); 596 596 if (!isMapModeDraw && !newSelection.contains(way)) { 597 597 newSelection.add(way); -
trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java
r12663 r12726 303 303 304 304 List<Command> cmds = new LinkedList<>(); 305 cmds.add(new AddCommand( n));305 cmds.add(new AddCommand(selectedNode.getDataSet(), n)); 306 306 if (dialog != null) { 307 307 dialog.update(selectedNode, Collections.singletonList(n), cmds); … … 440 440 Node newNode = new Node(originalNode, true /* clear OSM ID */); 441 441 newNodes.add(newNode); 442 cmds.add(new AddCommand( newNode));442 cmds.add(new AddCommand(originalNode.getDataSet(), newNode)); 443 443 444 444 List<Node> nn = new ArrayList<>(); … … 583 583 if (seen) { 584 584 Node newNode = new Node(n, true /* clear OSM ID */); 585 cmds.add(new AddCommand( newNode));585 cmds.add(new AddCommand(selectedNode.getDataSet(), newNode)); 586 586 newNodes.add(newNode); 587 587 addNodes.add(newNode); -
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r12643 r12726 487 487 return; 488 488 } 489 cmds.add(new AddCommand( n));489 cmds.add(new AddCommand(ds, n)); 490 490 491 491 if (!ctrl) { … … 576 576 way = new Way(); 577 577 way.addNode(n0); 578 cmds.add(new AddCommand( way));578 cmds.add(new AddCommand(ds, way)); 579 579 wayToSelect = way; 580 580 } else { -
trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
r12689 r12726 40 40 import org.openstreetmap.josm.data.coor.EastNorth; 41 41 import org.openstreetmap.josm.data.osm.DataIntegrityProblemException; 42 import org.openstreetmap.josm.data.osm.DataSet; 42 43 import org.openstreetmap.josm.data.osm.Node; 43 44 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 592 593 Way wnew = new Way(ws.way); 593 594 wnew.addNode(ws.lowerIndex+1, n); 594 SequenceCommand cmds = new SequenceCommand(tr("Add a new node to an existing way"),595 new AddCommand(n), new ChangeCommand(ws.way, wnew));596 MainApplication.undoRedo.add(cmds);595 DataSet ds = ws.way.getDataSet(); 596 MainApplication.undoRedo.add(new SequenceCommand(tr("Add a new node to an existing way"), 597 new AddCommand(ds, n), new ChangeCommand(ds, ws.way, wnew))); 597 598 } 598 599 } … … 603 604 private void createNewRectangle() { 604 605 if (selectedSegment == null) return; 605 // crete a new rectangle 606 DataSet ds = getLayerManager().getEditDataSet(); 607 // create a new rectangle 606 608 Collection<Command> cmds = new LinkedList<>(); 607 609 Node third = new Node(newN2en); … … 618 620 wnew.addNode(selectedSegment.getFirstNode()); 619 621 // undo support 620 cmds.add(new AddCommand( third));622 cmds.add(new AddCommand(ds, third)); 621 623 if (!dualAlignSegmentCollapsed) { 622 cmds.add(new AddCommand( fourth));623 } 624 cmds.add(new AddCommand( wnew));624 cmds.add(new AddCommand(ds, fourth)); 625 } 626 cmds.add(new AddCommand(ds, wnew)); 625 627 Command c = new SequenceCommand(tr("Extrude Way"), cmds); 626 628 MainApplication.undoRedo.add(c); 627 getLayerManager().getEditDataSet().setSelected(wnew);629 ds.setSelected(wnew); 628 630 } 629 631 … … 634 636 */ 635 637 private void performExtrusion() { 638 DataSet ds = getLayerManager().getEditDataSet(); 636 639 // create extrusion 637 640 Collection<Command> cmds = new LinkedList<>(); … … 661 664 wnew.removeNode(n1Old); 662 665 wayWasModified = true; 663 cmds.add(new AddCommand( n1New));666 cmds.add(new AddCommand(ds, n1New)); 664 667 changedNodes.add(n1New); 665 668 } else { … … 669 672 wayWasModified = true; 670 673 insertionPoint++; 671 cmds.add(new AddCommand( n1New));674 cmds.add(new AddCommand(ds, n1New)); 672 675 changedNodes.add(n1New); 673 676 } … … 691 694 wnew.removeNode(n2Old); 692 695 wayWasModified = true; 693 cmds.add(new AddCommand( n2New));696 cmds.add(new AddCommand(ds, n2New)); 694 697 changedNodes.add(n2New); 695 698 } else { … … 698 701 wnew.addNode(insertionPoint, n2New); 699 702 wayWasModified = true; 700 cmds.add(new AddCommand( n2New));703 cmds.add(new AddCommand(ds, n2New)); 701 704 changedNodes.add(n2New); 702 705 } -
trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java
r12718 r12726 399 399 } 400 400 401 DataSet ds = getLayerManager().getEditDataSet(); 401 402 updateKeyModifiers(e); 402 403 mousePos = e.getPoint(); … … 404 405 if (state == State.SELECTING) { 405 406 if (targetWay != null) { 406 getLayerManager().getEditDataSet().setSelected(targetWay.getPrimitiveId());407 ds.setSelected(targetWay.getPrimitiveId()); 407 408 updateStateByCurrentSelection(); 408 409 } … … 425 426 Node virtualNode = new Node(mv.getEastNorth(mousePos.x, 426 427 mousePos.y)); 427 virtualCmds.add(new AddCommand( virtualNode));428 virtualCmds.add(new AddCommand(ds, virtualNode)); 428 429 429 430 // Looking for candidateSegment copies in ways that are -
trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWays.java
r12641 r12726 11 11 import java.util.Set; 12 12 13 import org.openstreetmap.josm.Main; 13 14 import org.openstreetmap.josm.command.AddCommand; 14 15 import org.openstreetmap.josm.command.Command; 15 16 import org.openstreetmap.josm.command.SequenceCommand; 16 17 import org.openstreetmap.josm.data.coor.EastNorth; 18 import org.openstreetmap.josm.data.osm.DataSet; 17 19 import org.openstreetmap.josm.data.osm.Node; 18 20 import org.openstreetmap.josm.data.osm.NodeGraph; … … 186 188 187 189 private List<Command> makeAddWayAndNodesCommandList() { 190 DataSet ds = Main.main.getEditDataSet(); 188 191 List<Command> commands = new ArrayList<>(sortedNodes.size() + ways.size()); 189 192 for (int i = 0; i < sortedNodes.size() - (isClosedPath() ? 1 : 0); i++) { 190 commands.add(new AddCommand( sortedNodes.get(i)));193 commands.add(new AddCommand(ds, sortedNodes.get(i))); 191 194 } 192 195 for (Way w : ways) { 193 commands.add(new AddCommand( w));196 commands.add(new AddCommand(ds, w)); 194 197 } 195 198 return commands; -
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r12641 r12726 1235 1235 1236 1236 private void createMiddleNodeFromVirtual(EastNorth currentEN) { 1237 DataSet ds = getLayerManager().getEditDataSet(); 1237 1238 Collection<Command> virtualCmds = new LinkedList<>(); 1238 virtualCmds.add(new AddCommand( virtualNode));1239 virtualCmds.add(new AddCommand(ds, virtualNode)); 1239 1240 for (WaySegment virtualWay : virtualWays) { 1240 1241 Way w = virtualWay.way; 1241 1242 Way wnew = new Way(w); 1242 1243 wnew.addNode(virtualWay.lowerIndex + 1, virtualNode); 1243 virtualCmds.add(new ChangeCommand( w, wnew));1244 virtualCmds.add(new ChangeCommand(ds, w, wnew)); 1244 1245 } 1245 1246 virtualCmds.add(new MoveCommand(virtualNode, startEN, currentEN)); … … 1248 1249 virtualWays.size()); 1249 1250 MainApplication.undoRedo.add(new SequenceCommand(text, virtualCmds)); 1250 getLayerManager().getEditDataSet().setSelected(Collections.singleton((OsmPrimitive) virtualNode));1251 ds.setSelected(Collections.singleton((OsmPrimitive) virtualNode)); 1251 1252 clear(); 1252 1253 } -
trunk/src/org/openstreetmap/josm/command/AddCommand.java
r12718 r12726 36 36 * Creates the command and specify the element to add in the context of the current edit layer, if any. 37 37 * @param osm The primitive to add 38 * @deprecated to be removed end of 2017. Use {@link #AddCommand(DataSet, OsmPrimitive)} instead 38 39 */ 40 @Deprecated 39 41 public AddCommand(OsmPrimitive osm) { 40 42 this.osm = Objects.requireNonNull(osm, "osm"); -
trunk/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java
r12718 r12726 39 39 * Constructs a new {@code AddPrimitivesCommand} to add data to the current edit layer. 40 40 * @param data The OSM primitives data to add. Must not be {@code null} 41 */ 41 * @deprecated to be removed end of 2017. Use {@link #AddPrimitivesCommand(List, DataSet)} instead 42 */ 43 @Deprecated 42 44 public AddPrimitivesCommand(List<PrimitiveData> data) { 43 45 this(data, data); … … 49 51 * @param toSelect The OSM primitives to select at the end. Can be {@code null} 50 52 * @since 5953 51 */ 53 * @deprecated to be removed end of 2017. Use {@link #AddPrimitivesCommand(List, List, DataSet)} instead 54 */ 55 @Deprecated 52 56 public AddPrimitivesCommand(List<PrimitiveData> data, List<PrimitiveData> toSelect) { 53 57 init(data, toSelect); … … 77 81 super(ds); 78 82 init(data, toSelect); 83 } 84 85 /** 86 * Constructs a new {@code AddPrimitivesCommand} to add data to the given data set. 87 * @param data The OSM primitives data to add and select. Must not be {@code null} 88 * @param ds The target data set. Must not be {@code null} 89 * @since 12726 90 */ 91 public AddPrimitivesCommand(List<PrimitiveData> data, DataSet ds) { 92 this(data, data, ds); 79 93 } 80 94 -
trunk/src/org/openstreetmap/josm/command/ChangeCommand.java
r12718 r12726 30 30 31 31 /** 32 * Constructs a new {@code ChangeCommand} in the context of the current edit layer, if any.33 * @param osm The existing primitive to modify 32 * Constructs a new {@code ChangeCommand} in the context of {@code osm} data set. 33 * @param osm The existing primitive to modify. It must belong to a data set 34 34 * @param newOsm The new primitive 35 35 */ 36 36 public ChangeCommand(OsmPrimitive osm, OsmPrimitive newOsm) { 37 this.osm = osm; 38 this.newOsm = newOsm; 39 sanityChecks(); 37 this(osm.getDataSet(), osm, newOsm); 40 38 } 41 39 -
trunk/src/org/openstreetmap/josm/command/ChangeNodesCommand.java
r12663 r12726 10 10 import javax.swing.Icon; 11 11 12 import org.openstreetmap.josm.data.osm.DataSet; 12 13 import org.openstreetmap.josm.data.osm.DefaultNameFormatter; 13 14 import org.openstreetmap.josm.data.osm.Node; … … 36 37 */ 37 38 public ChangeNodesCommand(Way way, List<Node> newNodes) { 39 this(way.getDataSet(), way, newNodes); 40 } 41 42 /** 43 * Constructs a new {@code ChangeNodesCommand}. 44 * @param ds The target data set. Must not be {@code null} 45 * @param way The way to modify 46 * @param newNodes The new list of nodes for the given way 47 * @since 12726 48 */ 49 public ChangeNodesCommand(DataSet ds, Way way, List<Node> newNodes) { 50 super(ds); 38 51 this.way = way; 39 52 this.newNodes = newNodes; -
trunk/src/org/openstreetmap/josm/command/ChangePropertyCommand.java
r12663 r12726 13 13 import java.util.List; 14 14 import java.util.Map; 15 import java.util.NoSuchElementException; 15 16 import java.util.Objects; 16 17 import java.util.stream.Collectors; … … 72 73 * Creates a command to change multiple tags of multiple objects 73 74 * 74 * @param objects the objects to modify 75 * @param ds The target data set. Must not be {@code null} 76 * @param objects the objects to modify. Must not be empty 75 77 * @param tags the tags to set 76 */ 77 public ChangePropertyCommand(Collection<? extends OsmPrimitive> objects, Map<String, String> tags) { 78 * @since 12726 79 */ 80 public ChangePropertyCommand(DataSet ds, Collection<? extends OsmPrimitive> objects, Map<String, String> tags) { 81 super(ds); 78 82 this.tags = tags; 79 83 init(objects); … … 81 85 82 86 /** 87 * Creates a command to change multiple tags of multiple objects 88 * 89 * @param objects the objects to modify. Must not be empty, and objects must belong to a data set 90 * @param tags the tags to set 91 * @throws NullPointerException if objects is null or contain null item 92 * @throws NoSuchElementException if objects is empty 93 */ 94 public ChangePropertyCommand(Collection<? extends OsmPrimitive> objects, Map<String, String> tags) { 95 this(objects.iterator().next().getDataSet(), objects, tags); 96 } 97 98 /** 83 99 * Creates a command to change one tag of multiple objects 84 100 * 85 * @param objects the objects to modify 101 * @param objects the objects to modify. Must not be empty, and objects must belong to a data set 86 102 * @param key the key of the tag to set 87 103 * @param value the value of the key to set 104 * @throws NullPointerException if objects is null or contain null item 105 * @throws NoSuchElementException if objects is empty 88 106 */ 89 107 public ChangePropertyCommand(Collection<? extends OsmPrimitive> objects, String key, String value) { 108 super(objects.iterator().next().getDataSet()); 90 109 this.tags = new HashMap<>(1); 91 110 this.tags.put(key, value); … … 96 115 * Creates a command to change one tag of one object 97 116 * 98 * @param object the object to modify 117 * @param object the object to modify. Must belong to a data set 99 118 * @param key the key of the tag to set 100 119 * @param value the value of the key to set 120 * @throws NullPointerException if object is null 101 121 */ 102 122 public ChangePropertyCommand(OsmPrimitive object, String key, String value) { … … 134 154 @Override 135 155 public boolean executeCommand() { 136 if (objects.isEmpty())137 return true;138 156 final DataSet dataSet = objects.get(0).getDataSet(); 139 157 if (dataSet != null) { -
trunk/src/org/openstreetmap/josm/command/ChangePropertyKeyCommand.java
r11608 r12726 10 10 import java.util.LinkedList; 11 11 import java.util.List; 12 import java.util.NoSuchElementException; 12 13 import java.util.Objects; 13 14 14 15 import javax.swing.Icon; 15 16 17 import org.openstreetmap.josm.data.osm.DataSet; 16 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 19 import org.openstreetmap.josm.data.validation.util.NameVisitor; … … 66 68 * Constructs a new {@code ChangePropertyKeyCommand}. 67 69 * 68 * @param object the object subject to change replacement 70 * @param object the object subject to change replacement. Must not be null, and belong to a data set 69 71 * @param key The key to replace 70 72 * @param newKey the new value of the key … … 78 80 * Constructs a new {@code ChangePropertyKeyCommand}. 79 81 * 80 * @param objects all objects subject to change replacement 82 * @param objects all objects subject to change replacement. Must not be null or empty, and objects must belong to a data set 81 83 * @param key The key to replace 82 84 * @param newKey the new value of the key 85 * @throws NullPointerException if objects is null or contain null item 86 * @throws NoSuchElementException if objects is empty 83 87 */ 84 88 public ChangePropertyKeyCommand(Collection<? extends OsmPrimitive> objects, String key, String newKey) { 89 this(objects.iterator().next().getDataSet(), objects, key, newKey); 90 } 91 92 /** 93 * Constructs a new {@code ChangePropertyKeyCommand}. 94 * 95 * @param ds The target data set. Must not be {@code null} 96 * @param objects all objects subject to change replacement. 97 * @param key The key to replace 98 * @param newKey the new value of the key 99 * @since 12726 100 */ 101 public ChangePropertyKeyCommand(DataSet ds, Collection<? extends OsmPrimitive> objects, String key, String newKey) { 102 super(ds); 85 103 this.objects = new LinkedList<>(objects); 86 104 this.key = key; -
trunk/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java
r12663 r12726 37 37 /** 38 38 * Constructs a new {@code ChangeRelationMemberRoleCommand}. 39 * @param relation The relation to be changed 39 * @param relation The relation to be changed. Must not be null, and belong to a data set 40 40 * @param position Member position 41 41 * @param newRole New role 42 42 */ 43 43 public ChangeRelationMemberRoleCommand(Relation relation, int position, String newRole) { 44 this.relation = relation; 45 this.position = position; 46 this.newRole = newRole; 44 this(relation.getDataSet(), relation, position, newRole); 47 45 } 48 46 49 47 /** 50 48 * Constructs a new {@code ChangeRelationMemberRoleCommand}. 51 * @param dataSet The data set the role is in 49 * @param dataSet The data set the role is in. Must not be {@code null} 52 50 * @param relation The relation to be changed 53 51 * @param position Member position -
trunk/src/org/openstreetmap/josm/command/Command.java
r12718 r12726 147 147 /** 148 148 * Creates a new command in the context of the current edit layer, if any 149 */ 149 * @deprecated to be removed end of 2017. Use {@link #Command(DataSet)} instead 150 */ 151 @Deprecated 150 152 public Command() { 151 153 this.layer = MainApplication.getLayerManager().getEditLayer(); -
trunk/src/org/openstreetmap/josm/command/DeleteCommand.java
r12718 r12726 75 75 @Override 76 76 public String toString() { 77 return "DeleteChildCommand [osm=" + osm + "]";77 return "DeleteChildCommand [osm=" + osm + ']'; 78 78 } 79 79 } … … 88 88 * Constructor. Deletes a collection of primitives in the current edit layer. 89 89 * 90 * @param data the primitives to delete. Must neither be null nor empty .90 * @param data the primitives to delete. Must neither be null nor empty, and belong to a data set 91 91 * @throws IllegalArgumentException if data is null or empty 92 92 */ 93 93 public DeleteCommand(Collection<? extends OsmPrimitive> data) { 94 CheckParameterUtil.ensureParameterNotNull(data, "data"); 95 this.toDelete = data; 96 checkConsistency(); 94 this(data.iterator().next().getDataSet(), data); 97 95 } 98 96 -
trunk/src/org/openstreetmap/josm/command/MoveCommand.java
r12348 r12726 9 9 import java.util.LinkedList; 10 10 import java.util.List; 11 import java.util.NoSuchElementException; 11 12 import java.util.Objects; 12 13 … … 84 85 /** 85 86 * Constructs a new {@code MoveCommand} and assign the initial object set and movement vector. 86 * @param objects The primitives to move 87 * @param objects The primitives to move. Must neither be null nor empty. Objects must belong to a data set 87 88 * @param x X difference movement. Coordinates are in northern/eastern 88 89 * @param y Y difference movement. Coordinates are in northern/eastern 90 * @throws NullPointerException if objects is null or contain null item 91 * @throws NoSuchElementException if objects is empty 89 92 */ 90 93 public MoveCommand(Collection<OsmPrimitive> objects, double x, double y) { 94 super(objects.iterator().next().getDataSet()); 91 95 startEN = null; 92 96 saveCheckpoint(); // (0,0) displacement will be saved -
trunk/src/org/openstreetmap/josm/command/RemoveNodesCommand.java
r12663 r12726 33 33 /** 34 34 * Constructs a new {@code RemoveNodesCommand}. 35 * @param way The way to modify 35 * @param way The way to modify. Must not be null, and belong to a data set 36 36 * @param rmNodes The list of nodes to remove 37 37 */ 38 38 public RemoveNodesCommand(Way way, List<Node> rmNodes) { 39 super(way.getDataSet()); 39 40 this.way = way; 40 41 this.rmNodes = new HashSet<>(rmNodes); -
trunk/src/org/openstreetmap/josm/command/SelectCommand.java
r12350 r12726 28 28 * Constructs a new select command. 29 29 * @param newSelection the primitives to select when executing the command. 30 * @deprecated to be removed end of 2017. Use {@link #SelectCommand(DataSet, Collection)} instead 30 31 */ 32 @Deprecated 31 33 public SelectCommand(Collection<OsmPrimitive> newSelection) { 32 34 if (newSelection == null || newSelection.isEmpty()) { -
trunk/src/org/openstreetmap/josm/command/SequenceCommand.java
r12721 r12726 11 11 import javax.swing.Icon; 12 12 13 import org.openstreetmap.josm.data.osm.DataSet; 13 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 15 import org.openstreetmap.josm.gui.layer.Layer; … … 33 34 /** 34 35 * Create the command by specifying the list of commands to execute. 36 * @param ds The target data set. Must not be {@code null} 37 * @param name The description text 38 * @param sequenz The sequence that should be executed 39 * @param continueOnError Determines if the sequence execution should continue after one of its commands fails 40 * @since 12726 41 */ 42 public SequenceCommand(DataSet ds, String name, Collection<Command> sequenz, boolean continueOnError) { 43 super(ds); 44 this.name = name; 45 this.sequence = sequenz.toArray(new Command[sequenz.size()]); 46 this.continueOnError = continueOnError; 47 } 48 49 /** 50 * Create the command by specifying the list of commands to execute. 35 51 * @param name The description text 36 52 * @param sequenz The sequence that should be executed. Must not be null or empty … … 39 55 */ 40 56 public SequenceCommand(String name, Collection<Command> sequenz, boolean continueOnError) { 41 super(sequenz.iterator().next().getAffectedDataSet()); 42 this.name = name; 43 this.sequence = sequenz.toArray(new Command[sequenz.size()]); 44 this.continueOnError = continueOnError; 57 this(sequenz.iterator().next().getAffectedDataSet(), name, sequenz, continueOnError); 45 58 } 46 59 -
trunk/src/org/openstreetmap/josm/command/TransformNodesCommand.java
r10663 r12726 6 6 import java.util.Collection; 7 7 import java.util.HashMap; 8 import java.util.LinkedList;9 8 import java.util.Map; 9 import java.util.NoSuchElementException; 10 10 import java.util.Objects; 11 11 … … 28 28 * The nodes to transform. 29 29 */ 30 protected Collection<Node> nodes = new LinkedList<>();30 protected final Collection<Node> nodes; 31 31 32 32 /** 33 33 * List of all old states of the nodes. 34 34 */ 35 protected Map<Node, OldNodeState> oldStates = new HashMap<>();35 protected final Map<Node, OldNodeState> oldStates = new HashMap<>(); 36 36 37 37 /** … … 47 47 * Creates a TransformNodesObject. 48 48 * Find out the impacted nodes and store their initial state. 49 * @param objects objects to fetch nodes from 49 * @param objects objects to fetch nodes from. Must neither be null nor empty. Items must belong to a data set 50 * @throws NullPointerException if objects is null or contain null item 51 * @throws NoSuchElementException if objects is empty 50 52 */ 51 53 public TransformNodesCommand(Collection<? extends OsmPrimitive> objects) { 54 super(objects.iterator().next().getDataSet()); 52 55 this.nodes = AllNodesVisitor.getAllNodes(objects); 53 56 storeOldState(); -
trunk/src/org/openstreetmap/josm/command/conflict/ConflictAddCommand.java
r12718 r12726 79 79 public void undoCommand() { 80 80 DataSet ds = getAffectedDataSet(); 81 if ( !Main.main.containsDataSet(ds)) {81 if (Main.main != null && !Main.main.containsDataSet(ds)) { 82 82 Logging.warn(tr("Layer ''{0}'' does not exist any more. Cannot remove conflict for object ''{1}''.", 83 83 ds.getName(), -
trunk/src/org/openstreetmap/josm/command/conflict/ConflictResolveCommand.java
r12718 r12726 28 28 /** 29 29 * Constructs a new {@code ConflictResolveCommand} in the context of the current edit layer, if any. 30 * @deprecated to be removed end of 2017. Use {@link #ConflictResolveCommand(DataSet)} instead 30 31 */ 32 @Deprecated 31 33 public ConflictResolveCommand() { 32 // Do nothing34 this(Main.main.getEditDataSet()); 33 35 } 34 36 … … 81 83 82 84 DataSet ds = getAffectedDataSet(); 83 if (!Main.main.containsDataSet(ds)) { 84 Logging.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more", 85 this.toString(), 86 ds.getName() 87 )); 88 return; 85 if (Main.main != null) { 86 if (!Main.main.containsDataSet(ds)) { 87 Logging.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more", 88 this.toString(), 89 ds.getName() 90 )); 91 return; 92 } 93 94 Main.main.setEditDataSet(ds); 89 95 } 90 91 Main.main.setEditDataSet(ds);92 96 reconstituteConflicts(); 93 97 } -
trunk/src/org/openstreetmap/josm/command/conflict/CoordinateConflictResolveCommand.java
r11452 r12726 34 34 */ 35 35 public CoordinateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) { 36 super(conflict.getMy().getDataSet()); 36 37 this.conflict = conflict; 37 38 this.decision = decision; -
trunk/src/org/openstreetmap/josm/command/conflict/DeletedStateConflictResolveCommand.java
r11452 r12726 34 34 */ 35 35 public DeletedStateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) { 36 super(conflict.getMy().getDataSet()); 36 37 this.conflict = conflict; 37 38 this.decision = decision; -
trunk/src/org/openstreetmap/josm/command/conflict/ModifiedConflictResolveCommand.java
r12672 r12726 29 29 */ 30 30 public ModifiedConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) { 31 super(conflict.getMy().getDataSet()); 31 32 this.conflict = conflict; 32 33 } -
trunk/src/org/openstreetmap/josm/command/conflict/RelationMemberConflictResolverCommand.java
r12718 r12726 36 36 @SuppressWarnings("unchecked") 37 37 public RelationMemberConflictResolverCommand(Conflict<? extends OsmPrimitive> conflict, List<RelationMember> mergedMembers) { 38 super(conflict.getMy().getDataSet()); 38 39 this.conflict = (Conflict<Relation>) conflict; 39 40 this.mergedMembers = mergedMembers; -
trunk/src/org/openstreetmap/josm/command/conflict/TagConflictResolveCommand.java
r10671 r12726 50 50 */ 51 51 public TagConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, List<TagMergeItem> mergeItems) { 52 super(conflict.getMy().getDataSet()); 52 53 this.conflict = conflict; 53 54 this.mergeItems = mergeItems; -
trunk/src/org/openstreetmap/josm/command/conflict/VersionConflictResolveCommand.java
r12672 r12726 29 29 */ 30 30 public VersionConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) { 31 super(conflict.getMy().getDataSet()); 31 32 this.conflict = conflict; 32 33 } -
trunk/src/org/openstreetmap/josm/command/conflict/WayNodesConflictResolverCommand.java
r12620 r12726 36 36 @SuppressWarnings("unchecked") 37 37 public WayNodesConflictResolverCommand(Conflict<? extends OsmPrimitive> conflict, List<Node> mergedNodeList) { 38 super(conflict.getMy().getDataSet()); 38 39 this.conflict = (Conflict<Way>) conflict; 39 40 this.mergedNodeList = mergedNodeList; -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r12718 r12726 263 263 264 264 /** 265 * Constructs a new {@code DataSet} initially filled with the given primitives. 266 * @param osmPrimitives primitives to add to this data set 267 * @since 12726 268 */ 269 public DataSet(OsmPrimitive... osmPrimitives) { 270 this(); 271 beginUpdate(); 272 try { 273 for (OsmPrimitive o : osmPrimitives) { 274 addPrimitive(o); 275 } 276 } finally { 277 endUpdate(); 278 } 279 } 280 281 /** 265 282 * Adds a new data source. 266 283 * @param source data source to add -
trunk/src/org/openstreetmap/josm/data/osm/Node.java
r12725 r12726 106 106 * @return the east north coordinates or {@code null} if #is 107 107 */ 108 @Override 108 109 public EastNorth getEastNorth() { 109 110 return getEastNorth(Main.getProjection()); -
trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java
r12691 r12726 168 168 mindist = Main.pref.getDouble(PREFIX + ".node_way_distance", 10.0); 169 169 minmiddledist = Main.pref.getDouble(PREFIX + ".way_way_distance", 0.0); 170 DataSet dataSet = Main.main .getEditDataSet();170 DataSet dataSet = Main.main != null ? Main.main.getEditDataSet() : null; 171 171 dsArea = dataSet == null ? null : dataSet.getDataSourceArea(); 172 172 } -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r12718 r12726 197 197 public static UndoRedoHandler undoRedo; 198 198 199 private static final LayerChangeListener undoRedoCleaner = new LayerChangeListener() { 200 @Override 201 public void layerRemoving(LayerRemoveEvent e) { 202 Layer layer = e.getRemovedLayer(); 203 if (layer instanceof OsmDataLayer) { 204 undoRedo.clean(((OsmDataLayer) layer).data); 205 } 206 } 207 208 @Override 209 public void layerOrderChanged(LayerOrderChangeEvent e) { 210 // Do nothing 211 } 212 213 @Override 214 public void layerAdded(LayerAddEvent e) { 215 // Do nothing 216 } 217 }; 218 199 219 /** 200 220 * Listener that sets the enabled state of undo/redo menu entries. … … 220 240 this.mainFrame = mainFrame; 221 241 undoRedo = super.undoRedo; 222 getLayerManager().addLayerChangeListener(new LayerChangeListener() { 223 @Override 224 public void layerRemoving(LayerRemoveEvent e) { 225 Layer layer = e.getRemovedLayer(); 226 if (layer instanceof OsmDataLayer) { 227 undoRedo.clean(((OsmDataLayer) layer).data); 228 } 229 } 230 231 @Override 232 public void layerOrderChanged(LayerOrderChangeEvent e) { 233 // Do nothing 234 } 235 236 @Override 237 public void layerAdded(LayerAddEvent e) { 238 // Do nothing 239 } 240 }); 242 getLayerManager().addLayerChangeListener(undoRedoCleaner); 241 243 } 242 244 -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r12663 r12726 77 77 import org.openstreetmap.josm.data.osm.event.DatasetEventManager; 78 78 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 79 import org.openstreetmap.josm.data.osm.event.SelectionEventManager; 79 80 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 80 81 import org.openstreetmap.josm.data.osm.search.SearchSetting; 81 import org.openstreetmap.josm.data.osm.event.SelectionEventManager;82 82 import org.openstreetmap.josm.data.preferences.StringProperty; 83 83 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java
r12718 r12726 103 103 */ 104 104 protected void applyExistingNonConflictingRelation(TagEditorModel tagEditorModel) { 105 Relation editedRelation = new Relation(editor.getRelation()); 105 Relation originRelation = editor.getRelation(); 106 Relation editedRelation = new Relation(originRelation); 106 107 tagEditorModel.applyToPrimitive(editedRelation); 107 108 memberTableModel.applyToRelation(editedRelation); 108 if (!editedRelation.hasEqualSemanticAttributes( editor.getRelation(), false)) {109 MainApplication.undoRedo.add(new ChangeCommand( editor.getRelation(), editedRelation));109 if (!editedRelation.hasEqualSemanticAttributes(originRelation, false)) { 110 MainApplication.undoRedo.add(new ChangeCommand(originRelation, editedRelation)); 110 111 } 111 112 } -
trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java
r12719 r12726 158 158 class ChangesetReviewChangeListener implements ChangeListener { 159 159 160 private final String key= "review_requested";160 private static final String KEY = "review_requested"; 161 161 162 162 @Override … … 164 164 if (e.getSource() instanceof ChangesetReviewModel) { 165 165 boolean newState = ((ChangesetReviewModel) e.getSource()).isReviewRequested(); 166 boolean oldState = "yes".equals(Optional.ofNullable(getTagEditorValue( key)).orElse(""));166 boolean oldState = "yes".equals(Optional.ofNullable(getTagEditorValue(KEY)).orElse("")); 167 167 if (oldState != newState) { 168 setProperty( key, newState ? "yes" : null);168 setProperty(KEY, newState ? "yes" : null); 169 169 } 170 170 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java
r12641 r12726 12 12 import org.openstreetmap.josm.command.AddCommand; 13 13 import org.openstreetmap.josm.data.coor.LatLon; 14 import org.openstreetmap.josm.data.osm.DataSet; 14 15 import org.openstreetmap.josm.data.osm.Node; 15 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 96 97 } 97 98 99 DataSet ds = MainApplication.getLayerManager().getEditDataSet(); 98 100 if (node == null) { 99 101 node = new Node(ll); 100 102 // Now execute the commands to add this node. 101 MainApplication.undoRedo.add(new AddCommand( node));103 MainApplication.undoRedo.add(new AddCommand(ds, node)); 102 104 } 103 105 104 MainApplication.getLayerManager().getEditDataSet().setSelected(node);106 ds.setSelected(node); 105 107 if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) { 106 108 AutoScaleAction.autoScale("selection"); -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java
r12641 r12726 19 19 import org.openstreetmap.josm.command.SequenceCommand; 20 20 import org.openstreetmap.josm.data.coor.LatLon; 21 import org.openstreetmap.josm.data.osm.DataSet; 21 22 import org.openstreetmap.josm.data.osm.Node; 22 23 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 148 149 nd = new Node(ll); 149 150 // Now execute the commands to add this node. 150 commands.add(new AddCommand( nd));151 commands.add(new AddCommand(Main.main.getEditDataSet(), nd)); 151 152 addedNodes.put(ll, nd); 152 153 } … … 166 167 } 167 168 allCoordinates.clear(); 168 commands.add(new AddCommand(way)); 169 DataSet ds = MainApplication.getLayerManager().getEditDataSet(); 170 commands.add(new AddCommand(ds, way)); 169 171 MainApplication.undoRedo.add(new SequenceCommand(tr("Add way"), commands)); 170 MainApplication.getLayerManager().getEditDataSet().setSelected(way);172 ds.setSelected(way); 171 173 if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) { 172 174 AutoScaleAction.autoScale("selection"); -
trunk/src/org/openstreetmap/josm/tools/Geometry.java
r12718 r12726 228 228 newWay.setNodes(newNodes[pos]); 229 229 230 cmds.add(new ChangeCommand( way, newWay));230 cmds.add(new ChangeCommand(dataset, way, newWay)); 231 231 } 232 232 -
trunk/test/unit/org/openstreetmap/josm/TestUtils.java
r12130 r12726 22 22 23 23 import org.openstreetmap.josm.command.Command; 24 import org.openstreetmap.josm.data.osm.DataSet; 24 25 import org.openstreetmap.josm.data.osm.Node; 25 26 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 257 258 /** 258 259 * Creates a new empty command. 260 * @param ds data set 259 261 * @return a new empty command 260 262 */ 261 public static Command newCommand( ) {262 return new Command( ) {263 public static Command newCommand(DataSet ds) { 264 return new Command(ds) { 263 265 @Override 264 266 public String getDescriptionText() { -
trunk/test/unit/org/openstreetmap/josm/actions/CreateMultipolygonActionTest.java
r12659 r12726 17 17 import org.openstreetmap.josm.data.osm.RelationMember; 18 18 import org.openstreetmap.josm.data.osm.Way; 19 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 19 20 import org.openstreetmap.josm.data.osm.search.SearchParseError; 20 21 import org.openstreetmap.josm.data.osm.search.SearchSetting; 21 import org.openstreetmap.josm.data.osm.search.SearchCompiler;22 22 import org.openstreetmap.josm.io.OsmReader; 23 23 import org.openstreetmap.josm.testutils.JOSMTestRules; … … 42 42 Map<String, String> refToRole = new TreeMap<>(); 43 43 for (RelationMember i : relation.getMembers()) { 44 refToRole.put(i.getMember().get("ref"), i.getRole()); 44 String ref = i.getMember().get("ref"); 45 if (ref != null) { 46 refToRole.put(ref, i.getRole()); 47 } 45 48 } 46 49 return refToRole; -
trunk/test/unit/org/openstreetmap/josm/actions/SplitWayActionTest.java
r12643 r12726 162 162 void doTestRouteRelation(final boolean wayIsReversed, final int indexOfWayToKeep) { 163 163 final DataSet dataSet = new DataSet(); 164 final OsmDataLayer layer = new OsmDataLayer(dataSet, OsmDataLayer.createNewName(), null);165 164 final Node n1 = new Node(new LatLon(1, 0)); 166 165 final Node n2 = new Node(new LatLon(2, 0)); … … 197 196 }; 198 197 final SplitWayAction.SplitWayResult result = SplitWayAction.splitWay( 199 layer,w2, SplitWayAction.buildSplitChunks(w2, Arrays.asList(n3, n4, n5)), new ArrayList<OsmPrimitive>(), strategy);198 w2, SplitWayAction.buildSplitChunks(w2, Arrays.asList(n3, n4, n5)), new ArrayList<OsmPrimitive>(), strategy); 200 199 MainApplication.undoRedo.add(result.getCommand()); 201 200 -
trunk/test/unit/org/openstreetmap/josm/command/AddCommandTest.java
r12636 r12726 16 16 import org.openstreetmap.josm.data.osm.User; 17 17 import org.openstreetmap.josm.data.osm.Way; 18 import org.openstreetmap.josm.gui.MainApplication;19 18 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 20 19 import org.openstreetmap.josm.testutils.JOSMTestRules; … … 41 40 @Test 42 41 public void testAdd() { 43 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 44 MainApplication.getLayerManager().addLayer(layer1); 45 assertArrayEquals(new Object[0], layer1.data.allPrimitives().toArray()); 42 DataSet ds = new DataSet(); 43 assertArrayEquals(new Object[0], ds.allPrimitives().toArray()); 46 44 47 45 Node osm = new Node(LatLon.ZERO); 48 assertTrue(new AddCommand( osm).executeCommand());46 assertTrue(new AddCommand(ds, osm).executeCommand()); 49 47 50 assertArrayEquals(new Object[] {osm}, layer1.data.allPrimitives().toArray());51 assertArrayEquals(new Object[] {osm}, layer1.data.allModifiedPrimitives().toArray());48 assertArrayEquals(new Object[] {osm}, ds.allPrimitives().toArray()); 49 assertArrayEquals(new Object[] {osm}, ds.allModifiedPrimitives().toArray()); 52 50 assertTrue(osm.isModified()); 53 51 } 54 52 55 53 /** 56 * Tests if the add command respects the layer.54 * Tests if the add command respects the data set. 57 55 */ 58 56 @Test 59 57 public void testAddToLayer() { 60 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 61 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "l1", null); 62 63 MainApplication.getLayerManager().addLayer(layer1); 64 MainApplication.getLayerManager().addLayer(layer2); 58 DataSet ds1 = new DataSet(); 59 DataSet ds2 = new DataSet(); 65 60 66 61 Node osm = new Node(LatLon.ZERO); 67 assertTrue(new AddCommand( layer2, osm).executeCommand());62 assertTrue(new AddCommand(ds2, osm).executeCommand()); 68 63 69 assertArrayEquals(new Object[0], layer1.data.allPrimitives().toArray());70 assertArrayEquals(new Object[] {osm}, layer2.data.allPrimitives().toArray());64 assertArrayEquals(new Object[0], ds1.allPrimitives().toArray()); 65 assertArrayEquals(new Object[] {osm}, ds2.allPrimitives().toArray()); 71 66 } 72 67 … … 76 71 @Test 77 72 public void testUndo() { 78 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);79 MainApplication.getLayerManager().addLayer(layer1);80 73 Node osm = new Node(LatLon.ZERO); 81 layer1.data.addPrimitive(osm);74 DataSet ds = new DataSet(osm); 82 75 83 AddCommand command = new AddCommand( new Node(LatLon.ZERO));76 AddCommand command = new AddCommand(ds, new Node(LatLon.ZERO)); 84 77 command.executeCommand(); 85 78 86 79 command.undoCommand(); 87 assertArrayEquals(new Object[] {osm}, layer1.data.allPrimitives().toArray());80 assertArrayEquals(new Object[] {osm}, ds.allPrimitives().toArray()); 88 81 } 89 82 … … 95 88 Node osm = new Node(LatLon.ZERO); 96 89 97 assertArrayEquals(new Object[] {osm}, new AddCommand( osm).getParticipatingPrimitives().toArray());90 assertArrayEquals(new Object[] {osm}, new AddCommand(new DataSet(), osm).getParticipatingPrimitives().toArray()); 98 91 } 99 92 … … 108 101 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 109 102 ArrayList<OsmPrimitive> added = new ArrayList<>(); 110 new AddCommand( osm).fillModifiedData(modified, deleted, added);103 new AddCommand(new DataSet(), osm).fillModifiedData(modified, deleted, added); 111 104 assertArrayEquals(new Object[] {}, modified.toArray()); 112 105 assertArrayEquals(new Object[] {}, deleted.toArray()); … … 127 120 relation.put("name", "xy"); 128 121 129 assertTrue(new AddCommand(node).getDescriptionText().matches("Add node.*xy.*")); 130 assertTrue(new AddCommand(way).getDescriptionText().matches("Add way.*xy.*")); 131 assertTrue(new AddCommand(relation).getDescriptionText().matches("Add relation.*xy.*")); 122 DataSet ds = new DataSet(); 123 assertTrue(new AddCommand(ds, node).getDescriptionText().matches("Add node.*xy.*")); 124 assertTrue(new AddCommand(ds, way).getDescriptionText().matches("Add way.*xy.*")); 125 assertTrue(new AddCommand(ds, relation).getDescriptionText().matches("Add relation.*xy.*")); 132 126 } 133 127 -
trunk/test/unit/org/openstreetmap/josm/command/AddPrimitivesCommandTest.java
r12636 r12726 23 23 import org.openstreetmap.josm.data.osm.Way; 24 24 import org.openstreetmap.josm.data.osm.WayData; 25 import org.openstreetmap.josm.gui.MainApplication;26 25 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 27 26 import org.openstreetmap.josm.testutils.JOSMTestRules; … … 48 47 @Test 49 48 public void testAdd() { 50 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 51 MainApplication.getLayerManager().addLayer(layer1); 52 53 List<PrimitiveData> testData = createTestData(); 54 assertTrue(new AddPrimitivesCommand(testData).executeCommand()); 55 56 testContainsTestData(layer1); 57 assertEquals(3, layer1.data.getAllSelected().size()); 49 DataSet ds = new DataSet(); 50 51 List<PrimitiveData> testData = createTestData(); 52 assertTrue(new AddPrimitivesCommand(testData, ds).executeCommand()); 53 54 testContainsTestData(ds); 55 assertEquals(3, ds.getAllSelected().size()); 58 56 } 59 57 … … 63 61 @Test 64 62 public void testAddSetSelection() { 65 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 66 MainApplication.getLayerManager().addLayer(layer1); 67 68 List<PrimitiveData> testData = createTestData(); 69 assertTrue(new AddPrimitivesCommand(testData, testData.subList(2, 3)).executeCommand()); 70 71 testContainsTestData(layer1); 72 73 assertEquals(1, layer1.data.getAllSelected().size()); 74 assertEquals(1, layer1.data.getSelectedWays().size()); 75 } 76 77 /** 78 * Tests if the add command respects the layer. 63 DataSet ds = new DataSet(); 64 65 List<PrimitiveData> testData = createTestData(); 66 assertTrue(new AddPrimitivesCommand(testData, testData.subList(2, 3), ds).executeCommand()); 67 68 testContainsTestData(ds); 69 70 assertEquals(1, ds.getAllSelected().size()); 71 assertEquals(1, ds.getSelectedWays().size()); 72 } 73 74 /** 75 * Tests if the add command respects the data set. 79 76 */ 80 77 @Test 81 78 public void testAddToLayer() { 82 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 83 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "l1", null); 84 85 MainApplication.getLayerManager().addLayer(layer1); 86 MainApplication.getLayerManager().addLayer(layer2); 87 88 List<PrimitiveData> testData = createTestData(); 89 assertTrue(new AddPrimitivesCommand(testData, testData.subList(2, 3), layer1).executeCommand()); 90 91 testContainsTestData(layer1); 92 assertTrue(layer2.data.allPrimitives().isEmpty()); 93 94 assertEquals(1, layer1.data.getAllSelected().size()); 95 assertEquals(1, layer1.data.getSelectedWays().size()); 79 DataSet ds1 = new DataSet(); 80 DataSet ds2 = new DataSet(); 81 82 List<PrimitiveData> testData = createTestData(); 83 assertTrue(new AddPrimitivesCommand(testData, testData.subList(2, 3), ds1).executeCommand()); 84 85 testContainsTestData(ds1); 86 assertTrue(ds2.allPrimitives().isEmpty()); 87 88 assertEquals(1, ds1.getAllSelected().size()); 89 assertEquals(1, ds1.getSelectedWays().size()); 96 90 } 97 91 … … 101 95 @Test 102 96 public void testAddIgnoresExisting() { 103 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 104 MainApplication.getLayerManager().addLayer(layer1); 105 106 List<PrimitiveData> testData = createTestData(); 107 assertTrue(new AddPrimitivesCommand(testData).executeCommand()); 108 assertEquals(2, layer1.data.getNodes().size()); 109 assertEquals(1, layer1.data.getWays().size()); 97 DataSet ds = new DataSet(); 98 99 List<PrimitiveData> testData = createTestData(); 100 assertTrue(new AddPrimitivesCommand(testData, ds).executeCommand()); 101 assertEquals(2, ds.getNodes().size()); 102 assertEquals(1, ds.getWays().size()); 110 103 111 104 testData.set(2, createTestNode(7)); 112 assertTrue(new AddPrimitivesCommand(testData ).executeCommand());113 114 assertEquals(3, layer1.data.getNodes().size());115 assertEquals(1, layer1.data.getWays().size());105 assertTrue(new AddPrimitivesCommand(testData, ds).executeCommand()); 106 107 assertEquals(3, ds.getNodes().size()); 108 assertEquals(1, ds.getWays().size()); 116 109 } 117 110 … … 121 114 @Test 122 115 public void testDescription() { 123 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 124 MainApplication.getLayerManager().addLayer(layer1); 116 DataSet ds = new DataSet(); 125 117 126 118 List<PrimitiveData> testData = createTestData(); 127 119 NodeData data2 = createTestNode(7); 128 120 129 AddPrimitivesCommand command1 = new AddPrimitivesCommand(testData );130 AddPrimitivesCommand command2 = new AddPrimitivesCommand(Arrays.<PrimitiveData>asList(data2) );121 AddPrimitivesCommand command1 = new AddPrimitivesCommand(testData, ds); 122 AddPrimitivesCommand command2 = new AddPrimitivesCommand(Arrays.<PrimitiveData>asList(data2), ds); 131 123 132 124 assertEquals("Added 3 objects", command1.getDescriptionText()); … … 146 138 @Test 147 139 public void testUndo() { 148 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 149 MainApplication.getLayerManager().addLayer(layer1); 150 151 List<PrimitiveData> testData = createTestData(); 152 153 AddPrimitivesCommand command = new AddPrimitivesCommand(testData); 140 DataSet ds = new DataSet(); 141 142 List<PrimitiveData> testData = createTestData(); 143 144 AddPrimitivesCommand command = new AddPrimitivesCommand(testData, ds); 154 145 155 146 assertTrue(command.executeCommand()); 156 147 157 assertEquals(3, layer1.data.allPrimitives().size());158 assertEquals(1, layer1.data.getWays().size());159 Way way = layer1.data.getWays().iterator().next();148 assertEquals(3, ds.allPrimitives().size()); 149 assertEquals(1, ds.getWays().size()); 150 Way way = ds.getWays().iterator().next(); 160 151 161 152 for (int i = 0; i < 2; i++) { … … 163 154 command.undoCommand(); 164 155 165 assertEquals(0, layer1.data.allPrimitives().size());166 assertEquals(0, layer1.data.getWays().size());156 assertEquals(0, ds.allPrimitives().size()); 157 assertEquals(0, ds.getWays().size()); 167 158 168 159 // redo 169 160 assertTrue(command.executeCommand()); 170 161 171 assertEquals(3, layer1.data.allPrimitives().size());172 assertEquals(1, layer1.data.getWays().size());173 assertSame(way, layer1.data.getWays().iterator().next());162 assertEquals(3, ds.allPrimitives().size()); 163 assertEquals(1, ds.getWays().size()); 164 assertSame(way, ds.getWays().iterator().next()); 174 165 } 175 166 } … … 181 172 @Test 182 173 public void testUndoIgnoresExisting() { 183 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 184 MainApplication.getLayerManager().addLayer(layer1); 185 186 List<PrimitiveData> testData = createTestData(); 187 188 assertTrue(new AddPrimitivesCommand(testData).executeCommand()); 189 assertEquals(2, layer1.data.getNodes().size()); 190 assertEquals(1, layer1.data.getWays().size()); 174 DataSet ds = new DataSet(); 175 176 List<PrimitiveData> testData = createTestData(); 177 178 assertTrue(new AddPrimitivesCommand(testData, ds).executeCommand()); 179 assertEquals(2, ds.getNodes().size()); 180 assertEquals(1, ds.getWays().size()); 191 181 192 182 testData.set(2, createTestNode(7)); 193 183 194 AddPrimitivesCommand command = new AddPrimitivesCommand(testData );184 AddPrimitivesCommand command = new AddPrimitivesCommand(testData, ds); 195 185 196 186 assertTrue(command.executeCommand()); 197 187 198 assertEquals(3, layer1.data.getNodes().size());199 assertEquals(1, layer1.data.getWays().size());188 assertEquals(3, ds.getNodes().size()); 189 assertEquals(1, ds.getWays().size()); 200 190 201 191 for (int i = 0; i < 2; i++) { … … 203 193 command.undoCommand(); 204 194 205 assertEquals(2, layer1.data.getNodes().size());206 assertEquals(1, layer1.data.getWays().size());195 assertEquals(2, ds.getNodes().size()); 196 assertEquals(1, ds.getWays().size()); 207 197 208 198 // redo 209 199 assertTrue(command.executeCommand()); 210 200 211 assertEquals(3, layer1.data.getNodes().size());212 assertEquals(1, layer1.data.getWays().size());201 assertEquals(3, ds.getNodes().size()); 202 assertEquals(1, ds.getWays().size()); 213 203 } 214 204 } … … 219 209 @Test 220 210 public void testParticipatingPrimitives() { 221 OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null); 222 MainApplication.getLayerManager().addLayer(layer1); 223 224 List<PrimitiveData> testData = createTestData(); 225 AddPrimitivesCommand command = new AddPrimitivesCommand(testData); 211 DataSet ds = new DataSet(); 212 213 List<PrimitiveData> testData = createTestData(); 214 AddPrimitivesCommand command = new AddPrimitivesCommand(testData, ds); 226 215 assertTrue(command.executeCommand()); 227 216 228 217 assertEquals(3, command.getParticipatingPrimitives().size()); 229 HashSet<OsmPrimitive> should = new HashSet<>( layer1.data.allPrimitives());218 HashSet<OsmPrimitive> should = new HashSet<>(ds.allPrimitives()); 230 219 assertEquals(should, new HashSet<>(command.getParticipatingPrimitives())); 231 220 … … 245 234 246 235 List<PrimitiveData> testData = createTestData(); 247 new AddPrimitivesCommand(testData ).fillModifiedData(modified, deleted, added);236 new AddPrimitivesCommand(testData, new DataSet()).fillModifiedData(modified, deleted, added); 248 237 249 238 assertArrayEquals(new Object[] {}, modified.toArray()); … … 252 241 } 253 242 254 private void testContainsTestData( OsmDataLayer layer1) {255 assertEquals(3, layer1.data.allPrimitives().size());256 assertEquals(2, layer1.data.getNodes().size());257 assertEquals(1, layer1.data.getWays().size());258 assertEquals(3, layer1.data.allModifiedPrimitives().size());259 for (OsmPrimitive n : layer1.data.allPrimitives()) {243 private void testContainsTestData(DataSet data) { 244 assertEquals(3, data.allPrimitives().size()); 245 assertEquals(2, data.getNodes().size()); 246 assertEquals(1, data.getWays().size()); 247 assertEquals(3, data.allModifiedPrimitives().size()); 248 for (OsmPrimitive n : data.allPrimitives()) { 260 249 assertEquals("test", n.get("test")); 261 250 assertTrue(n.isModified()); 262 251 } 263 252 264 for (Node n : layer1.data.getNodes()) {253 for (Node n : data.getNodes()) { 265 254 assertEquals(LatLon.ZERO, n.getCoor()); 266 255 } 267 256 268 for (Way w : layer1.data.getWays()) {257 for (Way w : data.getWays()) { 269 258 assertEquals(2, w.getNodes().size()); 270 259 assertEquals(5, w.getNode(0).getId()); -
trunk/test/unit/org/openstreetmap/josm/command/ChangeCommandTest.java
r10758 r12726 142 142 Relation relation = new Relation(); 143 143 relation.put("name", "xy"); 144 DataSet ds = new DataSet(node, way, relation); 144 145 145 assertTrue(new ChangeCommand( node, node).getDescriptionText().matches("Change node.*xy.*"));146 assertTrue(new ChangeCommand( way, way).getDescriptionText().matches("Change way.*xy.*"));147 assertTrue(new ChangeCommand( relation, relation).getDescriptionText().matches("Change relation.*xy.*"));146 assertTrue(new ChangeCommand(ds, node, node).getDescriptionText().matches("Change node.*xy.*")); 147 assertTrue(new ChangeCommand(ds, way, way).getDescriptionText().matches("Change way.*xy.*")); 148 assertTrue(new ChangeCommand(ds, relation, relation).getDescriptionText().matches("Change relation.*xy.*")); 148 149 } 149 150 -
trunk/test/unit/org/openstreetmap/josm/command/ChangeNodesCommandTest.java
r10758 r12726 115 115 way.addNode(node); 116 116 way.put("name", "xy"); 117 117 DataSet ds = new DataSet(node, way); 118 118 assertTrue( 119 new ChangeNodesCommand( way, Arrays.asList(node)).getDescriptionText().matches("Change nodes of.*xy.*"));119 new ChangeNodesCommand(ds, way, Arrays.asList(node)).getDescriptionText().matches("Change nodes of.*xy.*")); 120 120 } 121 121 -
trunk/test/unit/org/openstreetmap/josm/command/ChangePropertyCommandTest.java
r10758 r12726 201 201 tagsRemove.put("existing", ""); 202 202 203 Way way = new Way(); 204 way.addNode(node1); 203 Way way = testData.createWay(20, node1); 205 204 way.put("name", "xy"); 206 205 way.put("existing", "existing"); 207 Relation relation = new Relation();206 Relation relation = testData.createRelation(30); 208 207 relation.put("name", "xy"); 209 208 relation.put("existing", "existing"); -
trunk/test/unit/org/openstreetmap/josm/command/CommandTest.java
r12718 r12726 2 2 package org.openstreetmap.josm.command; 3 3 4 import static org.junit.Assert.assertSame;4 import java.util.Arrays; 5 5 6 import java.util.Arrays;7 import java.util.Collection;8 9 import org.junit.Before;10 6 import org.junit.Rule; 11 7 import org.junit.Test; … … 13 9 import org.openstreetmap.josm.data.osm.DataSet; 14 10 import org.openstreetmap.josm.data.osm.Node; 15 import org.openstreetmap.josm.data.osm.OsmPrimitive;16 11 import org.openstreetmap.josm.data.osm.Relation; 17 12 import org.openstreetmap.josm.data.osm.RelationMember; … … 37 32 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 38 33 public JOSMTestRules test = new JOSMTestRules().preferences().i18n(); 39 private CommandTestData testData;40 41 /**42 * Set up the test data.43 */44 @Before45 public void createTestData() {46 testData = new CommandTestData();47 }48 49 /**50 * Test {@link Command#getLayer()}51 * @deprecated to be removed end of 201752 */53 @Test54 @Deprecated55 public void testGetLayer() {56 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "test", null);57 Command command = new NopCommand();58 Command command2 = new NopCommand(layer2.data);59 assertSame(testData.layer, command.getLayer());60 assertSame(layer2, command2.getLayer());61 }62 34 63 35 /** … … 75 47 .suppress(Warning.NONFINAL_FIELDS) 76 48 .verify(); 77 }78 79 private static final class NopCommand extends Command {80 NopCommand() {81 super();82 }83 84 NopCommand(DataSet dataset) {85 super(dataset);86 }87 88 @Override89 public String getDescriptionText() {90 return "";91 }92 93 @Override94 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,95 Collection<OsmPrimitive> added) {96 // nop97 }98 49 } 99 50 -
trunk/test/unit/org/openstreetmap/josm/command/DeleteCommandTest.java
r10775 r12726 11 11 import java.util.Collection; 12 12 import java.util.List; 13 import java.util.NoSuchElementException; 13 14 14 15 import org.junit.Before; … … 113 114 */ 114 115 @Test 115 public void testDel teNodesInWay() {116 public void testDeleteNodesInWay() { 116 117 testData.existingNode.removeAll(); 117 118 // That untagged node should be deleted. 118 119 testData.existingNode2.removeAll(); 119 DeleteCommand.delete( testData.layer,Arrays.asList(testData.existingWay), true, true).executeCommand();120 DeleteCommand.delete(Arrays.asList(testData.existingWay), true, true).executeCommand(); 120 121 121 122 assertTrue(testData.existingWay.isDeleted()); … … 137 138 way2.setNodes(Arrays.asList(node2, node3, node4)); 138 139 testData.layer.data.addPrimitive(way2); 139 DeleteCommand.delete( testData.layer,Arrays.asList(way1, way2), true, true).executeCommand();140 DeleteCommand.delete(Arrays.asList(way1, way2), true, true).executeCommand(); 140 141 141 142 assertTrue(way1.isDeleted()); … … 167 168 * Test that {@link DeleteCommand} checks for non-empty list 168 169 */ 169 @Test(expected = IllegalArgumentException.class)170 @Test(expected = NoSuchElementException.class) 170 171 public void testConsistencyNonEmpty() { 171 172 new DeleteCommand(Arrays.<OsmPrimitive>asList()); … … 175 176 * Test that {@link DeleteCommand} checks for non-null list 176 177 */ 177 @Test(expected = IllegalArgumentException.class)178 @Test(expected = NullPointerException.class) 178 179 public void testConsistencyNonNull() { 179 180 new DeleteCommand((Collection<OsmPrimitive>) null); -
trunk/test/unit/org/openstreetmap/josm/command/MoveCommandTest.java
r10758 r12726 248 248 Node node = new Node(LatLon.ZERO); 249 249 node.put("name", "xy"); 250 250 new DataSet(node); 251 251 List<OsmPrimitive> nodeList = Arrays.<OsmPrimitive>asList(node); 252 252 assertTrue(new MoveCommand(nodeList, 1, 2).getDescriptionText().matches("Move 1 node")); -
trunk/test/unit/org/openstreetmap/josm/command/RotateCommandTest.java
r10758 r12726 55 55 Node n2 = new Node(new EastNorth(-1, 0)); 56 56 Node n3 = new Node(new EastNorth(-9, -10)); 57 new DataSet(n1, n2, n3); 57 58 RotateCommand rotate = new RotateCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0)); 58 59 rotate.setRotationAngle(Math.PI / 4); … … 73 74 Node n2 = new Node(new EastNorth(-1, 0)); 74 75 Node n3 = new Node(new EastNorth(-9, -10)); 76 new DataSet(n1, n2, n3); 75 77 RotateCommand rotate = new RotateCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0)); 76 78 rotate.setRotationAngle(Math.PI / 4); -
trunk/test/unit/org/openstreetmap/josm/command/ScaleCommandTest.java
r10758 r12726 55 55 Node n2 = new Node(new EastNorth(-1, 0)); 56 56 Node n3 = new Node(new EastNorth(-9, -10)); 57 new DataSet(n1, n2, n3); 57 58 ScaleCommand scale = new ScaleCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0)); 58 59 scale.setScalingFactor(2.5); … … 73 74 Node n2 = new Node(new EastNorth(-1, 0)); 74 75 Node n3 = new Node(new EastNorth(-9, -10)); 76 new DataSet(n1, n2, n3); 75 77 ScaleCommand scale = new ScaleCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0)); 76 78 scale.setScalingFactor(2.5); -
trunk/test/unit/org/openstreetmap/josm/command/SelectCommandTest.java
r12368 r12726 50 50 @Test 51 51 public void testExecute() { 52 SelectCommand command = new SelectCommand( Arrays.asList(testData.existingNode, testData.existingWay));52 SelectCommand command = new SelectCommand(testData.layer.data, Arrays.asList(testData.existingNode, testData.existingWay)); 53 53 54 54 testData.layer.data.setSelected(Arrays.asList(testData.existingNode2)); … … 67 67 public void testExecuteAfterModify() { 68 68 List<OsmPrimitive> list = new ArrayList<>(Arrays.asList(testData.existingNode, testData.existingWay)); 69 SelectCommand command = new SelectCommand( list);69 SelectCommand command = new SelectCommand(testData.layer.data, list); 70 70 71 71 list.remove(testData.existingNode); … … 84 84 @Test 85 85 public void testUndo() { 86 SelectCommand command = new SelectCommand( Arrays.asList(testData.existingNode, testData.existingWay));86 SelectCommand command = new SelectCommand(testData.layer.data, Arrays.asList(testData.existingNode, testData.existingWay)); 87 87 testData.layer.data.setSelected(Arrays.asList(testData.existingNode2)); 88 88 … … 110 110 ArrayList<OsmPrimitive> deleted = new ArrayList<>(); 111 111 ArrayList<OsmPrimitive> added = new ArrayList<>(); 112 SelectCommand command = new SelectCommand( Arrays.asList(testData.existingNode, testData.existingWay));112 SelectCommand command = new SelectCommand(testData.layer.data, Arrays.asList(testData.existingNode, testData.existingWay)); 113 113 command.fillModifiedData(modified, deleted, added); 114 114 // intentionally empty. … … 123 123 @Test 124 124 public void testGetParticipatingPrimitives() { 125 SelectCommand command = new SelectCommand( Arrays.asList(testData.existingNode));125 SelectCommand command = new SelectCommand(testData.layer.data, Arrays.asList(testData.existingNode)); 126 126 command.executeCommand(); 127 127 assertArrayEquals(new Object[] {testData.existingNode}, command.getParticipatingPrimitives().toArray()); … … 133 133 @Test 134 134 public void testDescription() { 135 assertTrue(new SelectCommand(Arrays.<OsmPrimitive>asList(testData.existingNode)) 135 DataSet ds = testData.layer.data; 136 assertTrue(new SelectCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode)) 136 137 .getDescriptionText().matches("Selected 1 object")); 137 assertTrue(new SelectCommand( Arrays.asList(testData.existingNode, testData.existingWay))138 assertTrue(new SelectCommand(ds, Arrays.asList(testData.existingNode, testData.existingWay)) 138 139 .getDescriptionText().matches("Selected 2 objects")); 139 assertTrue(new SelectCommand( Arrays.<OsmPrimitive>asList())140 assertTrue(new SelectCommand(ds, Arrays.<OsmPrimitive>asList()) 140 141 .getDescriptionText().matches("Selected 0 objects")); 141 assertTrue(new SelectCommand( null)142 assertTrue(new SelectCommand(ds, null) 142 143 .getDescriptionText().matches("Selected 0 objects")); 143 144 } -
trunk/test/unit/org/openstreetmap/josm/command/SequenceCommandTest.java
r11874 r12726 12 12 import java.util.Arrays; 13 13 import java.util.Collection; 14 import java.util.Collections; 14 15 15 16 import org.junit.Before; … … 54 55 @Test 55 56 public void testExecute() { 56 final TestCommand command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode)); 57 TestCommand command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2)) { 57 DataSet ds = new DataSet(); 58 final TestCommand command1 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode)); 59 TestCommand command2 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode2)) { 58 60 @Override 59 61 public boolean executeCommand() { … … 75 77 @Test 76 78 public void testUndo() { 77 final TestCommand command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2)); 78 TestCommand command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode)) { 79 DataSet ds = new DataSet(); 80 final TestCommand command2 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode2)); 81 TestCommand command1 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode)) { 79 82 @Override 80 83 public void undoCommand() { … … 103 106 @Test 104 107 public void testExecuteRollback() { 105 TestCommand command1 = new TestCommand(null); 106 FailingCommand command2 = new FailingCommand(); 107 TestCommand command3 = new TestCommand(null); 108 DataSet ds = new DataSet(); 109 TestCommand command1 = new TestCommand(ds, null); 110 FailingCommand command2 = new FailingCommand(ds); 111 TestCommand command3 = new TestCommand(ds, null); 108 112 SequenceCommand command = new SequenceCommand("seq", Arrays.<Command>asList(command1, command2, command3)); 109 113 assertFalse(command.executeCommand()); … … 119 123 @Test 120 124 public void testContinueOnErrors() { 121 TestCommand command1 = new TestCommand(null); 122 FailingCommand command2 = new FailingCommand(); 123 TestCommand command3 = new TestCommand(null); 125 DataSet ds = new DataSet(); 126 TestCommand command1 = new TestCommand(ds, null); 127 FailingCommand command2 = new FailingCommand(ds); 128 TestCommand command3 = new TestCommand(ds, null); 124 129 SequenceCommand command = new SequenceCommand("seq", Arrays.<Command>asList(command1, command2, command3), true); 125 130 assertTrue(command.executeCommand()); … … 137 142 @Test 138 143 public void testGetLastCommand() { 139 final TestCommand command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode)); 140 final TestCommand command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2)); 141 142 assertEquals(command2, new SequenceCommand("seq", command1, command2).getLastCommand()); 143 assertNull(new SequenceCommand("seq").getLastCommand()); 144 DataSet ds = new DataSet(); 145 final TestCommand command1 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode)); 146 final TestCommand command2 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode2)); 147 148 assertEquals(command2, new SequenceCommand(ds, "seq", Arrays.asList(command1, command2), false).getLastCommand()); 149 assertNull(new SequenceCommand(ds, "seq", Collections.emptyList(), false).getLastCommand()); 144 150 } 145 151 … … 149 155 @Test 150 156 public void testFillModifiedData() { 151 Command command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode)); 152 Command command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2)); 153 Command command3 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingWay)) { 157 DataSet ds = new DataSet(); 158 Command command1 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode)); 159 Command command2 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode2)); 160 Command command3 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingWay)) { 154 161 @Override 155 162 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, … … 158 165 } 159 166 }; 160 Command command4 = new TestCommand( Arrays.<OsmPrimitive>asList(testData.existingRelation)) {167 Command command4 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingRelation)) { 161 168 @Override 162 169 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, … … 181 188 @Test 182 189 public void testGetParticipatingPrimitives() { 183 Command command1 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode)); 184 Command command2 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingNode2)); 190 DataSet ds = new DataSet(); 191 Command command1 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode)); 192 Command command2 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingNode2)); 185 193 186 194 SequenceCommand command = new SequenceCommand("seq", command1, command2); … … 197 205 @Test 198 206 public void testDescription() { 199 assertTrue(new SequenceCommand( "test").getDescriptionText().matches("Sequence: test"));207 assertTrue(new SequenceCommand(new DataSet(), "test", Collections.emptyList(), false).getDescriptionText().matches("Sequence: test")); 200 208 } 201 209 … … 205 213 @Test 206 214 public void testEqualsContract() { 215 DataSet ds = new DataSet(); 207 216 EqualsVerifier.forClass(SequenceCommand.class).usingGetClass() 208 217 .withPrefabValues(Command.class, 209 new AddCommand( new Node(1)), new AddCommand(new Node(2)))218 new AddCommand(ds, new Node(1)), new AddCommand(ds, new Node(2))) 210 219 .withPrefabValues(DataSet.class, 211 220 new DataSet(), new DataSet()) … … 222 231 protected boolean executed; 223 232 224 TestCommand( Collection<? extends OsmPrimitive> primitives) {225 super( );233 TestCommand(DataSet ds, Collection<? extends OsmPrimitive> primitives) { 234 super(ds); 226 235 this.primitives = primitives; 227 236 } … … 266 275 private static class FailingCommand extends TestCommand { 267 276 268 FailingCommand( ) {269 super( null);277 FailingCommand(DataSet ds) { 278 super(ds, null); 270 279 } 271 280 … … 286 295 return "FailingCommand"; 287 296 } 288 289 } 290 297 } 291 298 } -
trunk/test/unit/org/openstreetmap/josm/command/conflict/ConflictAddCommandTest.java
r12672 r12726 6 6 import static org.junit.Assert.assertTrue; 7 7 8 import org.junit.After;9 8 import org.junit.Before; 10 9 import org.junit.Rule; 11 10 import org.junit.Test; 11 import org.openstreetmap.josm.command.CommandTest.CommandTestData; 12 12 import org.openstreetmap.josm.data.conflict.Conflict; 13 13 import org.openstreetmap.josm.data.osm.DataSet; … … 15 15 import org.openstreetmap.josm.data.osm.User; 16 16 import org.openstreetmap.josm.data.osm.Way; 17 import org.openstreetmap.josm.gui.MainApplication;18 17 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 19 18 import org.openstreetmap.josm.testutils.JOSMTestRules; … … 28 27 public class ConflictAddCommandTest { 29 28 30 private OsmDataLayer layer;31 32 29 /** 33 30 * Setup test. … … 36 33 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 37 34 public JOSMTestRules test = new JOSMTestRules().platform(); 35 private CommandTestData testData; 38 36 39 37 /** … … 42 40 @Before 43 41 public void setUp() { 44 layer = new OsmDataLayer(new DataSet(), null, null); 45 MainApplication.getLayerManager().addLayer(layer); 46 } 47 48 /** 49 * Cleanup test resources. 50 */ 51 @After 52 public void tearDown() { 53 MainApplication.getLayerManager().removeLayer(layer); 42 testData = new CommandTestData(); 54 43 } 55 44 … … 59 48 @Test 60 49 public void testExecuteUndoCommand() { 61 DataSet ds = MainApplication.getLayerManager().getEditDataSet();62 Conflict<Node> conflict = new Conflict<>( new Node(), new Node());50 DataSet ds = testData.layer.data; 51 Conflict<Node> conflict = new Conflict<>(testData.existingNode, testData.existingNode2); 63 52 ConflictAddCommand cmd = new ConflictAddCommand(ds, conflict); 64 53 assertTrue(cmd.executeCommand()); … … 75 64 @Test 76 65 public void testGetDescriptionIcon() { 77 OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer(); 78 Conflict<Node> conflict = new Conflict<>(new Node(), new Node()); 79 assertNotNull(new ConflictAddCommand(layer, conflict).getDescriptionIcon()); 66 Conflict<Node> conflict = new Conflict<>(testData.existingNode, testData.existingNode2); 67 assertNotNull(new ConflictAddCommand(testData.layer.data, conflict).getDescriptionIcon()); 80 68 } 81 69 -
trunk/test/unit/org/openstreetmap/josm/command/conflict/CoordinateConflictResolveCommandTest.java
r12636 r12726 6 6 import static org.junit.Assert.assertTrue; 7 7 8 import org.junit.After;9 8 import org.junit.Before; 10 9 import org.junit.Rule; 11 10 import org.junit.Test; 11 import org.openstreetmap.josm.command.CommandTest.CommandTestData; 12 12 import org.openstreetmap.josm.data.conflict.Conflict; 13 13 import org.openstreetmap.josm.data.coor.LatLon; … … 16 16 import org.openstreetmap.josm.data.osm.User; 17 17 import org.openstreetmap.josm.data.osm.Way; 18 import org.openstreetmap.josm.gui.MainApplication;19 18 import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType; 20 19 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 30 29 public class CoordinateConflictResolveCommandTest { 31 30 32 private OsmDataLayer layer;31 private CommandTestData testData; 33 32 34 33 /** … … 44 43 @Before 45 44 public void setUp() { 46 layer = new OsmDataLayer(new DataSet(), null, null); 47 MainApplication.getLayerManager().addLayer(layer); 45 testData = new CommandTestData(); 48 46 } 49 47 50 /** 51 * Cleanup test resources. 52 */ 53 @After 54 public void tearDown() { 55 MainApplication.getLayerManager().removeLayer(layer); 56 } 57 58 private static Conflict<Node> createConflict() { 59 return new Conflict<>(new Node(LatLon.ZERO), new Node(new LatLon(50, 50))); 48 private Conflict<Node> createConflict() { 49 return new Conflict<>(testData.existingNode, testData.existingNode2); 60 50 } 61 51 -
trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java
r12620 r12726 25 25 import org.openstreetmap.josm.command.PseudoCommand; 26 26 import org.openstreetmap.josm.command.SequenceCommand; 27 import org.openstreetmap.josm.data.osm. Node;27 import org.openstreetmap.josm.data.osm.DataSet; 28 28 import org.openstreetmap.josm.data.osm.OsmPrimitive; 29 29 import org.openstreetmap.josm.data.osm.OsmUtils; … … 82 82 assertEquals("fixAdd: natural=wetland", check.fixCommands.get(1).toString()); 83 83 assertEquals("fixAdd: wetland=marsh", check.fixCommands.get(2).toString()); 84 final Node n1 = new Node(); 85 n1.put("natural", "marsh"); 84 final OsmPrimitive n1 = OsmUtils.createPrimitive("node natural=marsh"); 85 final OsmPrimitive n2 = OsmUtils.createPrimitive("node natural=wood"); 86 new DataSet(n1, n2); 86 87 assertTrue(check.test(n1)); 87 88 assertEquals("deprecated", check.getErrorForPrimitive(n1).getMessage()); … … 90 91 assertEquals("Sequence: Fix of natural=marsh is deprecated", check.fixPrimitive(n1).getDescriptionText()); 91 92 assertEquals("{natural=}", ((ChangePropertyCommand) check.fixPrimitive(n1).getChildren().iterator().next()).getTags().toString()); 92 final Node n2 = new Node();93 n2.put("natural", "wood");94 93 assertFalse(check.test(n2)); 95 94 assertEquals("The key is natural and the value is marsh", … … 109 108 "fixAdd: \"highway=construction\";\n" + 110 109 "}")).parseChecks.get(0); 110 new DataSet(p); 111 111 final Command command = check.fixPrimitive(p); 112 112 assertTrue(command instanceof SequenceCommand); -
trunk/test/unit/org/openstreetmap/josm/gui/conflict/pair/ConflictResolverTest.java
r11102 r12726 5 5 import static org.junit.Assert.assertNotNull; 6 6 7 import java.util.NoSuchElementException; 8 7 9 import org.junit.Rule; 8 10 import org.junit.Test; … … 10 12 import org.openstreetmap.josm.data.conflict.Conflict; 11 13 import org.openstreetmap.josm.data.coor.LatLon; 14 import org.openstreetmap.josm.data.osm.DataSet; 12 15 import org.openstreetmap.josm.data.osm.Node; 13 16 import org.openstreetmap.josm.data.osm.Relation; … … 32 35 * Unit test of {@link ConflictResolver#buildResolveCommand} - empty case. 33 36 */ 34 @Test 37 @Test(expected = NoSuchElementException.class) 35 38 public void testBuildResolveCommandEmpty() { 36 39 assertNotNull(new ConflictResolver().buildResolveCommand()); … … 47 50 Node n2 = new Node(LatLon.NORTH_POLE); 48 51 n2.put("source", "theirs"); 52 new DataSet(n1, n2); 49 53 resolver.populate(new Conflict<>(n1, n2)); 50 54 resolver.decideRemaining(MergeDecisionType.KEEP_MINE); … … 62 66 Way w2 = new Way(); 63 67 w2.put("source", "theirs"); 68 new DataSet(w1, w2); 64 69 resolver.populate(new Conflict<>(w1, w2)); 65 70 resolver.decideRemaining(MergeDecisionType.KEEP_MINE); … … 77 82 Relation r2 = new Relation(); 78 83 r2.put("source", "theirs"); 84 new DataSet(r1, r2); 79 85 resolver.populate(new Conflict<>(r1, r2)); 80 86 resolver.decideRemaining(MergeDecisionType.KEEP_MINE); -
trunk/test/unit/org/openstreetmap/josm/gui/datatransfer/OsmTransferHandlerTest.java
r12564 r12726 64 64 public void testPasteTags() { 65 65 Node n = new Node(LatLon.ZERO); 66 new DataSet(n); 66 67 67 68 ClipboardUtils.copyString("test=ok"); -
trunk/test/unit/org/openstreetmap/josm/gui/dialogs/CommandStackDialogTest.java
r12641 r12726 46 46 @Test 47 47 public void testCommandStackDialogNotEmpty() { 48 OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null); 48 DataSet ds = new DataSet(); 49 OsmDataLayer layer = new OsmDataLayer(ds, "", null); 49 50 MainApplication.getLayerManager().addLayer(layer); 50 51 try { 51 Command cmd1 = TestUtils.newCommand( );52 Command cmd2 = TestUtils.newCommand( );52 Command cmd1 = TestUtils.newCommand(ds); 53 Command cmd2 = TestUtils.newCommand(ds); 53 54 MainApplication.undoRedo.add(cmd1); 54 55 MainApplication.undoRedo.add(cmd2);
Note:
See TracChangeset
for help on using the changeset viewer.