source: josm/trunk/src/org/openstreetmap/josm/data/conflict/Conflict.java@ 13818

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

see #12472, fix #13230, fix #13225, fix #13228 - disable ReferenceEquality warning + partial revert of r10656 + r10659, causes too much problems

  • Property svn:eol-style set to native
File size: 3.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.conflict;
3
4import java.util.Map;
5import java.util.Objects;
6
7import org.openstreetmap.josm.data.osm.OsmPrimitive;
8import org.openstreetmap.josm.data.osm.PrimitiveId;
9
10/**
11 * Represents a conflict between two {@link OsmPrimitive}s. It is represented as
12 * a pair of {@link OsmPrimitive}s where one element of the pair has the role <em>my</em>
13 * and the other has the role <em>their</em>.
14 * <ul>
15 * <li><code>my</code> is the {@link OsmPrimitive} in the local dataset</li>
16 * <li><code>their</code> is the {@link OsmPrimitive} which caused the conflict when it
17 * it was tried to merge it onto <code>my</code>. <code>their</code> is usually the
18 * {@link OsmPrimitive} from the dataset in another layer or the one retrieved from the server.</li>
19 * </ul>
20 * @param <T> primitive type of the conflict
21 * @since 1750
22 */
23public class Conflict<T extends OsmPrimitive> {
24 private final T my;
25 private final T their;
26 private final boolean isMyDeleted;
27
28 // mergedMap is only set if the conflict results from merging two layers
29 private Map<PrimitiveId, PrimitiveId> mergedMap;
30
31 public Conflict(T my, T their) {
32 this(my, their, false);
33 }
34
35 public Conflict(T my, T their, boolean isMyDeleted) {
36 this.my = my;
37 this.their = their;
38 this.isMyDeleted = isMyDeleted;
39 }
40
41 public T getMy() {
42 return my;
43 }
44
45 public T getTheir() {
46 return their;
47 }
48
49 public boolean isMatchingMy(OsmPrimitive my) {
50 return this.my == my;
51 }
52
53 public boolean isMatchingTheir(OsmPrimitive their) {
54 return this.their == their;
55 }
56
57 /**
58 * Replies true if the primitive <code>primitive</code> is participating
59 * in this conflict
60 *
61 * @param primitive the primitive
62 * @return true if the primitive <code>primitive</code> is participating
63 * in this conflict
64 */
65 public boolean isParticipating(OsmPrimitive primitive) {
66 if (primitive == null) return false;
67 return primitive.getPrimitiveId().equals(my.getPrimitiveId())
68 || primitive.getPrimitiveId().equals(their.getPrimitiveId());
69 }
70
71 /**
72 * Replies true if the primitive with id <code>id</code> is participating
73 * in this conflict
74 *
75 * @param id the primitive id
76 * @return true if the primitive <code>primitive</code> is participating
77 * in this conflict
78 */
79 public boolean isParticipating(PrimitiveId id) {
80 if (id == null) return false;
81 return id.equals(my.getPrimitiveId())
82 || id.equals(their.getPrimitiveId());
83 }
84
85 @Override
86 public int hashCode() {
87 return Objects.hash(my, their);
88 }
89
90 @Override
91 public boolean equals(Object obj) {
92 if (this == obj) return true;
93 if (obj == null || getClass() != obj.getClass()) return false;
94 Conflict<?> conflict = (Conflict<?>) obj;
95 return Objects.equals(my, conflict.my) &&
96 Objects.equals(their, conflict.their);
97 }
98
99 /**
100 *
101 * @return True if my primitive was deleted but it has set non deleted status because it's referred by another
102 * primitive and references to deleted primitives are not allowed.
103 */
104 public boolean isMyDeleted() {
105 return isMyDeleted;
106 }
107
108 public final Map<PrimitiveId, PrimitiveId> getMergedMap() {
109 return mergedMap;
110 }
111
112 public final void setMergedMap(Map<PrimitiveId, PrimitiveId> mergedMap) {
113 this.mergedMap = mergedMap;
114 }
115
116 @Override
117 public String toString() {
118 return "Conflict [my=" + my + ", their=" + their + ']';
119 }
120}
Note: See TracBrowser for help on using the repository browser.