RESOLVED - issue BATCH-1265: Add FIeldSetUtils to help with common use cases with the FieldSet interface.

This commit is contained in:
dsyer
2009-11-04 12:42:24 +00:00
parent f2e96f4f71
commit 6fb571abe0
3 changed files with 113 additions and 0 deletions

View File

@@ -481,6 +481,17 @@ public class DefaultFieldSet implements FieldSet {
return parseDate(readAndTrim(index), dateFormat);
}
/* (non-Javadoc)
* @see org.springframework.batch.item.file.transform.FieldSet#readDate(int, java.util.Date)
*/
public Date readDate(int index, Date defaultValue) {
try {
return readDate(index);
} catch (IllegalArgumentException e) {
return defaultValue;
}
}
/*
* (non-Javadoc)
*
@@ -497,6 +508,17 @@ public class DefaultFieldSet implements FieldSet {
}
}
/* (non-Javadoc)
* @see org.springframework.batch.item.file.transform.FieldSet#readDate(int, java.util.Date)
*/
public Date readDate(String name, Date defaultValue) {
try {
return readDate(name);
} catch (IllegalArgumentException e) {
return defaultValue;
}
}
/*
* (non-Javadoc)
*
@@ -509,6 +531,20 @@ public class DefaultFieldSet implements FieldSet {
return parseDate(readAndTrim(index), sdf);
}
/*
* (non-Javadoc)
*
* @see org.springframework.batch.item.file.mapping.IFieldSet#readDate(int,
* java.lang.String)
*/
public Date readDate(int index, String pattern, Date defaultValue) {
try {
return readDate(index, pattern);
} catch (IllegalArgumentException e) {
return defaultValue;
}
}
/*
* (non-Javadoc)
*
@@ -525,6 +561,20 @@ public class DefaultFieldSet implements FieldSet {
}
}
/*
* (non-Javadoc)
*
* @see org.springframework.batch.item.file.mapping.IFieldSet#readDate(int,
* java.lang.String)
*/
public Date readDate(String name, String pattern, Date defaultValue) {
try {
return readDate(name, pattern);
} catch (IllegalArgumentException e) {
return defaultValue;
}
}
/*
* (non-Javadoc)
*

View File

@@ -316,6 +316,7 @@ public interface FieldSet {
* value at index '<code>index</code>' is blank.
*
* @param name the field name.
* @param defaultValue the default value to use if the field is blank
* @throws IllegalArgumentException if a column with given name is not
* defined.
*/
@@ -340,6 +341,27 @@ public interface FieldSet {
*/
Date readDate(String name);
/**
* Read the <code>java.util.Date</code> value in default format at
* designated column <code>index</code>.
*
* @param index the field index.
* @param defaultValue the default value to use if the field is blank
* @throws IndexOutOfBoundsException if the index is out of bounds.
*/
Date readDate(int index, Date defaultValue);
/**
* Read the <code>java.sql.Date</code> value in given format from column
* with given <code>name</code>.
*
* @param name the field name.
* @param defaultValue the default value to use if the field is blank
* @throws IllegalArgumentException if a column with given name is not
* defined.
*/
Date readDate(String name, Date defaultValue);
/**
* Read the <code>java.util.Date</code> value in default format at
* designated column <code>index</code>.
@@ -364,6 +386,32 @@ public interface FieldSet {
*/
Date readDate(String name, String pattern);
/**
* Read the <code>java.util.Date</code> value in default format at
* designated column <code>index</code>.
*
* @param index the field index.
* @param pattern the pattern describing the date and time format
* @param defaultValue the default value to use if the field is blank
* @throws IndexOutOfBoundsException if the index is out of bounds.
* @throws IllegalArgumentException if the date cannot be parsed.
*
*/
Date readDate(int index, String pattern, Date defaultValue);
/**
* Read the <code>java.sql.Date</code> value in given format from column
* with given <code>name</code>.
*
* @param name the field name.
* @param pattern the pattern describing the date and time format
* @param defaultValue the default value to use if the field is blank
* @throws IllegalArgumentException if a column with given name is not
* defined or if the specified field cannot be parsed
*
*/
Date readDate(String name, String pattern, Date defaultValue);
/**
* Return the number of fields in this '<code>FieldSet</code>'.
*/