You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2013/05/14 20:09:16 UTC

svn commit: r1482506 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilNumber.java

Author: doogie
Date: Tue May 14 18:09:16 2013
New Revision: 1482506

URL: http://svn.apache.org/r1482506
Log:
FEATURE: Add safeAdd, which protects against BigDecimal addition when the right operand is null.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilNumber.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilNumber.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilNumber.java?rev=1482506&r1=1482505&r2=1482506&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilNumber.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilNumber.java Tue May 14 18:09:16 2013
@@ -250,4 +250,15 @@ public class UtilNumber {
 
         return (bd.toString() + "%");
     }
+
+    /**
+     * A null-aware method for adding BigDecimal, but only for the right operand.
+     *
+     * @param left      The number to add to
+     * @param right     The number being added; if null, then nothing will be added
+     * @return          The result of the addition, or left if right is null.
+     */
+    public static BigDecimal safeAdd(BigDecimal left, BigDecimal right) {
+        return right != null ? left.add(right) : left;
+    }
 }