IN PROGRESS - BATCH-711: Upgrade ItemWriter and implementations to use parameterized types

separated implementation of PassThroughFieldSetMapper and ...Creator
This commit is contained in:
robokaso
2008-07-23 08:46:50 +00:00
parent f2a12eca46
commit 2740d79331
5 changed files with 77 additions and 80 deletions

View File

@@ -0,0 +1,22 @@
package org.springframework.batch.item.file.mapping;
public class PassThroughFieldSetCreator<T> implements FieldSetCreator<T> {
/**
* If the input is a {@link FieldSet} pass it to the caller. Otherwise
* convert to a String with toString() and convert it to a single field
* {@link FieldSet}.
*
* @see org.springframework.batch.item.file.mapping.FieldSetCreator#mapItem(java.lang.Object)
*/
public FieldSet mapItem(T item) {
if (item instanceof FieldSet) {
return (FieldSet) item;
}
String stringItem = item.toString();
return new DefaultFieldSet(new String[] { stringItem });
}
}

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.batch.item.file.mapping;
/**
* Pass through {@link FieldSetMapper} useful for passing a {@link FieldSet}
* back directly rather than a mapped object.
@@ -23,31 +22,17 @@ package org.springframework.batch.item.file.mapping;
* @author Lucas Ward
*
*/
public class PassThroughFieldSetMapper implements FieldSetMapper<FieldSet>, FieldSetCreator<Object> {
public class PassThroughFieldSetMapper implements FieldSetMapper<FieldSet> {
/*
* (non-Javadoc)
* @see org.springframework.batch.io.file.FieldSetMapper#mapLine(org.springframework.batch.io.file.FieldSet)
*
* @see
* org.springframework.batch.io.file.FieldSetMapper#mapLine(org.springframework
* .batch.io.file.FieldSet)
*/
public FieldSet mapLine(FieldSet fs, int lineNum) {
return fs;
}
/**
* If the input is a {@link FieldSet} pass it to the caller. Otherwise
* convert to a String with toString() and convert it to a single field
* {@link FieldSet}.
*
* @see org.springframework.batch.item.file.mapping.FieldSetCreator#mapItem(java.lang.Object)
*/
public FieldSet mapItem(Object data) {
if (data instanceof FieldSet) {
return (FieldSet) data;
}
if (!(data instanceof String)) {
data = "" + data;
}
return new DefaultFieldSet(new String[] { (String) data });
}
}