[8378] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[3142] | 2 | package org.openstreetmap.josm.command;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 5 |
|
---|
| 6 | import java.util.Collection;
|
---|
| 7 | import java.util.List;
|
---|
[6881] | 8 |
|
---|
[4918] | 9 | import javax.swing.Icon;
|
---|
[3142] | 10 |
|
---|
| 11 | import org.openstreetmap.josm.data.osm.Node;
|
---|
| 12 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
| 13 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
[6881] | 14 | import org.openstreetmap.josm.data.osm.Way;
|
---|
[3142] | 15 | import org.openstreetmap.josm.gui.DefaultNameFormatter;
|
---|
| 16 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
| 17 |
|
---|
| 18 | /**
|
---|
| 19 | * Command that changes the nodes list of a way.
|
---|
| 20 | * The same can be done with ChangeCommand, but this is more
|
---|
| 21 | * efficient. (Needed for the duplicate node fixing
|
---|
| 22 | * tool of the validator plugin, when processing large data sets.)
|
---|
| 23 | *
|
---|
| 24 | * @author Imi
|
---|
| 25 | */
|
---|
| 26 | public class ChangeNodesCommand extends Command {
|
---|
| 27 |
|
---|
| 28 | private final Way way;
|
---|
| 29 | private final List<Node> newNodes;
|
---|
| 30 |
|
---|
[6881] | 31 | /**
|
---|
| 32 | * Constructs a new {@code ChangeNodesCommand}.
|
---|
| 33 | * @param way The way to modify
|
---|
| 34 | * @param newNodes The new list of nodes for the given way
|
---|
| 35 | */
|
---|
[3142] | 36 | public ChangeNodesCommand(Way way, List<Node> newNodes) {
|
---|
| 37 | this.way = way;
|
---|
| 38 | this.newNodes = newNodes;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
[6881] | 41 | @Override
|
---|
| 42 | public boolean executeCommand() {
|
---|
[3142] | 43 | super.executeCommand();
|
---|
| 44 | way.setNodes(newNodes);
|
---|
| 45 | way.setModified(true);
|
---|
| 46 | return true;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
[6881] | 49 | @Override
|
---|
| 50 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
|
---|
[3142] | 51 | modified.add(way);
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[4918] | 54 | @Override
|
---|
| 55 | public String getDescriptionText() {
|
---|
| 56 | return tr("Changed nodes of {0}", way.getDisplayName(DefaultNameFormatter.getInstance()));
|
---|
[3142] | 57 | }
|
---|
[4918] | 58 |
|
---|
| 59 | @Override
|
---|
| 60 | public Icon getDescriptionIcon() {
|
---|
| 61 | return ImageProvider.get(OsmPrimitiveType.WAY);
|
---|
| 62 | }
|
---|
[8456] | 63 |
|
---|
| 64 | @Override
|
---|
| 65 | public int hashCode() {
|
---|
| 66 | final int prime = 31;
|
---|
| 67 | int result = super.hashCode();
|
---|
| 68 | result = prime * result + ((newNodes == null) ? 0 : newNodes.hashCode());
|
---|
| 69 | result = prime * result + ((way == null) ? 0 : way.hashCode());
|
---|
| 70 | return result;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | @Override
|
---|
| 74 | public boolean equals(Object obj) {
|
---|
| 75 | if (this == obj)
|
---|
| 76 | return true;
|
---|
| 77 | if (!super.equals(obj))
|
---|
| 78 | return false;
|
---|
| 79 | if (getClass() != obj.getClass())
|
---|
| 80 | return false;
|
---|
| 81 | ChangeNodesCommand other = (ChangeNodesCommand) obj;
|
---|
| 82 | if (newNodes == null) {
|
---|
| 83 | if (other.newNodes != null)
|
---|
| 84 | return false;
|
---|
| 85 | } else if (!newNodes.equals(other.newNodes))
|
---|
| 86 | return false;
|
---|
| 87 | if (way == null) {
|
---|
| 88 | if (other.way != null)
|
---|
| 89 | return false;
|
---|
| 90 | } else if (!way.equals(other.way))
|
---|
| 91 | return false;
|
---|
| 92 | return true;
|
---|
| 93 | }
|
---|
[3142] | 94 | }
|
---|