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; + } }