Zeldus

SelectOperator

function
SelectOperator()

Option name Type Description
filterOperator Object optional filter operator
childOperator Object a series of child operators to combine into a single row. Multiple child operators can be added

Select operator. Combines multiple columns together based on an optional filter operator

function SelectOperator(filterOperator, childOperator){
		var self = this;
		self.index = 0;
		self.operators = arguments;

		//validate arguments
		if(filterOperator != null && !(filterOperator instanceof Operator))
			throw 'Filter operator is not an instance of Operator.';
		if(!(childOperator instanceof Operator))
			throw 'Child operator is not an instance of Operator.';

        Operator.call(this, childOperator);

getNextValueBlock

method
self.getNextValueBlock() ->Object

Get the next matching row block from the child operators

self.getNextValueBlock = function(){
        	var block = null,
        		results = [],	
        		stop = false;

			if(this.childOperator != null){
				while(!stop){
					var position = null,
						row = [];
					//get next position from filter
					if(filterOperator != null){
						var filterBlock = filterOperator.getNextValueBlock();
						position = filterBlock != null ? filterBlock.getNext().position : null;
						//if position is null then we've reached the end
						if(position == null)
							stop = true;
					}

					if(!stop){
						for(var i = 1; i < self.operators.length; i++){
							block = self.operators[i].getNextValueBlock(position);
							if(block != null)
								row.push(block);
							else{
								stop = true;
								break;
							}
						}
					}
					if(!stop)
						results.push(row);
				}
			}
			return results.length > 0 ? results : null;
		};

getNextPositionBlock

method
self.getNextPositionBlock()

Get the next position block

self.getNextPositionBlock = function(){
			
		};
	}

	SelectOperator.prototype = Object.create(Operator.prototype);
    SelectOperator.prototype.constructor = SelectOperator;

	return SelectOperator;
});