Package com.opencsv.bean
Class BeanFieldSplit<T,I>
- java.lang.Object
-
- com.opencsv.bean.AbstractBeanField<T,I>
-
- com.opencsv.bean.BeanFieldSplit<T,I>
-
- Type Parameters:
T- The type of the bean being populatedI- Type of the index into a multivalued field
- All Implemented Interfaces:
BeanField<T,I>
public class BeanFieldSplit<T,I> extends AbstractBeanField<T,I>
This class concerns itself with handling collection-valued bean fields.- Since:
- 4.2
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.regex.Patterncaptureprivate java.lang.Class<? extends java.util.Collection>collectionTypeprivate java.lang.Class<?>elementTypeprivate java.util.regex.PatternsplitOnprivate java.lang.StringwriteDelimiterprivate java.lang.StringwriteFormat-
Fields inherited from class com.opencsv.bean.AbstractBeanField
converter, errorLocale, field, fieldAccess, required, type
-
-
Constructor Summary
Constructors Constructor Description BeanFieldSplit(java.lang.Class<?> type, java.lang.reflect.Field field, boolean required, java.util.Locale errorLocale, CsvConverter converter, java.lang.String splitOn, java.lang.String writeDelimiter, java.lang.Class<? extends java.util.Collection> collectionType, java.lang.Class<?> elementType, java.lang.String capture, java.lang.String format)The only valid constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Objectconvert(java.lang.String value)This method manages the collection being created as well as splitting the data.protected java.lang.StringconvertToWrite(java.lang.Object value)Manages converting a collection of values into a single string.protected booleanisFieldEmptyForWrite(java.lang.Object value)Checks thatvalueis not null and not an emptyCollection.-
Methods inherited from class com.opencsv.bean.AbstractBeanField
assignValueToField, getErrorLocale, getField, getFieldValue, getType, indexAndSplitMultivaluedField, isRequired, setErrorLocale, setField, setFieldValue, setRequired, setType, write
-
-
-
-
Field Detail
-
splitOn
private final java.util.regex.Pattern splitOn
-
capture
private final java.util.regex.Pattern capture
-
writeDelimiter
private final java.lang.String writeDelimiter
-
writeFormat
private final java.lang.String writeFormat
-
collectionType
private final java.lang.Class<? extends java.util.Collection> collectionType
-
elementType
private final java.lang.Class<?> elementType
-
-
Constructor Detail
-
BeanFieldSplit
public BeanFieldSplit(java.lang.Class<?> type, java.lang.reflect.Field field, boolean required, java.util.Locale errorLocale, CsvConverter converter, java.lang.String splitOn, java.lang.String writeDelimiter, java.lang.Class<? extends java.util.Collection> collectionType, java.lang.Class<?> elementType, java.lang.String capture, java.lang.String format)The only valid constructor.- Parameters:
type- The type of the class in which this field is found. This is the type as instantiated by opencsv, and not necessarily the type in which the field is declared in the case of inheritance.field- AFieldobject.required- Whether or not this field is required in inputerrorLocale- The errorLocale to use for error messages.converter- The converter to be used to perform the actual data conversionsplitOn- SeeCsvBindAndSplitByName.splitOn()writeDelimiter- SeeCsvBindAndSplitByName.writeDelimiter()collectionType- SeeCsvBindAndSplitByName.collectionType()elementType- SeeCsvBindAndSplitByName.elementType()capture- SeeCsvBindAndSplitByName.capture()format- The format string used for packaging values to be written. Ifnullor empty, it is ignored.
-
-
Method Detail
-
convert
protected java.lang.Object convert(java.lang.String value) throws CsvDataTypeMismatchException, CsvConstraintViolationExceptionThis method manages the collection being created as well as splitting the data. Once the data are split, they are sent to the converter for the actual conversion.- Specified by:
convertin classAbstractBeanField<T,I>- Parameters:
value- The string from the selected field of the CSV file. If the field is marked as required in the annotation, this value is guaranteed not to be null, empty or blank according toStringUtils.isBlank(java.lang.CharSequence)- Returns:
- An
Objectrepresenting the input data converted into the proper type - Throws:
CsvDataTypeMismatchException- If the input string cannot be converted into the proper typeCsvConstraintViolationException- When the internal structure of data would be violated by the data in the CSV file- See Also:
ConverterPrimitiveTypes.convertToRead(java.lang.String),ConverterDate.convertToRead(java.lang.String),ConverterNumber.convertToRead(String)
-
convertToWrite
protected java.lang.String convertToWrite(java.lang.Object value) throws CsvDataTypeMismatchExceptionManages converting a collection of values into a single string. The conversion of each individual value is performed by the converter.- Overrides:
convertToWritein classAbstractBeanField<T,I>- Parameters:
value- The contents of the field currently being processed from the bean to be written. Can be null if the field is not marked as required.- Returns:
- A string representation of the value of the field in question in
the bean passed in, or an empty string if
valueis null - Throws:
CsvDataTypeMismatchException- This implementation does not throw this exception- See Also:
AbstractBeanField.write(java.lang.Object, java.lang.Object)
-
isFieldEmptyForWrite
protected boolean isFieldEmptyForWrite(java.lang.Object value)
Checks thatvalueis not null and not an emptyCollection.- Overrides:
isFieldEmptyForWritein classAbstractBeanField<T,I>- Parameters:
value- The value of a field out of a bean that is being written to a CSV file. Can benull.- Returns:
- Whether or not this implementation considers
valueto be empty for the purposes of its conversion
-
-