diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/StandardFunctions.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/StandardFunctions.java index cae63192d4525f2664de05c2e695ea1251baa5ed..22d3b2e1934525192f77a672e2842ebde9cb233a 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/StandardFunctions.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/server/calculator/StandardFunctions.java @@ -116,6 +116,26 @@ final class StandardFunctions return condition != null && condition.booleanValue() ? thenValue : elseValue; } + /** + * Calculates the sum of the specified values. + * Blank strings or <code>null</code> values in the list are ignored. + * + * @throws NumberFormatException if an element can not be parsed as a floating-point number. + * @throws IllegalArgumentException if the list is empty. + */ + public static Double sum(List<Object> values) + { + List<Double> array = toDoubleArray(values); + String functionName = "sum"; + assertNotEmpty(array, functionName); + double sum = 0.0; + for (double value : array) + { + sum += value; + } + return sum; + } + /** * Calculates the mean of the specified values. * Blank strings or <code>null</code> values in the list are ignored.