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  /*** 
31      Ordering is used in the task chaining process for PrimitiveTasks 
32      ChangeLog
33      ---------
34      07 -06 -01 Simon adds () init for extensibility
35      */
36  public class Ordering implements Reference {
37     protected String lhs;
38     protected String rhs;
39     
40     public Ordering () { 
41     }
42     
43     public Ordering( String lhs, String rhs ) {
44        Assert.notNull(lhs);
45        Assert.notNull(rhs);
46  
47        this.lhs = lhs;
48        this.rhs = rhs;
49     }
50  
51     public Ordering( Ordering constr ) {
52        lhs = constr.getLHS();
53        rhs = constr.getRHS();
54     }
55  
56     public String getLHS()       { return lhs; }
57     public String getRHS()       { return rhs; }
58     public String getId()        { return lhs+rhs;  }
59  
60     public void setLHS(String arg) {
61        Assert.notNull(arg);
62        lhs = arg;
63     }
64  
65     public void setRHS(String arg) {
66        Assert.notNull(arg);
67        rhs = arg;
68     }
69  
70     public boolean equals(Ordering constr ) {
71        return lhs.equals(constr.getLHS()) &&
72               rhs.equals(constr.getRHS());
73     }
74  
75     public String toString() {
76        return( "(" +
77                 ":lhs " + lhs + " " +
78                 ":rhs " + rhs +
79                ")"
80              );
81     }
82  
83     public String pprint() {
84        return pprint(0);
85     }
86     public String pprint(int sp) {
87        String tabs = Misc.spaces(sp);
88        String eol  = "\n" + tabs + " ";
89  
90        String s = "(:lhs " + lhs + eol +
91                    ":rhs " + rhs + eol;
92        return s.trim() + "\n" + tabs + ")";
93     }
94  
95     public boolean references( String id ) {
96        StringTokenizer st;
97        String token;
98  
99        st = new StringTokenizer(lhs,".");
100       token = st.nextToken();
101       if ( token.equals(id) ) return true;
102       return false;
103    }
104 
105    public Ordering duplicate(String name, GenSym genSym) {
106       DuplicationTable table = new DuplicationTable(name,genSym);
107       return duplicate(table);
108    }
109    public Ordering duplicate(DuplicationTable table) {
110       ValueFunction lhs_fn = new VarFn(lhs);
111       ValueFunction rhs_fn = new VarFn(rhs);
112       String _lhs = (lhs_fn.duplicate(table)).toString();
113       String _rhs = (rhs_fn.duplicate(table)).toString();
114       return new Ordering(_lhs,_rhs);
115    }
116 }