MathUtils { public static double calculateWeightedGeometricAverage(long[][] valuesAndWeight) { long weightSum = 0; double weightedValues = 1; for (long[] weightAndvalue : valuesAndWeight) { long value = weightAndvalue[0]; long weight = weightAndvalue[1]; weightSum += weight; weightedValues *= Math.pow(value, weight); } return weightSum == 0 ? 0 : Math.pow(weightedValues, (1.0d / weightSum)); }  static double calculateWeightedGeometricAverage(long[][] valuesAndWeight); static Double zeroIfNaN(Double d); static Integer median(Collection<? extends Number> numbers); static Double median(double[] numbers); static final Double ZERO; }
@Test public void testCalculateWeightedGeometricAverage() { long[][] values = new long[][]{{1, 2}, {3, 4}, {9, 2}, {27, 1}}; double result = MathUtils.calculateWeightedGeometricAverage(values); Assert.assertEquals(3.8296, result, 4); }