Author: niallp
Date: Wed May 28 09:28:49 2008
New Revision: 661007
URL: http://svn.apache.org/viewvc?rev=661007&view=rev
Log:
Use more efficient iterator on the entrySet to avoid the Map.get() lookup -
thanks to FindBugs
Modified:
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/portlet/PortletApplicationScopeMap.java
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/portlet/PortletRequestScopeMap.java
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/portlet/PortletSessionScopeMap.java
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ServletApplicationScopeMap.java
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ServletRequestScopeMap.java
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ServletSessionScopeMap.java
commons/proper/chain/trunk/src/test/org/apache/commons/chain/web/portlet/PortletWebContextTestCase.java
commons/proper/chain/trunk/src/test/org/apache/commons/chain/web/servlet/ServletWebContextTestCase.java
Modified:
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/portlet/PortletApplicationScopeMap.java
URL:
http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/portlet/PortletApplicationScopeMap.java?rev=661007&r1=661006&r2=661007&view=diff
==============================================================================
---
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/portlet/PortletApplicationScopeMap.java
(original)
+++
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/portlet/PortletApplicationScopeMap.java
Wed May 28 09:28:49 2008
@@ -130,10 +130,10 @@
public void putAll(Map map) {
- Iterator keys = map.keySet().iterator();
- while (keys.hasNext()) {
- String key = (String) keys.next();
- context.setAttribute(key, map.get(key));
+ Iterator entries = map.entrySet().iterator();
+ while (entries.hasNext()) {
+ Map.Entry entry = (Map.Entry)entries.next();
+ put(entry.getKey(), entry.getValue());
}
}
Modified:
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/portlet/PortletRequestScopeMap.java
URL:
http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/portlet/PortletRequestScopeMap.java?rev=661007&r1=661006&r2=661007&view=diff
==============================================================================
---
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/portlet/PortletRequestScopeMap.java
(original)
+++
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/portlet/PortletRequestScopeMap.java
Wed May 28 09:28:49 2008
@@ -130,10 +130,10 @@
public void putAll(Map map) {
- Iterator keys = map.keySet().iterator();
- while (keys.hasNext()) {
- String key = (String) keys.next();
- request.setAttribute(key, map.get(key));
+ Iterator entries = map.entrySet().iterator();
+ while (entries.hasNext()) {
+ Map.Entry entry = (Map.Entry)entries.next();
+ put(entry.getKey(), entry.getValue());
}
}
Modified:
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/portlet/PortletSessionScopeMap.java
URL:
http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/portlet/PortletSessionScopeMap.java?rev=661007&r1=661006&r2=661007&view=diff
==============================================================================
---
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/portlet/PortletSessionScopeMap.java
(original)
+++
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/portlet/PortletSessionScopeMap.java
Wed May 28 09:28:49 2008
@@ -171,10 +171,10 @@
public void putAll(Map map) {
- Iterator keys = map.keySet().iterator();
- while (keys.hasNext()) {
- Object key = keys.next();
- put(key, map.get(key));
+ Iterator entries = map.entrySet().iterator();
+ while (entries.hasNext()) {
+ Map.Entry entry = (Map.Entry)entries.next();
+ put(entry.getKey(), entry.getValue());
}
}
Modified:
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ServletApplicationScopeMap.java
URL:
http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ServletApplicationScopeMap.java?rev=661007&r1=661006&r2=661007&view=diff
==============================================================================
---
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ServletApplicationScopeMap.java
(original)
+++
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ServletApplicationScopeMap.java
Wed May 28 09:28:49 2008
@@ -130,10 +130,10 @@
public void putAll(Map map) {
- Iterator keys = map.keySet().iterator();
- while (keys.hasNext()) {
- String key = (String) keys.next();
- context.setAttribute(key, map.get(key));
+ Iterator entries = map.entrySet().iterator();
+ while (entries.hasNext()) {
+ Map.Entry entry = (Map.Entry)entries.next();
+ put(entry.getKey(), entry.getValue());
}
}
Modified:
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ServletRequestScopeMap.java
URL:
http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ServletRequestScopeMap.java?rev=661007&r1=661006&r2=661007&view=diff
==============================================================================
---
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ServletRequestScopeMap.java
(original)
+++
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ServletRequestScopeMap.java
Wed May 28 09:28:49 2008
@@ -130,10 +130,10 @@
public void putAll(Map map) {
- Iterator keys = map.keySet().iterator();
- while (keys.hasNext()) {
- String key = (String) keys.next();
- request.setAttribute(key, map.get(key));
+ Iterator entries = map.entrySet().iterator();
+ while (entries.hasNext()) {
+ Map.Entry entry = (Map.Entry)entries.next();
+ put(entry.getKey(), entry.getValue());
}
}
Modified:
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ServletSessionScopeMap.java
URL:
http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ServletSessionScopeMap.java?rev=661007&r1=661006&r2=661007&view=diff
==============================================================================
---
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ServletSessionScopeMap.java
(original)
+++
commons/proper/chain/trunk/src/java/org/apache/commons/chain/web/servlet/ServletSessionScopeMap.java
Wed May 28 09:28:49 2008
@@ -168,10 +168,10 @@
public void putAll(Map map) {
- Iterator keys = map.keySet().iterator();
- while (keys.hasNext()) {
- Object key = keys.next();
- put(key, map.get(key));
+ Iterator entries = map.entrySet().iterator();
+ while (entries.hasNext()) {
+ Map.Entry entry = (Map.Entry)entries.next();
+ put(entry.getKey(), entry.getValue());
}
}
Modified:
commons/proper/chain/trunk/src/test/org/apache/commons/chain/web/portlet/PortletWebContextTestCase.java
URL:
http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/test/org/apache/commons/chain/web/portlet/PortletWebContextTestCase.java?rev=661007&r1=661006&r2=661007&view=diff
==============================================================================
---
commons/proper/chain/trunk/src/test/org/apache/commons/chain/web/portlet/PortletWebContextTestCase.java
(original)
+++
commons/proper/chain/trunk/src/test/org/apache/commons/chain/web/portlet/PortletWebContextTestCase.java
Wed May 28 09:28:49 2008
@@ -166,6 +166,15 @@
map.clear();
checkMapSize(map, 0);
+ // Test putAll()
+ Map values = new HashMap();
+ values.put(new Integer(1), "One");
+ values.put("2", "Two");
+ map.putAll(values);
+ assertEquals("putAll(1)", "One", map.get("1"));
+ assertEquals("putAll(2)", "Two", map.get("2"));
+ checkMapSize(map, 2);
+
}
@@ -519,6 +528,15 @@
map.clear();
checkMapSize(map, 0);
+ // Test putAll()
+ Map values = new HashMap();
+ values.put(new Integer(1), "One");
+ values.put("2", "Two");
+ map.putAll(values);
+ assertEquals("putAll(1)", "One", map.get("1"));
+ assertEquals("putAll(2)", "Two", map.get("2"));
+ checkMapSize(map, 2);
+
}
@@ -571,6 +589,15 @@
map.clear();
checkMapSize(map, 0);
+ // Test putAll()
+ Map values = new HashMap();
+ values.put(new Integer(1), "One");
+ values.put("2", "Two");
+ map.putAll(values);
+ assertEquals("putAll(1)", "One", map.get("1"));
+ assertEquals("putAll(2)", "Two", map.get("2"));
+ checkMapSize(map, 2);
+
}
Modified:
commons/proper/chain/trunk/src/test/org/apache/commons/chain/web/servlet/ServletWebContextTestCase.java
URL:
http://svn.apache.org/viewvc/commons/proper/chain/trunk/src/test/org/apache/commons/chain/web/servlet/ServletWebContextTestCase.java?rev=661007&r1=661006&r2=661007&view=diff
==============================================================================
---
commons/proper/chain/trunk/src/test/org/apache/commons/chain/web/servlet/ServletWebContextTestCase.java
(original)
+++
commons/proper/chain/trunk/src/test/org/apache/commons/chain/web/servlet/ServletWebContextTestCase.java
Wed May 28 09:28:49 2008
@@ -175,6 +175,14 @@
map.clear();
checkMapSize(map, 0);
+ // Test putAll()
+ Map values = new HashMap();
+ values.put(new Integer(1), "One");
+ values.put("2", "Two");
+ map.putAll(values);
+ assertEquals("putAll(1)", "One", map.get("1"));
+ assertEquals("putAll(2)", "Two", map.get("2"));
+ checkMapSize(map, 2);
}
@@ -629,6 +637,15 @@
map.clear();
checkMapSize(map, 0);
+ // Test putAll()
+ Map values = new HashMap();
+ values.put(new Integer(1), "One");
+ values.put("2", "Two");
+ map.putAll(values);
+ assertEquals("putAll(1)", "One", map.get("1"));
+ assertEquals("putAll(2)", "Two", map.get("2"));
+ checkMapSize(map, 2);
+
}
@@ -681,6 +698,15 @@
map.clear();
checkMapSize(map, 0);
+ // Test putAll()
+ Map values = new HashMap();
+ values.put(new Integer(1), "One");
+ values.put("2", "Two");
+ map.putAll(values);
+ assertEquals("putAll(1)", "One", map.get("1"));
+ assertEquals("putAll(2)", "Two", map.get("2"));
+ checkMapSize(map, 2);
+
}