in progress
[jalview.git] / forester / java / src / org / forester / phylogeny / data / Taxonomy.java
index 955e298..117f831 100644 (file)
@@ -35,6 +35,7 @@ import org.forester.io.parsers.phyloxml.PhyloXmlDataFormatException;
 import org.forester.io.parsers.phyloxml.PhyloXmlMapping;
 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
 import org.forester.util.ForesterUtil;
+import org.forester.util.TaxonomyUtil;
 
 public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonomy> {
 
@@ -248,12 +249,12 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
 
     public boolean isEmpty() {
         return ( ( getIdentifier() == null ) && ForesterUtil.isEmpty( getTaxonomyCode() )
-                && ForesterUtil.isEmpty( getCommonName() ) && ForesterUtil.isEmpty( getScientificName() ) && ForesterUtil
-                    .isEmpty( _lineage ) );
+                && ForesterUtil.isEmpty( getCommonName() ) && ForesterUtil.isEmpty( getScientificName() )
+                && ForesterUtil.isEmpty( _lineage ) );
     }
 
     /**
-     * 
+     *
      * If this and taxonomy 'data' has an identifier, comparison will be based on that.
      * Otherwise,  if this and taxonomy 'data' has a code, comparison will be based on that.
      * Otherwise,  if Taxonomy 'data' has a scientific name, comparison will be
@@ -261,7 +262,7 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
      * Otherwise,  if Taxonomy 'data' has a common  name, comparison will be
      * based on that (case insensitive!).
      * (Note. This is important and should not be change without a very good reason.)
-     * 
+     *
      */
     @Override
     public boolean isEqual( final PhylogenyData data ) {
@@ -304,7 +305,7 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
     }
 
     public void setRank( final String rank ) throws PhyloXmlDataFormatException {
-        if ( !ForesterUtil.isEmpty( rank ) && !PhyloXmlUtil.TAXONOMY_RANKS_SET.contains( rank ) ) {
+        if ( !ForesterUtil.isEmpty( rank ) && !TaxonomyUtil.TAXONOMY_RANKS_SET.contains( rank ) ) {
             throw new PhyloXmlDataFormatException( "illegal rank: [" + rank + "]" );
         }
         _rank = rank;
@@ -391,8 +392,10 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
             PhylogenyDataUtil.appendElement( writer, PhyloXmlMapping.TAXONOMY_AUTHORITY, getAuthority(), indentation );
         }
         if ( !ForesterUtil.isEmpty( getCommonName() ) ) {
-            PhylogenyDataUtil
-                    .appendElement( writer, PhyloXmlMapping.TAXONOMY_COMMON_NAME, getCommonName(), indentation );
+            PhylogenyDataUtil.appendElement( writer,
+                                             PhyloXmlMapping.TAXONOMY_COMMON_NAME,
+                                             getCommonName(),
+                                             indentation );
         }
         if ( _synonyms != null ) {
             for( final String syn : getSynonyms() ) {
@@ -411,6 +414,24 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
                 }
             }
         }
+        if ( getLineage() != null ) {
+            final StringBuilder sb = new StringBuilder();
+            boolean first = true;
+            for( final String lin : getLineage() ) {
+                if ( !ForesterUtil.isEmpty( lin ) ) {
+                    if ( first ) {
+                        first = false;
+                    }
+                    else {
+                        sb.append( "," );
+                    }
+                    sb.append( lin );
+                }
+            }
+            if ( sb.length() > 0 ) {
+                PhylogenyDataUtil.appendElement( writer, PhyloXmlMapping.TAXONOMY_LINEAGE, sb.toString(), indentation );
+            }
+        }
         writer.write( ForesterUtil.LINE_SEPARATOR );
         writer.write( indentation );
         PhylogenyDataUtil.appendClose( writer, PhyloXmlMapping.TAXONOMY );