View Javadoc

1   // Project.java, created Jun 29, 2004 12:25:38 PM 2004 by jwhaley
2   // Copyright (C) 2004 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
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/* <Attribute> */attributes;
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       * (non-Javadoc)
37       * 
38       * @see java.lang.Object#toString()
39       */
40      public String toString() {
41          return r0.toString() + " = " + getExpressionString();
42      }
43  
44      /*
45       * (non-Javadoc)
46       * 
47       * @see net.sf.bddbddb.ir.Operation#getExpressionString()
48       */
49      public String getExpressionString() {
50          return "project(" + r1.toString() + "," + attributes.toString() + ")";
51      }
52  
53      /*
54       * (non-Javadoc)
55       * 
56       * @see net.sf.bddbddb.ir.Operation#visit(net.sf.bddbddb.ir.HighLevelOperationVisitor)
57       */
58      public Object visit(HighLevelOperationVisitor i) {
59          return i.visit(this);
60      }
61  
62      /*
63       * (non-Javadoc)
64       * 
65       * @see net.sf.bddbddb.ir.Operation#getDest()
66       */
67      public Relation getRelationDest() {
68          return r0;
69      }
70  
71      /*
72       * (non-Javadoc)
73       * 
74       * @see net.sf.bddbddb.ir.Operation#getSrcs()
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/*<Attribute>*/ getAttributes() {
91          return attributes;
92      }
93  
94      /* (non-Javadoc)
95       * @see net.sf.bddbddb.ir.Operation#copy()
96       */
97      public Operation copy() {
98          return new Project(r0, r1);
99      }
100 
101     /*
102      * (non-Javadoc)
103      * 
104      * @see net.sf.bddbddb.ir.Operation#replaceSrc(net.sf.bddbddb.Relation,
105      *      net.sf.bddbddb.Relation)
106      */
107     public void replaceSrc(Relation r_old, Relation r_new) {
108         if (r1 == r_old) r1 = r_new;
109     }
110 
111     /*
112      * (non-Javadoc)
113      * 
114      * @see net.sf.bddbddb.ir.Operation#setRelationDest(net.sf.bddbddb.Relation)
115      */
116     public void setRelationDest(Relation r0) {
117         this.r0 = r0;
118     }
119 }