source: josm/trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictDecision.java@ 3083

Last change on this file since 3083 was 3083, checked in by bastiK, 14 years ago

added svn:eol-style=native to source files

  • Property svn:eol-style set to native
File size: 3.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.conflict.tags;
3
4import org.openstreetmap.josm.data.osm.OsmPrimitive;
5import org.openstreetmap.josm.data.osm.Relation;
6import org.openstreetmap.josm.data.osm.RelationMember;
7import org.openstreetmap.josm.tools.CheckParameterUtil;
8
9import static org.openstreetmap.josm.tools.I18n.tr;
10import static org.openstreetmap.josm.gui.conflict.tags.RelationMemberConflictDecisionType.*;
11
12public class RelationMemberConflictDecision {
13
14 private Relation relation;
15 private int pos;
16 private OsmPrimitive originalPrimitive;
17 private String role;
18 private RelationMemberConflictDecisionType decision;
19
20 public RelationMemberConflictDecision(Relation relation, int pos) throws IllegalArgumentException {
21 CheckParameterUtil.ensureParameterNotNull(relation, "relation");
22 RelationMember member = relation.getMember(pos);
23 if (member == null)
24 throw new IndexOutOfBoundsException(tr("Position {0} is out of range. Current number of members is {1}.", pos, relation.getMembersCount()));
25 this.relation = relation;
26 this.pos = pos;
27 this.originalPrimitive = member.getMember();
28 this.role = member.hasRole()? member.getRole() : "";
29 this.decision = UNDECIDED;
30 }
31
32 public Relation getRelation() {
33 return relation;
34 }
35
36 public int getPos() {
37 return pos;
38 }
39
40 public OsmPrimitive getOriginalPrimitive() {
41 return originalPrimitive;
42 }
43
44 public String getRole() {
45 return role;
46 }
47
48 public RelationMemberConflictDecisionType getDecision() {
49 return decision;
50 }
51
52 public void setRole(String role) {
53 this.role = role == null ? "" : role;
54 }
55
56 public void decide(RelationMemberConflictDecisionType decision) {
57 if (decision == null) {
58 decision = UNDECIDED;
59 }
60 this.decision = decision;
61 }
62
63 public boolean isDecided() {
64 return ! UNDECIDED.equals(decision);
65 }
66
67 public boolean matches(Relation relation, int pos) {
68 return this.relation == relation && this.pos == pos;
69 }
70
71 @Override
72 public int hashCode() {
73 final int prime = 31;
74 int result = 1;
75 result = prime * result + ((decision == null) ? 0 : decision.hashCode());
76 result = prime * result + ((originalPrimitive == null) ? 0 : originalPrimitive.hashCode());
77 result = prime * result + pos;
78 result = prime * result + ((relation == null) ? 0 : relation.hashCode());
79 result = prime * result + ((role == null) ? 0 : role.hashCode());
80 return result;
81 }
82
83 @Override
84 public boolean equals(Object obj) {
85 if (this == obj)
86 return true;
87 if (obj == null)
88 return false;
89 if (getClass() != obj.getClass())
90 return false;
91 RelationMemberConflictDecision other = (RelationMemberConflictDecision) obj;
92 if (decision == null) {
93 if (other.decision != null)
94 return false;
95 } else if (!decision.equals(other.decision))
96 return false;
97 if (originalPrimitive == null) {
98 if (other.originalPrimitive != null)
99 return false;
100 } else if (!originalPrimitive.equals(other.originalPrimitive))
101 return false;
102 if (pos != other.pos)
103 return false;
104 if (relation == null) {
105 if (other.relation != null)
106 return false;
107 } else if (!relation.equals(other.relation))
108 return false;
109 if (role == null) {
110 if (other.role != null)
111 return false;
112 } else if (!role.equals(other.role))
113 return false;
114 return true;
115 }
116}
Note: See TracBrowser for help on using the repository browser.