source: josm/trunk/src/org/openstreetmap/josm/gui/conflict/pair/ComparePairType.java@ 11489

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

error-prone - enums should be immutable, and cannot have non-final fields

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