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

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

sonarqube - squid:S4551 - Enum values should be compared with "=="

  • 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 * @since 1650
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"), 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"), 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"), 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 pair
51 *
52 * @param role the list role
53 * @return true, if <code>role</code> is participating in this comparison pair; false, otherwise
54 */
55 public boolean isParticipatingIn(ListRole role) {
56 for (ListRole r: participatingRoles) {
57 if (r == role) return true;
58 }
59 return false;
60 }
61
62 /**
63 * replies the pair of {@link ListRole}s participating in this comparison pair
64 *
65 * @return the pair of list roles
66 */
67 public ListRole[] getParticipatingRoles() {
68 return Utils.copyArray(participatingRoles);
69 }
70
71 /**
72 * replies the opposite role of <code>role</code> participating in this comparison pair
73 *
74 * @param role one of the two roles in this pair
75 * @return the opposite role
76 * @throws IllegalStateException if role is not participating in this pair
77 */
78 public ListRole getOppositeRole(ListRole role) {
79 if (!isParticipatingIn(role))
80 throw new IllegalStateException(tr("Role {0} is not participating in compare pair {1}.", role.toString(), this.toString()));
81 if (participatingRoles[0] == role)
82 return participatingRoles[1];
83 else
84 return participatingRoles[0];
85 }
86}
Note: See TracBrowser for help on using the repository browser.