001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.command.conflict; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import java.util.Collection; 007import java.util.List; 008 009import javax.swing.Icon; 010 011import org.openstreetmap.josm.Main; 012import org.openstreetmap.josm.data.conflict.Conflict; 013import org.openstreetmap.josm.data.osm.Node; 014import org.openstreetmap.josm.data.osm.OsmPrimitive; 015import org.openstreetmap.josm.data.osm.Way; 016import org.openstreetmap.josm.tools.ImageProvider; 017 018/** 019 * Represents the resolution of conflicts in the node list of two {@link Way}s. 020 * 021 */ 022public class WayNodesConflictResolverCommand extends ConflictResolveCommand { 023 /** the conflict to resolve */ 024 private final Conflict<Way> conflict; 025 026 /** the list of merged nodes. This becomes the list of news of my way after the 027 * command is executed 028 */ 029 private final List<Node> mergedNodeList; 030 031 /** 032 * @param conflict the conflict data set 033 * @param mergedNodeList the list of merged nodes 034 */ 035 @SuppressWarnings("unchecked") 036 public WayNodesConflictResolverCommand(Conflict<? extends OsmPrimitive> conflict, List<Node> mergedNodeList) { 037 this.conflict = (Conflict<Way>) conflict; 038 this.mergedNodeList = mergedNodeList; 039 } 040 041 @Override 042 public String getDescriptionText() { 043 return tr("Resolve conflicts in node list of way {0}", conflict.getMy().getId()); 044 } 045 046 @Override 047 public Icon getDescriptionIcon() { 048 return ImageProvider.get("data", "object"); 049 } 050 051 @Override 052 public boolean executeCommand() { 053 // remember the current state of 'my' way 054 // 055 super.executeCommand(); 056 057 // replace the list of nodes of 'my' way by the list of merged nodes 058 // 059 for (Node n:mergedNodeList) { 060 if (!getLayer().data.getNodes().contains(n)) { 061 Main.warn(tr("Main dataset does not include node {0}", n.toString())); 062 } 063 } 064 conflict.getMy().setNodes(mergedNodeList); 065 rememberConflict(conflict); 066 return true; 067 } 068 069 @Override 070 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 071 Collection<OsmPrimitive> added) { 072 modified.add(conflict.getMy()); 073 } 074 075 @Override 076 public int hashCode() { 077 final int prime = 31; 078 int result = super.hashCode(); 079 result = prime * result + ((conflict == null) ? 0 : conflict.hashCode()); 080 result = prime * result + ((mergedNodeList == null) ? 0 : mergedNodeList.hashCode()); 081 return result; 082 } 083 084 @Override 085 public boolean equals(Object obj) { 086 if (this == obj) 087 return true; 088 if (!super.equals(obj)) 089 return false; 090 if (getClass() != obj.getClass()) 091 return false; 092 WayNodesConflictResolverCommand other = (WayNodesConflictResolverCommand) obj; 093 if (conflict == null) { 094 if (other.conflict != null) 095 return false; 096 } else if (!conflict.equals(other.conflict)) 097 return false; 098 if (mergedNodeList == null) { 099 if (other.mergedNodeList != null) 100 return false; 101 } else if (!mergedNodeList.equals(other.mergedNodeList)) 102 return false; 103 return true; 104 } 105}