1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.conflict.pair;
|
---|
3 | import static org.openstreetmap.josm.gui.conflict.pair.ListRole.MERGED_ENTRIES;
|
---|
4 | import static org.openstreetmap.josm.gui.conflict.pair.ListRole.MY_ENTRIES;
|
---|
5 | import static org.openstreetmap.josm.gui.conflict.pair.ListRole.THEIR_ENTRIES;
|
---|
6 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
7 |
|
---|
8 | /**
|
---|
9 | * Enumeration of the possible comparison pairs
|
---|
10 | *
|
---|
11 | */
|
---|
12 | public enum ComparePairType {
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * compare my version of an {@see OsmPrimitive} with their version
|
---|
16 | */
|
---|
17 | MY_WITH_THEIR (tr("My with Their"), new ListRole[] {MY_ENTRIES, THEIR_ENTRIES}),
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * compare my version of an {@see OsmPrimitive} with the merged version
|
---|
21 | */
|
---|
22 | MY_WITH_MERGED (tr("My with Merged"), new ListRole[] {MY_ENTRIES, MERGED_ENTRIES}),
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * compare their version of an {@see OsmPrimitive} with the merged veresion
|
---|
26 | */
|
---|
27 | THEIR_WITH_MERGED(tr("Their with Merged"), new ListRole[] {THEIR_ENTRIES, MERGED_ENTRIES});
|
---|
28 |
|
---|
29 | /** the localized display name */
|
---|
30 | private final String displayName;
|
---|
31 | private ListRole[] participatingRoles;
|
---|
32 |
|
---|
33 | ComparePairType(String displayName, ListRole[] participatingRoles) {
|
---|
34 | this.displayName = displayName;
|
---|
35 | this.participatingRoles = participatingRoles;
|
---|
36 | }
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * replies the display name
|
---|
40 | *
|
---|
41 | * @return the display name
|
---|
42 | */
|
---|
43 | public String getDisplayName() {
|
---|
44 | return displayName;
|
---|
45 | }
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * replies true, if <code>role</code> is participating in this comparison
|
---|
49 | * pair
|
---|
50 | *
|
---|
51 | * @param role the list role
|
---|
52 | * @return true, if <code>role</code> is participating in this comparison
|
---|
53 | * pair; false, otherwise
|
---|
54 | */
|
---|
55 | public boolean isParticipatingIn(ListRole role) {
|
---|
56 | for (ListRole r: participatingRoles) {
|
---|
57 | if (r.equals(role)) return true;
|
---|
58 | }
|
---|
59 | return false;
|
---|
60 | }
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * replies the pair of {@see ListRole}s participating in this comparison
|
---|
64 | * pair
|
---|
65 | *
|
---|
66 | * @return the pair of list roles
|
---|
67 | */
|
---|
68 | public ListRole[] getParticipatingRoles() {
|
---|
69 | return participatingRoles;
|
---|
70 | }
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * replies the opposite role of <code>role</code> participating in this comparison
|
---|
74 | * pair
|
---|
75 | *
|
---|
76 | * @param role one of the two roles in this pair
|
---|
77 | * @return the opposite role
|
---|
78 | * @exception IllegalStateException if role is not participating in this pair
|
---|
79 | */
|
---|
80 | public ListRole getOppositeRole(ListRole role) {
|
---|
81 | if (!isParticipatingIn(role))
|
---|
82 | throw new IllegalStateException(tr("Role {0} is not participating in compare pair {1}.", role.toString(), this.toString()));
|
---|
83 | if (participatingRoles[0].equals(role))
|
---|
84 | return participatingRoles[1];
|
---|
85 | else
|
---|
86 | return participatingRoles[0];
|
---|
87 | }
|
---|
88 | }
|
---|