Permalink
Browse files

Replace use of Iterator with Java 5 foreach loops

Issues: SWF-1532
  • Loading branch information...
1 parent 22b018e commit 34f4837ebd9c1afabd83e66d4086443c711adc1a @philwebb philwebb committed Apr 5, 2012
Showing with 112 additions and 254 deletions.
  1. +2 −4 spring-binding/src/main/java/org/springframework/binding/convert/converters/ArrayToCollection.java
  2. +1 −4 ...-binding/src/main/java/org/springframework/binding/convert/converters/CollectionToCollection.java
  3. +1 −4 spring-binding/src/main/java/org/springframework/binding/expression/el/DefaultELResolver.java
  4. +1 −4 spring-binding/src/main/java/org/springframework/binding/mapping/impl/DefaultMapper.java
  5. +3 −10 spring-binding/src/main/java/org/springframework/binding/mapping/impl/DefaultMappingResults.java
  6. +2 −7 spring-binding/src/main/java/org/springframework/binding/message/DefaultMessageContext.java
  7. +1 −4 spring-binding/src/main/java/org/springframework/binding/message/MessageContextErrors.java
  8. +1 −6 spring-faces/src/main/java/org/springframework/faces/mvc/JsfView.java
  9. +1 −4 spring-faces/src/main/java/org/springframework/faces/ui/AjaxViewRoot.java
  10. +7 −13 spring-faces/src/main/java/org/springframework/faces/ui/ProgressiveCommandButtonRenderer.java
  11. +8 −19 spring-faces/src/main/java/org/springframework/faces/ui/ProgressiveCommandLinkRenderer.java
  12. +2 −5 spring-faces/src/main/java/org/springframework/faces/ui/resource/ResourceHelper.java
  13. +3 −3 spring-faces/src/main/java/org/springframework/faces/webflow/FlowFacesContextMessageDelegate.java
  14. +1 −3 spring-js/src/main/java/org/springframework/js/ajax/tiles2/AjaxTilesView.java
  15. +2 −7 spring-js/src/main/java/org/springframework/js/resource/ResourceServlet.java
  16. +1 −4 ...flow/src/main/java/org/springframework/webflow/config/FlowExecutionListenerLoaderFactoryBean.java
  17. +3 −5 spring-webflow/src/main/java/org/springframework/webflow/core/collection/LocalAttributeMap.java
  18. +1 −4 ...low/src/main/java/org/springframework/webflow/definition/registry/FlowDefinitionRegistryImpl.java
  19. +3 −4 spring-webflow/src/main/java/org/springframework/webflow/engine/ActionList.java
  20. +6 −16 spring-webflow/src/main/java/org/springframework/webflow/engine/Flow.java
  21. +2 −5 ...ng-webflow/src/main/java/org/springframework/webflow/engine/FlowExecutionExceptionHandlerSet.java
  22. +4 −7 spring-webflow/src/main/java/org/springframework/webflow/engine/TransitionSet.java
  23. +3 −12 spring-webflow/src/main/java/org/springframework/webflow/engine/ViewState.java
  24. +1 −4 spring-webflow/src/main/java/org/springframework/webflow/engine/builder/BinderConfiguration.java
  25. +1 −1 spring-webflow/src/main/java/org/springframework/webflow/engine/impl/FlowExecutionImplFactory.java
  26. +30 −30 spring-webflow/src/main/java/org/springframework/webflow/engine/model/AbstractModel.java
  27. +2 −5 spring-webflow/src/main/java/org/springframework/webflow/engine/support/TransitionCriteriaChain.java
  28. +2 −5 ...in/java/org/springframework/webflow/execution/factory/ConditionalFlowExecutionListenerHolder.java
  29. +4 −7 ...in/java/org/springframework/webflow/execution/factory/ConditionalFlowExecutionListenerLoader.java
  30. +2 −10 spring-webflow/src/main/java/org/springframework/webflow/mvc/portlet/FlowHandlerAdapter.java
  31. +2 −11 spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapter.java
  32. +1 −4 spring-webflow/src/main/java/org/springframework/webflow/mvc/view/AbstractMvcView.java
  33. +2 −4 spring-webflow/src/main/java/org/springframework/webflow/security/SecurityFlowExecutionListener.java
  34. +5 −14 spring-webflow/src/main/java/org/springframework/webflow/security/SecurityRule.java
  35. +1 −5 ...bflow/src/test/java/org/springframework/webflow/config/FlowRegistryBeanDefinitionParserTests.java
@@ -19,7 +19,6 @@
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -101,8 +100,7 @@ public Object convertTargetToSourceClass(Object target, Class<?> sourceClass) th
Collection<?> collection = (Collection<?>) target;
Object array = Array.newInstance(sourceClass.getComponentType(), collection.size());
int i = 0;
- for (Iterator<?> it = collection.iterator(); it.hasNext(); i++) {
- Object value = it.next();
+ for (Object value : collection) {
if (value != null) {
ConversionExecutor converter;
if (elementConverter != null) {
@@ -113,7 +111,7 @@ public Object convertTargetToSourceClass(Object target, Class<?> sourceClass) th
}
value = converter.execute(value);
}
- Array.set(array, i, value);
+ Array.set(array, i++, value);
}
return array;
}
@@ -1,7 +1,6 @@
package org.springframework.binding.convert.converters;
import java.util.Collection;
-import java.util.Iterator;
import org.springframework.binding.convert.ConversionExecutor;
import org.springframework.binding.convert.ConversionService;
@@ -54,9 +53,7 @@ public Object convertSourceToTargetClass(Object source, Class<?> targetClass) th
Collection targetCollection = CollectionFactory.createCollection(targetClass, DEFAULT_INITIAL_SIZE);
ConversionExecutor elementConverter = getElementConverter(source, (Class<? extends Collection<?>>) targetClass);
Collection sourceCollection = (Collection) source;
- Iterator it = sourceCollection.iterator();
- while (it.hasNext()) {
- Object value = it.next();
+ for (Object value : sourceCollection) {
if (elementConverter != null) {
value = elementConverter.execute(value);
}
@@ -15,7 +15,6 @@
*/
package org.springframework.binding.expression.el;
-import java.util.Iterator;
import java.util.List;
import javax.el.ArrayELResolver;
@@ -91,9 +90,7 @@ public void setValue(ELContext context, Object base, Object property, Object val
private void configureResolvers(List<? extends ELResolver> customResolvers) {
if (customResolvers != null) {
- Iterator<? extends ELResolver> i = customResolvers.iterator();
- while (i.hasNext()) {
- ELResolver resolver = i.next();
+ for (ELResolver resolver : customResolvers) {
add(resolver);
}
}
@@ -16,7 +16,6 @@
package org.springframework.binding.mapping.impl;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import org.apache.commons.logging.Log;
@@ -62,9 +61,7 @@ public MappingResults map(Object source, Object target) {
+ target.getClass().getName() + "]");
}
DefaultMappingContext context = new DefaultMappingContext(source, target);
- Iterator<DefaultMapping> it = mappings.iterator();
- while (it.hasNext()) {
- DefaultMapping mapping = it.next();
+ for (DefaultMapping mapping : mappings) {
mapping.map(context);
}
MappingResults results = context.getMappingResults();
@@ -17,7 +17,6 @@
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import org.springframework.binding.mapping.MappingResult;
@@ -61,9 +60,7 @@ public Object getTarget() {
}
public boolean hasErrorResults() {
- Iterator<MappingResult> it = mappingResults.iterator();
- while (it.hasNext()) {
- MappingResult result = it.next();
+ for (MappingResult result : mappingResults) {
if (result.isError()) {
return true;
}
@@ -73,9 +70,7 @@ public boolean hasErrorResults() {
public List<MappingResult> getErrorResults() {
List<MappingResult> errorResults = new ArrayList<MappingResult>();
- Iterator<MappingResult> it = mappingResults.iterator();
- while (it.hasNext()) {
- MappingResult result = it.next();
+ for (MappingResult result : mappingResults) {
if (result.isError()) {
errorResults.add(result);
}
@@ -85,9 +80,7 @@ public boolean hasErrorResults() {
public List<MappingResult> getResults(MappingResultsCriteria criteria) {
List<MappingResult> results = new ArrayList<MappingResult>();
- Iterator<MappingResult> it = mappingResults.iterator();
- while (it.hasNext()) {
- MappingResult result = it.next();
+ for (MappingResult result : mappingResults) {
if (criteria.test(result)) {
results.add(result);
}
@@ -18,7 +18,6 @@
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
@@ -88,9 +87,7 @@ public MessageSource getMessageSource() {
public Message[] getMessagesByCriteria(MessageCriteria criteria) {
List<Message> messages = new ArrayList<Message>();
- Iterator<List<Message>> it = sourceMessages.values().iterator();
- while (it.hasNext()) {
- List<Message> sourceMessages = it.next();
+ for (List<Message> sourceMessages : this.sourceMessages.values()) {
for (Message message : sourceMessages) {
if (criteria.test(message)) {
messages.add(message);
@@ -101,9 +98,7 @@ public MessageSource getMessageSource() {
}
public boolean hasErrorMessages() {
- Iterator<List<Message>> it = sourceMessages.values().iterator();
- while (it.hasNext()) {
- List<Message> sourceMessages = it.next();
+ for (List<Message> sourceMessages : this.sourceMessages.values()) {
for (Message message : sourceMessages) {
if (message.getSeverity() == Severity.ERROR) {
return true;
@@ -17,7 +17,6 @@
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import org.springframework.binding.expression.Expression;
@@ -100,9 +99,7 @@ public void rejectValue(String field, String errorCode, Object[] errorArgs, Stri
}
public void addAllErrors(Errors errors) {
- Iterator<ObjectError> it = errors.getAllErrors().iterator();
- while (it.hasNext()) {
- ObjectError error = it.next();
+ for (ObjectError error : errors.getAllErrors()) {
MessageBuilder builder = new MessageBuilder().error().codes(error.getCodes()).args(error.getArguments())
.defaultText(error.getDefaultMessage());
if (error instanceof FieldError) {
@@ -18,7 +18,6 @@
import static org.springframework.faces.webflow.JsfRuntimeInformation.isAtLeastJsf12;
import static org.springframework.faces.webflow.JsfRuntimeInformation.isPortletRequest;
-import java.util.Iterator;
import java.util.Map;
import javax.faces.FactoryFinder;
@@ -89,11 +88,7 @@ protected void renderMergedOutputModel(Map<String, Object> model, HttpServletReq
}
private void populateRequestMap(FacesContext facesContext, Map<String, Object> model) {
- Iterator<String> i = model.keySet().iterator();
- while (i.hasNext()) {
- String key = i.next().toString();
- facesContext.getExternalContext().getRequestMap().put(key, model.get(key));
- }
+ facesContext.getExternalContext().getRequestMap().putAll(model);
}
private Lifecycle createFacesLifecycle() {
@@ -18,7 +18,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
@@ -266,9 +265,7 @@ private void broadCastEvents(FacesContext context, PhaseId phaseId) {
}
boolean abort = false;
int phaseIdOrdinal = phaseId.getOrdinal();
- Iterator<FacesEvent> i = events.iterator();
- while (i.hasNext()) {
- FacesEvent event = i.next();
+ for (FacesEvent event : events) {
int ordinal = event.getPhaseId().getOrdinal();
if (ordinal == PhaseId.ANY_PHASE.getOrdinal() || ordinal == phaseIdOrdinal) {
UIComponent source = event.getComponent();
@@ -20,7 +20,6 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
-import java.util.ListIterator;
import java.util.Map;
import javax.faces.component.UIComponent;
@@ -37,7 +36,6 @@
* {@link Renderer} for the {@code <sf:commandButton>} tag.
*
* @author Jeremy Grelle
- *
*/
public class ProgressiveCommandButtonRenderer extends BaseDojoComponentRenderer {
@@ -46,17 +44,13 @@
private static String INPUT_TAG_NAME = "input";
static {
- List<String> tempList = new ArrayList<String>();
- tempList.addAll(Arrays.asList(HTML.STANDARD_ATTRIBUTES));
- tempList.addAll(Arrays.asList(HTML.BUTTON_ATTRIBUTES));
- tempList.addAll(Arrays.asList(HTML.COMMON_ELEMENT_EVENTS));
- tempList.addAll(Arrays.asList(HTML.KEYBOARD_EVENTS));
- tempList.addAll(Arrays.asList(HTML.MOUSE_EVENTS));
- ATTRIBUTES_TO_RENDER = new String[tempList.size()];
- ListIterator<String> i = tempList.listIterator();
- while (i.hasNext()) {
- ATTRIBUTES_TO_RENDER[i.nextIndex()] = i.next();
- }
+ List<String> attributes = new ArrayList<String>();
+ attributes.addAll(Arrays.asList(HTML.STANDARD_ATTRIBUTES));
+ attributes.addAll(Arrays.asList(HTML.BUTTON_ATTRIBUTES));
+ attributes.addAll(Arrays.asList(HTML.COMMON_ELEMENT_EVENTS));
+ attributes.addAll(Arrays.asList(HTML.KEYBOARD_EVENTS));
+ attributes.addAll(Arrays.asList(HTML.MOUSE_EVENTS));
+ ATTRIBUTES_TO_RENDER = attributes.toArray(new String[attributes.size()]);
}
private Map<String, RenderAttributeCallback> attributeCallbacks;
@@ -22,7 +22,6 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
-import java.util.ListIterator;
import java.util.Map;
import javax.faces.component.UIComponent;
@@ -58,24 +57,14 @@
private static String TAG_NAME_WHEN_DISABLED = "span";
static {
-
- List<String> tempList = new ArrayList<String>();
- tempList.addAll(Arrays.asList(HTML.STANDARD_ATTRIBUTES));
- tempList.addAll(Arrays.asList(HTML.COMMON_ELEMENT_EVENTS));
- tempList.addAll(Arrays.asList(HTML.KEYBOARD_EVENTS));
- tempList.addAll(Arrays.asList(HTML.MOUSE_EVENTS));
- ATTRIBUTES_TO_RENDER_WHEN_DISABLED = new String[tempList.size()];
- ListIterator<String> i = tempList.listIterator();
- while (i.hasNext()) {
- ATTRIBUTES_TO_RENDER_WHEN_DISABLED[i.nextIndex()] = i.next();
- }
-
- tempList.addAll(Arrays.asList(HTML.ANCHOR_ATTRIBUTES));
- ATTRIBUTES_TO_RENDER = new String[tempList.size()];
- i = tempList.listIterator();
- while (i.hasNext()) {
- ATTRIBUTES_TO_RENDER[i.nextIndex()] = i.next();
- }
+ List<String> attributes = new ArrayList<String>();
+ attributes.addAll(Arrays.asList(HTML.STANDARD_ATTRIBUTES));
+ attributes.addAll(Arrays.asList(HTML.COMMON_ELEMENT_EVENTS));
+ attributes.addAll(Arrays.asList(HTML.KEYBOARD_EVENTS));
+ attributes.addAll(Arrays.asList(HTML.MOUSE_EVENTS));
+ ATTRIBUTES_TO_RENDER_WHEN_DISABLED = attributes.toArray(new String[attributes.size()]);
+ attributes.addAll(Arrays.asList(HTML.ANCHOR_ATTRIBUTES));
+ ATTRIBUTES_TO_RENDER = attributes.toArray(new String[attributes.size()]);
}
private Map<String, RenderAttributeCallback> attributeCallbacks;
@@ -19,7 +19,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -92,10 +91,8 @@ public static void renderScriptLink(FacesContext facesContext, String scriptPath
ResponseWriter writer = facesContext.getResponseWriter();
writer.startElement(SCRIPT_ELEMENT, null);
writer.writeAttribute("type", "text/javascript", null);
- Iterator<String> i = attributes.keySet().iterator();
- while (i.hasNext()) {
- String key = i.next();
- writer.writeAttribute(key, attributes.get(key), null);
+ for (Map.Entry<String, Object> entry : attributes.entrySet()) {
+ writer.writeAttribute(entry.getKey(), entry.getValue(), null);
}
String src = facesContext.getExternalContext().getRequestContextPath() + "/resources" + scriptPath;
writer.writeAttribute("src", src, null);
@@ -95,9 +95,9 @@ public void addToFlowMessageContext(String clientId, FacesMessage message) {
return null;
}
FacesMessage.Severity max = FacesMessage.SEVERITY_INFO;
- Iterator<FacesMessage> i = getMessages();
- while (i.hasNext()) {
- FacesMessage message = i.next();
+ Iterator<FacesMessage> messages = getMessages();
+ while (messages.hasNext()) {
+ FacesMessage message = messages.next();
if (message.getSeverity().getOrdinal() > max.getOrdinal()) {
max = message.getSeverity();
}
@@ -196,9 +196,7 @@ protected void addRuntimeAttributes(BasicTilesContainer container, Map<String, A
if (attributeContext.getCascadedAttributeNames() != null) {
attributeNames.addAll(attributeContext.getCascadedAttributeNames());
}
- Iterator<String> iterator = attributeNames.iterator();
- while (iterator.hasNext()) {
- String name = iterator.next();
+ for (String name : attributeNames) {
Attribute attr = attributeContext.getAttribute(name);
resultMap.put(name, attr);
}
@@ -25,7 +25,6 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.zip.GZIPOutputStream;
@@ -166,9 +165,7 @@ private OutputStream selectOutputStream(HttpServletRequest request, HttpServletR
private boolean matchesCompressedMimeTypes(String mimeType) {
PathMatcher pathMatcher = new AntPathMatcher();
- Iterator<String> compressedMimeTypesIt = compressedMimeTypes.iterator();
- while (compressedMimeTypesIt.hasNext()) {
- String compressedMimeType = compressedMimeTypesIt.next();
+ for (String compressedMimeType : compressedMimeTypes) {
if (pathMatcher.match(compressedMimeType, mimeType)) {
return true;
}
@@ -298,9 +295,7 @@ private boolean isAllowed(String resourcePath) {
return false;
}
PathMatcher pathMatcher = new AntPathMatcher();
- Iterator<String> allowedResourcePathsIt = allowedResourcePaths.iterator();
- while (allowedResourcePathsIt.hasNext()) {
- String pattern = allowedResourcePathsIt.next();
+ for (String pattern : allowedResourcePaths) {
if (pathMatcher.match(pattern, resourcePath)) {
return true;
}
@@ -15,7 +15,6 @@
*/
package org.springframework.webflow.config;
-import java.util.Iterator;
import java.util.Map;
import org.springframework.beans.factory.FactoryBean;
@@ -60,9 +59,7 @@ public void setListeners(Map<FlowExecutionListener, String> listenersWithCriteri
public void afterPropertiesSet() {
listenerLoader = new ConditionalFlowExecutionListenerLoader();
- Iterator<Map.Entry<FlowExecutionListener, String>> it = listenersWithCriteria.entrySet().iterator();
- while (it.hasNext()) {
- Map.Entry<FlowExecutionListener, String> entry = it.next();
+ for (Map.Entry<FlowExecutionListener, String> entry : listenersWithCriteria.entrySet()) {
FlowExecutionListener listener = entry.getKey();
String criteria = entry.getValue();
listenerLoader.addListener(listener, listenerCriteriaFactory.getListenerCriteria(criteria));
Oops, something went wrong.

0 comments on commit 34f4837

Please sign in to comment.