View Javadoc

1   
2   package com.sri.emo.wizard.branch;
3   
4   import java.util.List;
5   import java.util.Iterator;
6   import java.util.Collection;
7   import java.util.ListIterator;
8   import java.util.ArrayList;
9   import com.sri.emo.wizard.WizardPage;
10  import java.util.*;
11  import com.sri.emo.wizard.creation.StringUtil;
12  
13  /***
14   * <p>Title: </p>
15   *
16   * <p>Description: </p>
17   *
18   * <p>Copyright: Copyright (c) 2003</p>
19   *
20   * <p>Company: </p>
21   *
22   * @author not attributable
23   * @version 1.0
24   */
25  public class BranchList {
26      List nodes;
27  //    BranchNode previouslyAddedNode;
28      List branches;
29      String defaultTransitionKey;
30      public BranchList(int initialSize, String defaultTransitionKey) {
31          nodes = new ArrayList(initialSize);
32          this.defaultTransitionKey = defaultTransitionKey;
33          branches = new ArrayList(4);
34      }
35  
36      public void addBranch(BranchNode node){
37          nodes.add(node);
38          branches.add(node);
39  //        previouslyAddedNode = node;
40      }
41  
42      public String getDefaultTransitionKey(){
43          return this.defaultTransitionKey;
44      }
45  
46      public BranchList generateNewBranchList(){
47          return new BranchList(4, defaultTransitionKey);
48      }
49  
50      public void addConverging(BranchNode node){
51          addDefaultPageToBranches(node.getPage());
52          branches.clear();
53          //always retain 1 branch
54          addBranch(node);
55  
56      }
57  
58      public BranchNode addConvergingWizardPage(WizardPage page) {
59          System.out.println("addConvergingWizardPage(" + page + ")");
60          BranchNode node = new BranchNode(page, defaultTransitionKey);
61          addConverging(node);
62          return node;
63      }
64  
65      protected void addDefaultPageToBranches(WizardPage page){
66          Iterator iter = branches.iterator();
67          while (iter.hasNext()) {
68              BranchNode item = (BranchNode) iter.next();
69              item.addNext(BranchNode.DEFAULT_TRANSITION, defaultTransitionKey, page);
70          }
71      }
72  
73      public List getBranches(){
74          return branches;
75      }
76  
77      public List getNodes(){
78          System.out.println("BranchList.getNodes() = ");
79  //        System.out.println(StringUtil.toString(nodes, "", ",\n",""));
80          return nodes;
81      }
82  
83      /***
84       * addBranch
85       *
86       * @param string String
87       * @param branchList BranchList
88       */
89      public void addBranch(BranchNode node, String transition, BranchList branchList) {
90          node.addNext(transition, (BranchNode)branchList.getNodes().get(0));
91          Iterator iter = branchList.nodes.iterator();
92          while (iter.hasNext()) {
93              BranchNode item = (BranchNode) iter.next();
94              nodes.add(item);
95          }
96          this.branches.addAll(branchList.getBranches());
97      }
98  
99  
100 }