/*******************************************************************************
 * Copyright (c) 2004 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

package org.eclipse.birt.data.engine.executor.transform.group;

import org.eclipse.birt.data.engine.core.DataException;
import org.eclipse.birt.data.engine.odi.IQuery.GroupSpec;

/**
 * Row poistion range implementation of GroupBy.
 */
class GroupByPositionRange extends GroupBy
{

	/** interval value */
	private int posInterval;

	/**
	 * @param groupDefn
	 */
	GroupByPositionRange( GroupSpec groupDefn )
	{
		posInterval = (int) groupDefn.getIntervalRange( );
	}

	/*
	 * @see org.eclipse.birt.data.engine.executor.GroupBy#isInSameGroup(java.lang.Object,
	 *      java.lang.Object, java.lang.Object, int)
	 */
	boolean isInSameGroup( Object currentGroupKey, Object previousGroupKey,
			Object groupStartValue, int currRowPos ) throws DataException
	{
		if ( posInterval == 0 )
			return false;

		assert groupStartValue instanceof Integer;
		int startPos = ( (Integer) groupStartValue ).intValue( );

		return GroupUtil.isWithinInterval( startPos,
				posInterval,
				currRowPos,
				currRowPos - 1 );
	}

	/*
	 * @see org.eclipse.birt.data.engine.executor.GroupBy#needsGroupStartValue()
	 */
	boolean needsGroupStartValue( )
	{
		return true;
	}

	/*
	 * Will never be called
	 * 
	 * @see org.eclipse.birt.data.engine.executor.GroupBy#isSameGroup(java.lang.Object,
	 *      java.lang.Object)
	 */
	boolean isSameGroup( Object currentGroupKey, Object previousGroupKey )
			throws DataException
	{
		return false;
	}

}
