in progress
[jalview.git] / forester / java / src / org / forester / phylogeny / data / NodeData.java
index d1c75e2..ab6f055 100644 (file)
@@ -7,7 +7,7 @@
 // Copyright (C) 2000-2001 Washington University School of Medicine
 // and Howard Hughes Medical Institute
 // 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
 // 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
 //
 // Contact: phylosoft @ gmail . com
-// WWW: www.phylosoft.org/forester
+// WWW: https://sites.google.com/site/cmzmasek/home/software/forester
 
 package org.forester.phylogeny.data;
 
@@ -38,10 +38,23 @@ import org.forester.util.ForesterUtil;
 
 public class NodeData implements PhylogenyData {
 
+    public enum NODE_DATA {
+        NODE_NAME,
+        EVENT,
+        SEQUENCE_NAME,
+        GENE_NAME,
+        SEQUENCE_SYMBOL,
+        SEQUENCE_MOL_SEQ,
+        SEQUENCE_MOL_SEQ_FASTA,
+        SEQUENCE_ACC,
+        TAXONOMY_SCIENTIFIC_NAME,
+        TAXONOMY_COMM0N_NAME,
+        TAXONOMY_CODE,
+        UNKNOWN;
+    }
     private String             _node_name;
     private Event              _event;
     private List<Sequence>     _sequences;
-    private Identifier         _node_identifier;
     private List<Taxonomy>     _taxonomies;
     private List<Distribution> _distributions;
     private Date               _date;
@@ -49,6 +62,7 @@ public class NodeData implements PhylogenyData {
     private PropertiesMap      _properties;
     private List<Reference>    _references;
     private List<Double>       _vector;
+    private NodeVisualData     _node_visual_data;
 
     public NodeData() {
         init();
@@ -56,6 +70,16 @@ public class NodeData implements PhylogenyData {
 
     private void init() {
         _node_name = "";
+        _event = null;
+        _sequences = null;
+        _taxonomies = null;
+        _distributions = null;
+        _date = null;
+        _binary_characters = null;
+        _properties = null;
+        _references = null;
+        _vector = null;
+        _node_visual_data = null;
     }
 
     public void addDistribution( final Distribution distribution ) {
@@ -86,14 +110,17 @@ public class NodeData implements PhylogenyData {
         _taxonomies.add( taxonomy );
     }
 
+    @Override
     public StringBuffer asSimpleText() {
         throw new UnsupportedOperationException();
     }
 
+    @Override
     public StringBuffer asText() {
         throw new UnsupportedOperationException();
     }
 
+    @Override
     public PhylogenyData copy() {
         final NodeData new_data = new NodeData();
         new_data.setNodeName( getNodeName() );
@@ -108,9 +135,6 @@ public class NodeData implements PhylogenyData {
         if ( isHasEvent() ) {
             new_data.setEvent( ( Event ) getEvent().copy() );
         }
-        if ( isHasNodeIdentifier() ) {
-            new_data.setNodeIdentifier( ( Identifier ) getNodeIdentifier().copy() );
-        }
         if ( ( getTaxonomies() != null ) && ( getTaxonomies().size() > 0 ) ) {
             new_data.setTaxonomies( new ArrayList<Taxonomy>() );
             for( final Taxonomy t : getTaxonomies() ) {
@@ -138,6 +162,9 @@ public class NodeData implements PhylogenyData {
                 }
             }
         }
+        if ( ( getNodeVisualData() != null ) && !getNodeVisualData().isEmpty() ) {
+            new_data.setNodeVisualData( ( NodeVisualData ) getNodeVisualData().copy() );
+        }
         if ( isHasDate() ) {
             new_data.setDate( ( Date ) getDate().copy() );
         }
@@ -176,10 +203,6 @@ public class NodeData implements PhylogenyData {
         return _event;
     }
 
-    public Identifier getNodeIdentifier() {
-        return _node_identifier;
-    }
-
     public PropertiesMap getProperties() {
         return _properties;
     }
@@ -237,19 +260,26 @@ public class NodeData implements PhylogenyData {
         return _taxonomies.get( index );
     }
 
+    @Override
     public boolean isEqual( final PhylogenyData data ) {
-        throw new UnsupportedOperationException();
+        throw new NoSuchMethodError();
     }
 
     public boolean isHasBinaryCharacters() {
         return getBinaryCharacters() != null;
     }
 
+    public boolean isEmpty() {
+        return ( ForesterUtil.isEmpty( _node_name ) && !isHasSequence() && !isHasTaxonomy() && !isHasBinaryCharacters()
+                && !isHasDate() && !isHasDistribution() && !isHasEvent() && !isHasProperties() && !isHasReference() && ( ( _vector == null ) || _vector
+                .isEmpty() ) );
+    }
+
     public boolean isHasDate() {
         return ( getDate() != null )
                 && ( !ForesterUtil.isEmpty( getDate().getDesc() ) || !ForesterUtil.isNull( getDate().getMax() )
                         || !ForesterUtil.isNull( getDate().getMin() ) || !ForesterUtil.isNull( getDate().getValue() ) || !ForesterUtil
-                        .isEmpty( getDate().getUnit() ) );
+                            .isEmpty( getDate().getUnit() ) );
     }
 
     public boolean isHasDistribution() {
@@ -263,12 +293,8 @@ public class NodeData implements PhylogenyData {
         return getEvent() != null;
     }
 
-    public boolean isHasNodeIdentifier() {
-        return getNodeIdentifier() != null;
-    }
-
     public boolean isHasProperties() {
-        return getProperties() != null;
+        return ( getProperties() != null ) && ( getProperties().size() > 0 );
     }
 
     public boolean isHasReference() {
@@ -324,10 +350,6 @@ public class NodeData implements PhylogenyData {
         _event = event;
     }
 
-    public void setNodeIdentifier( final Identifier node_identifier ) {
-        _node_identifier = node_identifier;
-    }
-
     public void setProperties( final PropertiesMap custom_data ) {
         _properties = custom_data;
     }
@@ -413,11 +435,9 @@ public class NodeData implements PhylogenyData {
         }
     }
 
+    @Override
     public StringBuffer toNHX() {
         final StringBuffer sb = new StringBuffer();
-        if ( isHasNodeIdentifier() ) {
-            sb.append( getNodeIdentifier().toNHX() );
-        }
         if ( isHasTaxonomy() ) {
             sb.append( getTaxonomy().toNHX() );
         }
@@ -427,25 +447,11 @@ public class NodeData implements PhylogenyData {
         if ( isHasEvent() ) {
             sb.append( getEvent().toNHX() );
         }
-        if ( isHasProperties() ) {
-            sb.append( getProperties().toNHX() );
-        }
         return sb;
     }
 
+    @Override
     public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
-        if ( isHasNodeIdentifier() ) {
-            writer.write( ForesterUtil.LINE_SEPARATOR );
-            writer.write( indentation );
-            //  if ( !org.forester.util.ForesterUtil.isEmpty( getNodeIdentifier().getProvider() ) ) {
-            //     PhylogenyDataUtil.appendElement( writer, PhyloXmlMapping.NODE_IDENTIFIER, getNodeIdentifier()
-            //             .getValue(), PhyloXmlMapping.IDENTIFIER_PROVIDER_ATTR, getNodeIdentifier().getProvider() );
-            // }
-            // else {
-            //     PhylogenyDataUtil.appendElement( writer, PhyloXmlMapping.NODE_IDENTIFIER, getNodeIdentifier()
-            //             .getValue() );
-            // }
-        }
         if ( isHasTaxonomy() ) {
             for( final Taxonomy t : getTaxonomies() ) {
                 if ( !t.isEmpty() ) {
@@ -482,6 +488,9 @@ public class NodeData implements PhylogenyData {
         if ( isHasProperties() ) {
             getProperties().toPhyloXML( writer, level, indentation.substring( 0, indentation.length() - 2 ) );
         }
+        if ( ( level == 0 ) && ( getNodeVisualData() != null ) && !getNodeVisualData().isEmpty() ) {
+            getNodeVisualData().toPhyloXML( writer, level, indentation.substring( 0, indentation.length() - 2 ) );
+        }
         if ( ( getVector() != null )
                 && !getVector().isEmpty()
                 && ( ( getProperties() == null ) || getProperties()
@@ -521,4 +530,12 @@ public class NodeData implements PhylogenyData {
     public void setNodeName( final String node_name ) {
         _node_name = node_name;
     }
+
+    public void setNodeVisualData( final NodeVisualData node_visual_data ) {
+        _node_visual_data = node_visual_data;
+    }
+
+    public NodeVisualData getNodeVisualData() {
+        return _node_visual_data;
+    }
 }