trunk/adhoc-internal/src/main/java/org/jfree/data/time/MovingAverage.java
/**
     * Creates a new {@link TimeSeries} containing moving average values for
     * the given series, calculated by number of points (irrespective of the
     * 'age' of those points).  If the series is empty (contains zero items),
     * the result is an empty series.
     * <p>
     * Developed by Benoit Xhenseval (www.ObjectLab.co.uk).
     *
     * @param source  the source series.
     * @param name  the name of the new series.
     * @param pointCount  the number of POINTS used in the average calculation
     *                    (not periods!)
     *
     * @return The moving average series.
     */
Creates a new  TimeSeries containing moving average values for
the given series, calculated by number of points (irrespective of the
'age' of those points).  If the series is empty (contains zero items),
the result is an empty series.

@param source  the source series.
@param name  the name of the new series.
@param pointCount  the number of POINTS used in the average calculation
(not periods!)

@return The moving average series.
Creates a new TimeSeries containing moving average values for the given series calculated by number of points ( irrespective of the ' age ' of those points ) . If the series is empty ( contains zero items ) the result is an empty series . @param source the source series . @param name the name of the new series . @param pointCount the number of POINTS used in the average calculation ( not periods! ) @return The moving average series .
public static TimeSeries createPointMovingAverage(TimeSeries source,
            String name, int pointCount) {
        if (source == null) {
            throw new IllegalArgumentException("Null 'source'.");
        }
        if (pointCount < 2) {
            throw new IllegalArgumentException("periodCount must be greater " +
                    "than or equal to 2.");
        }
        TimeSeries result = new TimeSeries(name);
        double rollingSumForPeriod = 0.0;
        for (int i = 0; i < source.getItemCount(); i++) {
            TimeSeriesDataItem current = source.getDataItem(i);
            RegularTimePeriod period = current.getPeriod();
            rollingSumForPeriod += current.getValue().doubleValue();
            if (i > pointCount - 1) {
                TimeSeriesDataItem startOfMovingAvg = source.getDataItem(
                        i - pointCount);
                rollingSumForPeriod -= startOfMovingAvg.getValue()
                        .doubleValue();
                result.add(period, rollingSumForPeriod / pointCount);
            }
            else if (i == pointCount - 1) {
                result.add(period, rollingSumForPeriod / pointCount);
            }
        }
        return result;
    }
public static TimeSeries createPointMovingAverage ( TimeSeries source , String name , int pointCount ) { if ( source == null ) { throw new IllegalArgumentException ( "Null 'source'." ) ; } if ( pointCount < 2 ) { throw new IllegalArgumentException ( "periodCount must be greater " + "than or equal to 2." ) ; } TimeSeries result = new TimeSeries ( name ) ; double rollingSumForPeriod = 0.0 ; for ( int i = 0 ; i < source . getItemCount ( ) ; i ++ ) { TimeSeriesDataItem current = source . getDataItem ( i ) ; RegularTimePeriod period = current . getPeriod ( ) ; rollingSumForPeriod += current . getValue ( ) . doubleValue ( ) ; if ( i > pointCount - 1 ) { TimeSeriesDataItem startOfMovingAvg = source . getDataItem ( i - pointCount ) ; rollingSumForPeriod -= startOfMovingAvg . getValue ( ) . doubleValue ( ) ; result . add ( period , rollingSumForPeriod / pointCount ) ; } else if ( i == pointCount - 1 ) { result . add ( period , rollingSumForPeriod / pointCount ) ; } } return result ; }
Creates a new {@link TimeSeries} containing moving average values for
 the given series, calculated by number of points (irrespective of the
 'age' of those points).
Creates a new { @link TimeSeries } containing moving average values for the given series calculated by number of points ( irrespective of the ' age ' of those points ) .
// get the current data item...
 // remove the point i-periodCount out of the rolling sum.
