public static CounterStats calculateStats(Object[] list) {
		int resType = list.length > 0 ? ((CounterValue)list[0]).type : DATATYPE_DEFAULT;
		
		CounterStats stats = new CounterStats();

		int count = list.length;	

		double avg = 0;
		double max = Double.NEGATIVE_INFINITY;
		double min = Double.POSITIVE_INFINITY;
		double std = 0;

		for (int i = 0; i < list.length; ++i) {
			double val = ((CounterValue)list[i]).value;
			avg += val;
			if (min > val)
				min = val;
			if (max < val)
				max = val;
		}

		if (count > 0) {
			avg /= count;
			for (int i = 0; i < list.length; ++i) {
				double val = ((CounterValue)list[i]).value;
				std += (val - avg) * (val - avg);
			}
			std = Math.sqrt(std / count);
		}
		
		stats.samples = new CounterValue(count, DATATYPE_INTEGER);
		stats.minimum = new CounterValue(min, resType);
		stats.average = new CounterValue(avg, resType);
		stats.maximum = new CounterValue(max, resType);
		stats.stdDeviation = new CounterValue(std, resType);
		
		return stats;
	}