source: josm/trunk/src/org/openstreetmap/josm/command/conflict/VersionConflictResolveCommand.java@ 8961

Last change on this file since 8961 was 8910, checked in by Don-vip, 9 years ago

add unit test for ConflictAddCommand

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command.conflict;
3
4import static org.openstreetmap.josm.tools.I18n.marktr;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.util.Collection;
8
9import javax.swing.Icon;
10
11import org.openstreetmap.josm.data.conflict.Conflict;
12import org.openstreetmap.josm.data.osm.OsmPrimitive;
13import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
14import org.openstreetmap.josm.tools.ImageProvider;
15
16/**
17 * Represents the resolution of a version conflict between two {@link OsmPrimitive}s.
18 *
19 *
20 */
21public class VersionConflictResolveCommand extends ConflictResolveCommand {
22
23 /** the conflict to resolve */
24 private final Conflict<? extends OsmPrimitive> conflict;
25
26 /**
27 * constructor
28 * @param conflict the conflict data set
29 */
30 public VersionConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
31 this.conflict = conflict;
32 }
33
34 @Override
35 public String getDescriptionText() {
36 String msg = "";
37 switch(OsmPrimitiveType.from(conflict.getMy())) {
38 case NODE: msg = marktr("Resolve version conflict for node {0}"); break;
39 case WAY: msg = marktr("Resolve version conflict for way {0}"); break;
40 case RELATION: msg = marktr("Resolve version conflict for relation {0}"); break;
41 }
42 return tr(msg, conflict.getMy().getId());
43 }
44
45 @Override
46 public Icon getDescriptionIcon() {
47 return ImageProvider.get("data", "object");
48 }
49
50 @Override
51 public boolean executeCommand() {
52 super.executeCommand();
53 if (!conflict.getMy().isNew()) {
54 long myVersion = conflict.getMy().getVersion();
55 long theirVersion = conflict.getTheir().getVersion();
56 conflict.getMy().setOsmId(
57 conflict.getMy().getId(),
58 (int) Math.max(myVersion, theirVersion)
59 );
60 // update visiblity state
61 if (theirVersion >= myVersion) {
62 conflict.getMy().setVisible(conflict.getTheir().isVisible());
63 }
64 }
65 getLayer().getConflicts().remove(conflict);
66 rememberConflict(conflict);
67 return true;
68 }
69
70 @Override
71 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
72 Collection<OsmPrimitive> added) {
73 modified.add(conflict.getMy());
74 }
75
76 @Override
77 public int hashCode() {
78 final int prime = 31;
79 int result = super.hashCode();
80 result = prime * result + ((conflict == null) ? 0 : conflict.hashCode());
81 return result;
82 }
83
84 @Override
85 public boolean equals(Object obj) {
86 if (this == obj)
87 return true;
88 if (!super.equals(obj))
89 return false;
90 if (getClass() != obj.getClass())
91 return false;
92 VersionConflictResolveCommand other = (VersionConflictResolveCommand) obj;
93 if (conflict == null) {
94 if (other.conflict != null)
95 return false;
96 } else if (!conflict.equals(other.conflict))
97 return false;
98 return true;
99 }
100}
Note: See TracBrowser for help on using the repository browser.