subtree deletion changed
authorcmzmasek <cmzmasek@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Wed, 20 Jun 2012 05:06:20 +0000 (05:06 +0000)
committercmzmasek <cmzmasek@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Wed, 20 Jun 2012 05:06:20 +0000 (05:06 +0000)
forester/java/src/org/forester/phylogeny/Phylogeny.java
forester/java/src/org/forester/phylogeny/PhylogenyNode.java
forester/java/src/org/forester/util/ForesterConstants.java

index f3b6c5f..44851b2 100644 (file)
@@ -221,14 +221,13 @@ public class Phylogeny {
      * @param remove_us the parent node of the subtree to be deleted
      */
     public void deleteSubtree( final PhylogenyNode remove_us, final boolean collapse_resulting_node_with_one_desc ) {
-        if ( isEmpty() ) {
+        if ( isEmpty() || ( remove_us.isRoot() && getNumberOfExternalNodes() != 1 ) ) {
             return;
         }
-        if ( remove_us.isRoot() ) {
+        if ( remove_us.isRoot() && getNumberOfExternalNodes() == 1 ) {
             init();
-            return;
         }
-        if ( !collapse_resulting_node_with_one_desc ) {
+        else if ( !collapse_resulting_node_with_one_desc ) {
             remove_us.getParent().removeChildNode( remove_us );
         }
         else {
@@ -269,7 +268,7 @@ public class Phylogeny {
                 }
             }
         }
-        remove_us.setParent( null );
+        remove_us.reset();
         setIdHash( null );
         externalNodesHaveChanged();
     }
index 4045537..8dedcd2 100644 (file)
@@ -70,6 +70,14 @@ public final class PhylogenyNode implements PhylogenyNodeI, Comparable<Phylogeny
         setSumExtNodes( 1 ); // For ext node, this number is 1 (not 0!!)
     }
 
+    public void reset() {
+        _parent = null;
+        _link = null;
+        _descendants = null;
+        _node_data = null;
+        _branch_data = null;
+    }
+
     /**
      * Adds PhylogenyNode n to the list of child nodes and sets the _parent of n
      * to this.
index ccb270a..39dd287 100644 (file)
@@ -27,8 +27,8 @@ package org.forester.util;
 
 public final class ForesterConstants {
 
-    public final static String  FORESTER_VERSION            = "1.003";
-    public final static String  FORESTER_DATE               = "120608";
+    public final static String  FORESTER_VERSION            = "1.004";
+    public final static String  FORESTER_DATE               = "120619";
     
     public final static String  PHYLO_XML_VERSION           = "1.10";
     public final static String  PHYLO_XML_LOCATION          = "http://www.phyloxml.org";