in progress...
[jalview.git] / forester / java / src / org / forester / phylogeny / data / NodeData.java
index a40cc74..3a4c670 100644 (file)
@@ -38,30 +38,17 @@ import org.forester.util.ForesterUtil;
 
 public class NodeData implements PhylogenyData {
 
-    public enum NODE_DATA {
-        NODE_NAME,
-        EVENT,
-        SEQUENCE_NAME,
-        SEQUENCE_SYMBOL,
-        SEQUENCE_MOL_SEQ,
-        SEQUENCE_MOL_SEQ_FASTA,
-        SEQUENCE_ACC,
-        TAXONOMY_SCIENTIFIC_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;
-    private BinaryCharacters        _binary_characters;
-    private PropertiesMap           _properties;
-    private List<Reference>         _references;
-    private List<Double>            _vector;
-    private List<NodeVisualization> _node_visualizations;
+    private String             _node_name;
+    private Event              _event;
+    private List<Sequence>     _sequences;
+    private List<Taxonomy>     _taxonomies;
+    private List<Distribution> _distributions;
+    private Date               _date;
+    private BinaryCharacters   _binary_characters;
+    private PropertiesList      _properties;
+    private List<Reference>    _references;
+    private List<Double>       _vector;
+    private NodeVisualData     _node_visual_data;
 
     public NodeData() {
         init();
@@ -69,6 +56,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 ) {
@@ -124,9 +121,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() ) {
@@ -154,19 +148,14 @@ public class NodeData implements PhylogenyData {
                 }
             }
         }
-        if ( ( getNodeVisualizations() != null ) && ( getNodeVisualizations().size() > 0 ) ) {
-            new_data.setNodeVisualizations( new ArrayList<NodeVisualization>() );
-            for( final NodeVisualization v : getNodeVisualizations() ) {
-                if ( v != null ) {
-                    new_data.getNodeVisualizations().add( ( NodeVisualization ) v.copy() );
-                }
-            }
+        if ( ( getNodeVisualData() != null ) && !getNodeVisualData().isEmpty() ) {
+            new_data.setNodeVisualData( ( NodeVisualData ) getNodeVisualData().copy() );
         }
         if ( isHasDate() ) {
             new_data.setDate( ( Date ) getDate().copy() );
         }
         if ( isHasProperties() ) {
-            new_data.setProperties( ( PropertiesMap ) getProperties().copy() );
+            new_data.setProperties( ( PropertiesList ) getProperties().copy() );
         }
         return new_data;
     }
@@ -181,7 +170,7 @@ public class NodeData implements PhylogenyData {
 
     /**
      * Convenience method -- always returns the first Distribution.
-     *  
+     *
      * @return Distribution
      */
     public Distribution getDistribution() {
@@ -189,6 +178,9 @@ public class NodeData implements PhylogenyData {
     }
 
     public Distribution getDistribution( final int index ) {
+        if ( _distributions == null ) {
+            return null;
+        }
         return _distributions.get( index );
     }
 
@@ -200,25 +192,24 @@ public class NodeData implements PhylogenyData {
         return _event;
     }
 
-    public Identifier getNodeIdentifier() {
-        return _node_identifier;
-    }
-
-    public PropertiesMap getProperties() {
+    public PropertiesList getProperties() {
         return _properties;
     }
 
     /**
      * Convenience method -- always returns the first Reference.
-     * 
+     *
      *  @return Reference
-     *  
+     *
      */
     public Reference getReference() {
         return getReference( 0 );
     }
 
     public Reference getReference( final int index ) {
+        if ( _references == null ) {
+            return null;
+        }
         return _references.get( index );
     }
 
@@ -228,7 +219,7 @@ public class NodeData implements PhylogenyData {
 
     /**
      * Convenience method -- always returns the first Sequence.
-     * 
+     *
      * @return Sequence
      */
     public Sequence getSequence() {
@@ -236,6 +227,9 @@ public class NodeData implements PhylogenyData {
     }
 
     public Sequence getSequence( final int index ) {
+        if ( _sequences == null ) {
+            return null;
+        }
         return _sequences.get( index );
     }
 
@@ -249,27 +243,36 @@ public class NodeData implements PhylogenyData {
 
     /**
      * Convenience method -- always returns the first Taxonomy.
-     * 
+     *
      * @return  Taxonomy
-     * 
+     *
      */
     public Taxonomy getTaxonomy() {
         return getTaxonomy( 0 );
     }
 
     public Taxonomy getTaxonomy( final int index ) {
+        if ( _taxonomies == null ) {
+            return null;
+        }
         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() )
@@ -281,17 +284,13 @@ public class NodeData implements PhylogenyData {
         return ( ( ( getDistributions() != null ) && ( getDistributions().size() > 0 ) ) && ( ( !ForesterUtil
                 .isEmpty( getDistribution().getDesc() ) )
                 || ( ( getDistribution().getPoints() != null ) && ( getDistribution().getPoints().size() > 0 ) ) || ( ( getDistribution()
-                .getPolygons() != null ) && ( getDistribution().getPolygons().size() > 0 ) ) ) );
+                        .getPolygons() != null ) && ( getDistribution().getPolygons().size() > 0 ) ) ) );
     }
 
     public boolean isHasEvent() {
         return getEvent() != null;
     }
 
-    public boolean isHasNodeIdentifier() {
-        return getNodeIdentifier() != null;
-    }
-
     public boolean isHasProperties() {
         return ( getProperties() != null ) && ( getProperties().size() > 0 );
     }
@@ -299,7 +298,7 @@ public class NodeData implements PhylogenyData {
     public boolean isHasReference() {
         return ( ( getReferences() != null ) && ( getReferences().size() > 0 ) )
                 && ( !ForesterUtil.isEmpty( getReference().getDoi() ) || !ForesterUtil.isEmpty( getReference()
-                        .getDescription() ) );
+                                                                                                .getDescription() ) );
     }
 
     public boolean isHasSequence() {
@@ -320,7 +319,7 @@ public class NodeData implements PhylogenyData {
 
     /**
      * Convenience method -- always sets the first Distribution.
-     * 
+     *
      */
     public void setDistribution( final Distribution distribution ) {
         if ( _distributions == null ) {
@@ -349,11 +348,7 @@ 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 ) {
+    public void setProperties( final PropertiesList custom_data ) {
         _properties = custom_data;
     }
 
@@ -366,7 +361,7 @@ public class NodeData implements PhylogenyData {
 
     /**
      * Convenience method -- always sets the first Reference.
-     * 
+     *
      */
     public void setReference( final Reference reference ) {
         if ( _references == null ) {
@@ -393,7 +388,7 @@ public class NodeData implements PhylogenyData {
 
     /**
      * Convenience method -- always sets the first Sequence.
-     * 
+     *
      */
     public void setSequence( final Sequence sequence ) {
         if ( _sequences == null ) {
@@ -424,7 +419,7 @@ public class NodeData implements PhylogenyData {
 
     /**
      * Convenience method -- always sets the first Taxonomy.
-     * 
+     *
      */
     public void setTaxonomy( final Taxonomy taxonomy ) {
         if ( _taxonomies == null ) {
@@ -455,18 +450,6 @@ public class NodeData implements PhylogenyData {
 
     @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() ) {
@@ -503,6 +486,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()
@@ -543,11 +529,11 @@ public class NodeData implements PhylogenyData {
         _node_name = node_name;
     }
 
-    public void setNodeVisualizations( final List<NodeVisualization> _node_visualizations ) {
-        this._node_visualizations = _node_visualizations;
+    public void setNodeVisualData( final NodeVisualData node_visual_data ) {
+        _node_visual_data = node_visual_data;
     }
 
-    public List<NodeVisualization> getNodeVisualizations() {
-        return _node_visualizations;
+    public NodeVisualData getNodeVisualData() {
+        return _node_visual_data;
     }
 }