View Javadoc

1   /*
2   * The contents of this file are subject to the BT "ZEUS" Open Source 
3   * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
4   * except in compliance with the Licence. You may obtain a copy of the Licence
5   * from $ZEUS_INSTALL/licence.html or alternatively from
6   * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7   * 
8   * Except as stated in Clause 7 of the Licence, software distributed under the
9   * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or 
10  * implied. See the Licence for the specific language governing rights and 
11  * limitations under the Licence.
12  * 
13  * The Original Code is within the package zeus.*.
14  * The Initial Developer of the Original Code is British Telecommunications
15  * public limited company, whose registered office is at 81 Newgate Street, 
16  * London, EC1A 7AJ, England. Portions created by British Telecommunications 
17  * public limited company are Copyright 1996-9. All Rights Reserved.
18  * 
19  * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
20  */
21  
22  
23  
24  package zeus.concepts;
25  
26  import java.util.*;
27  import zeus.util.*;
28  import zeus.concepts.fn.*;
29  
30  public class TaskLink implements Reference {
31     protected String leftNode;
32     protected String rightNode;
33     protected String leftArg;
34     protected String rightArg;
35     protected String leftGroup;
36     protected String rightGroup;
37  
38     public TaskLink(String leftNode, String leftGroup, String leftArg,
39                     String rightNode, String rightGroup, String rightArg) {
40  
41        Assert.notNull(leftNode);
42        Assert.notNull(leftGroup);
43        Assert.notNull(leftArg);
44        Assert.notNull(rightNode);
45        Assert.notNull(rightGroup);
46        Assert.notNull(rightArg);
47  
48        this.leftNode = leftNode;
49        this.leftGroup = leftGroup;
50        this.leftArg = leftArg;
51        this.rightNode = rightNode;
52        this.rightGroup = rightGroup;
53        this.rightArg = rightArg;
54     }
55  
56     public TaskLink(TaskLink link) {
57        leftNode = link.getLeftNode();
58        rightNode = link.getRightNode();
59        leftGroup = link.getLeftGroup();
60        rightGroup = link.getRightGroup();
61        leftArg = link.getLeftArg();
62        rightArg = link.getRightArg();
63     }
64  
65     public void setLeftNode(String leftNode) {
66        Assert.notNull(leftNode);
67        this.leftNode = leftNode;
68     }
69     public void setRightNode(String rightNode) {
70        Assert.notNull(rightNode);
71        this.rightNode = rightNode;
72     }
73     public void setLeftArg(String leftArg) {
74        Assert.notNull(leftArg);
75        this.leftArg = leftArg;
76     }
77     public void setRightArg(String rightArg) {
78        Assert.notNull(rightArg);
79        this.rightArg = rightArg;
80     }
81     public void setLeftGroup(String leftGroup) {
82        Assert.notNull(leftGroup);
83        this.leftGroup = leftGroup;
84     }
85     public void setRightGroup(String rightGroup) {
86        Assert.notNull(rightGroup);
87        this.rightGroup = rightGroup;
88     }
89  
90     public String getLeftNode()   { return leftNode; }
91     public String getRightNode()  { return rightNode; }
92     public String getLeftGroup()  { return leftGroup; }
93     public String getRightGroup() { return rightGroup; }
94     public String getLeftArg()    { return leftArg; }
95     public String getRightArg()   { return rightArg; }
96  
97     public boolean isFromBeginNode() { return leftNode.equals(TaskNode.BEGIN); }
98     public boolean isToEndNode()     { return rightNode.equals(TaskNode.END); }
99  
100    public String getId() {
101       return leftNode + ":" + leftGroup + ":" + leftArg +
102              "==" +
103 	     rightNode + ":" + rightGroup + ":" + rightArg;
104    }
105 
106    public boolean equals(TaskLink link) {
107       return getId().equals(link.getId());
108    }
109 
110    public String toString() {
111       return( "(" +
112                ":left_node " + leftNode + " " +
113                ":left_group " + leftGroup + " " +
114                ":left_arg " + leftArg + " " +
115                ":right_node " + rightNode + " " +
116                ":right_group " + rightGroup + " " +
117                ":right_arg " + rightArg +
118               ")"
119             );
120    }
121 
122    public String pprint() {
123       return pprint(0);
124    }
125    public String pprint(int sp) {
126       String tabs = Misc.spaces(sp);
127       String eol  = "\n" + tabs + " ";
128 
129       String s = "(:left_node " + leftNode + eol +
130                   ":left_group " + leftGroup + eol +
131                   ":left_arg " + leftArg + eol +
132                   ":right_node " + rightNode + eol +
133                   ":right_group " + rightGroup + eol +
134                   ":right_arg " + rightArg + eol;
135       return s.trim() + "\n" + tabs + ")";
136    }
137 
138    public boolean referencesNode(String node) {
139       return leftNode.equals(node) || rightNode.equals(node);
140    }
141    public boolean references(String id) {
142       return leftArg.equals(id) || rightArg.equals(id);
143    }
144 
145    public TaskLink duplicate(String name, GenSym genSym) {
146       DuplicationTable table = new DuplicationTable(name,genSym);
147       return duplicate(table);
148    }
149    public TaskLink duplicate(DuplicationTable table) {
150       ValueFunction leftArgFn = new VarFn(leftArg);
151       ValueFunction rightArgFn = new VarFn(rightArg);
152       String _leftArg = (leftArgFn.duplicate(table)).toString();
153       String _rightArg = (rightArgFn.duplicate(table)).toString();
154       return new TaskLink(leftNode,leftGroup,_leftArg,
155                           rightNode,rightGroup,_rightArg);
156    }
157 }