1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 }