001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.data.osm.event;
003
004import java.util.Collections;
005import java.util.List;
006
007import org.openstreetmap.josm.data.osm.DataSet;
008import org.openstreetmap.josm.data.osm.OsmPrimitive;
009import org.openstreetmap.josm.data.osm.Way;
010
011/**
012 * An event that is triggered when the nodes of a way have been changed (nodes added, removed or the order was changed)
013 */
014public class WayNodesChangedEvent extends AbstractDatasetChangedEvent {
015
016    private final Way way;
017
018    /**
019     * Constructs a new {@code WayNodesChangedEvent}.
020     * @param dataSet the dataset from which the event comes from
021     * @param way the way affected by the change
022     */
023    public WayNodesChangedEvent(DataSet dataSet, Way way) {
024        super(dataSet);
025        this.way = way;
026    }
027
028    @Override
029    public void fire(DataSetListener listener) {
030        listener.wayNodesChanged(this);
031    }
032
033    /**
034     * Returns the way affected by the change.
035     * @return the way affected by the change
036     */
037    public Way getChangedWay() {
038        return way;
039    }
040
041    @Override
042    public List<? extends OsmPrimitive> getPrimitives() {
043        return Collections.singletonList(way);
044    }
045
046    @Override
047    public DatasetEventType getType() {
048        return DatasetEventType.WAY_NODES_CHANGED;
049    }
050
051}