1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.conflict.tags;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.gui.conflict.tags.RelationMemberConflictDecisionType.UNDECIDED;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 |
|
---|
7 | import java.util.Objects;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
10 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
11 | import org.openstreetmap.josm.data.osm.RelationMember;
|
---|
12 | import org.openstreetmap.josm.tools.CheckParameterUtil;
|
---|
13 |
|
---|
14 | public class RelationMemberConflictDecision {
|
---|
15 |
|
---|
16 | private final Relation relation;
|
---|
17 | private final int pos;
|
---|
18 | private final OsmPrimitive originalPrimitive;
|
---|
19 | private String role;
|
---|
20 | private RelationMemberConflictDecisionType decision;
|
---|
21 |
|
---|
22 | public RelationMemberConflictDecision(Relation relation, int pos) {
|
---|
23 | CheckParameterUtil.ensureParameterNotNull(relation, "relation");
|
---|
24 | RelationMember member = relation.getMember(pos);
|
---|
25 | if (member == null)
|
---|
26 | throw new IndexOutOfBoundsException(
|
---|
27 | tr("Position {0} is out of range. Current number of members is {1}.", pos, relation.getMembersCount()));
|
---|
28 | this.relation = relation;
|
---|
29 | this.pos = pos;
|
---|
30 | this.originalPrimitive = member.getMember();
|
---|
31 | this.role = member.hasRole() ? member.getRole() : "";
|
---|
32 | this.decision = UNDECIDED;
|
---|
33 | }
|
---|
34 |
|
---|
35 | public Relation getRelation() {
|
---|
36 | return relation;
|
---|
37 | }
|
---|
38 |
|
---|
39 | public int getPos() {
|
---|
40 | return pos;
|
---|
41 | }
|
---|
42 |
|
---|
43 | public OsmPrimitive getOriginalPrimitive() {
|
---|
44 | return originalPrimitive;
|
---|
45 | }
|
---|
46 |
|
---|
47 | public String getRole() {
|
---|
48 | return role;
|
---|
49 | }
|
---|
50 |
|
---|
51 | public RelationMemberConflictDecisionType getDecision() {
|
---|
52 | return decision;
|
---|
53 | }
|
---|
54 |
|
---|
55 | public void setRole(String role) {
|
---|
56 | this.role = role == null ? "" : role;
|
---|
57 | }
|
---|
58 |
|
---|
59 | public void decide(RelationMemberConflictDecisionType decision) {
|
---|
60 | if (decision == null) {
|
---|
61 | decision = UNDECIDED;
|
---|
62 | }
|
---|
63 | this.decision = decision;
|
---|
64 | }
|
---|
65 |
|
---|
66 | public boolean isDecided() {
|
---|
67 | return !UNDECIDED.equals(decision);
|
---|
68 | }
|
---|
69 |
|
---|
70 | public boolean matches(Relation relation, int pos) {
|
---|
71 | return this.relation == relation && this.pos == pos;
|
---|
72 | }
|
---|
73 |
|
---|
74 | @Override
|
---|
75 | public int hashCode() {
|
---|
76 | return Objects.hash(relation, pos, originalPrimitive, role, decision);
|
---|
77 | }
|
---|
78 |
|
---|
79 | @Override
|
---|
80 | public boolean equals(Object obj) {
|
---|
81 | if (this == obj) return true;
|
---|
82 | if (obj == null || getClass() != obj.getClass()) return false;
|
---|
83 | RelationMemberConflictDecision that = (RelationMemberConflictDecision) obj;
|
---|
84 | return pos == that.pos &&
|
---|
85 | decision == that.decision &&
|
---|
86 | Objects.equals(relation, that.relation) &&
|
---|
87 | Objects.equals(originalPrimitive, that.originalPrimitive) &&
|
---|
88 | Objects.equals(role, that.role);
|
---|
89 | }
|
---|
90 |
|
---|
91 | @Override
|
---|
92 | public String toString() {
|
---|
93 | return originalPrimitive.getPrimitiveId() + " at index " + pos + " with role " + role + " in " + relation.getUniqueId()
|
---|
94 | + " => " + decision;
|
---|
95 | }
|
---|
96 | }
|
---|