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 008/** 009 * Enumeration of the possible comparison pairs 010 * @since 1650 011 */ 012public enum ComparePairType { 013 014 /** 015 * compare my version of an {@link org.openstreetmap.josm.data.osm.OsmPrimitive} with their version 016 */ 017 MY_WITH_THEIR(tr("My with Their"), MY_ENTRIES, THEIR_ENTRIES), 018 019 /** 020 * compare my version of an {@link org.openstreetmap.josm.data.osm.OsmPrimitive} with the merged version 021 */ 022 MY_WITH_MERGED(tr("My with Merged"), MY_ENTRIES, MERGED_ENTRIES), 023 024 /** 025 * compare their version of an {@link org.openstreetmap.josm.data.osm.OsmPrimitive} with the merged veresion 026 */ 027 THEIR_WITH_MERGED(tr("Their with Merged"), THEIR_ENTRIES, MERGED_ENTRIES); 028 029 /** the localized display name */ 030 private final String displayName; 031 private final ListRole participatingRole1; 032 private final ListRole participatingRole2; 033 034 ComparePairType(String displayName, ListRole participatingRole1, ListRole participatingRole2) { 035 this.displayName = displayName; 036 this.participatingRole1 = participatingRole1; 037 this.participatingRole2 = participatingRole2; 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 pair 051 * 052 * @param role the list role 053 * @return true, if <code>role</code> is participating in this comparison pair; false, otherwise 054 */ 055 public boolean isParticipatingIn(ListRole role) { 056 return participatingRole1 == role || participatingRole2 == role; 057 } 058 059 /** 060 * replies the pair of {@link ListRole}s participating in this comparison pair 061 * 062 * @return the pair of list roles 063 */ 064 public ListRole[] getParticipatingRoles() { 065 return new ListRole[]{participatingRole1, participatingRole2}; 066 } 067 068 /** 069 * replies the opposite role of <code>role</code> participating in this comparison pair 070 * 071 * @param role one of the two roles in this pair 072 * @return the opposite role 073 * @throws IllegalStateException if role is not participating in this pair 074 */ 075 public ListRole getOppositeRole(ListRole role) { 076 if (!isParticipatingIn(role)) 077 throw new IllegalStateException(tr("Role {0} is not participating in compare pair {1}.", role.toString(), this.toString())); 078 return participatingRole1 == role ? participatingRole2 : participatingRole1; 079 } 080}