velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbris...@apache.org
Subject svn commit: r995743 - /velocity/tools/trunk/src/main/java/org/apache/velocity/tools/ConversionUtils.java
Date Fri, 10 Sep 2010 10:49:22 GMT
Author: cbrisson
Date: Fri Sep 10 10:49:21 2010
New Revision: 995743

URL: http://svn.apache.org/viewvc?rev=995743&view=rev
Log:
Added a custom number formats cache in ConversionUtils

Modified:
    velocity/tools/trunk/src/main/java/org/apache/velocity/tools/ConversionUtils.java

Modified: velocity/tools/trunk/src/main/java/org/apache/velocity/tools/ConversionUtils.java
URL: http://svn.apache.org/viewvc/velocity/tools/trunk/src/main/java/org/apache/velocity/tools/ConversionUtils.java?rev=995743&r1=995742&r2=995743&view=diff
==============================================================================
--- velocity/tools/trunk/src/main/java/org/apache/velocity/tools/ConversionUtils.java (original)
+++ velocity/tools/trunk/src/main/java/org/apache/velocity/tools/ConversionUtils.java Fri
Sep 10 10:49:21 2010
@@ -32,6 +32,8 @@ import java.util.Date;
 import java.util.Calendar;
 import java.util.Locale;
 import java.util.TimeZone;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * Utility methods for parsing or otherwise converting between types.
@@ -50,6 +52,9 @@ public class ConversionUtils
     //NOTE: '3' belongs to a non-public "scientific" style
     private static final int STYLE_INTEGER      = 4;
 
+    // cache custom formats
+    private static ConcurrentMap<String,NumberFormat> customFormatsCache = new ConcurrentHashMap<String,NumberFormat>();
+
     private ConversionUtils() {}
 
     public ConversionUtils getInstance()
@@ -83,7 +88,13 @@ public class ConversionUtils
         if (style < 0)
         {
             // we have a custom format
-            nf = new DecimalFormat(format, new DecimalFormatSymbols(locale));
+            String cacheKey = format + "%" + locale.toString();
+            nf = customFormatsCache.get(cacheKey);
+            if( nf == null )
+            {
+                nf = new DecimalFormat(format, new DecimalFormatSymbols(locale));
+                customFormatsCache.put(cacheKey,nf);
+            }
         }
         else
         {



Mime
View raw message