001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.conflict.pair; 003import static org.openstreetmap.josm.gui.conflict.pair.ListRole.MERGED_ENTRIES; 004import static org.openstreetmap.josm.gui.conflict.pair.ListRole.MY_ENTRIES; 005import static org.openstreetmap.josm.gui.conflict.pair.ListRole.THEIR_ENTRIES; 006import static org.openstreetmap.josm.tools.I18n.tr; 007 008import org.openstreetmap.josm.tools.Utils; 009 010/** 011 * Enumeration of the possible comparison pairs 012 * 013 */ 014public enum ComparePairType { 015 016 /** 017 * compare my version of an {@link org.openstreetmap.josm.data.osm.OsmPrimitive} with their version 018 */ 019 MY_WITH_THEIR (tr("My with Their"), new ListRole[] {MY_ENTRIES, THEIR_ENTRIES}), 020 021 /** 022 * compare my version of an {@link org.openstreetmap.josm.data.osm.OsmPrimitive} with the merged version 023 */ 024 MY_WITH_MERGED (tr("My with Merged"), new ListRole[] {MY_ENTRIES, MERGED_ENTRIES}), 025 026 /** 027 * compare their version of an {@link org.openstreetmap.josm.data.osm.OsmPrimitive} with the merged veresion 028 */ 029 THEIR_WITH_MERGED(tr("Their with Merged"), new ListRole[] {THEIR_ENTRIES, MERGED_ENTRIES}); 030 031 /** the localized display name */ 032 private final String displayName; 033 private ListRole[] participatingRoles; 034 035 ComparePairType(String displayName, ListRole[] participatingRoles) { 036 this.displayName = displayName; 037 this.participatingRoles = Utils.copyArray(participatingRoles); 038 } 039 040 /** 041 * replies the display name 042 * 043 * @return the display name 044 */ 045 public String getDisplayName() { 046 return displayName; 047 } 048 049 /** 050 * replies true, if <code>role</code> is participating in this comparison 051 * pair 052 * 053 * @param role the list role 054 * @return true, if <code>role</code> is participating in this comparison 055 * pair; false, otherwise 056 */ 057 public boolean isParticipatingIn(ListRole role) { 058 for (ListRole r: participatingRoles) { 059 if (r.equals(role)) return true; 060 } 061 return false; 062 } 063 064 /** 065 * replies the pair of {@link ListRole}s participating in this comparison 066 * pair 067 * 068 * @return the pair of list roles 069 */ 070 public ListRole[] getParticipatingRoles() { 071 return participatingRoles; 072 } 073 074 /** 075 * replies the opposite role of <code>role</code> participating in this comparison 076 * pair 077 * 078 * @param role one of the two roles in this pair 079 * @return the opposite role 080 * @exception IllegalStateException if role is not participating in this pair 081 */ 082 public ListRole getOppositeRole(ListRole role) { 083 if (!isParticipatingIn(role)) 084 throw new IllegalStateException(tr("Role {0} is not participating in compare pair {1}.", role.toString(), this.toString())); 085 if (participatingRoles[0].equals(role)) 086 return participatingRoles[1]; 087 else 088 return participatingRoles[0]; 089 } 090}