Author: chinmoy
Date: 2009-06-26 15:22:16 -0700 (Fri, 26 Jun 2009)
New Revision: 17123

Modified:
   
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/parser/PhylipTreeImpl.java
Log:
Split parser into smaller methods

Modified: 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/parser/PhylipTreeImpl.java
===================================================================
--- 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/parser/PhylipTreeImpl.java
        2009-06-26 22:01:05 UTC (rev 17122)
+++ 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/parser/PhylipTreeImpl.java
        2009-06-26 22:22:16 UTC (rev 17123)
@@ -64,81 +64,83 @@
                }
 
        }
-
-       /*
-        * parse()
-        * Traverses the tree string 'treeStr'and creates appropriate nodes and 
edges
-        */
-       private void parse()
+       
+       private List<String> convertTreeStringToList(String treeString)
        {
-               Stack <String> stack = new Stack<String>();  
-               Stack<PhylipNode> parentNodeStack = new Stack<PhylipNode>();
-               List<String> list = new LinkedList<String>();
-               List<PhylipNode> childNodeList = new LinkedList<PhylipNode>();
-               // ChildNodeList records the children of a node for the purpose 
of creating edges.
-               // It is cleared after the edges for each node are created. 
+               List<String> returnList = new LinkedList<String>();
+               // Split the tree string into a list
+                               String [] substrings = 
treeString.split(":|,|;");
 
-               List<Double> branchLengthList = new LinkedList<Double>(); 
-               // Reflects the ChildNodeList but records the edge lengths 
instead of the child nodes. 
 
+                               // Parse the input into a list ignoring ',' but 
adding names, lengths and parentheses
 
-               // Iterators for lists
-               Iterator<String> iterator;
-               Iterator<PhylipNode> childNodeListIterator;
-               Iterator<Double> branchLengthListIterator;
+                               for(int i = 0; i<substrings.length; i++)
+                               {
+                                       substrings[i] = substrings[i].trim();
 
-               Double branchLength = 0.0;
+                                       // For every parenthesis encountered, 
add it to the list
+                                       if (substrings[i].charAt(0) == '(')
+                                       {
+                                               returnList.add("(");
+                                               for (int k = 1; 
k<substrings[i].length(); k++)
+                                               {
+                                                       
if(substrings[i].charAt(k) == '(')
+                                                       {
+                                                               
returnList.add("("); 
+                                                       }
+                                                       else
+                                                       {
+                                                               // Split the 
remainder of the string around the '(' if a name is encountered
+                                                               // Add the name 
to the list 
+                                                               String[] 
tempSub = substrings[i].split("\\(+");
 
-               // Split the tree string into a list
-               String [] substrings = treeStr.split(":|,|;");
+                                                               
returnList.add(tempSub[1]);
+                                                               break;
 
 
-               // Parse the input into a list ignoring ',' but adding names, 
lengths and parentheses
+                                                       }
+                                               }         
+                                       }
 
-               for(int i = 0; i<substrings.length; i++)
-               {
-                       substrings[i] = substrings[i].trim();
+                                       // For every name/length encountered, 
splice off the ')' and add it to the list
+                                       else if(substrings[i].charAt(0) != '(' 
&& substrings[i].charAt(0) != ')')
+                                       {
+                                               String[] tempSub2 = 
substrings[i].split("\\)");
+                                               returnList.add(tempSub2[0]);
+                                       }
 
-                       // For every parenthesis encountered, add it to the list
-                       if (substrings[i].charAt(0) == '(')
-                       {
-                               list.add("(");
-                               for (int k = 1; k<substrings[i].length(); k++)
-                               {
-                                       if(substrings[i].charAt(k) == '(')
+                                       // For every ')' encountered add it to 
the list
+                                       
if(substrings[i].charAt(substrings[i].length()-1)== ')')
                                        {
-                                               list.add("("); 
+                                               returnList.add(")");
                                        }
-                                       else
-                                       {
-                                               // Split the remainder of the 
string around the '(' if a name is encountered
-                                               // Add the name to the list 
-                                               String[] tempSub = 
substrings[i].split("\\(+");
+                               }
 
-                                               list.add(tempSub[1]);
-                                               break;
 
+       
+               return returnList;
+       }
 
-                                       }
-                               }         
-                       }
+       private void readListIntoStack(List<String> list)
+       {
+               
+               Stack <String> stack = new Stack<String>();  
+               Stack<PhylipNode> parentNodeStack = new Stack<PhylipNode>();
+               
+               List<PhylipNode> childNodeList = new LinkedList<PhylipNode>();
+               // ChildNodeList records the children of a node for the purpose 
of creating edges.
+               // It is cleared after the edges for each node are created. 
 
-                       // For every name/length encountered, splice off the 
')' and add it to the list
-                       else if(substrings[i].charAt(0) != '(' && 
substrings[i].charAt(0) != ')')
-                       {
-                               String[] tempSub2 = substrings[i].split("\\)");
-                               list.add(tempSub2[0]);
-                       }
+               List<Double> branchLengthList = new LinkedList<Double>(); 
+               // Reflects the ChildNodeList but records the edge lengths 
instead of the child nodes. 
 
-                       // For every ')' encountered add it to the list
-                       if(substrings[i].charAt(substrings[i].length()-1)== ')')
-                       {
-                               list.add(")");
-                       }
-               }
 
+               // Iterators for lists
+               Iterator<String> iterator;
+               Iterator<PhylipNode> childNodeListIterator;
+               Iterator<Double> branchLengthListIterator;
 
-               // Traverse the list into node and edge lists using a stack
+               Double branchLength = 0.0;
 
                iterator = list.iterator();
                int parentNodeIndex = 0;
@@ -248,8 +250,22 @@
                                }
                        }
 
-               } 
+               }
+       }
+       /*
+        * parse()
+        * Traverses the tree string 'treeStr'and reads it into a list
+        * Then reads the list into a stack creating nodes and edges when 
required.
+        */
+       private void parse()
+       {
+               
+               // Parse the treeStr into a list of subelements
+               List<String> list = convertTreeStringToList(treeStr);
 
+               // Traverse the list into node and edge lists using a stack
+               readListIntoStack(list);
+                
 
        }
 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to