diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PropertyMatches.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PropertyMatches.java index 43b586115..40e484373 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PropertyMatches.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/mapping/PropertyMatches.java @@ -54,7 +54,7 @@ final class PropertyMatches { * @param propertyName the name of the property to find possible matches for * @param beanClass the bean class to search for matches */ - public static PropertyMatches forProperty(String propertyName, Class beanClass) { + public static PropertyMatches forProperty(String propertyName, Class beanClass) { return forProperty(propertyName, beanClass, DEFAULT_MAX_DISTANCE); } @@ -64,7 +64,7 @@ final class PropertyMatches { * @param beanClass the bean class to search for matches * @param maxDistance the maximum property distance allowed for matches */ - public static PropertyMatches forProperty(String propertyName, Class beanClass, int maxDistance) { + public static PropertyMatches forProperty(String propertyName, Class beanClass, int maxDistance) { return new PropertyMatches(propertyName, beanClass, maxDistance); } @@ -81,7 +81,7 @@ final class PropertyMatches { /** * Create a new PropertyMatches instance for the given property. */ - private PropertyMatches(String propertyName, Class beanClass, int maxDistance) { + private PropertyMatches(String propertyName, Class beanClass, int maxDistance) { this.propertyName = propertyName; this.possibleMatches = calculateMatches(BeanUtils.getPropertyDescriptors(beanClass), maxDistance); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/transform/CompositeItemTransformer.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/transform/CompositeItemTransformer.java index c35659d53..740417111 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/transform/CompositeItemTransformer.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/transform/CompositeItemTransformer.java @@ -7,35 +7,33 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.util.Assert; /** - * Composite {@link ItemTransformer} that passes the item through a sequence - * of injected ItemTransformers (return value of previous transformation - * is the entry value of the next). + * Composite {@link ItemTransformer} that passes the item through a sequence of + * injected ItemTransformers (return value of previous + * transformation is the entry value of the next). * * @author Robert Kasanicky */ public class CompositeItemTransformer implements ItemTransformer, InitializingBean { - private List itemTransformers; - + private List itemTransformers; + public Object transform(Object item) throws Exception { Object result = item; - for (Iterator iterator = itemTransformers.listIterator(); iterator.hasNext();) { - result = ((ItemTransformer)iterator.next()).transform(result); + for (Iterator iterator = itemTransformers.listIterator(); iterator.hasNext();) { + result = iterator.next().transform(result); } return result; } public void afterPropertiesSet() throws Exception { Assert.notEmpty(itemTransformers); - for (Iterator iterator = itemTransformers.iterator(); iterator.hasNext();) { - Assert.isInstanceOf(ItemTransformer.class, iterator.next()); - } } /** - * @param itemTransformers will be chained to produce a composite transformation. + * @param itemTransformers will be chained to produce a composite + * transformation. */ - public void setItemTransformers(List itemTransformers) { + public void setItemTransformers(List itemTransformers) { this.itemTransformers = itemTransformers; } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/validator/SpringValidator.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/validator/SpringValidator.java index d33981d99..28c3eaacf 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/validator/SpringValidator.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/validator/SpringValidator.java @@ -17,7 +17,6 @@ package org.springframework.batch.item.validator; import java.util.Collection; -import java.util.Iterator; import org.springframework.beans.factory.InitializingBean; import org.springframework.util.Assert; @@ -70,10 +69,10 @@ public class SpringValidator implements Validator, InitializingBean { * Append the string representation of elements of the collection (separated * by new lines) to the given StringBuilder. */ - private void appendCollection(Collection collection, StringBuffer builder) { - for (Iterator iterator = collection.iterator(); iterator.hasNext();) { + private void appendCollection(Collection collection, StringBuffer builder) { + for (Object value : collection) { builder.append("\n"); - builder.append(iterator.next().toString()); + builder.append(value.toString()); } } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java index 5eeb36549..4935a4d20 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/xml/StaxEventItemWriter.java @@ -81,7 +81,7 @@ public class StaxEventItemWriter extends ExecutionContextUserSupport implements private String rootTagName = DEFAULT_ROOT_TAG_NAME; // root element attributes - private Map rootElementAttributes = null; + private Map rootElementAttributes = null; // signalizes that marshalling was restarted private boolean restarted = false; @@ -113,9 +113,9 @@ public class StaxEventItemWriter extends ExecutionContextUserSupport implements // holds the list of items for writing before they are actually written on // #flush() - private List buffer = new ArrayList(); + private List buffer = new ArrayList(); - private List headers = new ArrayList(); + private List headers = new ArrayList(); public StaxEventItemWriter() { setName(ClassUtils.getShortName(StaxEventItemWriter.class)); @@ -199,7 +199,7 @@ public class StaxEventItemWriter extends ExecutionContextUserSupport implements * * @return attributes of the root element */ - public Map getRootElementAttributes() { + public Map getRootElementAttributes() { return rootElementAttributes; } @@ -208,7 +208,7 @@ public class StaxEventItemWriter extends ExecutionContextUserSupport implements * * @param rootElementAttributes attributes of the root element */ - public void setRootElementAttributes(Map rootElementAttributes) { + public void setRootElementAttributes(Map rootElementAttributes) { this.rootElementAttributes = rootElementAttributes; } @@ -260,11 +260,11 @@ public class StaxEventItemWriter extends ExecutionContextUserSupport implements } open(startAtPosition); - - if (startAtPosition==0) { - for (Iterator iterator = headers.iterator(); iterator.hasNext();) { - Object header = (Object) iterator.next(); - write(header); + + if (startAtPosition == 0) { + for (Iterator iterator = headers.listIterator(); iterator.hasNext();) { + Object header = iterator.next(); + write(header); } } } @@ -328,9 +328,8 @@ public class StaxEventItemWriter extends ExecutionContextUserSupport implements // write root tag attributes if (!CollectionUtils.isEmpty(getRootElementAttributes())) { - for (Iterator i = getRootElementAttributes().entrySet().iterator(); i.hasNext();) { - Map.Entry entry = (Map.Entry) i.next(); - writer.add(factory.createAttribute((String) entry.getKey(), (String) entry.getValue())); + for (Map.Entry entry : getRootElementAttributes().entrySet()) { + writer.add(factory.createAttribute(entry.getKey(), entry.getValue())); } } @@ -455,7 +454,7 @@ public class StaxEventItemWriter extends ExecutionContextUserSupport implements */ public void flush() throws FlushFailedException { - for (Iterator iterator = buffer.listIterator(); iterator.hasNext();) { + for (Iterator iterator = buffer.listIterator(); iterator.hasNext();) { Object item = iterator.next(); serializer.serializeObject(eventWriter, item); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/transform/CompositeItemTransformerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/transform/CompositeItemTransformerTests.java index 33e880642..358b6e698 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/transform/CompositeItemTransformerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/transform/CompositeItemTransformerTests.java @@ -82,14 +82,5 @@ public class CompositeItemTransformerTests extends TestCase { // expected } - // invalid list member - composite.setItemTransformers(new ArrayList() {{ add(new Object()); }}); - try { - composite.afterPropertiesSet(); - fail(); - } - catch (IllegalArgumentException e) { - // expected - } } }