/*
* Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006.
*
* Licensed under the Aduna BSD-style license.
*/
package org.openrdf.query.algebra;
import java.util.Set;
/**
* An abstract superclass for unary tuple operators which, by definition, has
* one argument.
*/
public abstract class UnaryTupleOperator extends QueryModelNodeBase implements TupleExpr {
/*-----------*
* Variables *
*-----------*/
/**
* The operator's argument.
*/
protected TupleExpr arg;
/*--------------*
* Constructors *
*--------------*/
public UnaryTupleOperator() {
}
/**
* Creates a new unary tuple operator.
*
* @param arg
* The operator's argument, must not be <tt>null</tt>.
*/
public UnaryTupleOperator(TupleExpr arg) {
setArg(arg);
}
/*---------*
* Methods *
*---------*/
/**
* Gets the argument of this unary tuple operator.
*
* @return The operator's argument.
*/
public TupleExpr getArg() {
return arg;
}
/**
* Sets the argument of this unary tuple operator.
*
* @param arg
* The (new) argument for this operator, must not be <tt>null</tt>.
*/
public void setArg(TupleExpr arg) {
assert arg != null : "arg must not be null";
arg.setParentNode(this);
this.arg = arg;
}
public Set<String> getBindingNames() {
return getArg().getBindingNames();
}
@Override
public <X extends Exception> void visitChildren(QueryModelVisitor<X> visitor)
throws X
{
arg.visit(visitor);
}
@Override
public void replaceChildNode(QueryModelNode current, QueryModelNode replacement)
{
if (arg == current) {
setArg((TupleExpr)replacement);
}
else {
super.replaceChildNode(current, replacement);
}
}
@Override
public UnaryTupleOperator clone() {
UnaryTupleOperator clone = (UnaryTupleOperator)super.clone();
clone.setArg(getArg().clone());
return clone;
}
}