svn commit: r430253 - in /incubator/ofbiz/trunk/framework: base/src/base/org/ofbiz/base/util/StringUtil.java minilang/src/org/ofbiz/minilang/method/envops/ToString.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r430253 - in /incubator/ofbiz/trunk/framework: base/src/base/org/ofbiz/base/util/StringUtil.java minilang/src/org/ofbiz/minilang/method/envops/ToString.java

jonesde
Author: jonesde
Date: Wed Aug  9 22:19:05 2006
New Revision: 430253

URL: http://svn.apache.org/viewvc?rev=430253&view=rev
Log:
Added some handy methods to StringUtil for padding number strings and adding a number to a number string

Modified:
    incubator/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/StringUtil.java
    incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/ToString.java

Modified: incubator/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/StringUtil.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/StringUtil.java?rev=430253&r1=430252&r2=430253&view=diff
==============================================================================
--- incubator/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/StringUtil.java (original)
+++ incubator/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/StringUtil.java Wed Aug  9 22:19:05 2006
@@ -346,4 +346,25 @@
         Matcher matcher = pattern.matcher(str);
         return matcher.replaceAll("");
     }
+    
+    /**
+     * Add the number to the string, keeping (padding to min of original length)
+     *
+     * @return
+     */
+    public static String addToNumberString(String numberString, long addAmount) {
+ if (numberString == null) return null;
+
+ int origLength = numberString.length();
+ long number = Long.parseLong(numberString);
+ return padNumberString(new Long(number + addAmount).toString(), origLength);
+    }
+    
+    public static String padNumberString(String numberString, int targetMinLength) {
+        StringBuffer outStrBfr = new StringBuffer(numberString);
+        while (targetMinLength > outStrBfr.length()) {
+            outStrBfr.insert(0, '0');
+        }
+        return outStrBfr.toString();
+    }
 }

Modified: incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/ToString.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/ToString.java?rev=430253&r1=430252&r2=430253&view=diff
==============================================================================
--- incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/ToString.java (original)
+++ incubator/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/ToString.java Wed Aug  9 22:19:05 2006
@@ -95,11 +95,7 @@
         }
         
         if (this.numericPadding != null) {
-            StringBuffer outStrBfr = new StringBuffer(outStr);
-            while (this.numericPadding.intValue() > outStrBfr.length()) {
-                outStrBfr.insert(0, '0');
-            }
-            outStr = outStrBfr.toString();
+            outStr = StringUtil.padNumberString(outStr, this.numericPadding.intValue());
         }
         
         return outStr;