/*
 *************************************************************************
 * 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.aggregation;

import org.eclipse.birt.data.engine.api.aggregation.Accumulator;
import org.eclipse.birt.data.engine.api.aggregation.IAggregation;

/**
 * Implements the built-in Total.count aggregation
 */
class TotalCount implements IAggregation
{

    public String getName()
    {
        return BuiltInAggregationFactory.TOTAL_COUNT_FUNC;
    }
    
    public int getType()
    {
        return SUMMARY_AGGR;
    }
    
    public boolean[] getParameterDefn()
    {
        // 0 argument 
        final boolean paramDefn[] = {  };
        return paramDefn;
    }
    
    public Accumulator newAccumulator()
    {
        return new MyAccumulator();
    }
    
    private class MyAccumulator extends SummaryAccumulator
    {
        private int 	count = 0;
        
        public void start()
        {
            super.start();
            count = 0;
        }
        
        public void onRow( Object[] args )
        {
            ++count;
        }


        /* (non-Javadoc)
         * @see org.eclipse.birt.data.engine.aggregation.SummaryAccumulator#getSummaryValue()
         */
        public Object getSummaryValue()
        {
            return new Integer( count);
        }
    }
}
