moved to: https://sites.google.com/site/cmzmasek/home/software/forester
[jalview.git] / forester / java / src / org / forester / phylogeny / data / Taxonomy.java
index 5d4411d..b354921 100644 (file)
@@ -21,7 +21,7 @@
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 //
 // Contact: phylosoft @ gmail . com
-// WWW: www.phylosoft.org/forester
+// WWW: https://sites.google.com/site/cmzmasek/home/software/forester
 
 package org.forester.phylogeny.data;
 
@@ -46,6 +46,7 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
     private String       _taxonomy_code;
     private String       _rank;
     private List<Uri>    _uris;
+    private List<String> _lineage;
 
     public Taxonomy() {
         init();
@@ -108,7 +109,12 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
     @Override
     public PhylogenyData copy() {
         final Taxonomy t = new Taxonomy();
-        t.setTaxonomyCode( getTaxonomyCode() );
+        try {
+            t.setTaxonomyCode( getTaxonomyCode() );
+        }
+        catch ( final PhyloXmlDataFormatException e ) {
+            e.printStackTrace();
+        }
         t.setScientificName( getScientificName() );
         t.setCommonName( getCommonName() );
         t.setAuthority( getAuthority() );
@@ -121,7 +127,12 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
         else {
             t.setIdentifier( null );
         }
-        t.setRank( new String( getRank() ) );
+        try {
+            t.setRank( new String( getRank() ) );
+        }
+        catch ( final PhyloXmlDataFormatException e ) {
+            e.printStackTrace();
+        }
         if ( getUris() != null ) {
             t.setUris( new ArrayList<Uri>() );
             for( final Uri uri : getUris() ) {
@@ -130,6 +141,14 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
                 }
             }
         }
+        if ( getLineage() != null ) {
+            t.setLineage( new ArrayList<String>() );
+            for( final String l : getLineage() ) {
+                if ( l != null ) {
+                    t.getLineage().add( l );
+                }
+            }
+        }
         return t;
     }
 
@@ -188,7 +207,7 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
 
     @Override
     public int hashCode() {
-        if ( getIdentifier() != null ) {
+        if ( ( getIdentifier() != null ) && !ForesterUtil.isEmpty( getIdentifier().getValue() ) ) {
             return getIdentifier().hashCode();
         }
         else if ( !ForesterUtil.isEmpty( getTaxonomyCode() ) ) {
@@ -209,18 +228,30 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
         setScientificName( "" );
         setCommonName( "" );
         setIdentifier( null );
-        setRank( "" );
-        setTaxonomyCode( "" );
+        try {
+            setRank( "" );
+        }
+        catch ( final PhyloXmlDataFormatException e ) {
+            e.printStackTrace();
+        }
+        try {
+            setTaxonomyCode( "" );
+        }
+        catch ( final PhyloXmlDataFormatException e ) {
+            e.printStackTrace();
+        }
         setAuthority( "" );
         setSynonyms( null );
         setUris( null );
+        setLineage( null );
     }
 
     public boolean isEmpty() {
         return ( ( getIdentifier() == null ) && ForesterUtil.isEmpty( getTaxonomyCode() )
                 && ForesterUtil.isEmpty( getCommonName() ) && ForesterUtil.isEmpty( getScientificName() )
                 && ForesterUtil.isEmpty( getRank() ) && ForesterUtil.isEmpty( _uris )
-                && ForesterUtil.isEmpty( getAuthority() ) && ForesterUtil.isEmpty( _synonyms ) );
+                && ForesterUtil.isEmpty( getAuthority() ) && ForesterUtil.isEmpty( _synonyms ) && ForesterUtil
+                .isEmpty( _lineage ) );
     }
 
     /**
@@ -240,7 +271,9 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
             return true;
         }
         final Taxonomy tax = ( Taxonomy ) data;
-        if ( ( getIdentifier() != null ) && ( tax.getIdentifier() != null ) ) {
+        if ( ( getIdentifier() != null ) && ( tax.getIdentifier() != null )
+                && !ForesterUtil.isEmpty( getIdentifier().getValue() )
+                && !ForesterUtil.isEmpty( tax.getIdentifier().getValue() ) ) {
             return getIdentifier().isEqual( tax.getIdentifier() );
         }
         else if ( !ForesterUtil.isEmpty( getTaxonomyCode() ) && !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) {
@@ -277,8 +310,8 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
         _identifier = identifier;
     }
 
-    public void setRank( final String rank ) {
-        if ( !ForesterUtil.isEmpty( rank ) && !PhyloXmlUtil.TAXONOMY_RANKS.contains( rank ) ) {
+    public void setRank( final String rank ) throws PhyloXmlDataFormatException {
+        if ( !ForesterUtil.isEmpty( rank ) && !PhyloXmlUtil.TAXONOMY_RANKS_SET.contains( rank ) ) {
             throw new PhyloXmlDataFormatException( "illegal rank: [" + rank + "]" );
         }
         _rank = rank;
@@ -292,7 +325,7 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
         _synonyms = synonyms;
     }
 
-    public void setTaxonomyCode( final String taxonomy_code ) {
+    public void setTaxonomyCode( final String taxonomy_code ) throws PhyloXmlDataFormatException {
         if ( !ForesterUtil.isEmpty( taxonomy_code )
                 && !PhyloXmlUtil.TAXOMONY_CODE_PATTERN.matcher( taxonomy_code ).matches() ) {
             throw new PhyloXmlDataFormatException( "illegal taxonomy code: [" + taxonomy_code + "]" );
@@ -401,4 +434,12 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
         }
         return 0;
     }
+
+    public void setLineage( final List<String> lineage ) {
+        _lineage = lineage;
+    }
+
+    public List<String> getLineage() {
+        return _lineage;
+    }
 }