click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r922569 - in /click/trunk/click/framework/src/org/apache/click/util: MessagesMap.java PropertyUtils.java
Date Sat, 13 Mar 2010 13:48:51 GMT
Author: sabob
Date: Sat Mar 13 13:48:51 2010
New Revision: 922569

URL: http://svn.apache.org/viewvc?rev=922569&view=rev
Log:
use cache key instead of string concatenation

Modified:
    click/trunk/click/framework/src/org/apache/click/util/MessagesMap.java
    click/trunk/click/framework/src/org/apache/click/util/PropertyUtils.java

Modified: click/trunk/click/framework/src/org/apache/click/util/MessagesMap.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/util/MessagesMap.java?rev=922569&r1=922568&r2=922569&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/util/MessagesMap.java (original)
+++ click/trunk/click/framework/src/org/apache/click/util/MessagesMap.java Sat Mar 13 13:48:51
2010
@@ -251,8 +251,8 @@ public class MessagesMap implements Map<
     private void ensureInitialized() {
         if (messages == null) {
 
-            String resourceKey =
-                globalBaseName + baseClass.getName() + locale.toString();
+            CacheKey resourceKey = new CacheKey(globalBaseName,
+                baseClass.getName(), locale.toString());
 
             messages = (Map) MESSAGES_CACHE.get(resourceKey);
 
@@ -317,4 +317,84 @@ public class MessagesMap implements Map<
         }
     }
 
+    /**
+     * See DRY Performance article by Kirk Pepperdine.
+     * <p/>
+     * http://www.javaspecialists.eu/archive/Issue134.html
+     */
+    private static class CacheKey {
+
+        /** Global base name to encapsulate in cache key. */
+        private final String globalBaseName;
+
+        /** Base class name to encapsulate in cache key. */
+        private final String baseClass;
+
+        /** Locale to encapsulate in cache key. */
+        private final String locale;
+
+        /**
+         * Constructs a new CacheKey for the given baseName, baseClass and
+         * locale.
+         *
+         * @param globalBaseName the base name to build the cache key for
+         * @param baseClass the base class name to build the cache key for
+         * @param locale the request locale to build the cache key for
+         */
+        public CacheKey(String globalBaseName, String baseClass, String locale) {
+            if (globalBaseName == null) {
+                throw new IllegalArgumentException("Null globalBaseName parameter");
+            }
+            if (baseClass == null) {
+                throw new IllegalArgumentException("Null baseClass parameter");
+            }
+            if (locale == null) {
+                throw new IllegalArgumentException("Null locale parameter");
+            }
+            this.globalBaseName = globalBaseName;
+            this.baseClass = baseClass;
+            this.locale = locale;
+        }
+
+        /**
+         * @see Object#equals(Object)
+         *
+         * @param o the object with which to compare this instance with
+         * @return true if the specified object is the same as this object
+         */
+        @Override
+        public final boolean equals(Object o) {
+            if (this == o) {
+                return true;
+            }
+
+            CacheKey that = (CacheKey) o;
+
+            if (!globalBaseName.equals(that.globalBaseName)) {
+                return false;
+            }
+
+            if (!baseClass.equals(that.baseClass)) {
+                return false;
+            }
+
+            if (!locale.equals(that.locale)) {
+                return false;
+            }
+
+            return true;
+        }
+
+        /**
+         * @see Object#hashCode()
+         *
+         * @return a hash code value for this object.
+         */
+        @Override
+        public final int hashCode() {
+            return globalBaseName.hashCode()
+                * 31 + baseClass.hashCode()
+                * 31 + locale.hashCode();
+        }
+    }
 }

Modified: click/trunk/click/framework/src/org/apache/click/util/PropertyUtils.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/util/PropertyUtils.java?rev=922569&r1=922568&r2=922569&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/util/PropertyUtils.java (original)
+++ click/trunk/click/framework/src/org/apache/click/util/PropertyUtils.java Sat Mar 13 13:48:51
2010
@@ -242,7 +242,7 @@ public class PropertyUtils {
     /**
      * See DRY Performance article by Kirk Pepperdine.
      * <p/>
-     * http://www.javaspecialists.co.za/archive/newsletter.do?issue=134
+     * http://www.javaspecialists.eu/archive/Issue134.html
      */
     private static class CacheKey {
 



Mime
View raw message