@Override
    public double getStdDev() {
        // two-pass algorithm for variance, avoids numeric overflow

        if (values.length <= 1) {
            return 0;
        }

        final double mean = getMean();
        double variance = 0;

        for (int i = 0; i < values.length; i++) {
            final double diff = values[i] - mean;
            variance += normWeights[i] * diff*diff;
        }

        return Math.sqrt(variance);
    }
@Test
    public void calculatesAStdDevOfZeroForASingletonSnapshot() throws Exception {
        final Snapshot singleItemSnapshot = new WeightedSnapshot(
            WeightedArray(new long[]{ 1 }, new double[]{ 1.0 }) );

        assertThat(singleItemSnapshot.getStdDev())
                .isZero();
    }