All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bigdata.bop.Bind Maven / Gradle / Ivy

package com.bigdata.bop;

import java.util.Map;

/**
 * Operator causes a variable to be bound to the result of its evaluation as a
 * side-effect.
 * 
 * @author thompsonbry
 */
public class Bind extends ImmutableBOp implements IValueExpression, IBind {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Constructor required for {@link com.bigdata.bop.BOpUtility#deepCopy(FilterNode)}.
	 */
	public Bind(Bind op) {
		super(op);
	}

	/**
	 * @param var
	 *            The {@link IVariable} which will be bound to the result of
	 *            evaluating the associated value expression.
	 * @param expr
	 *            The {@link IValueExpression} to be evaluated.
	 */
	public Bind(IVariable var, IValueExpression expr) {

		this(new BOp[] { var, expr }, null/* annotations */);
		
	}
    
    /**
	 * Required shallow copy constructor.
	 * @param args
	 * @param annotations
	 */
	public Bind(BOp[] args, Map annotations) {
		super(args, annotations);
	}

	/**
	 * Return the variable which will be bound to the result of evaluating the
	 * associated value expression.
	 */
	@SuppressWarnings("unchecked")
    public IVariable getVar() {

        return (IVariable) get(0);

	}

	/**
	 * Return the value expression.
	 */
	@SuppressWarnings("unchecked")
	public IValueExpression getExpr() {

		return (IValueExpression) get(1);

	}

	public E get(final IBindingSet bindingSet) {

		final IVariable var = getVar();

		final IValueExpression expr = getExpr();

		// evaluate the value expression.
		final E val = expr.get(bindingSet);

		if(val==null){
		      return null;
		}
		
		// bind the variable as a side-effect.
		bindingSet.set(var, new Constant(val));

		// return the evaluated value
		return val;

	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy