ref #7761: add isInvalidDeisgnation() method to taxon
authorKatja Luther <k.luther@bgbm.org>
Fri, 14 Sep 2018 11:37:41 +0000 (13:37 +0200)
committerKatja Luther <k.luther@bgbm.org>
Fri, 14 Sep 2018 11:39:11 +0000 (13:39 +0200)
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/taxon/Taxon.java

index 82bac15dba888beb63df1db8aef673aa8596dae3..0fbf0c3b234b0e8c09db86ea354d24701b21ccac 100644 (file)
@@ -855,6 +855,31 @@ public class Taxon
         return count;
     }
 
+    /**
+     * Returns the boolean value indicating whether <i>this</i> taxon is a invalid designation
+     * for at least one other taxon.
+     */
+    // TODO cache as for #hasTaxonomicChildren
+    @Transient
+    public boolean isInvalidDesignation(){
+        return computeInvalidDesignationRelations() > 0;
+    }
+
+    /**
+     * Counts the number of invalid designation relationships where this taxon represents the
+     * invalid designation for another taxon.
+     * @return
+     */
+    private int computeInvalidDesignationRelations(){
+        int count = 0;
+        for (TaxonRelationship rel: this.getRelationsFromThisTaxon()){
+            if (rel.getType().equals(TaxonRelationshipType.INVALID_DESIGNATION_FOR())){
+                count++;
+            }
+        }
+        return count;
+    }
+
     /**
      * Returns the boolean value indicating whether <i>this</i> taxon is a related
      * concept for at least one other taxon.