KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > prefuse > data > expression > BinaryExpression


1 package prefuse.data.expression;
2
3 /**
4  * Abstract base class for Expression implementations that maintain two
5  * sub-expressions. These are referred to as the left expression (the first
6  * one) and the right expression (the second one).
7  *
8  * @author <a HREF="http://jheer.org">jeffrey heer</a>
9  */

10 public abstract class BinaryExpression extends AbstractExpression {
11
12     protected int m_op;
13     protected Expression m_left;
14     protected Expression m_right;
15     
16     /**
17      * Create a new BinaryExpression.
18      * @param operation int value indicating the operation to be
19      * performed on the subtrees. The actual range of acceptable values
20      * are determined by subclasses.
21      * @param minOp the minimum legal operation code value
22      * @param maxOp the maximum legal operation code value
23      * @param left the left sub-expression
24      * @param right the right sub-expression
25      */

26     protected BinaryExpression(int operation, int minOp, int maxOp,
27             Expression left, Expression right)
28     {
29         // operation check
30
if ( operation < minOp || operation > maxOp ) {
31             throw new IllegalArgumentException JavaDoc(
32                 "Unknown operation type: " + operation);
33         }
34         // null check;
35
if ( left == null || right == null ) {
36             throw new IllegalArgumentException JavaDoc(
37                     "Expressions must be non-null.");
38         }
39         this.m_op = operation;
40         this.m_left = left;
41         this.m_right = right;
42     }
43     
44     /**
45      * Get the left sub-expression.
46      * @return the left sub-expression
47      */

48     public Expression getLeftExpression() {
49         return m_left;
50     }
51
52     /**
53      * Get the right sub-expression.
54      * @return the right sub-expression
55      */

56     public Expression getRightExpression() {
57         return m_right;
58     }
59     
60     /**
61      * Set the left sub-expression. Any listeners will be notified.
62      * @param e the left sub-expression to use
63      */

64     public void setLeftExpression(Expression e) {
65         m_left.removeExpressionListener(this);
66         m_left = e;
67         if ( hasListeners() ) e.addExpressionListener(this);
68         fireExpressionChange();
69     }
70     
71     /**
72      * Set the right sub-expression. Any listeners will be notified.
73      * @param e the right sub-expression to use
74      */

75     public void setRightExpression(Expression e) {
76         m_right.removeExpressionListener(this);
77         m_right = e;
78         if ( hasListeners() ) e.addExpressionListener(this);
79         fireExpressionChange();
80     }
81     
82     /**
83      * Get the operation code for this expression. The meaning of this
84      * code is left for subclasses to determine.
85      * @return the operation code
86      */

87     public int getOperation() {
88         return m_op;
89     }
90     
91     /**
92      * @see prefuse.data.expression.Expression#visit(prefuse.data.expression.ExpressionVisitor)
93      */

94     public void visit(ExpressionVisitor v) {
95         v.visitExpression(this);
96         v.down(); m_left.visit(v); v.up();
97         v.down(); m_right.visit(v); v.up();
98     }
99     
100     /**
101      * @see prefuse.data.expression.AbstractExpression#addChildListeners()
102      */

103     protected void addChildListeners() {
104         m_left.addExpressionListener(this);
105         m_right.addExpressionListener(this);
106     }
107     
108     /**
109      * @see prefuse.data.expression.AbstractExpression#removeChildListeners()
110      */

111     protected void removeChildListeners() {
112         m_left.removeExpressionListener(this);
113         m_right.removeExpressionListener(this);
114     }
115
116 } // end of abstract class BinaryExpression
117
Popular Tags