Change ClassifierCompositeItemWriter to honor item order

The ClassifierCompositeItemWriter loops through the items passed to the
write method twice.  The first time to classifier each item.  The second
tiem to perform the actual writes (this prevents the unnecessicary IO if
an error occurs during classification).  A HashMap was previously used
to hold the classified items (key to the writer : item) however this
causes the items to be written out of order.  This update changes it to
a LinkedHashMap to honor the order the items come in.
This commit is contained in:
Adam Richeimer
2014-09-15 18:15:04 -07:00
committed by Michael Minella
parent 04b339b8f4
commit 44fc2b1069
2 changed files with 4 additions and 4 deletions

View File

@@ -17,7 +17,7 @@
package org.springframework.batch.item.support;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -52,7 +52,7 @@ public class ClassifierCompositeItemWriter<T> implements ItemWriter<T> {
@Override
public void write(List<? extends T> items) throws Exception {
Map<ItemWriter<? super T>, List<T>> map = new HashMap<ItemWriter<? super T>, List<T>>();
Map<ItemWriter<? super T>, List<T>> map = new LinkedHashMap<ItemWriter<? super T>, List<T>>();
for (T item : items) {
ItemWriter<? super T> key = classifier.classify(item);