Merge branch 'develop' into feature/JAL-244_Automatically_adjust_left_margin_to_avoid...
[jalview.git] / src / jalview / analysis / TreeModel.java
index 703702a..0e57a58 100644 (file)
@@ -20,7 +20,6 @@
  */
 package jalview.analysis;
 
-import jalview.bin.Cache;
 import jalview.datamodel.AlignmentView;
 import jalview.datamodel.BinaryNode;
 import jalview.datamodel.NodeTransformI;
@@ -51,7 +50,7 @@ public class TreeModel
 
   int noseqs;
 
-  SequenceNode top;
+  BinaryNode top;
 
   double maxDistValue;
 
@@ -59,7 +58,7 @@ public class TreeModel
 
   int ycount;
 
-  Vector<SequenceNode> node;
+  Vector<BinaryNode> node;
 
   boolean hasDistances = true; // normal case for jalview trees
 
@@ -95,7 +94,7 @@ public class TreeModel
    */
   public TreeModel(TreeBuilder tree)
   {
-    this(tree.getSequences(), (SequenceNode) tree.getTopNode(), tree.hasDistances(),
+    this(tree.getSequences(), tree.getTopNode(), tree.hasDistances(),
             tree.hasBootstrap(), tree.hasRootDistance());
     seqData = tree.getOriginalData();
   }
@@ -109,7 +108,7 @@ public class TreeModel
    * @param hasBoot
    * @param hasRootDist
    */
-  public TreeModel(SequenceI[] seqs, SequenceNode root, boolean hasDist,
+  public TreeModel(SequenceI[] seqs, BinaryNode root, boolean hasDist,
           boolean hasBoot, boolean hasRootDist)
   {
     this.sequences = seqs;
@@ -129,7 +128,7 @@ public class TreeModel
   {
     SequenceIdMatcher algnIds = new SequenceIdMatcher(seqs);
 
-    Vector<SequenceNode> leaves = findLeaves(top);
+    Vector<BinaryNode> leaves = findLeaves(top);
 
     int i = 0;
     int namesleft = seqs.length;
@@ -141,7 +140,8 @@ public class TreeModel
     // int countOne2Many = 0;
     while (i < leaves.size())
     {
-      j = leaves.elementAt(i++);
+      // TODO - decide if we get rid of the polymorphism here ?
+      j = (SequenceNode) leaves.elementAt(i++);
       realnam = j.getName();
       nam = null;
 
@@ -206,7 +206,7 @@ public class TreeModel
    */
   public void updatePlaceHolders(List<SequenceI> list)
   {
-    Vector<SequenceNode> leaves = findLeaves(top);
+    Vector<BinaryNode> leaves = findLeaves(top);
 
     int sz = leaves.size();
     SequenceIdMatcher seqmatcher = null;
@@ -214,7 +214,7 @@ public class TreeModel
 
     while (i < sz)
     {
-      SequenceNode leaf = leaves.elementAt(i++);
+      SequenceNode leaf = (SequenceNode) leaves.elementAt(i++);
 
       if (list.contains(leaf.element()))
       {
@@ -289,15 +289,15 @@ public class TreeModel
   /**
    * Search for leaf nodes below (or at) the given node
    * 
-   * @param nd
+   * @param top2
    *          root node to search from
    * 
    * @return
    */
-  public Vector<SequenceNode> findLeaves(SequenceNode nd)
+  public Vector<BinaryNode> findLeaves(BinaryNode top2)
   {
-    Vector<SequenceNode> leaves = new Vector<SequenceNode>();
-    findLeaves(nd, leaves);
+    Vector<BinaryNode> leaves = new Vector<BinaryNode>();
+    findLeaves(top2, leaves);
     return leaves;
   }
 
@@ -311,8 +311,7 @@ public class TreeModel
    * 
    * @return Vector of leaf nodes on binary tree
    */
-  Vector<SequenceNode> findLeaves(SequenceNode nd,
-          Vector<SequenceNode> leaves)
+  Vector<BinaryNode> findLeaves(BinaryNode nd, Vector<BinaryNode> leaves)
   {
     if (nd == null)
     {
@@ -332,8 +331,8 @@ public class TreeModel
        * TODO: Identify internal nodes... if (node.isSequenceLabel()) {
        * leaves.addElement(node); }
        */
-      findLeaves((SequenceNode) nd.left(), leaves);
-      findLeaves((SequenceNode) nd.right(), leaves);
+      findLeaves(nd.left(), leaves);
+      findLeaves(nd.right(), leaves);
     }
 
     return leaves;
@@ -388,14 +387,14 @@ public class TreeModel
    * @param threshold
    * @see #getGroups()
    */
-  public List<SequenceNode> groupNodes(float threshold)
+  public List<BinaryNode> groupNodes(float threshold)
   {
-    List<SequenceNode> groups = new ArrayList<SequenceNode>();
+    List<BinaryNode> groups = new ArrayList<BinaryNode>();
     _groupNodes(groups, getTopNode(), threshold);
     return groups;
   }
 
-  protected void _groupNodes(List<SequenceNode> groups, SequenceNode nd,
+  protected void _groupNodes(List<BinaryNode> groups, BinaryNode nd,
           float threshold)
   {
     if (nd == null)
@@ -409,8 +408,8 @@ public class TreeModel
     }
     else
     {
-      _groupNodes(groups, (SequenceNode) nd.left(), threshold);
-      _groupNodes(groups, (SequenceNode) nd.right(), threshold);
+      _groupNodes(groups, nd.left(), threshold);
+      _groupNodes(groups, nd.right(), threshold);
     }
   }
 
@@ -630,7 +629,7 @@ public class TreeModel
    * 
    * @return DOCUMENT ME!
    */
-  public SequenceNode getTopNode()
+  public BinaryNode getTopNode()
   {
     return top;
   }
@@ -665,7 +664,7 @@ public class TreeModel
    */
   public void applyToNodes(NodeTransformI nodeTransformI)
   {
-    for (Enumeration<SequenceNode> nodes = node.elements(); nodes
+    for (Enumeration<BinaryNode> nodes = node.elements(); nodes
             .hasMoreElements(); nodeTransformI
                     .transform(nodes.nextElement()))
     {