1 56 package org.objectstyle.cayenne.exp; 57 58 import java.io.PrintWriter ; 59 60 67 public class BinaryExpression extends Expression { 68 protected Object leftOperand; 69 protected Object rightOperand; 70 71 public BinaryExpression() { 72 } 73 74 public BinaryExpression(int type) { 75 this.type = type; 76 } 77 78 protected void flattenTree() { 79 80 } 81 82 protected boolean pruneNodeForPrunedChild(Object prunedChild) { 83 return true; 84 } 85 86 public final int getOperandCount() { 87 return 2; 88 } 89 90 95 public Expression shallowCopy() { 96 return new BinaryExpression(type); 97 } 98 99 public Object getOperand(int index) { 100 if (index == 0) 101 return leftOperand; 102 else if (index == 1) 103 return rightOperand; 104 105 throw new IllegalArgumentException ( 106 "Invalid operand index for BinaryExpression: " + index); 107 } 108 109 public void setOperand(int index, Object value) { 110 if (index == 0) { 111 leftOperand = value; 112 return; 113 } 114 else if (index == 1) { 115 rightOperand = value; 116 return; 117 } 118 119 throw new IllegalArgumentException ( 120 "Invalid operand index for BinaryExpression: " + index); 121 } 122 123 126 public void encodeAsString(PrintWriter pw) { 127 StringBuffer buffer = new StringBuffer (); 130 toStringBuffer(buffer); 131 pw.print(buffer.toString()); 132 } 133 } 134 | Popular Tags |