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

Last change on this file since 9917 was 9371, checked in by simon04, 8 years ago

Java 7: use Objects.equals and Objects.hash

  • 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 *
20 *
21 */
22public class ModifiedConflictResolveCommand extends ConflictResolveCommand {
23
24 /** the conflict to resolve */
25 private final Conflict<? extends OsmPrimitive> conflict;
26
27 /**
28 * constructor
29 * @param conflict the conflict data set
30 */
31 public ModifiedConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
32 this.conflict = conflict;
33 }
34
35 @Override
36 public String getDescriptionText() {
37 String msg = "";
38 switch(OsmPrimitiveType.from(conflict.getMy())) {
39 case NODE: msg = marktr("Set the ''modified'' flag for node {0}"); break;
40 case WAY: msg = marktr("Set the ''modified'' flag for way {0}"); break;
41 case RELATION: msg = marktr("Set the ''modified'' flag for relation {0}"); break;
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.