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