Changeset 12726 in josm


Ignore:
Timestamp:
2017-09-04T23:45:49+02:00 (7 years ago)
Author:
Don-vip
Message:

see #13036 - deprecate Command() default constructor, fix unit tests and java warnings

Location:
trunk
Files:
67 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java

    r12641 r12726  
    1212import org.openstreetmap.josm.command.AddCommand;
    1313import org.openstreetmap.josm.data.coor.LatLon;
     14import org.openstreetmap.josm.data.osm.DataSet;
    1415import org.openstreetmap.josm.data.osm.Node;
    1516import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    6667
    6768        // 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);
    7072        MapView mapView = MainApplication.getMap().mapView;
    7173        if (mapView != null && !mapView.getRealBounds().contains(nnew.getCoor())) {
  • trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java

    r12641 r12726  
    2525import org.openstreetmap.josm.data.coor.EastNorth;
    2626import org.openstreetmap.josm.data.coor.LatLon;
     27import org.openstreetmap.josm.data.osm.DataSet;
    2728import org.openstreetmap.josm.data.osm.Node;
    2829import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    137138        }
    138139
    139         Collection<OsmPrimitive> sel = getLayerManager().getEditDataSet().getSelected();
     140        DataSet ds = getLayerManager().getEditDataSet();
     141        Collection<OsmPrimitive> sel = ds.getSelected();
    140142        List<Node> nodes = OsmPrimitive.getFilteredList(sel, Node.class);
    141143        List<Way> ways = OsmPrimitive.getFilteredList(sel, Way.class);
     
    222224                Node n = new Node(ll);
    223225                nodesToAdd.add(n);
    224                 cmds.add(new AddCommand(n));
     226                cmds.add(new AddCommand(ds, n));
    225227            }
    226228        }
     
    234236            Way newWay = new Way();
    235237            newWay.setNodes(nodesToAdd);
    236             cmds.add(new AddCommand(newWay));
     238            cmds.add(new AddCommand(ds, newWay));
    237239        } else {
    238240            Way newWay = new Way(existingWay);
    239241            newWay.setNodes(nodesToAdd);
    240             cmds.add(new ChangeCommand(existingWay, newWay));
     242            cmds.add(new ChangeCommand(ds, existingWay, newWay));
    241243        }
    242244
  • trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java

    r12641 r12726  
    248248        final String commandName;
    249249        if (existingRelation == null) {
    250             list.add(new AddCommand(relation));
     250            list.add(new AddCommand(selectedWays.iterator().next().getDataSet(), relation));
    251251            commandName = getName(false);
    252252        } else {
  • trunk/src/org/openstreetmap/josm/actions/FollowLineAction.java

    r12641 r12726  
    1515import org.openstreetmap.josm.command.SelectCommand;
    1616import org.openstreetmap.josm.command.SequenceCommand;
     17import org.openstreetmap.josm.data.osm.DataSet;
    1718import org.openstreetmap.josm.data.osm.Node;
    1819import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    2021import org.openstreetmap.josm.gui.MainApplication;
    2122import org.openstreetmap.josm.gui.MapFrame;
    22 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2323import org.openstreetmap.josm.tools.Shortcut;
    2424import org.openstreetmap.josm.tools.Utils;
     
    6161    @Override
    6262    public void actionPerformed(ActionEvent evt) {
    63         OsmDataLayer osmLayer = getLayerManager().getEditLayer();
    64         if (osmLayer == null)
     63        DataSet ds = getLayerManager().getEditDataSet();
     64        if (ds == null)
    6565            return;
    6666        MapFrame map = MainApplication.getMap();
    6767        if (!(map.mapMode instanceof DrawAction)) return; // We are not on draw mode
    6868
    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();
    7171        if ((selectedPoints.size() > 1) || (selectedLines.size() != 1)) // Unsuitable selection
    7272            return;
     
    115115            }
    116116            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 way
     117                    new ChangeCommand(ds, follower, newFollower),
     118                    new SelectCommand(ds, newFollower.isClosed() // see #10028 - unselect last node when closing a way
    119119                            ? Arrays.<OsmPrimitive>asList(follower)
    120120                            : Arrays.<OsmPrimitive>asList(follower, newPoint)
  • trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java

    r12641 r12726  
    2424import org.openstreetmap.josm.command.SequenceCommand;
    2525import org.openstreetmap.josm.data.coor.EastNorth;
     26import org.openstreetmap.josm.data.osm.DataSet;
    2627import org.openstreetmap.josm.data.osm.Node;
    2728import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    8485        if (!isEnabled())
    8586            return;
    86         Collection<Node> selectedNodes = getLayerManager().getEditDataSet().getSelectedNodes();
     87        DataSet ds = getLayerManager().getEditDataSet();
     88        Collection<Node> selectedNodes = ds.getSelectedNodes();
    8789        Collection<Command> cmds = new LinkedList<>();
    8890        Map<Way, MultiMap<Integer, Node>> data = new HashMap<>();
    8991
    9092        // 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();
    9394
    9495        // Planning phase: decide where we'll insert the nodes and put it all in "data"
     
    155156            Way wnew = new Way(w);
    156157            wnew.setNodes(wayNodes);
    157             cmds.add(new ChangeCommand(w, wnew));
     158            cmds.add(new ChangeCommand(ds, w, wnew));
    158159        }
    159160
  • trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java

    r12641 r12726  
    157157            corrCmds = (new ReverseWayTagCorrector()).execute(w, wnew);
    158158        }
    159         return new ReverseWayResult(wnew, corrCmds, new ChangeCommand(w.getDataSet(), w, wnew));
     159        return new ReverseWayResult(wnew, corrCmds, new ChangeCommand(w, wnew));
    160160    }
    161161
  • trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java

    r12718 r12726  
    593593        final Way changedWay = new Way(way);
    594594        changedWay.setNodes(wayToKeep.getNodes());
    595         commandList.add(new ChangeCommand(way.getDataSet(), way, changedWay));
     595        commandList.add(new ChangeCommand(way, changedWay));
    596596        if (!isMapModeDraw && !newSelection.contains(way)) {
    597597            newSelection.add(way);
  • trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java

    r12663 r12726  
    303303
    304304        List<Command> cmds = new LinkedList<>();
    305         cmds.add(new AddCommand(n));
     305        cmds.add(new AddCommand(selectedNode.getDataSet(), n));
    306306        if (dialog != null) {
    307307            dialog.update(selectedNode, Collections.singletonList(n), cmds);
     
    440440        Node newNode = new Node(originalNode, true /* clear OSM ID */);
    441441        newNodes.add(newNode);
    442         cmds.add(new AddCommand(newNode));
     442        cmds.add(new AddCommand(originalNode.getDataSet(), newNode));
    443443
    444444        List<Node> nn = new ArrayList<>();
     
    583583                if (seen) {
    584584                    Node newNode = new Node(n, true /* clear OSM ID */);
    585                     cmds.add(new AddCommand(newNode));
     585                    cmds.add(new AddCommand(selectedNode.getDataSet(), newNode));
    586586                    newNodes.add(newNode);
    587587                    addNodes.add(newNode);
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r12643 r12726  
    487487                return;
    488488            }
    489             cmds.add(new AddCommand(n));
     489            cmds.add(new AddCommand(ds, n));
    490490
    491491            if (!ctrl) {
     
    576576                    way = new Way();
    577577                    way.addNode(n0);
    578                     cmds.add(new AddCommand(way));
     578                    cmds.add(new AddCommand(ds, way));
    579579                    wayToSelect = way;
    580580                } else {
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java

    r12689 r12726  
    4040import org.openstreetmap.josm.data.coor.EastNorth;
    4141import org.openstreetmap.josm.data.osm.DataIntegrityProblemException;
     42import org.openstreetmap.josm.data.osm.DataSet;
    4243import org.openstreetmap.josm.data.osm.Node;
    4344import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    592593            Way wnew = new Way(ws.way);
    593594            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)));
    597598        }
    598599    }
     
    603604    private void createNewRectangle() {
    604605        if (selectedSegment == null) return;
    605         // crete a new rectangle
     606        DataSet ds = getLayerManager().getEditDataSet();
     607        // create a new rectangle
    606608        Collection<Command> cmds = new LinkedList<>();
    607609        Node third = new Node(newN2en);
     
    618620        wnew.addNode(selectedSegment.getFirstNode());
    619621        // undo support
    620         cmds.add(new AddCommand(third));
     622        cmds.add(new AddCommand(ds, third));
    621623        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));
    625627        Command c = new SequenceCommand(tr("Extrude Way"), cmds);
    626628        MainApplication.undoRedo.add(c);
    627         getLayerManager().getEditDataSet().setSelected(wnew);
     629        ds.setSelected(wnew);
    628630    }
    629631
     
    634636     */
    635637    private void performExtrusion() {
     638        DataSet ds = getLayerManager().getEditDataSet();
    636639        // create extrusion
    637640        Collection<Command> cmds = new LinkedList<>();
     
    661664            wnew.removeNode(n1Old);
    662665            wayWasModified = true;
    663             cmds.add(new AddCommand(n1New));
     666            cmds.add(new AddCommand(ds, n1New));
    664667            changedNodes.add(n1New);
    665668        } else {
     
    669672            wayWasModified = true;
    670673            insertionPoint++;
    671             cmds.add(new AddCommand(n1New));
     674            cmds.add(new AddCommand(ds, n1New));
    672675            changedNodes.add(n1New);
    673676        }
     
    691694            wnew.removeNode(n2Old);
    692695            wayWasModified = true;
    693             cmds.add(new AddCommand(n2New));
     696            cmds.add(new AddCommand(ds, n2New));
    694697            changedNodes.add(n2New);
    695698        } else {
     
    698701            wnew.addNode(insertionPoint, n2New);
    699702            wayWasModified = true;
    700             cmds.add(new AddCommand(n2New));
     703            cmds.add(new AddCommand(ds, n2New));
    701704            changedNodes.add(n2New);
    702705        }
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java

    r12718 r12726  
    399399        }
    400400
     401        DataSet ds = getLayerManager().getEditDataSet();
    401402        updateKeyModifiers(e);
    402403        mousePos = e.getPoint();
     
    404405        if (state == State.SELECTING) {
    405406            if (targetWay != null) {
    406                 getLayerManager().getEditDataSet().setSelected(targetWay.getPrimitiveId());
     407                ds.setSelected(targetWay.getPrimitiveId());
    407408                updateStateByCurrentSelection();
    408409            }
     
    425426                Node virtualNode = new Node(mv.getEastNorth(mousePos.x,
    426427                        mousePos.y));
    427                 virtualCmds.add(new AddCommand(virtualNode));
     428                virtualCmds.add(new AddCommand(ds, virtualNode));
    428429
    429430                // Looking for candidateSegment copies in ways that are
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWays.java

    r12641 r12726  
    1111import java.util.Set;
    1212
     13import org.openstreetmap.josm.Main;
    1314import org.openstreetmap.josm.command.AddCommand;
    1415import org.openstreetmap.josm.command.Command;
    1516import org.openstreetmap.josm.command.SequenceCommand;
    1617import org.openstreetmap.josm.data.coor.EastNorth;
     18import org.openstreetmap.josm.data.osm.DataSet;
    1719import org.openstreetmap.josm.data.osm.Node;
    1820import org.openstreetmap.josm.data.osm.NodeGraph;
     
    186188
    187189    private List<Command> makeAddWayAndNodesCommandList() {
     190        DataSet ds = Main.main.getEditDataSet();
    188191        List<Command> commands = new ArrayList<>(sortedNodes.size() + ways.size());
    189192        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)));
    191194        }
    192195        for (Way w : ways) {
    193             commands.add(new AddCommand(w));
     196            commands.add(new AddCommand(ds, w));
    194197        }
    195198        return commands;
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r12641 r12726  
    12351235
    12361236        private void createMiddleNodeFromVirtual(EastNorth currentEN) {
     1237            DataSet ds = getLayerManager().getEditDataSet();
    12371238            Collection<Command> virtualCmds = new LinkedList<>();
    1238             virtualCmds.add(new AddCommand(virtualNode));
     1239            virtualCmds.add(new AddCommand(ds, virtualNode));
    12391240            for (WaySegment virtualWay : virtualWays) {
    12401241                Way w = virtualWay.way;
    12411242                Way wnew = new Way(w);
    12421243                wnew.addNode(virtualWay.lowerIndex + 1, virtualNode);
    1243                 virtualCmds.add(new ChangeCommand(w, wnew));
     1244                virtualCmds.add(new ChangeCommand(ds, w, wnew));
    12441245            }
    12451246            virtualCmds.add(new MoveCommand(virtualNode, startEN, currentEN));
     
    12481249                    virtualWays.size());
    12491250            MainApplication.undoRedo.add(new SequenceCommand(text, virtualCmds));
    1250             getLayerManager().getEditDataSet().setSelected(Collections.singleton((OsmPrimitive) virtualNode));
     1251            ds.setSelected(Collections.singleton((OsmPrimitive) virtualNode));
    12511252            clear();
    12521253        }
  • trunk/src/org/openstreetmap/josm/command/AddCommand.java

    r12718 r12726  
    3636     * Creates the command and specify the element to add in the context of the current edit layer, if any.
    3737     * @param osm The primitive to add
     38     * @deprecated to be removed end of 2017. Use {@link #AddCommand(DataSet, OsmPrimitive)} instead
    3839     */
     40    @Deprecated
    3941    public AddCommand(OsmPrimitive osm) {
    4042        this.osm = Objects.requireNonNull(osm, "osm");
  • trunk/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java

    r12718 r12726  
    3939     * Constructs a new {@code AddPrimitivesCommand} to add data to the current edit layer.
    4040     * @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
    4244    public AddPrimitivesCommand(List<PrimitiveData> data) {
    4345        this(data, data);
     
    4951     * @param toSelect The OSM primitives to select at the end. Can be {@code null}
    5052     * @since 5953
    51      */
     53     * @deprecated to be removed end of 2017. Use {@link #AddPrimitivesCommand(List, List, DataSet)} instead
     54     */
     55    @Deprecated
    5256    public AddPrimitivesCommand(List<PrimitiveData> data, List<PrimitiveData> toSelect) {
    5357        init(data, toSelect);
     
    7781        super(ds);
    7882        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);
    7993    }
    8094
  • trunk/src/org/openstreetmap/josm/command/ChangeCommand.java

    r12718 r12726  
    3030
    3131    /**
    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
    3434     * @param newOsm The new primitive
    3535     */
    3636    public ChangeCommand(OsmPrimitive osm, OsmPrimitive newOsm) {
    37         this.osm = osm;
    38         this.newOsm = newOsm;
    39         sanityChecks();
     37        this(osm.getDataSet(), osm, newOsm);
    4038    }
    4139
  • trunk/src/org/openstreetmap/josm/command/ChangeNodesCommand.java

    r12663 r12726  
    1010import javax.swing.Icon;
    1111
     12import org.openstreetmap.josm.data.osm.DataSet;
    1213import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
    1314import org.openstreetmap.josm.data.osm.Node;
     
    3637     */
    3738    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);
    3851        this.way = way;
    3952        this.newNodes = newNodes;
  • trunk/src/org/openstreetmap/josm/command/ChangePropertyCommand.java

    r12663 r12726  
    1313import java.util.List;
    1414import java.util.Map;
     15import java.util.NoSuchElementException;
    1516import java.util.Objects;
    1617import java.util.stream.Collectors;
     
    7273     * Creates a command to change multiple tags of multiple objects
    7374     *
    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
    7577     * @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);
    7882        this.tags = tags;
    7983        init(objects);
     
    8185
    8286    /**
     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    /**
    8399     * Creates a command to change one tag of multiple objects
    84100     *
    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
    86102     * @param key the key of the tag to set
    87103     * @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
    88106     */
    89107    public ChangePropertyCommand(Collection<? extends OsmPrimitive> objects, String key, String value) {
     108        super(objects.iterator().next().getDataSet());
    90109        this.tags = new HashMap<>(1);
    91110        this.tags.put(key, value);
     
    96115     * Creates a command to change one tag of one object
    97116     *
    98      * @param object the object to modify
     117     * @param object the object to modify. Must belong to a data set
    99118     * @param key the key of the tag to set
    100119     * @param value the value of the key to set
     120     * @throws NullPointerException if object is null
    101121     */
    102122    public ChangePropertyCommand(OsmPrimitive object, String key, String value) {
     
    134154    @Override
    135155    public boolean executeCommand() {
    136         if (objects.isEmpty())
    137             return true;
    138156        final DataSet dataSet = objects.get(0).getDataSet();
    139157        if (dataSet != null) {
  • trunk/src/org/openstreetmap/josm/command/ChangePropertyKeyCommand.java

    r11608 r12726  
    1010import java.util.LinkedList;
    1111import java.util.List;
     12import java.util.NoSuchElementException;
    1213import java.util.Objects;
    1314
    1415import javax.swing.Icon;
    1516
     17import org.openstreetmap.josm.data.osm.DataSet;
    1618import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1719import org.openstreetmap.josm.data.validation.util.NameVisitor;
     
    6668     * Constructs a new {@code ChangePropertyKeyCommand}.
    6769     *
    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
    6971     * @param key The key to replace
    7072     * @param newKey the new value of the key
     
    7880     * Constructs a new {@code ChangePropertyKeyCommand}.
    7981     *
    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
    8183     * @param key The key to replace
    8284     * @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
    8387     */
    8488    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);
    85103        this.objects = new LinkedList<>(objects);
    86104        this.key = key;
  • trunk/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java

    r12663 r12726  
    3737    /**
    3838     * 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
    4040     * @param position Member position
    4141     * @param newRole New role
    4242     */
    4343    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);
    4745    }
    4846
    4947    /**
    5048     * 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}
    5250     * @param relation The relation to be changed
    5351     * @param position Member position
  • trunk/src/org/openstreetmap/josm/command/Command.java

    r12718 r12726  
    147147    /**
    148148     * 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
    150152    public Command() {
    151153        this.layer = MainApplication.getLayerManager().getEditLayer();
  • trunk/src/org/openstreetmap/josm/command/DeleteCommand.java

    r12718 r12726  
    7575        @Override
    7676        public String toString() {
    77             return "DeleteChildCommand [osm=" + osm + "]";
     77            return "DeleteChildCommand [osm=" + osm + ']';
    7878        }
    7979    }
     
    8888     * Constructor. Deletes a collection of primitives in the current edit layer.
    8989     *
    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
    9191     * @throws IllegalArgumentException if data is null or empty
    9292     */
    9393    public DeleteCommand(Collection<? extends OsmPrimitive> data) {
    94         CheckParameterUtil.ensureParameterNotNull(data, "data");
    95         this.toDelete = data;
    96         checkConsistency();
     94        this(data.iterator().next().getDataSet(), data);
    9795    }
    9896
  • trunk/src/org/openstreetmap/josm/command/MoveCommand.java

    r12348 r12726  
    99import java.util.LinkedList;
    1010import java.util.List;
     11import java.util.NoSuchElementException;
    1112import java.util.Objects;
    1213
     
    8485    /**
    8586     * 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
    8788     * @param x X difference movement. Coordinates are in northern/eastern
    8889     * @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
    8992     */
    9093    public MoveCommand(Collection<OsmPrimitive> objects, double x, double y) {
     94        super(objects.iterator().next().getDataSet());
    9195        startEN = null;
    9296        saveCheckpoint(); // (0,0) displacement will be saved
  • trunk/src/org/openstreetmap/josm/command/RemoveNodesCommand.java

    r12663 r12726  
    3333    /**
    3434     * 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
    3636     * @param rmNodes The list of nodes to remove
    3737     */
    3838    public RemoveNodesCommand(Way way, List<Node> rmNodes) {
     39        super(way.getDataSet());
    3940        this.way = way;
    4041        this.rmNodes = new HashSet<>(rmNodes);
  • trunk/src/org/openstreetmap/josm/command/SelectCommand.java

    r12350 r12726  
    2828     * Constructs a new select command.
    2929     * @param newSelection the primitives to select when executing the command.
     30     * @deprecated to be removed end of 2017. Use {@link #SelectCommand(DataSet, Collection)} instead
    3031     */
     32    @Deprecated
    3133    public SelectCommand(Collection<OsmPrimitive> newSelection) {
    3234        if (newSelection == null || newSelection.isEmpty()) {
  • trunk/src/org/openstreetmap/josm/command/SequenceCommand.java

    r12721 r12726  
    1111import javax.swing.Icon;
    1212
     13import org.openstreetmap.josm.data.osm.DataSet;
    1314import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1415import org.openstreetmap.josm.gui.layer.Layer;
     
    3334    /**
    3435     * 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.
    3551     * @param name The description text
    3652     * @param sequenz The sequence that should be executed. Must not be null or empty
     
    3955     */
    4056    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);
    4558    }
    4659
  • trunk/src/org/openstreetmap/josm/command/TransformNodesCommand.java

    r10663 r12726  
    66import java.util.Collection;
    77import java.util.HashMap;
    8 import java.util.LinkedList;
    98import java.util.Map;
     9import java.util.NoSuchElementException;
    1010import java.util.Objects;
    1111
     
    2828     * The nodes to transform.
    2929     */
    30     protected Collection<Node> nodes = new LinkedList<>();
     30    protected final Collection<Node> nodes;
    3131
    3232    /**
    3333     * List of all old states of the nodes.
    3434     */
    35     protected Map<Node, OldNodeState> oldStates = new HashMap<>();
     35    protected final Map<Node, OldNodeState> oldStates = new HashMap<>();
    3636
    3737    /**
     
    4747     * Creates a TransformNodesObject.
    4848     * 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
    5052     */
    5153    public TransformNodesCommand(Collection<? extends OsmPrimitive> objects) {
     54        super(objects.iterator().next().getDataSet());
    5255        this.nodes = AllNodesVisitor.getAllNodes(objects);
    5356        storeOldState();
  • trunk/src/org/openstreetmap/josm/command/conflict/ConflictAddCommand.java

    r12718 r12726  
    7979    public void undoCommand() {
    8080        DataSet ds = getAffectedDataSet();
    81         if (!Main.main.containsDataSet(ds)) {
     81        if (Main.main != null && !Main.main.containsDataSet(ds)) {
    8282            Logging.warn(tr("Layer ''{0}'' does not exist any more. Cannot remove conflict for object ''{1}''.",
    8383                    ds.getName(),
  • trunk/src/org/openstreetmap/josm/command/conflict/ConflictResolveCommand.java

    r12718 r12726  
    2828    /**
    2929     * 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
    3031     */
     32    @Deprecated
    3133    public ConflictResolveCommand() {
    32         // Do nothing
     34        this(Main.main.getEditDataSet());
    3335    }
    3436
     
    8183
    8284        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);
    8995        }
    90 
    91         Main.main.setEditDataSet(ds);
    9296        reconstituteConflicts();
    9397    }
  • trunk/src/org/openstreetmap/josm/command/conflict/CoordinateConflictResolveCommand.java

    r11452 r12726  
    3434     */
    3535    public CoordinateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) {
     36        super(conflict.getMy().getDataSet());
    3637        this.conflict = conflict;
    3738        this.decision = decision;
  • trunk/src/org/openstreetmap/josm/command/conflict/DeletedStateConflictResolveCommand.java

    r11452 r12726  
    3434     */
    3535    public DeletedStateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) {
     36        super(conflict.getMy().getDataSet());
    3637        this.conflict = conflict;
    3738        this.decision = decision;
  • trunk/src/org/openstreetmap/josm/command/conflict/ModifiedConflictResolveCommand.java

    r12672 r12726  
    2929     */
    3030    public ModifiedConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
     31        super(conflict.getMy().getDataSet());
    3132        this.conflict = conflict;
    3233    }
  • trunk/src/org/openstreetmap/josm/command/conflict/RelationMemberConflictResolverCommand.java

    r12718 r12726  
    3636    @SuppressWarnings("unchecked")
    3737    public RelationMemberConflictResolverCommand(Conflict<? extends OsmPrimitive> conflict, List<RelationMember> mergedMembers) {
     38        super(conflict.getMy().getDataSet());
    3839        this.conflict = (Conflict<Relation>) conflict;
    3940        this.mergedMembers = mergedMembers;
  • trunk/src/org/openstreetmap/josm/command/conflict/TagConflictResolveCommand.java

    r10671 r12726  
    5050     */
    5151    public TagConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, List<TagMergeItem> mergeItems) {
     52        super(conflict.getMy().getDataSet());
    5253        this.conflict = conflict;
    5354        this.mergeItems = mergeItems;
  • trunk/src/org/openstreetmap/josm/command/conflict/VersionConflictResolveCommand.java

    r12672 r12726  
    2929     */
    3030    public VersionConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
     31        super(conflict.getMy().getDataSet());
    3132        this.conflict = conflict;
    3233    }
  • trunk/src/org/openstreetmap/josm/command/conflict/WayNodesConflictResolverCommand.java

    r12620 r12726  
    3636    @SuppressWarnings("unchecked")
    3737    public WayNodesConflictResolverCommand(Conflict<? extends OsmPrimitive> conflict, List<Node> mergedNodeList) {
     38        super(conflict.getMy().getDataSet());
    3839        this.conflict = (Conflict<Way>) conflict;
    3940        this.mergedNodeList = mergedNodeList;
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r12718 r12726  
    263263
    264264    /**
     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    /**
    265282     * Adds a new data source.
    266283     * @param source data source to add
  • trunk/src/org/openstreetmap/josm/data/osm/Node.java

    r12725 r12726  
    106106     * @return the east north coordinates or {@code null} if #is
    107107     */
     108    @Override
    108109    public EastNorth getEastNorth() {
    109110        return getEastNorth(Main.getProjection());
  • trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java

    r12691 r12726  
    168168        mindist = Main.pref.getDouble(PREFIX + ".node_way_distance", 10.0);
    169169        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;
    171171        dsArea = dataSet == null ? null : dataSet.getDataSourceArea();
    172172    }
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r12718 r12726  
    197197    public static UndoRedoHandler undoRedo;
    198198
     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
    199219    /**
    200220     * Listener that sets the enabled state of undo/redo menu entries.
     
    220240        this.mainFrame = mainFrame;
    221241        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);
    241243    }
    242244
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r12663 r12726  
    7777import org.openstreetmap.josm.data.osm.event.DatasetEventManager;
    7878import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
     79import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
    7980import org.openstreetmap.josm.data.osm.search.SearchCompiler;
    8081import org.openstreetmap.josm.data.osm.search.SearchSetting;
    81 import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
    8282import org.openstreetmap.josm.data.preferences.StringProperty;
    8383import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java

    r12718 r12726  
    103103     */
    104104    protected void applyExistingNonConflictingRelation(TagEditorModel tagEditorModel) {
    105         Relation editedRelation = new Relation(editor.getRelation());
     105        Relation originRelation = editor.getRelation();
     106        Relation editedRelation = new Relation(originRelation);
    106107        tagEditorModel.applyToPrimitive(editedRelation);
    107108        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));
    110111        }
    111112    }
  • trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java

    r12719 r12726  
    158158    class ChangesetReviewChangeListener implements ChangeListener {
    159159
    160         private final String key = "review_requested";
     160        private static final String KEY = "review_requested";
    161161
    162162        @Override
     
    164164            if (e.getSource() instanceof ChangesetReviewModel) {
    165165                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(""));
    167167                if (oldState != newState) {
    168                     setProperty(key, newState ? "yes" : null);
     168                    setProperty(KEY, newState ? "yes" : null);
    169169                }
    170170            }
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java

    r12641 r12726  
    1212import org.openstreetmap.josm.command.AddCommand;
    1313import org.openstreetmap.josm.data.coor.LatLon;
     14import org.openstreetmap.josm.data.osm.DataSet;
    1415import org.openstreetmap.josm.data.osm.Node;
    1516import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    9697        }
    9798
     99        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
    98100        if (node == null) {
    99101            node = new Node(ll);
    100102            // Now execute the commands to add this node.
    101             MainApplication.undoRedo.add(new AddCommand(node));
     103            MainApplication.undoRedo.add(new AddCommand(ds, node));
    102104        }
    103105
    104         MainApplication.getLayerManager().getEditDataSet().setSelected(node);
     106        ds.setSelected(node);
    105107        if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) {
    106108            AutoScaleAction.autoScale("selection");
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java

    r12641 r12726  
    1919import org.openstreetmap.josm.command.SequenceCommand;
    2020import org.openstreetmap.josm.data.coor.LatLon;
     21import org.openstreetmap.josm.data.osm.DataSet;
    2122import org.openstreetmap.josm.data.osm.Node;
    2223import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    148149            nd = new Node(ll);
    149150            // Now execute the commands to add this node.
    150             commands.add(new AddCommand(nd));
     151            commands.add(new AddCommand(Main.main.getEditDataSet(), nd));
    151152            addedNodes.put(ll, nd);
    152153        }
     
    166167        }
    167168        allCoordinates.clear();
    168         commands.add(new AddCommand(way));
     169        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
     170        commands.add(new AddCommand(ds, way));
    169171        MainApplication.undoRedo.add(new SequenceCommand(tr("Add way"), commands));
    170         MainApplication.getLayerManager().getEditDataSet().setSelected(way);
     172        ds.setSelected(way);
    171173        if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) {
    172174            AutoScaleAction.autoScale("selection");
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r12718 r12726  
    228228            newWay.setNodes(newNodes[pos]);
    229229
    230             cmds.add(new ChangeCommand(way, newWay));
     230            cmds.add(new ChangeCommand(dataset, way, newWay));
    231231        }
    232232
  • trunk/test/unit/org/openstreetmap/josm/TestUtils.java

    r12130 r12726  
    2222
    2323import org.openstreetmap.josm.command.Command;
     24import org.openstreetmap.josm.data.osm.DataSet;
    2425import org.openstreetmap.josm.data.osm.Node;
    2526import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    257258    /**
    258259     * Creates a new empty command.
     260     * @param ds data set
    259261     * @return a new empty command
    260262     */
    261     public static Command newCommand() {
    262         return new Command() {
     263    public static Command newCommand(DataSet ds) {
     264        return new Command(ds) {
    263265            @Override
    264266            public String getDescriptionText() {
  • trunk/test/unit/org/openstreetmap/josm/actions/CreateMultipolygonActionTest.java

    r12659 r12726  
    1717import org.openstreetmap.josm.data.osm.RelationMember;
    1818import org.openstreetmap.josm.data.osm.Way;
     19import org.openstreetmap.josm.data.osm.search.SearchCompiler;
    1920import org.openstreetmap.josm.data.osm.search.SearchParseError;
    2021import org.openstreetmap.josm.data.osm.search.SearchSetting;
    21 import org.openstreetmap.josm.data.osm.search.SearchCompiler;
    2222import org.openstreetmap.josm.io.OsmReader;
    2323import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    4242        Map<String, String> refToRole = new TreeMap<>();
    4343        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            }
    4548        }
    4649        return refToRole;
  • trunk/test/unit/org/openstreetmap/josm/actions/SplitWayActionTest.java

    r12643 r12726  
    162162    void doTestRouteRelation(final boolean wayIsReversed, final int indexOfWayToKeep) {
    163163        final DataSet dataSet = new DataSet();
    164         final OsmDataLayer layer = new OsmDataLayer(dataSet, OsmDataLayer.createNewName(), null);
    165164        final Node n1 = new Node(new LatLon(1, 0));
    166165        final Node n2 = new Node(new LatLon(2, 0));
     
    197196            };
    198197        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);
    200199        MainApplication.undoRedo.add(result.getCommand());
    201200
  • trunk/test/unit/org/openstreetmap/josm/command/AddCommandTest.java

    r12636 r12726  
    1616import org.openstreetmap.josm.data.osm.User;
    1717import org.openstreetmap.josm.data.osm.Way;
    18 import org.openstreetmap.josm.gui.MainApplication;
    1918import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2019import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    4140    @Test
    4241    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());
    4644
    4745        Node osm = new Node(LatLon.ZERO);
    48         assertTrue(new AddCommand(osm).executeCommand());
     46        assertTrue(new AddCommand(ds, osm).executeCommand());
    4947
    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());
    5250        assertTrue(osm.isModified());
    5351    }
    5452
    5553    /**
    56      * Tests if the add command respects the layer.
     54     * Tests if the add command respects the data set.
    5755     */
    5856    @Test
    5957    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();
    6560
    6661        Node osm = new Node(LatLon.ZERO);
    67         assertTrue(new AddCommand(layer2, osm).executeCommand());
     62        assertTrue(new AddCommand(ds2, osm).executeCommand());
    6863
    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());
    7166    }
    7267
     
    7671    @Test
    7772    public void testUndo() {
    78         OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
    79         MainApplication.getLayerManager().addLayer(layer1);
    8073        Node osm = new Node(LatLon.ZERO);
    81         layer1.data.addPrimitive(osm);
     74        DataSet ds = new DataSet(osm);
    8275
    83         AddCommand command = new AddCommand(new Node(LatLon.ZERO));
     76        AddCommand command = new AddCommand(ds, new Node(LatLon.ZERO));
    8477        command.executeCommand();
    8578
    8679        command.undoCommand();
    87         assertArrayEquals(new Object[] {osm}, layer1.data.allPrimitives().toArray());
     80        assertArrayEquals(new Object[] {osm}, ds.allPrimitives().toArray());
    8881    }
    8982
     
    9588        Node osm = new Node(LatLon.ZERO);
    9689
    97         assertArrayEquals(new Object[] {osm}, new AddCommand(osm).getParticipatingPrimitives().toArray());
     90        assertArrayEquals(new Object[] {osm}, new AddCommand(new DataSet(), osm).getParticipatingPrimitives().toArray());
    9891    }
    9992
     
    108101        ArrayList<OsmPrimitive> deleted = new ArrayList<>();
    109102        ArrayList<OsmPrimitive> added = new ArrayList<>();
    110         new AddCommand(osm).fillModifiedData(modified, deleted, added);
     103        new AddCommand(new DataSet(), osm).fillModifiedData(modified, deleted, added);
    111104        assertArrayEquals(new Object[] {}, modified.toArray());
    112105        assertArrayEquals(new Object[] {}, deleted.toArray());
     
    127120        relation.put("name", "xy");
    128121
    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.*"));
    132126    }
    133127
  • trunk/test/unit/org/openstreetmap/josm/command/AddPrimitivesCommandTest.java

    r12636 r12726  
    2323import org.openstreetmap.josm.data.osm.Way;
    2424import org.openstreetmap.josm.data.osm.WayData;
    25 import org.openstreetmap.josm.gui.MainApplication;
    2625import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2726import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    4847    @Test
    4948    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());
    5856    }
    5957
     
    6361    @Test
    6462    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.
    7976     */
    8077    @Test
    8178    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());
    9690    }
    9791
     
    10195    @Test
    10296    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());
    110103
    111104        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());
    116109    }
    117110
     
    121114    @Test
    122115    public void testDescription() {
    123         OsmDataLayer layer1 = new OsmDataLayer(new DataSet(), "l1", null);
    124         MainApplication.getLayerManager().addLayer(layer1);
     116        DataSet ds = new DataSet();
    125117
    126118        List<PrimitiveData> testData = createTestData();
    127119        NodeData data2 = createTestNode(7);
    128120
    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);
    131123
    132124        assertEquals("Added 3 objects", command1.getDescriptionText());
     
    146138    @Test
    147139    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);
    154145
    155146        assertTrue(command.executeCommand());
    156147
    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();
    160151
    161152        for (int i = 0; i < 2; i++) {
     
    163154            command.undoCommand();
    164155
    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());
    167158
    168159            // redo
    169160            assertTrue(command.executeCommand());
    170161
    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());
    174165        }
    175166    }
     
    181172    @Test
    182173    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());
    191181
    192182        testData.set(2, createTestNode(7));
    193183
    194         AddPrimitivesCommand command = new AddPrimitivesCommand(testData);
     184        AddPrimitivesCommand command = new AddPrimitivesCommand(testData, ds);
    195185
    196186        assertTrue(command.executeCommand());
    197187
    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());
    200190
    201191        for (int i = 0; i < 2; i++) {
     
    203193            command.undoCommand();
    204194
    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());
    207197
    208198            // redo
    209199            assertTrue(command.executeCommand());
    210200
    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());
    213203        }
    214204    }
     
    219209    @Test
    220210    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);
    226215        assertTrue(command.executeCommand());
    227216
    228217        assertEquals(3, command.getParticipatingPrimitives().size());
    229         HashSet<OsmPrimitive> should = new HashSet<>(layer1.data.allPrimitives());
     218        HashSet<OsmPrimitive> should = new HashSet<>(ds.allPrimitives());
    230219        assertEquals(should, new HashSet<>(command.getParticipatingPrimitives()));
    231220
     
    245234
    246235        List<PrimitiveData> testData = createTestData();
    247         new AddPrimitivesCommand(testData).fillModifiedData(modified, deleted, added);
     236        new AddPrimitivesCommand(testData, new DataSet()).fillModifiedData(modified, deleted, added);
    248237
    249238        assertArrayEquals(new Object[] {}, modified.toArray());
     
    252241    }
    253242
    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()) {
    260249            assertEquals("test", n.get("test"));
    261250            assertTrue(n.isModified());
    262251        }
    263252
    264         for (Node n : layer1.data.getNodes()) {
     253        for (Node n : data.getNodes()) {
    265254            assertEquals(LatLon.ZERO, n.getCoor());
    266255        }
    267256
    268         for (Way w : layer1.data.getWays()) {
     257        for (Way w : data.getWays()) {
    269258            assertEquals(2, w.getNodes().size());
    270259            assertEquals(5, w.getNode(0).getId());
  • trunk/test/unit/org/openstreetmap/josm/command/ChangeCommandTest.java

    r10758 r12726  
    142142        Relation relation = new Relation();
    143143        relation.put("name", "xy");
     144        DataSet ds = new DataSet(node, way, relation);
    144145
    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.*"));
    148149    }
    149150
  • trunk/test/unit/org/openstreetmap/josm/command/ChangeNodesCommandTest.java

    r10758 r12726  
    115115        way.addNode(node);
    116116        way.put("name", "xy");
    117 
     117        DataSet ds = new DataSet(node, way);
    118118        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.*"));
    120120    }
    121121
  • trunk/test/unit/org/openstreetmap/josm/command/ChangePropertyCommandTest.java

    r10758 r12726  
    201201        tagsRemove.put("existing", "");
    202202
    203         Way way = new Way();
    204         way.addNode(node1);
     203        Way way = testData.createWay(20, node1);
    205204        way.put("name", "xy");
    206205        way.put("existing", "existing");
    207         Relation relation = new Relation();
     206        Relation relation = testData.createRelation(30);
    208207        relation.put("name", "xy");
    209208        relation.put("existing", "existing");
  • trunk/test/unit/org/openstreetmap/josm/command/CommandTest.java

    r12718 r12726  
    22package org.openstreetmap.josm.command;
    33
    4 import static org.junit.Assert.assertSame;
     4import java.util.Arrays;
    55
    6 import java.util.Arrays;
    7 import java.util.Collection;
    8 
    9 import org.junit.Before;
    106import org.junit.Rule;
    117import org.junit.Test;
     
    139import org.openstreetmap.josm.data.osm.DataSet;
    1410import org.openstreetmap.josm.data.osm.Node;
    15 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1611import org.openstreetmap.josm.data.osm.Relation;
    1712import org.openstreetmap.josm.data.osm.RelationMember;
     
    3732    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    3833    public JOSMTestRules test = new JOSMTestRules().preferences().i18n();
    39     private CommandTestData testData;
    40 
    41     /**
    42      * Set up the test data.
    43      */
    44     @Before
    45     public void createTestData() {
    46         testData = new CommandTestData();
    47     }
    48 
    49     /**
    50      * Test {@link Command#getLayer()}
    51      * @deprecated to be removed end of 2017
    52      */
    53     @Test
    54     @Deprecated
    55     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     }
    6234
    6335    /**
     
    7547            .suppress(Warning.NONFINAL_FIELDS)
    7648            .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         @Override
    89         public String getDescriptionText() {
    90             return "";
    91         }
    92 
    93         @Override
    94         public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
    95                 Collection<OsmPrimitive> added) {
    96             // nop
    97         }
    9849    }
    9950
  • trunk/test/unit/org/openstreetmap/josm/command/DeleteCommandTest.java

    r10775 r12726  
    1111import java.util.Collection;
    1212import java.util.List;
     13import java.util.NoSuchElementException;
    1314
    1415import org.junit.Before;
     
    113114     */
    114115    @Test
    115     public void testDelteNodesInWay() {
     116    public void testDeleteNodesInWay() {
    116117        testData.existingNode.removeAll();
    117118        // That untagged node should be deleted.
    118119        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();
    120121
    121122        assertTrue(testData.existingWay.isDeleted());
     
    137138        way2.setNodes(Arrays.asList(node2, node3, node4));
    138139        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();
    140141
    141142        assertTrue(way1.isDeleted());
     
    167168     * Test that {@link DeleteCommand} checks for non-empty list
    168169     */
    169     @Test(expected = IllegalArgumentException.class)
     170    @Test(expected = NoSuchElementException.class)
    170171    public void testConsistencyNonEmpty() {
    171172        new DeleteCommand(Arrays.<OsmPrimitive>asList());
     
    175176     * Test that {@link DeleteCommand} checks for non-null list
    176177     */
    177     @Test(expected = IllegalArgumentException.class)
     178    @Test(expected = NullPointerException.class)
    178179    public void testConsistencyNonNull() {
    179180        new DeleteCommand((Collection<OsmPrimitive>) null);
  • trunk/test/unit/org/openstreetmap/josm/command/MoveCommandTest.java

    r10758 r12726  
    248248        Node node = new Node(LatLon.ZERO);
    249249        node.put("name", "xy");
    250 
     250        new DataSet(node);
    251251        List<OsmPrimitive> nodeList = Arrays.<OsmPrimitive>asList(node);
    252252        assertTrue(new MoveCommand(nodeList, 1, 2).getDescriptionText().matches("Move 1 node"));
  • trunk/test/unit/org/openstreetmap/josm/command/RotateCommandTest.java

    r10758 r12726  
    5555        Node n2 = new Node(new EastNorth(-1, 0));
    5656        Node n3 = new Node(new EastNorth(-9, -10));
     57        new DataSet(n1, n2, n3);
    5758        RotateCommand rotate = new RotateCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0));
    5859        rotate.setRotationAngle(Math.PI / 4);
     
    7374        Node n2 = new Node(new EastNorth(-1, 0));
    7475        Node n3 = new Node(new EastNorth(-9, -10));
     76        new DataSet(n1, n2, n3);
    7577        RotateCommand rotate = new RotateCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0));
    7678        rotate.setRotationAngle(Math.PI / 4);
  • trunk/test/unit/org/openstreetmap/josm/command/ScaleCommandTest.java

    r10758 r12726  
    5555        Node n2 = new Node(new EastNorth(-1, 0));
    5656        Node n3 = new Node(new EastNorth(-9, -10));
     57        new DataSet(n1, n2, n3);
    5758        ScaleCommand scale = new ScaleCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0));
    5859        scale.setScalingFactor(2.5);
     
    7374        Node n2 = new Node(new EastNorth(-1, 0));
    7475        Node n3 = new Node(new EastNorth(-9, -10));
     76        new DataSet(n1, n2, n3);
    7577        ScaleCommand scale = new ScaleCommand(Arrays.asList(n1, n2, n3), new EastNorth(0, 0));
    7678        scale.setScalingFactor(2.5);
  • trunk/test/unit/org/openstreetmap/josm/command/SelectCommandTest.java

    r12368 r12726  
    5050    @Test
    5151    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));
    5353
    5454        testData.layer.data.setSelected(Arrays.asList(testData.existingNode2));
     
    6767    public void testExecuteAfterModify() {
    6868        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);
    7070
    7171        list.remove(testData.existingNode);
     
    8484    @Test
    8585    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));
    8787        testData.layer.data.setSelected(Arrays.asList(testData.existingNode2));
    8888
     
    110110        ArrayList<OsmPrimitive> deleted = new ArrayList<>();
    111111        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));
    113113        command.fillModifiedData(modified, deleted, added);
    114114        // intentionally empty.
     
    123123    @Test
    124124    public void testGetParticipatingPrimitives() {
    125         SelectCommand command = new SelectCommand(Arrays.asList(testData.existingNode));
     125        SelectCommand command = new SelectCommand(testData.layer.data, Arrays.asList(testData.existingNode));
    126126        command.executeCommand();
    127127        assertArrayEquals(new Object[] {testData.existingNode}, command.getParticipatingPrimitives().toArray());
     
    133133    @Test
    134134    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))
    136137                .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))
    138139                .getDescriptionText().matches("Selected 2 objects"));
    139         assertTrue(new SelectCommand(Arrays.<OsmPrimitive>asList())
     140        assertTrue(new SelectCommand(ds, Arrays.<OsmPrimitive>asList())
    140141                .getDescriptionText().matches("Selected 0 objects"));
    141         assertTrue(new SelectCommand(null)
     142        assertTrue(new SelectCommand(ds, null)
    142143                .getDescriptionText().matches("Selected 0 objects"));
    143144    }
  • trunk/test/unit/org/openstreetmap/josm/command/SequenceCommandTest.java

    r11874 r12726  
    1212import java.util.Arrays;
    1313import java.util.Collection;
     14import java.util.Collections;
    1415
    1516import org.junit.Before;
     
    5455    @Test
    5556    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)) {
    5860            @Override
    5961            public boolean executeCommand() {
     
    7577    @Test
    7678    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)) {
    7982            @Override
    8083            public void undoCommand() {
     
    103106    @Test
    104107    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);
    108112        SequenceCommand command = new SequenceCommand("seq", Arrays.<Command>asList(command1, command2, command3));
    109113        assertFalse(command.executeCommand());
     
    119123    @Test
    120124    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);
    124129        SequenceCommand command = new SequenceCommand("seq", Arrays.<Command>asList(command1, command2, command3), true);
    125130        assertTrue(command.executeCommand());
     
    137142    @Test
    138143    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());
    144150    }
    145151
     
    149155    @Test
    150156    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)) {
    154161            @Override
    155162            public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
     
    158165            }
    159166        };
    160         Command command4 = new TestCommand(Arrays.<OsmPrimitive>asList(testData.existingRelation)) {
     167        Command command4 = new TestCommand(ds, Arrays.<OsmPrimitive>asList(testData.existingRelation)) {
    161168            @Override
    162169            public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
     
    181188    @Test
    182189    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));
    185193
    186194        SequenceCommand command = new SequenceCommand("seq", command1, command2);
     
    197205    @Test
    198206    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"));
    200208    }
    201209
     
    205213    @Test
    206214    public void testEqualsContract() {
     215        DataSet ds = new DataSet();
    207216        EqualsVerifier.forClass(SequenceCommand.class).usingGetClass()
    208217            .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)))
    210219            .withPrefabValues(DataSet.class,
    211220                    new DataSet(), new DataSet())
     
    222231        protected boolean executed;
    223232
    224         TestCommand(Collection<? extends OsmPrimitive> primitives) {
    225             super();
     233        TestCommand(DataSet ds, Collection<? extends OsmPrimitive> primitives) {
     234            super(ds);
    226235            this.primitives = primitives;
    227236        }
     
    266275    private static class FailingCommand extends TestCommand {
    267276
    268         FailingCommand() {
    269             super(null);
     277        FailingCommand(DataSet ds) {
     278            super(ds, null);
    270279        }
    271280
     
    286295            return "FailingCommand";
    287296        }
    288 
    289     }
    290 
     297    }
    291298}
  • trunk/test/unit/org/openstreetmap/josm/command/conflict/ConflictAddCommandTest.java

    r12672 r12726  
    66import static org.junit.Assert.assertTrue;
    77
    8 import org.junit.After;
    98import org.junit.Before;
    109import org.junit.Rule;
    1110import org.junit.Test;
     11import org.openstreetmap.josm.command.CommandTest.CommandTestData;
    1212import org.openstreetmap.josm.data.conflict.Conflict;
    1313import org.openstreetmap.josm.data.osm.DataSet;
     
    1515import org.openstreetmap.josm.data.osm.User;
    1616import org.openstreetmap.josm.data.osm.Way;
    17 import org.openstreetmap.josm.gui.MainApplication;
    1817import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1918import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    2827public class ConflictAddCommandTest {
    2928
    30     private OsmDataLayer layer;
    31 
    3229    /**
    3330     * Setup test.
     
    3633    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    3734    public JOSMTestRules test = new JOSMTestRules().platform();
     35    private CommandTestData testData;
    3836
    3937    /**
     
    4240    @Before
    4341    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();
    5443    }
    5544
     
    5948    @Test
    6049    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);
    6352        ConflictAddCommand cmd = new ConflictAddCommand(ds, conflict);
    6453        assertTrue(cmd.executeCommand());
     
    7564    @Test
    7665    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());
    8068    }
    8169
  • trunk/test/unit/org/openstreetmap/josm/command/conflict/CoordinateConflictResolveCommandTest.java

    r12636 r12726  
    66import static org.junit.Assert.assertTrue;
    77
    8 import org.junit.After;
    98import org.junit.Before;
    109import org.junit.Rule;
    1110import org.junit.Test;
     11import org.openstreetmap.josm.command.CommandTest.CommandTestData;
    1212import org.openstreetmap.josm.data.conflict.Conflict;
    1313import org.openstreetmap.josm.data.coor.LatLon;
     
    1616import org.openstreetmap.josm.data.osm.User;
    1717import org.openstreetmap.josm.data.osm.Way;
    18 import org.openstreetmap.josm.gui.MainApplication;
    1918import org.openstreetmap.josm.gui.conflict.pair.MergeDecisionType;
    2019import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    3029public class CoordinateConflictResolveCommandTest {
    3130
    32     private OsmDataLayer layer;
     31    private CommandTestData testData;
    3332
    3433    /**
     
    4443    @Before
    4544    public void setUp() {
    46         layer = new OsmDataLayer(new DataSet(), null, null);
    47         MainApplication.getLayerManager().addLayer(layer);
     45        testData = new CommandTestData();
    4846    }
    4947
    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);
    6050    }
    6151
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/MapCSSTagCheckerTest.java

    r12620 r12726  
    2525import org.openstreetmap.josm.command.PseudoCommand;
    2626import org.openstreetmap.josm.command.SequenceCommand;
    27 import org.openstreetmap.josm.data.osm.Node;
     27import org.openstreetmap.josm.data.osm.DataSet;
    2828import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2929import org.openstreetmap.josm.data.osm.OsmUtils;
     
    8282        assertEquals("fixAdd: natural=wetland", check.fixCommands.get(1).toString());
    8383        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);
    8687        assertTrue(check.test(n1));
    8788        assertEquals("deprecated", check.getErrorForPrimitive(n1).getMessage());
     
    9091        assertEquals("Sequence: Fix of natural=marsh is deprecated", check.fixPrimitive(n1).getDescriptionText());
    9192        assertEquals("{natural=}", ((ChangePropertyCommand) check.fixPrimitive(n1).getChildren().iterator().next()).getTags().toString());
    92         final Node n2 = new Node();
    93         n2.put("natural", "wood");
    9493        assertFalse(check.test(n2));
    9594        assertEquals("The key is natural and the value is marsh",
     
    109108                "fixAdd: \"highway=construction\";\n" +
    110109                "}")).parseChecks.get(0);
     110        new DataSet(p);
    111111        final Command command = check.fixPrimitive(p);
    112112        assertTrue(command instanceof SequenceCommand);
  • trunk/test/unit/org/openstreetmap/josm/gui/conflict/pair/ConflictResolverTest.java

    r11102 r12726  
    55import static org.junit.Assert.assertNotNull;
    66
     7import java.util.NoSuchElementException;
     8
    79import org.junit.Rule;
    810import org.junit.Test;
     
    1012import org.openstreetmap.josm.data.conflict.Conflict;
    1113import org.openstreetmap.josm.data.coor.LatLon;
     14import org.openstreetmap.josm.data.osm.DataSet;
    1215import org.openstreetmap.josm.data.osm.Node;
    1316import org.openstreetmap.josm.data.osm.Relation;
     
    3235     * Unit test of {@link ConflictResolver#buildResolveCommand} - empty case.
    3336     */
    34     @Test
     37    @Test(expected = NoSuchElementException.class)
    3538    public void testBuildResolveCommandEmpty() {
    3639        assertNotNull(new ConflictResolver().buildResolveCommand());
     
    4750        Node n2 = new Node(LatLon.NORTH_POLE);
    4851        n2.put("source", "theirs");
     52        new DataSet(n1, n2);
    4953        resolver.populate(new Conflict<>(n1, n2));
    5054        resolver.decideRemaining(MergeDecisionType.KEEP_MINE);
     
    6266        Way w2 = new Way();
    6367        w2.put("source", "theirs");
     68        new DataSet(w1, w2);
    6469        resolver.populate(new Conflict<>(w1, w2));
    6570        resolver.decideRemaining(MergeDecisionType.KEEP_MINE);
     
    7782        Relation r2 = new Relation();
    7883        r2.put("source", "theirs");
     84        new DataSet(r1, r2);
    7985        resolver.populate(new Conflict<>(r1, r2));
    8086        resolver.decideRemaining(MergeDecisionType.KEEP_MINE);
  • trunk/test/unit/org/openstreetmap/josm/gui/datatransfer/OsmTransferHandlerTest.java

    r12564 r12726  
    6464    public void testPasteTags() {
    6565        Node n = new Node(LatLon.ZERO);
     66        new DataSet(n);
    6667
    6768        ClipboardUtils.copyString("test=ok");
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/CommandStackDialogTest.java

    r12641 r12726  
    4646    @Test
    4747    public void testCommandStackDialogNotEmpty() {
    48         OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null);
     48        DataSet ds = new DataSet();
     49        OsmDataLayer layer = new OsmDataLayer(ds, "", null);
    4950        MainApplication.getLayerManager().addLayer(layer);
    5051        try {
    51             Command cmd1 = TestUtils.newCommand();
    52             Command cmd2 = TestUtils.newCommand();
     52            Command cmd1 = TestUtils.newCommand(ds);
     53            Command cmd2 = TestUtils.newCommand(ds);
    5354            MainApplication.undoRedo.add(cmd1);
    5455            MainApplication.undoRedo.add(cmd2);
Note: See TracChangeset for help on using the changeset viewer.