source: josm/trunk/src/org/openstreetmap/josm/command/conflict/ModifiedConflictResolveCommand.java@ 12630

Last change on this file since 12630 was 10216, checked in by Don-vip, 8 years ago

findbugs - SF_SWITCH_NO_DEFAULT + various sonar fixes

  • Property svn:eol-style set to native
File size: 2.6 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;
8import java.util.Objects;
9
10import javax.swing.Icon;
11
12import org.openstreetmap.josm.data.conflict.Conflict;
13import org.openstreetmap.josm.data.osm.OsmPrimitive;
14import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
15import org.openstreetmap.josm.tools.ImageProvider;
16
17/**
18 * Represents the resolution of a conflict between the modified flag of two {@link OsmPrimitive}s.
19 * @since 2624
20 */
21public class ModifiedConflictResolveCommand 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 ModifiedConflictResolveCommand(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("Set the ''modified'' flag for node {0}"); break;
39 case WAY: msg = marktr("Set the ''modified'' flag for way {0}"); break;
40 case RELATION: msg = marktr("Set the ''modified'' flag for relation {0}"); break;
41 default: throw new AssertionError();
42 }
43 return tr(msg, conflict.getMy().getId());
44 }
45
46 @Override
47 public Icon getDescriptionIcon() {
48 return ImageProvider.get("data", "object");
49 }
50
51 @Override
52 public boolean executeCommand() {
53 super.executeCommand();
54 if (!conflict.getMy().isNew() && conflict.getMy().hasEqualSemanticAttributes(conflict.getTheir())) {
55 conflict.getMy().setModified(conflict.getTheir().isModified());
56 }
57 getLayer().getConflicts().remove(conflict);
58 rememberConflict(conflict);
59 return true;
60 }
61
62 @Override
63 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
64 Collection<OsmPrimitive> added) {
65 modified.add(conflict.getMy());
66 }
67
68 @Override
69 public int hashCode() {
70 return Objects.hash(super.hashCode(), conflict);
71 }
72
73 @Override
74 public boolean equals(Object obj) {
75 if (this == obj) return true;
76 if (obj == null || getClass() != obj.getClass()) return false;
77 if (!super.equals(obj)) return false;
78 ModifiedConflictResolveCommand that = (ModifiedConflictResolveCommand) obj;
79 return Objects.equals(conflict, that.conflict);
80 }
81}
Note: See TracBrowser for help on using the repository browser.