JAL-4134 - refactor tree calculation code to work with binaryNode base type.
[jalview.git] / src / jalview / datamodel / SequenceNode.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.datamodel;
22
23 /**
24  * DOCUMENT ME!
25  * 
26  * @author $author$
27  * @version $Revision$
28  */
29 public class SequenceNode extends BinaryNode
30 {
31   private boolean placeholder = false;
32
33   /**
34    * Creates a new SequenceNode object.
35    */
36   public SequenceNode()
37   {
38     super();
39   }
40
41   /**
42    * Creates a new SequenceNode object.
43    * 
44    * @param val
45    *          DOCUMENT ME!
46    * @param parent
47    *          DOCUMENT ME!
48    * @param dist
49    *          DOCUMENT ME!
50    * @param name
51    *          DOCUMENT ME!
52    */
53   public SequenceNode(Object val, BinaryNode parent, double dist,
54           String name)
55   {
56     super(val, parent, name);
57     this.dist = dist;
58   }
59
60   /**
61    * Creates a new SequenceNode object.
62    * 
63    * @param val
64    *          DOCUMENT ME!
65    * @param parent
66    *          DOCUMENT ME!
67    * @param name
68    *          DOCUMENT ME!
69    * @param dist
70    *          DOCUMENT ME!
71    * @param bootstrap
72    *          DOCUMENT ME!
73    * @param dummy
74    *          DOCUMENT ME!
75    */
76   public SequenceNode(Object val, BinaryNode parent, String name,
77           double dist, int bootstrap, boolean dummy)
78   {
79     super(val, parent, name);
80     this.dist = dist;
81     this.bootstrap = bootstrap;
82     this.dummy = dummy;
83   }
84
85   /**
86    * @param dummy
87    *          true if node is created for the representation of polytomous trees
88    */
89   public boolean isDummy()
90   {
91     return dummy;
92   }
93
94   /*
95    * @param placeholder is true if the sequence refered to in the element node
96    * is not actually present in the associated alignment
97    */
98   public boolean isPlaceholder()
99   {
100     return placeholder;
101   }
102
103   /**
104    * DOCUMENT ME!
105    * 
106    * @param newstate
107    *          DOCUMENT ME!
108    * 
109    * @return DOCUMENT ME!
110    */
111   public boolean setDummy(boolean newstate)
112   {
113     boolean oldstate = dummy;
114     dummy = newstate;
115
116     return oldstate;
117   }
118
119   /**
120    * DOCUMENT ME!
121    * 
122    * @param Placeholder
123    *          DOCUMENT ME!
124    */
125   public void setPlaceholder(boolean Placeholder)
126   {
127     this.placeholder = Placeholder;
128   }
129
130   /**
131    * test if this node has a name that might be a label rather than a bootstrap
132    * value
133    * 
134    * @return true if node has a non-numeric label
135    */
136   public boolean isSequenceLabel()
137   {
138     if (name != null && name.length() > 0)
139     {
140       for (int c = 0, s = name.length(); c < s; c++)
141       {
142         char q = name.charAt(c);
143         if ('0' <= q && q <= '9')
144         {
145           continue;
146         }
147         return true;
148       }
149     }
150     return false;
151   }
152 }