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.lowlevel;
5   
6   import java.util.Collections;
7   import java.util.LinkedList;
8   import java.util.List;
9   
10  import net.sf.bddbddb.BDDRelation;
11  import net.sf.bddbddb.Relation;
12  import net.sf.bddbddb.ir.Operation;
13  
14  /***
15   * Project
16   * 
17   * @author jwhaley
18   * @version $Id: BDDProject.java 445 2005-02-21 02:32:50Z cs343 $
19   */
20  public class BDDProject extends LowLevelOperation {
21      BDDRelation r0, r1;
22      List/* <BDDDomains> */ domainProjectSet;
23      /***
24       * @param r0
25       * @param r1
26       */
27      public BDDProject(BDDRelation r0, BDDRelation r1) {
28          super();
29          this.r0 = r0;
30          this.r1 = r1;
31          this.domainProjectSet = new LinkedList(r1.getBDDDomains());
32          this.domainProjectSet.removeAll(r0.getBDDDomains());
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 "bddproject(" + r1.toString() + "," + domainProjectSet.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(LowLevelOperationVisitor 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 domains being projected
89       */
90      public List/*<BDDDomains>*/ getDomains() {
91          return domainProjectSet;
92      }
93  
94      /* (non-Javadoc)
95       * @see net.sf.bddbddb.ir.Operation#copy()
96       */
97      public Operation copy() {
98          return new BDDProject(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 = (BDDRelation) 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 = (BDDRelation) r0;
118     }
119 }