JBoss Portal SVN: r12405 - in branches/JBoss_Portal_Branch_2_7: faces/src/main and 2 other directories.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2008-12-18 11:11:24 -0500 (Thu, 18 Dec 2008)
New Revision: 12405
Added:
branches/JBoss_Portal_Branch_2_7/faces/src/main/util/
branches/JBoss_Portal_Branch_2_7/faces/src/main/util/JSFFunctorTestCase.java
Modified:
branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/InstanceManagerBean.java
branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/util/JSFFunctor.java
Log:
- JBPORTAL-2264, JBPORTAL-2259: Improved performance of functor.
- Added test cases.
Modified: branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/InstanceManagerBean.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/InstanceManagerBean.java 2008-12-18 16:10:45 UTC (rev 12404)
+++ branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/InstanceManagerBean.java 2008-12-18 16:11:24 UTC (rev 12405)
@@ -23,11 +23,11 @@
package org.jboss.portal.core.admin.ui;
import org.jboss.portal.Mode;
-import org.jboss.portal.faces.util.JSFFunctor;
import org.jboss.portal.core.model.instance.Instance;
import org.jboss.portal.core.model.instance.InstanceContainer;
import org.jboss.portal.core.model.instance.InstanceDefinition;
import org.jboss.portal.core.model.instance.NoSuchInstanceException;
+import org.jboss.portal.faces.util.JSFFunctor;
import org.jboss.portal.identity.RoleModule;
import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletInvokerException;
@@ -106,20 +106,6 @@
/** . */
private AuthorizationBean auth = new InstanceAuthorizationBean();
- /** Removes white spaces from identifiers so that we can assign them to HTML id attributes. */
- private JSFFunctor idSanitizer = new JSFFunctor()
- {
- public Object get(Object parameter)
- {
- if (parameter instanceof String)
- {
- String id = (String)parameter;
- return id.replaceAll("\\W|\\.", "_");
- }
- return null;
- }
- };
-
// Services accessors
public RoleModule getRoleModule()
@@ -159,7 +145,7 @@
*/
public JSFFunctor getIdSanitizer()
{
- return idSanitizer;
+ return JSFFunctor.ID_SANITIZER;
}
// Navigational state accessor
Modified: branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/util/JSFFunctor.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/util/JSFFunctor.java 2008-12-18 16:10:45 UTC (rev 12404)
+++ branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/util/JSFFunctor.java 2008-12-18 16:11:24 UTC (rev 12405)
@@ -22,9 +22,9 @@
package org.jboss.portal.faces.util;
+import java.util.Collection;
import java.util.Map;
import java.util.Set;
-import java.util.Collection;
/**
* Allows to call a parameterized function in JSF EL expressions. See <a href="http://wiki.apache.org/myfaces/Parameters_In_EL_Functions">http://wiki.apache.org/myfaces/Parameters_In_EL_Functions</a>
@@ -34,8 +34,34 @@
* @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
* @version $Revision$
*/
-public abstract class JSFFunctor implements Map
+public abstract class JSFFunctor implements Map<String, Object>
{
+
+ /** Removes white spaces and periods from identifiers so that we can assign them to HTML id attributes. */
+ public static final JSFFunctor ID_SANITIZER = new JSFFunctor()
+ {
+ private String recent;
+ private String recentSanitized;
+
+ @Override
+ public Object get(Object parameter)
+ {
+ if (parameter instanceof String)
+ {
+ if (parameter.equals(recent))
+ {
+ return recentSanitized;
+ }
+
+ String id = (String)parameter;
+ recent = id;
+ recentSanitized = id.replace(' ', '_').replace('.', '_');
+ return recentSanitized;
+ }
+ return null;
+ }
+ };
+
public int size()
{
return 0;
@@ -65,7 +91,7 @@
*/
public abstract Object get(Object parameter);
- public Object put(Object key, Object value)
+ public Object put(String key, Object value)
{
return null;
}
@@ -75,7 +101,7 @@
return null;
}
- public void putAll(Map m)
+ public void putAll(Map<? extends String, ? extends Object> m)
{
}
@@ -83,17 +109,17 @@
{
}
- public Set keySet()
+ public Set<String> keySet()
{
return null;
}
- public Collection values()
+ public Collection<Object> values()
{
return null;
}
- public Set entrySet()
+ public Set<Entry<String, Object>> entrySet()
{
return null;
}
Added: branches/JBoss_Portal_Branch_2_7/faces/src/main/util/JSFFunctorTestCase.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/faces/src/main/util/JSFFunctorTestCase.java (rev 0)
+++ branches/JBoss_Portal_Branch_2_7/faces/src/main/util/JSFFunctorTestCase.java 2008-12-18 16:11:24 UTC (rev 12405)
@@ -0,0 +1,63 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package util;
+
+import junit.framework.TestCase;
+import org.jboss.portal.faces.util.JSFFunctor;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ */
+public class JSFFunctorTestCase extends TestCase
+{
+ private JSFFunctor functor = JSFFunctor.ID_SANITIZER;
+
+ public void testGet()
+ {
+ assertNull(functor.get(null));
+ assertEquals("foo_bar", functor.get("foo bar"));
+ assertEquals("foo_bar", functor.get("foo.bar"));
+ assertEquals("foo______bar", functor.get("foo .bar"));
+ assertEquals("foo_bar_baz_boo", functor.get("foo.bar baz.boo"));
+ }
+
+ public void testSimplePerformance()
+ {
+ for (int i = 0; i < 500000; i++)
+ {
+ assertEquals("foo" + i + "_bar", functor.get("foo" + i + " bar"));
+ }
+ }
+
+ public void testRepeatedPerformance()
+ {
+ for (int i = 0; i < 100000; i++)
+ {
+ assertEquals("foo" + i + "_bar", functor.get("foo" + i + " bar"));
+ assertEquals("foo" + i + "_bar", functor.get("foo" + i + " bar"));
+ assertEquals("foo" + i + "_bar", functor.get("foo" + i + " bar"));
+ assertEquals("foo" + i + "_bar", functor.get("foo" + i + " bar"));
+ }
+ }
+}
17 years, 5 months
JBoss Portal SVN: r12404 - in branches/JBoss_Portal_Branch_2_6: faces/src/main/org/jboss/portal/faces/util and 1 other directory.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2008-12-18 11:10:45 -0500 (Thu, 18 Dec 2008)
New Revision: 12404
Modified:
branches/JBoss_Portal_Branch_2_6/core-admin/src/main/org/jboss/portal/core/admin/ui/InstanceManagerBean.java
branches/JBoss_Portal_Branch_2_6/faces/src/main/org/jboss/portal/faces/util/JSFFunctor.java
Log:
- JBPORTAL-2264, JBPORTAL-2259: Improved performance of functor.
Modified: branches/JBoss_Portal_Branch_2_6/core-admin/src/main/org/jboss/portal/core/admin/ui/InstanceManagerBean.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/core-admin/src/main/org/jboss/portal/core/admin/ui/InstanceManagerBean.java 2008-12-18 11:13:47 UTC (rev 12403)
+++ branches/JBoss_Portal_Branch_2_6/core-admin/src/main/org/jboss/portal/core/admin/ui/InstanceManagerBean.java 2008-12-18 16:10:45 UTC (rev 12404)
@@ -110,20 +110,6 @@
/** . */
private AuthorizationBean auth = new InstanceAuthorizationBean();
- /** Removes white spaces from identifiers so that we can assign them to HTML id attributes. */
- private JSFFunctor idSanitizer = new JSFFunctor()
- {
- public Object get(Object parameter)
- {
- if (parameter instanceof String)
- {
- String id = (String)parameter;
- return id.replaceAll("\\W|\\.", "_");
- }
- return null;
- }
- };
-
// Services accessors
public RoleModule getRoleModule()
@@ -163,7 +149,7 @@
*/
public JSFFunctor getIdSanitizer()
{
- return idSanitizer;
+ return JSFFunctor.ID_SANITIZER;
}
// Navigational state accessor
Modified: branches/JBoss_Portal_Branch_2_6/faces/src/main/org/jboss/portal/faces/util/JSFFunctor.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/faces/src/main/org/jboss/portal/faces/util/JSFFunctor.java 2008-12-18 11:13:47 UTC (rev 12403)
+++ branches/JBoss_Portal_Branch_2_6/faces/src/main/org/jboss/portal/faces/util/JSFFunctor.java 2008-12-18 16:10:45 UTC (rev 12404)
@@ -36,6 +36,30 @@
*/
public abstract class JSFFunctor implements Map
{
+ /** Removes white spaces and periods from identifiers so that we can assign them to HTML id attributes. */
+ public static final JSFFunctor ID_SANITIZER = new JSFFunctor()
+ {
+ private String recent;
+ private String recentSanitized;
+
+ public Object get(Object parameter)
+ {
+ if (parameter instanceof String)
+ {
+ if(parameter.equals(recent))
+ {
+ return recentSanitized;
+ }
+
+ String id = (String) parameter;
+ recent = id;
+ recentSanitized = id.replace(' ', '_').replace('.', '_');
+ return recentSanitized;
+ }
+ return null;
+ }
+ };
+
public int size()
{
return 0;
17 years, 5 months