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

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

fix javadoc errors/warnings

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