@@ -0,0 +1,1274 @@
+package org.apache.derby.agg;%0D%0Aimport java.util.ArrayList;%0D%0Aimport java.util.Collections;%0D%0Aimport org.apache.derby.agg.Aggregator;%0D%0A%0D%0Apublic class stddev%3CK extends Double%3E %0D%0A        implements Aggregator%3CK,K,stddev%3CK%3E%3E%0D%0A%7B%0D%0A    private ArrayList%3CK%3E _values;%0D%0A%0D%0A    public stddev() %7B%7D%0D%0A%0D%0A    public void init() %7B _values = new ArrayList%3CK%3E(); %7D%0D%0A%0D%0A    public void accumulate( K value ) %7B _values.add( value ); %7D%0D%0A%0D%0A    public void merge( stddev%3CK%3E other )%0D%0A    %7B %0D%0A        _values.addAll( other._values ); %0D%0A    %7D%0D%0A%0D%0A    public K terminate()%0D%0A    %7B   %0D%0A        double s = sum();%0D%0A        %0D%0A        //Collections.sort( _values );%0D%0A%0D%0A        int count = _values.size();%0D%0A        %0D%0A        double a = s/count;%0D%0A        double v = var(a);%0D%0A        double d = Math.sqrt(v);%0D%0A        Double rt = new Double(d);%0D%0A        return (K)rt;%0D%0A    %7D%0D%0A    private double sum() %7B%0D%0A        double d = 0.0;%0D%0A        for(int i = 0; i %3C _values.size(); i++) %7B%0D%0A            d = d + _values.get(i).doubleValue();%0D%0A        %7D%0D%0A        return d;%0D%0A    %7D%0D%0A    private double var(double a) %7B%0D%0A        double v = 0.0;%0D%0A        for(int i = 0; i %3C _values.size(); i++) %7B%0D%0A            v = v + (_values.get(i).doubleValue() - a) * (_values.get(i).doubleValue() - a);%0D%0A        %7D%0D%0A        return v;%0D%0A    %7D%0D%0A%7D%0D%0A%0D%0A

add stddev.java