X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fphylogeny%2FPhylogenyNode.java;h=25b33d79650d9cb4db8d1dae9e5914ebbb53b47d;hb=c0439ed8b088887ffea2faf11bc7897333287cb3;hp=899c0cc91c2ba3b2e8470e51a35cbac184323dcb;hpb=10297bd8b8a4b4ab198a17a42fc6ff24ae2ed49b;p=jalview.git diff --git a/forester/java/src/org/forester/phylogeny/PhylogenyNode.java b/forester/java/src/org/forester/phylogeny/PhylogenyNode.java index 899c0cc..25b33d7 100644 --- a/forester/java/src/org/forester/phylogeny/PhylogenyNode.java +++ b/forester/java/src/org/forester/phylogeny/PhylogenyNode.java @@ -86,7 +86,23 @@ public final class PhylogenyNode implements Comparable { private PhylogenyNode( final String nhx, final NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction, final boolean replace_underscores ) throws NHXFormatException, PhyloXmlDataFormatException { - NHXParser.parseNHX( nhx, this, taxonomy_extraction, replace_underscores, false, false ); + NHXParser.parseNHX( nhx, this, taxonomy_extraction, replace_underscores, false, false, false ); + setId( PhylogenyNode.getNodeCount() ); + PhylogenyNode.increaseNodeCount(); + setSumExtNodes( 1 ); // For ext node, this number is 1 (not 0!!). + } + + private PhylogenyNode( final String nhx, + final NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction, + final boolean replace_underscores, + final boolean parse_extended_tags ) throws NHXFormatException, PhyloXmlDataFormatException { + NHXParser.parseNHX( nhx, + this, + taxonomy_extraction, + replace_underscores, + false, + false, + parse_extended_tags ); setId( PhylogenyNode.getNodeCount() ); PhylogenyNode.increaseNodeCount(); setSumExtNodes( 1 ); // For ext node, this number is 1 (not 0!!). @@ -232,10 +248,7 @@ public final class PhylogenyNode implements Comparable { } } - final public List getAllDescendants() { - return _descendants; - } - + /** * Returns a List containing references to all external children of this * PhylogenyNode. @@ -452,12 +465,12 @@ public final class PhylogenyNode implements Comparable { public final PhylogenyNode getNextExternalNodeWhileTakingIntoAccountCollapsedNodes() { //TODO work on me ~~ - if ( isInternal() && !isCollapse() ) { - throw new UnsupportedOperationException( "attempt to get next external node of an uncollapsed internal node" ); - } if ( isRoot() ) { return null; } + if ( isInternal() && !isCollapse() ) { + throw new UnsupportedOperationException( "attempt to get next external node of an uncollapsed internal node" ); + } if ( getParent().isCollapse() ) { throw new UnsupportedOperationException( "attempt to get next external node of node with a collapsed parent" ); } @@ -499,6 +512,10 @@ public final class PhylogenyNode implements Comparable { } return _node_data; } + + public final boolean isHasNodeData() { + return ( !( _node_data == null || _node_data.isEmpty() ) ); + } final public int getNumberOfDescendants() { if ( _descendants == null ) { @@ -597,9 +614,10 @@ public final class PhylogenyNode implements Comparable { /** * Returns whether this PhylogenyNode should be drawn as collapsed. + * Root can not be collapsed. */ final public boolean isCollapse() { - return _collapse; + return _collapse && _parent != null; } /** @@ -620,10 +638,7 @@ public final class PhylogenyNode implements Comparable { * @return true if this PhylogenyNode is external, false otherwise */ final public boolean isExternal() { - if ( _descendants == null ) { - return true; - } - return ( getNumberOfDescendants() < 1 ); + return ( _descendants == null ) || ( _descendants.size() == 0 ); } final public boolean isFirstChildNode() { @@ -768,14 +783,14 @@ public final class PhylogenyNode implements Comparable { } /** - * Inserts PhylogenyNode n at the specified position i into the list of + * Inserts PhylogenyNode node at the specified position i into the list of * child nodes. This does not allow null slots in the list of child nodes: - * If i is larger than the number of child nodes, n is just added to the - * list, not place at index i. + * If i is larger than the number of child nodes, node is just added to the + * list, not placed at index i. * * @param i * the index of position where to add the child - * @param n + * @param node * the PhylogenyNode to add */ final public void setChildNode( final int i, final PhylogenyNode node ) { @@ -1082,6 +1097,14 @@ public final class PhylogenyNode implements Comparable { throws NHXFormatException, PhyloXmlDataFormatException { return new PhylogenyNode( nhx, taxonomy_extraction, replace_underscores ); } + + public static PhylogenyNode createInstanceFromNhxString( final String nhx, + final NHXParser.TAXONOMY_EXTRACTION taxonomy_extraction, + final boolean replace_underscores, + final boolean parse_extended_tags ) + throws NHXFormatException, PhyloXmlDataFormatException { + return new PhylogenyNode( nhx, taxonomy_extraction, replace_underscores, parse_extended_tags ); + } /** * Returns the total number of all Nodes created so far.