View Javadoc

1   // JoinConstant.java, created Jun 29, 2004 2:57:29 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.List;
8   import net.sf.bddbddb.Attribute;
9   import net.sf.bddbddb.Relation;
10  import net.sf.bddbddb.ir.Operation;
11  
12  /***
13   * JoinConstant
14   * 
15   * @author jwhaley
16   * @version $Id: JoinConstant.java 328 2004-10-16 02:45:30Z joewhaley $
17   */
18  public class JoinConstant extends HighLevelOperation {
19      Relation r0, r1;
20      Attribute a;
21      long value;
22  
23      /***
24       * @param r0
25       * @param r1
26       * @param a
27       * @param value
28       */
29      public JoinConstant(Relation r0, Relation r1, Attribute a, long value) {
30          super();
31          this.r0 = r0;
32          this.r1 = r1;
33          this.a = a;
34          this.value = value;
35      }
36  
37      /*
38       * (non-Javadoc)
39       * 
40       * @see java.lang.Object#toString()
41       */
42      public String toString() {
43          return r0.toString() + " = " + getExpressionString();
44      }
45  
46      /*
47       * (non-Javadoc)
48       * 
49       * @see net.sf.bddbddb.ir.Operation#getExpressionString()
50       */
51      public String getExpressionString() {
52          return "restrict(" + r1.toString() + "," + a.toString() + "=" + value + ")";
53      }
54  
55      /*
56       * (non-Javadoc)
57       * 
58       * @see net.sf.bddbddb.ir.Operation#visit(net.sf.bddbddb.ir.HighLevelOperationVisitor)
59       */
60      public Object visit(HighLevelOperationVisitor i) {
61          return i.visit(this);
62      }
63  
64      /*
65       * (non-Javadoc)
66       * 
67       * @see net.sf.bddbddb.ir.Operation#getDest()
68       */
69      public Relation getRelationDest() {
70          return r0;
71      }
72  
73      /*
74       * (non-Javadoc)
75       * 
76       * @see net.sf.bddbddb.ir.Operation#getSrcs()
77       */
78      public List getSrcs() {
79          return Collections.singletonList(r1);
80      }
81  
82      /***
83       * @return Returns the source relation.
84       */
85      public Relation getSrc() {
86          return r1;
87      }
88  
89      /***
90       * @return  the value being joined
91       */
92      public long getValue() {
93          return value;
94      }
95  
96      /***
97       * @return  the attribute of the value being joined
98       */
99      public Attribute getAttribute() {
100         return a;
101     }
102 
103     public Operation copy() {
104         return new JoinConstant(r0, r1, a, value);
105     }
106 
107     /*
108      * (non-Javadoc)
109      * 
110      * @see net.sf.bddbddb.ir.Operation#replaceSrc(net.sf.bddbddb.Relation,
111      *      net.sf.bddbddb.Relation)
112      */
113     public void replaceSrc(Relation r_old, Relation r_new) {
114         if (r1 == r_old) r1 = r_new;
115     }
116 
117     /*
118      * (non-Javadoc)
119      * 
120      * @see net.sf.bddbddb.ir.Operation#setRelationDest(net.sf.bddbddb.Relation)
121      */
122     public void setRelationDest(Relation r0) {
123         this.r0 = r0;
124     }
125 }