1
2
3
4 package net.sf.bddbddb.ir.highlevel;
5
6 import java.util.Collections;
7 import java.util.Iterator;
8 import java.util.List;
9 import java.util.Map;
10 import net.sf.bddbddb.Attribute;
11 import net.sf.bddbddb.Relation;
12 import net.sf.bddbddb.ir.Operation;
13
14 /***
15 * Rename
16 *
17 * @author jwhaley
18 * @version $Id: Rename.java 328 2004-10-16 02:45:30Z joewhaley $
19 */
20 public class Rename extends HighLevelOperation {
21 Relation r0, r1;
22 Map
23
24 /***
25 * @param r0
26 * @param r1
27 */
28 public Rename(Relation r0, Relation r1, Map
29 super();
30 this.r0 = r0;
31 this.r1 = r1;
32 this.renames = renames;
33 }
34
35
36
37
38
39
40 public String toString() {
41 return r0.toString() + " = " + getExpressionString();
42 }
43
44
45
46
47
48
49 public String getExpressionString() {
50 StringBuffer sb = new StringBuffer();
51 sb.append("rename(");
52 sb.append(r1.toString());
53 for (Iterator i = renames.entrySet().iterator(); i.hasNext();) {
54 Map.Entry p = (Map.Entry) i.next();
55 sb.append(',');
56 Attribute a1 = (Attribute) p.getKey();
57 sb.append(a1.getRelation());
58 sb.append('.');
59 sb.append(a1.toString());
60 sb.append("->");
61 Attribute a2 = (Attribute) p.getValue();
62 sb.append(a2.getRelation());
63 sb.append('.');
64 sb.append(a2.toString());
65 }
66 sb.append(")");
67 return sb.toString();
68 }
69
70
71
72
73
74
75 public Object visit(HighLevelOperationVisitor i) {
76 return i.visit(this);
77 }
78
79
80
81
82
83
84 public Relation getRelationDest() {
85 return r0;
86 }
87
88
89
90
91
92
93 public List getSrcs() {
94 return Collections.singletonList(r1);
95 }
96
97 /***
98 * @return Returns the source relation.
99 */
100 public Relation getSrc() {
101 return r1;
102 }
103
104 /***
105 * @return the rename map
106 */
107 public Map getRenameMap() {
108 return renames;
109 }
110
111
112
113
114
115
116 public Operation copy() {
117 return new Rename(r0, r1, renames);
118 }
119
120
121
122
123
124
125
126 public void replaceSrc(Relation r_old, Relation r_new) {
127 if (r1 == r_old) r1 = r_new;
128 }
129
130
131
132
133
134
135 public void setRelationDest(Relation r0) {
136 this.r0 = r0;
137 }
138 }