From 61a9d65d84fbd3e623fe1beb9adad27d043add23 Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Thu, 21 Jan 2010 08:14:45 +0000
Subject: [PATCH] add sum()

SVN: 14366
---
 .../server/calculator/StandardFunctions.java  | 20 +++++++++++++++++++
 1 file changed, 20 insertions(+)

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 cae63192d45..22d3b2e1934 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.
-- 
GitLab