
/*******************************************************************************
 * Copyright (c) 2004, 2005 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.olap.data.impl.aggregation;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.birt.data.engine.olap.data.impl.dimension.Member;
import org.eclipse.birt.data.engine.olap.data.util.IStructure;
import org.eclipse.birt.data.engine.olap.data.util.IStructureCreator;
import org.eclipse.birt.data.engine.olap.data.util.ObjectArrayUtil;

/**
 * 
 */

public class Row4Aggregation implements IStructure
{
	private Member[] levelMembers;
	private Object[] measures;
	private List<Object[]> measureList = new ArrayList<Object[]>();
	private int pos = -1;
	private Object[] parameterValues;
	private int[] dimPos;
	private Object[] firstMeasures;
	
	/*
	 * (non-Javadoc)
	 * @see org.eclipse.birt.data.olap.data.util.IStructure#getFieldValues()
	 */
	public Object[] getFieldValues( )
	{
		Integer[] memberSize = new Integer[1];
		memberSize[0] = Integer.valueOf(getLevelMembers().length);
		Object[][] objectArrays = new Object[getLevelMembers().length + 1 + 3 + measureList.size() ][];
		objectArrays[0] = memberSize;
		for ( int i = 0; i < getLevelMembers().length; i++ )
		{
			objectArrays[i+1] = getLevelMembers()[i].getFieldValues( );
		}
		objectArrays[getLevelMembers().length+1] = measures;
		for( int i = 0; i < measureList.size(); i++ )
		{
			objectArrays[getLevelMembers().length + i + 2] = measureList.get( i );
		}
		objectArrays[objectArrays.length-2] = parameterValues;
		Integer[] dimPosObj = null;
		if( dimPos == null )
		{
			dimPosObj = new Integer[1];
			dimPosObj[0] = Integer.valueOf( 0 );
		}
		else
		{
			dimPosObj = new Integer[dimPos.length + 1];
			dimPosObj[0] = Integer.valueOf( 1 );
			for ( int i = 0; i < dimPos.length; i++ )
			{
				dimPosObj[i + 1] = Integer.valueOf( dimPos[i] );
			}
		}
		objectArrays[objectArrays.length-1] = dimPosObj;
		return ObjectArrayUtil.convert( objectArrays );
	}
	
	/*
	 * 
	 */
	public static IStructureCreator getCreator()
	{
		return new Row4AggregationCreator( );
	}

	
	public int[] getDimPos( )
	{
		return dimPos;
	}

	
	public void setDimPos( int[] dimPos )
	{
		this.dimPos = dimPos;
	}

	public void setLevelMembers( Member[] levelMembers )
	{
		this.levelMembers = levelMembers;
	}

	public Member[] getLevelMembers( )
	{
		return levelMembers;
	}

	public void setMeasures( Object[] measures )
	{
		this.measures = measures;
	}

	public void addMeasure( Object[] measures )
	{
		this.measureList.add( measures );
	}
	
	public void clearMeasure( )
	{
		this.measureList.clear( );
	}
	
	public Object[] getMeasures( )
	{
		return measures;
	}
	
	public boolean nextMeasures( )
	{
		if( pos == -1 )
		{
			firstMeasures = measures;
			pos = 0;
			return true;
		}
		else
		{
			if( pos < this.measureList.size() )
			{
				measures = this.measureList.get( pos );
				pos++;
				return true;
			}
			else
			{
				return false;
			}
		}
	}
	
	public void firstMeasure( )
	{
		measures = firstMeasures;
		pos = -1;
	}
	
	public void resetPosition( )
	{
		pos = -1;
	}
	
	public Object[] getParameterValues( )
	{
		return parameterValues;
	}

	
	public void setParameterValues( Object[] parameterValues )
	{
		this.parameterValues = parameterValues;
	}
}

/**
 * 
 * @author Administrator
 *
 */
class Row4AggregationCreator implements IStructureCreator
{
	private static IStructureCreator levelMemberCreator = Member.getCreator( );
	
	/*
	 * (non-Javadoc)
	 * @see org.eclipse.birt.data.olap.data.util.IStructureCreator#createInstance(java.lang.Object[])
	 */
	public IStructure createInstance( Object[] fields )
	{
		Object[][] objectArrays = ObjectArrayUtil.convert( fields );
		Row4Aggregation result = new Row4Aggregation( );
		int memberSize = (Integer)objectArrays[0][0];
		result.setLevelMembers( new Member[memberSize] );
		for ( int i = 0; i < result.getLevelMembers().length; i++ )
		{
			result.getLevelMembers()[i] = (Member) levelMemberCreator.createInstance( objectArrays[i+1] );
		}
		result.setMeasures( objectArrays[memberSize+1] );
		for( int i = 0; i < ( objectArrays.length - memberSize -1 - 3 ); i++ )
		{
			result.addMeasure( objectArrays[memberSize+1+i+1] );
		}
		result.setParameterValues( objectArrays[objectArrays.length-2] );
		if( objectArrays[objectArrays.length-1][0].equals( Integer.valueOf( 1 ) ) )
		{
			int[] dimPos = new int[objectArrays[objectArrays.length - 1].length - 1];
			for ( int i = 0; i < dimPos.length; i++ )
			{
				dimPos[i] = ((Integer)(objectArrays[objectArrays.length-1][i+1])).intValue( );
			}
			result.setDimPos( dimPos );
		}
		
		return result;
	}
}

@@ -2884,24 +2884,203 @@
 easures;%0A%09%7D%0A
+%09%0A%09public void setMeasureList( List%3CObject%5B%5D%3E measureList )%0A%09%7B%0A%09%09this.measureList = measureList;%0A%09%7D%0A%09%0A%09public List%3CObject%5B%5D%3E getMeasureList( )%0A%09%7B%0A%09%09return this.measureList;%0A%09%7D%0A%09%0A%09
 %0A%09public voi

Add two method in the class Row4Aggregation