source: josm/trunk/src/org/openstreetmap/josm/command/conflict/ConflictResolveCommand.java@ 13186

Last change on this file since 13186 was 13173, checked in by Don-vip, 6 years ago

see #15310 - remove most of deprecated APIs

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command.conflict;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.Objects;
7
8import org.openstreetmap.josm.Main;
9import org.openstreetmap.josm.command.Command;
10import org.openstreetmap.josm.data.conflict.Conflict;
11import org.openstreetmap.josm.data.conflict.ConflictCollection;
12import org.openstreetmap.josm.data.osm.DataSet;
13import org.openstreetmap.josm.tools.Logging;
14
15/**
16 * This is the common base class for {@link Command}s which manipulate {@link Conflict}s in
17 * addition to {@link org.openstreetmap.josm.data.osm.OsmPrimitive}s.
18 *
19 * A ConflictResolverCommand can remember a collection of conflicts it resolves. Upon undoing
20 * it reconstitutes them.
21 *
22 */
23public abstract class ConflictResolveCommand extends Command {
24 /** the list of resolved conflicts */
25 private final ConflictCollection resolvedConflicts = new ConflictCollection();
26
27 /**
28 * Constructs a new {@code ConflictResolveCommand} in the context of a given data set.
29 * @param ds the data set. Must not be null.
30 */
31 public ConflictResolveCommand(DataSet ds) {
32 super(ds);
33 }
34
35 /**
36 * remembers a conflict in the internal list of remembered conflicts
37 *
38 * @param c the remembered conflict
39 */
40 protected void rememberConflict(Conflict<?> c) {
41 if (!resolvedConflicts.hasConflictForMy(c.getMy())) {
42 resolvedConflicts.add(c);
43 }
44 }
45
46 /**
47 * reconstitutes all remembered conflicts. Add the remembered conflicts to the
48 * set of conflicts of the {@link DataSet} this command was applied to.
49 *
50 */
51 protected void reconstituteConflicts() {
52 DataSet ds = getAffectedDataSet();
53 for (Conflict<?> c : resolvedConflicts) {
54 if (!ds.getConflicts().hasConflictForMy(c.getMy())) {
55 ds.getConflicts().add(c);
56 }
57 }
58 }
59
60 @Override
61 public void undoCommand() {
62 super.undoCommand();
63
64 DataSet ds = getAffectedDataSet();
65 if (Main.main != null) {
66 if (!Main.main.containsDataSet(ds)) {
67 Logging.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more",
68 this.toString(),
69 ds.getName()
70 ));
71 return;
72 }
73
74 Main.main.setEditDataSet(ds);
75 }
76 reconstituteConflicts();
77 }
78
79 @Override
80 public int hashCode() {
81 return Objects.hash(super.hashCode(), resolvedConflicts);
82 }
83
84 @Override
85 public boolean equals(Object obj) {
86 if (this == obj) return true;
87 if (obj == null || getClass() != obj.getClass()) return false;
88 if (!super.equals(obj)) return false;
89 ConflictResolveCommand that = (ConflictResolveCommand) obj;
90 return Objects.equals(resolvedConflicts, that.resolvedConflicts);
91 }
92}
Note: See TracBrowser for help on using the repository browser.