Implemented new basionym / homotypic group methods in Editor per #552.
authorp.ciardelli <p.ciardelli@localhost>
Mon, 29 Jun 2009 15:53:06 +0000 (15:53 +0000)
committerp.ciardelli <p.ciardelli@localhost>
Mon, 29 Jun 2009 15:53:06 +0000 (15:53 +0000)
taxeditor-store/src/main/java/eu/etaxonomy/taxeditor/model/NameUtil.java

index 091920ea667dfe20e7568aa812b6d29cebac90ec..94e2957a84476255d14f1659106ba44cf4ca8cd8 100644 (file)
@@ -9,12 +9,7 @@
 
 package eu.etaxonomy.taxeditor.model;
 
-import java.util.Set;
-
 import eu.etaxonomy.cdm.common.CdmUtils;
-import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
-import eu.etaxonomy.cdm.model.name.NameRelationship;
-import eu.etaxonomy.cdm.model.name.NameRelationshipType;
 import eu.etaxonomy.cdm.model.name.Rank;
 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
@@ -62,68 +57,19 @@ public class NameUtil {
                if (name == null) {
                        return false;
                }
-               
-               HomotypicalGroup homotypicalGroup = name.getHomotypicalGroup();
-               if (homotypicalGroup == null) {
-                       return false;
-               }               
-               
-               Set<TaxonNameBase> typifiedNames = homotypicalGroup.getTypifiedNames();
-               
-               // Check whether there are any other names in the group
-               if (typifiedNames.size() == 1) {
-                       return false;
-               }
-               
-               for (TaxonNameBase taxonName : typifiedNames) {
-                       if (!taxonName.equals(name)) {
-                               if (!isNameBasionymOf(name, taxonName)) {
-                                       return false;
-                               }
-                       }
-               }
-               return true;            
+               return name.isGroupsBasionym();         
        }
        
-       /**
-        * Checks whether a basionym relationship exists between fromName and toName.
-        * 
-        * @param fromName
-        * @param toName
-        * @return
-        */
-       @SuppressWarnings("unchecked")
-       public static boolean isNameBasionymOf(TaxonNameBase fromName, TaxonNameBase toName) {
-               Set<NameRelationship> relations = toName.getRelationsToThisName();
-               for (NameRelationship relation : relations) {
-                       if (relation.getType().equals(NameRelationshipType.BASIONYM()) &&
-                                       relation.getFromName().equals(fromName)) {
-                               return true;
-                       }
-               }
-               return false;
-       }
 
        /**
         * @param name
         * @return
         */
        public static boolean isNameSupraSpecific(TaxonNameBase<?, ?> name) {
-               
                if (name == null || name.getRank() == null) {
                        return false;
                }
-               
-//             Rank rank = CdmBase.deproxy(name.getRank(), Rank.class);
-               Rank rank = name.getRank();
-               
-               if (rank.isHigher(Rank.SPECIES())) {
-//             if (name.getRank().isHigher(Rank.SPECIES())) {
-//             if (name.isInfraGeneric() || name.isSupraGeneric() || name.isGenus()) {
-                       return true;
-               } else {
-                       return false;
-               }
+               return name.getRank().isHigher(Rank.SPECIES());
        }
        
        /**
@@ -134,18 +80,7 @@ public class NameUtil {
         * @return
         */
        public static boolean isNameHomotypic(TaxonNameBase<?, ?> name, Taxon taxon) {
-               TaxonNameBase<?, ?> taxonName = taxon.getName();
-               if (taxonName == null || name == null) {
-                       return false;
-               }
-               HomotypicalGroup homotypicGroup = taxonName.getHomotypicalGroup();
-               if (homotypicGroup == null) {
-                       return false;
-               }
-               if (homotypicGroup.equals(name.getHomotypicalGroup())) {
-                       return true;
-               }
-               return false;
+               return name.isHomotypic(taxon.getName());
        }
        
 }