001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.command;
003
004import static org.openstreetmap.josm.tools.I18n.tr;
005
006import java.util.HashSet;
007import java.util.List;
008import java.util.Set;
009
010import org.openstreetmap.josm.data.osm.DataSet;
011import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
012import org.openstreetmap.josm.data.osm.Node;
013import org.openstreetmap.josm.data.osm.Way;
014
015/**
016 * Command that removes a set of nodes from a way.
017 * The same can be done with ChangeNodesCommand, but this is more
018 * efficient. (Needed for the tool to disconnect nodes from ways.)
019 *
020 * @author Giuseppe Bilotta
021 */
022public class RemoveNodesCommand extends AbstractNodesCommand<Set<Node>> {
023
024    /**
025     * Constructs a new {@code RemoveNodesCommand}.
026     * @param way The way to modify. Must not be null, and belong to a data set
027     * @param rmNodes The list of nodes to remove
028     * @deprecated Use {@link #RemoveNodesCommand(Way, Set)}
029     */
030    @Deprecated
031    public RemoveNodesCommand(Way way, List<Node> rmNodes) {
032        super(way.getDataSet(), way, new HashSet<>(rmNodes));
033    }
034
035    /**
036     * Constructs a new {@code RemoveNodesCommand}.
037     * @param way The way to modify. Must not be null, and belong to a data set
038     * @param rmNodes The set of nodes to remove
039     * @since 15013
040     */
041    public RemoveNodesCommand(Way way, Set<Node> rmNodes) {
042        super(way.getDataSet(), way, rmNodes);
043    }
044
045    /**
046     * Constructs a new {@code RemoveNodesCommand}.
047     * @param ds The target data set. Must not be {@code null}
048     * @param way The way to modify. Must not be null, and belong to a data set
049     * @param rmNodes The list of nodes to remove
050     * @since 15013
051     */
052    public RemoveNodesCommand(DataSet ds, Way way, Set<Node> rmNodes) {
053        super(ds, way, rmNodes);
054    }
055
056    @Override
057    protected void modifyWay() {
058        way.removeNodes(cmdNodes);
059    }
060
061    @Override
062    public String getDescriptionText() {
063        return tr("Removed nodes from {0}", way.getDisplayName(DefaultNameFormatter.getInstance()));
064    }
065}