in progress
[jalview.git] / forester / java / src / org / forester / phylogeny / data / Taxonomy.java
index 026d68b..d403a8e 100644 (file)
@@ -5,7 +5,7 @@
 // Copyright (C) 2008-2009 Christian M. Zmasek
 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
 // All rights reserved
-// 
+//
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
@@ -15,7 +15,7 @@
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 // Lesser General Public License for more details.
-// 
+//
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
@@ -46,19 +46,23 @@ 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();
     }
 
+    @Override
     public StringBuffer asSimpleText() {
         return asText();
     }
 
+    @Override
     public Uri getUri( final int index ) {
         return getUris().get( index );
     }
 
+    @Override
     public void addUri( final Uri uri ) {
         if ( getUris() == null ) {
             setUris( new ArrayList<Uri>() );
@@ -66,6 +70,7 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
         getUris().add( uri );
     }
 
+    @Override
     public StringBuffer asText() {
         final StringBuffer sb = new StringBuffer();
         if ( getIdentifier() != null ) {
@@ -101,6 +106,7 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
         return sb;
     }
 
+    @Override
     public PhylogenyData copy() {
         final Taxonomy t = new Taxonomy();
         t.setTaxonomyCode( getTaxonomyCode() );
@@ -125,6 +131,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;
     }
 
@@ -176,6 +190,7 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
         return _taxonomy_code;
     }
 
+    @Override
     public List<Uri> getUris() {
         return _uris;
     }
@@ -208,13 +223,15 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
         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 ) );
     }
 
     /**
@@ -228,6 +245,7 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
      * (Note. This is important and should not be change without a very good reason.)
      * 
      */
+    @Override
     public boolean isEqual( final PhylogenyData data ) {
         if ( this == data ) {
             return true;
@@ -271,7 +289,7 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
     }
 
     public void setRank( final String rank ) {
-        if ( !ForesterUtil.isEmpty( rank ) && !PhyloXmlUtil.TAXONOMY_RANKS.contains( rank ) ) {
+        if ( !ForesterUtil.isEmpty( rank ) && !PhyloXmlUtil.TAXONOMY_RANKS_SET.contains( rank ) ) {
             throw new PhyloXmlDataFormatException( "illegal rank: [" + rank + "]" );
         }
         _rank = rank;
@@ -293,10 +311,12 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
         _taxonomy_code = taxonomy_code;
     }
 
+    @Override
     public void setUris( final List<Uri> uris ) {
         _uris = uris;
     }
 
+    @Override
     public StringBuffer toNHX() {
         final StringBuffer sb = new StringBuffer();
         if ( getIdentifier() != null ) {
@@ -322,6 +342,7 @@ public class Taxonomy implements PhylogenyData, MultipleUris, Comparable<Taxonom
         return sb;
     }
 
+    @Override
     public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
         if ( isEmpty() ) {
             return;
@@ -391,4 +412,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;
+    }
 }