001: /*
002: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006.
003: *
004: * Licensed under the Aduna BSD-style license.
005: */
006: package org.openrdf.query.algebra;
007:
008: /**
009: * An abstract superclass for binary tuple operators which, by definition, has
010: * two arguments.
011: */
012: public abstract class BinaryTupleOperator extends QueryModelNodeBase
013: implements TupleExpr {
014:
015: /*-----------*
016: * Variables *
017: *-----------*/
018:
019: /**
020: * The operator's left argument.
021: */
022: protected TupleExpr leftArg;
023:
024: /**
025: * The operator's right argument.
026: */
027: protected TupleExpr rightArg;
028:
029: /*--------------*
030: * Constructors *
031: *--------------*/
032:
033: public BinaryTupleOperator() {
034: }
035:
036: /**
037: * Creates a new binary tuple operator.
038: *
039: * @param leftArg
040: * The operator's left argument, must not be <tt>null</tt>.
041: * @param rightArg
042: * The operator's right argument, must not be <tt>null</tt>.
043: */
044: public BinaryTupleOperator(TupleExpr leftArg, TupleExpr rightArg) {
045: setLeftArg(leftArg);
046: setRightArg(rightArg);
047: }
048:
049: /*---------*
050: * Methods *
051: *---------*/
052:
053: /**
054: * Gets the left argument of this binary tuple operator.
055: *
056: * @return The operator's left argument.
057: */
058: public TupleExpr getLeftArg() {
059: return leftArg;
060: }
061:
062: /**
063: * Sets the left argument of this binary tuple operator.
064: *
065: * @param leftArg
066: * The (new) left argument for this operator, must not be
067: * <tt>null</tt>.
068: */
069: public void setLeftArg(TupleExpr leftArg) {
070: assert leftArg != null : "leftArg must not be null";
071: leftArg.setParentNode(this );
072: this .leftArg = leftArg;
073: }
074:
075: /**
076: * Gets the right argument of this binary tuple operator.
077: *
078: * @return The operator's right argument.
079: */
080: public TupleExpr getRightArg() {
081: return rightArg;
082: }
083:
084: /**
085: * Sets the right argument of this binary tuple operator.
086: *
087: * @param rightArg
088: * The (new) right argument for this operator, must not be
089: * <tt>null</tt>.
090: */
091: public void setRightArg(TupleExpr rightArg) {
092: assert rightArg != null : "rightArg must not be null";
093: rightArg.setParentNode(this );
094: this .rightArg = rightArg;
095: }
096:
097: @Override
098: public <X extends Exception> void visitChildren(
099: QueryModelVisitor<X> visitor) throws X {
100: leftArg.visit(visitor);
101: rightArg.visit(visitor);
102: }
103:
104: @Override
105: public void replaceChildNode(QueryModelNode current,
106: QueryModelNode replacement) {
107: if (leftArg == current) {
108: setLeftArg((TupleExpr) replacement);
109: } else if (rightArg == current) {
110: setRightArg((TupleExpr) replacement);
111: } else {
112: super .replaceChildNode(current, replacement);
113: }
114: }
115:
116: @Override
117: public BinaryTupleOperator clone() {
118: BinaryTupleOperator clone = (BinaryTupleOperator) super.clone();
119: clone.setLeftArg(getLeftArg().clone());
120: clone.setRightArg(getRightArg().clone());
121: return clone;
122: }
123: }
|