Code Search for Developers
 
 
  

TotalRunningSum.java from BIRT at Krugle


Show TotalRunningSum.java syntax highlighted

/*
 *************************************************************************
 * 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.core.data.DataTypeUtil;
import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.data.engine.api.aggregation.Accumulator;
import org.eclipse.birt.data.engine.api.aggregation.IAggregation;
import org.eclipse.birt.data.engine.core.DataException;
import org.eclipse.birt.data.engine.i18n.ResourceConstants;


/**
 * 
 * Implements the built-in Total.movingAva aggregation
 */
public class TotalRunningSum implements IAggregation
{

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.birt.data.engine.aggregation.Aggregation#getName()
     */
    public String getName()
    {
        return BuiltInAggregationFactory.TOTAL_RUNNINGSUM_FUNC;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.birt.data.engine.aggregation.Aggregation#getType()
     */
    public int getType()
    {
        return RUNNING_AGGR;
    }

     /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.birt.data.engine.aggregation.Aggregation#getParameterDefn()
     */
    public boolean[] getParameterDefn()
    {
        return new boolean[] { true };
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.birt.data.engine.aggregation.Aggregation#newAccumulator()
     */
    public Accumulator newAccumulator()
    {
        return new MyAccumulator();
    }

    private class MyAccumulator extends RunningAccumulator
    {
        private boolean isRowAvailable = false;

        private double sum = 0D;

        public void start()
        {
            sum = 0D;
            isRowAvailable = false;
        }

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.birt.data.engine.aggregation.Accumulator#onRow(java.lang.Object[])
         */
        public void onRow(Object[] args) throws DataException
        {
            assert (args.length > 0);
            if ( args[0] != null )
            {
                try
				{
					double value = DataTypeUtil.toDouble(args[0]).doubleValue();
					if (!isRowAvailable)
					{
					    isRowAvailable = true;
					}
					sum += value;
				}
				catch ( BirtException e )
				{
					throw new DataException( ResourceConstants.DATATYPEUTIL_ERROR, e );
				}
            }
        }

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.birt.data.engine.aggregation.Accumulator#getValue()
         */
        public Object getValue()
        {
            return (isRowAvailable ? new Double(sum) : null);
        }

    }

}



See more files for this project here

BIRT

BIRT is an open source, Eclipse-based reporting system that integrates with your application to produce compelling reports for both web and PDF.

Project homepage: http://www.eclipse.org/birt/phoenix/
Programming language(s): Java,XML
License: gpl2

  rank/
    BaseTopBottomAccumulator.java
    BaseTopBottomAggregation.java
    BasicCachedListExt.java
    NAccumulator.java
    PercentAccumulator.java
    PercentileAccumulator.java
    RankAggregationUtil.java
    TotalIsBottomN.java
    TotalIsBottomNPercent.java
    TotalIsTopN.java
    TotalIsTopNPercent.java
    TotalPercentRank.java
    TotalPercentSum.java
    TotalPercentile.java
    TotalQuartile.java
    TotalRank.java
  AggregationFactory.java
  BuiltInAggregationFactory.java
  Finance.java
  RunningAccumulator.java
  SummaryAccumulator.java
  TotalAve.java
  TotalCount.java
  TotalCountDistinct.java
  TotalFirst.java
  TotalIrr.java
  TotalLast.java
  TotalMax.java
  TotalMedian.java
  TotalMin.java
  TotalMirr.java
  TotalMode.java
  TotalMovingAve.java
  TotalNpv.java
  TotalRunningCount.java
  TotalRunningNpv.java
  TotalRunningSum.java
  TotalStdDev.java
  TotalSum.java
  TotalVariance.java
  TotalWeightedAve.java
  package.html