// Path: src/main/java/org/deri/cqels/data/Mapping.java
// public interface Mapping extends Map<Var, Long>{
// 	
// 
// 	public long get(Var var); 
// 	
// 	public void from(OpRouter router);
// 	
// 	public OpRouter from();
// 	
// 	public ExecContext getCtx();
// 	
// 	public Iterator<Var> vars();
// 	
// 	public void addParent(Mapping parent);
// 	
// 	public boolean hasParent();
// 	
// 	public boolean isCompatible(Mapping mapping);
// }
// 
// Path: src/main/java/org/deri/cqels/engine/iterator/MappingIterMatch.java
// public class MappingIterMatch extends MappingIterProcessBinding {
// 	Mapping mapping;
// 	public MappingIterMatch(ExecContext context, MappingIterator mIter, Mapping mapping) {
// 		super(mIter, context);
// 		this.mapping = mapping;
// 	}
// 	
// 	@Override
// 	public Mapping accept(Mapping mapping) {
// 		//System.out.println("compa "+ mapping +" "+this.mapping.isCompatible(mapping) +" "+ this.mapping );
// 		if(this.mapping.isCompatible(mapping)) { 
// 			return new MappingWrapped(context, mapping, this.mapping);
// 		}
// 		//TODO : check order of MappingWrapper initialization new MappingWrapped(context, this.mapping, mapping);
// 		return null;
// 	}
// 
// }
// 
// Path: src/main/java/org/deri/cqels/engine/iterator/MappingIterator.java
// public interface MappingIterator extends Closeable, Iterator<Mapping> {
// 
//     /**
//      * Get next binding
//      */
//     public Mapping nextMapping();
// 
//     /**
//      * Cancels the query as soon as is possible for the given iterator
//      */
//     public void cancel();
// }
// 
// Path: src/main/java/org/deri/cqels/engine/iterator/MappingNestedLoopEqJoin.java
// public class MappingNestedLoopEqJoin extends MappingIter {
// 	private MappingIterator curItr,leftItr;
// 	private Mapping nextMapping;
// 	OpRouter leftRouter, rightRouter;
// 	public MappingNestedLoopEqJoin(ExecContext context, OpRouter leftRouter, 
// 				OpRouter rightRouter) {
// 		super(context);
// 		this.leftRouter = leftRouter;
// 		leftItr = leftRouter.getBuff();
// 		this.rightRouter = rightRouter;
// 		//System.out.println("MappingNestedLoopEqJoin");
// 	}
// 
// 	@Override
// 	protected void closeIterator() {
// 		leftItr.close();
// 		if(curItr != null) {
// 			curItr.close();
// 		}
// 	}
// 
// 	@Override
// 	protected boolean hasNextMapping() {
// 		if(isFinished()) {
// 			return false;
// 		}
// 		if(nextMapping != null) {
// 			return true;
// 		}
// 		nextMapping = move2Next();
// 		return nextMapping != null;
// 	}
// 	
// 	//Move to next Mapping
// 	private Mapping move2Next() {
// 		//System.out.println("move cursor "+Thread.currentThread());
// 		while(true) {
// 			if(curItr != null) {
// 				if(curItr.hasNext()) {
// 					return curItr.nextMapping();
// 				}
// 				curItr.close();
// 				curItr = null;
// 			}
// 			curItr = eqJoinWorker();
// 			if(curItr == null) {
// 				return null;
// 			}
// 			//System.out.println("loop move2Next");
// 		}
// 	}
// 	
// 	private MappingIterator eqJoinWorker() {
// 		if(leftItr == null || !leftItr.hasNext()) {
// 			return null;//NullMappingIter.instance();
// 		}
// 		//System.out.println("call for another filter ");
// 		return rightRouter.searchBuff4Match(leftItr.next());
// 	}
// 	
// 	@Override
// 	protected Mapping moveToNextMapping() {
// 		if ( nextMapping == null ) {
//             throw new ARQInternalErrorException("moveToNextMapping: slot empty but hasNext was true)") ;
// 		}
//         Mapping m = nextMapping;
//         nextMapping = move2Next();
//         return m;
// 	}
// 
// 	@Override
// 	protected void requestCancel() {
// 		performRequestCancel(leftItr);
// 		if(curItr != null) {
// 			performRequestCancel(curItr);
// 		}
// 	}
// 
// 
// }


import org.deri.cqels.data.Mapping;
import org.deri.cqels.engine.iterator.MappingIterMatch;
import org.deri.cqels.engine.iterator.MappingIterator;
import org.deri.cqels.engine.iterator.MappingNestedLoopEqJoin;
import com.hp.hpl.jena.sparql.algebra.op.OpJoin;
package org.deri.cqels.engine;


/**
 * This class implements a binary router processing the join operator
 *
 * @author Danh Le Phuoc
 * @author Chan Le Van
 * @organization DERI Galway, NUIG, Ireland www.deri.ie
 * @email danh.lephuoc@deri.org
 * @email chan.levan@deri.org
 * @see OpRouter2
 */
public class JoinRouter extends OpRouter2 {

    public JoinRouter(ExecContext context, OpJoin op, 
            OpRouter left, OpRouter right) {
        super(context, op, left, right);
    }

// Path: src/main/java/org/deri/cqels/data/Mapping.java
// public interface Mapping extends Map<Var, Long>{
// 	
// 
// 	public long get(Var var); 
// 	
// 	public void from(OpRouter router);
// 	
// 	public OpRouter from();
// 	
// 	public ExecContext getCtx();
// 	
// 	public Iterator<Var> vars();
// 	
// 	public void addParent(Mapping parent);
// 	
// 	public boolean hasParent();
// 	
// 	public boolean isCompatible(Mapping mapping);
// }
// 
// Path: src/main/java/org/deri/cqels/engine/iterator/MappingIterMatch.java
// public class MappingIterMatch extends MappingIterProcessBinding {
// 	Mapping mapping;
// 	public MappingIterMatch(ExecContext context, MappingIterator mIter, Mapping mapping) {
// 		super(mIter, context);
// 		this.mapping = mapping;
// 	}
// 	
// 	@Override
// 	public Mapping accept(Mapping mapping) {
// 		//System.out.println("compa "+ mapping +" "+this.mapping.isCompatible(mapping) +" "+ this.mapping );
// 		if(this.mapping.isCompatible(mapping)) { 
// 			return new MappingWrapped(context, mapping, this.mapping);
// 		}
// 		//TODO : check order of MappingWrapper initialization new MappingWrapped(context, this.mapping, mapping);
// 		return null;
// 	}
// 
// }
// 
// Path: src/main/java/org/deri/cqels/engine/iterator/MappingIterator.java
// public interface MappingIterator extends Closeable, Iterator<Mapping> {
// 
//     /**
//      * Get next binding
//      */
//     public Mapping nextMapping();
// 
//     /**
//      * Cancels the query as soon as is possible for the given iterator
//      */
//     public void cancel();
// }
// 
// Path: src/main/java/org/deri/cqels/engine/iterator/MappingNestedLoopEqJoin.java
// public class MappingNestedLoopEqJoin extends MappingIter {
// 	private MappingIterator curItr,leftItr;
// 	private Mapping nextMapping;
// 	OpRouter leftRouter, rightRouter;
// 	public MappingNestedLoopEqJoin(ExecContext context, OpRouter leftRouter, 
// 				OpRouter rightRouter) {
// 		super(context);
// 		this.leftRouter = leftRouter;
// 		leftItr = leftRouter.getBuff();
// 		this.rightRouter = rightRouter;
// 		//System.out.println("MappingNestedLoopEqJoin");
// 	}
// 
// 	@Override
// 	protected void closeIterator() {
// 		leftItr.close();
// 		if(curItr != null) {
// 			curItr.close();
// 		}
// 	}
// 
// 	@Override
// 	protected boolean hasNextMapping() {
// 		if(isFinished()) {
// 			return false;
// 		}
// 		if(nextMapping != null) {
// 			return true;
// 		}
// 		nextMapping = move2Next();
// 		return nextMapping != null;
// 	}
// 	
// 	//Move to next Mapping
// 	private Mapping move2Next() {
// 		//System.out.println("move cursor "+Thread.currentThread());
// 		while(true) {
// 			if(curItr != null) {
// 				if(curItr.hasNext()) {
// 					return curItr.nextMapping();
// 				}
// 				curItr.close();
// 				curItr = null;
// 			}
// 			curItr = eqJoinWorker();
// 			if(curItr == null) {
// 				return null;
// 			}
// 			//System.out.println("loop move2Next");
// 		}
// 	}
// 	
// 	private MappingIterator eqJoinWorker() {
// 		if(leftItr == null || !leftItr.hasNext()) {
// 			return null;//NullMappingIter.instance();
// 		}
// 		//System.out.println("call for another filter ");
// 		return rightRouter.searchBuff4Match(leftItr.next());
// 	}
// 	
// 	@Override
// 	protected Mapping moveToNextMapping() {
// 		if ( nextMapping == null ) {
//             throw new ARQInternalErrorException("moveToNextMapping: slot empty but hasNext was true)") ;
// 		}
//         Mapping m = nextMapping;
//         nextMapping = move2Next();
//         return m;
// 	}
// 
// 	@Override
// 	protected void requestCancel() {
// 		performRequestCancel(leftItr);
// 		if(curItr != null) {
// 			performRequestCancel(curItr);
// 		}
// 	}
// 
// 
// }


// Path: src/main/java/org/deri/cqels/engine/JoinRouter.java
import org.deri.cqels.data.Mapping;
import org.deri.cqels.engine.iterator.MappingIterMatch;
import org.deri.cqels.engine.iterator.MappingIterator;
import org.deri.cqels.engine.iterator.MappingNestedLoopEqJoin;
import com.hp.hpl.jena.sparql.algebra.op.OpJoin;

package org.deri.cqels.engine;


/**
 * This class implements a binary router processing the join operator
 *
 * @author Danh Le Phuoc
 * @author Chan Le Van
 * @organization DERI Galway, NUIG, Ireland www.deri.ie
 * @email danh.lephuoc@deri.org
 * @email chan.levan@deri.org
 * @see OpRouter2
 */
public class JoinRouter extends OpRouter2 {

    public JoinRouter(ExecContext context, OpJoin op, 
            OpRouter left, OpRouter right) {
        super(context, op, left, right);
    }

    @Override