1
2
3
4 package net.sf.bddbddb.ir.highlevel;
5
6 import java.util.Collections;
7 import java.util.LinkedList;
8 import java.util.List;
9 import net.sf.bddbddb.Relation;
10 import net.sf.bddbddb.ir.Operation;
11
12 /***
13 * Project
14 *
15 * @author jwhaley
16 * @version $Id: Project.java 445 2005-02-21 02:32:50Z cs343 $
17 */
18 public class Project extends HighLevelOperation {
19 Relation r0, r1;
20 List
21
22 /***
23 * @param r0
24 * @param r1
25 */
26 public Project(Relation r0, Relation r1) {
27 super();
28 this.r0 = r0;
29 this.r1 = r1;
30 this.attributes = new LinkedList(r1.getAttributes());
31 this.attributes.removeAll(r0.getAttributes());
32 }
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 return "project(" + r1.toString() + "," + attributes.toString() + ")";
51 }
52
53
54
55
56
57
58 public Object visit(HighLevelOperationVisitor i) {
59 return i.visit(this);
60 }
61
62
63
64
65
66
67 public Relation getRelationDest() {
68 return r0;
69 }
70
71
72
73
74
75
76 public List getSrcs() {
77 return Collections.singletonList(r1);
78 }
79
80 /***
81 * @return Returns the source relation.
82 */
83 public Relation getSrc() {
84 return r1;
85 }
86
87 /***
88 * @return list of attributes being projected
89 */
90 public List
91 return attributes;
92 }
93
94
95
96
97 public Operation copy() {
98 return new Project(r0, r1);
99 }
100
101
102
103
104
105
106
107 public void replaceSrc(Relation r_old, Relation r_new) {
108 if (r1 == r_old) r1 = r_new;
109 }
110
111
112
113
114
115
116 public void setRelationDest(Relation r0) {
117 this.r0 = r0;
118 }
119 }