T
- Type of the bean being populatedpublic abstract class AbstractBeanField<T> extends Object implements BeanField<T>
Modifier and Type | Field and Description |
---|---|
protected Field |
field
The field this class represents.
|
protected boolean |
required
Whether or not this field is required.
|
Constructor and Description |
---|
AbstractBeanField()
Default nullary constructor, so derived classes aren't forced to create
a constructor identical to the one below.
|
AbstractBeanField(Field field)
Constructor for an optional field.
|
AbstractBeanField(Field field,
boolean required) |
Modifier and Type | Method and Description |
---|---|
protected abstract Object |
convert(String value)
Method for converting from a string to the proper datatype of the
destination field.
|
protected String |
convertToWrite(Object value)
This is the method that actually performs the conversion from field to
string for
write(java.lang.Object) and should be overridden in
derived classes. |
Field |
getField()
Gets the field to be processed.
|
boolean |
isRequired()
Answers the query, whether this field is required or not.
|
void |
setField(Field field)
Sets the field to be processed.
|
<T> void |
setFieldValue(T bean,
String value)
Populates the selected field of the bean.
|
void |
setRequired(boolean required)
Determines whether or not a field is required.
|
String |
write(T bean)
This method takes the current value of the field in question in the bean
passed in and converts it to a string.
|
protected Field field
protected boolean required
public AbstractBeanField()
public AbstractBeanField(Field field)
field
- A Field
object.public void setField(Field field)
BeanField
public Field getField()
BeanField
public boolean isRequired()
BeanField
isRequired
in interface BeanField<T>
public void setRequired(boolean required)
BeanField
setRequired
in interface BeanField<T>
required
- Whether or not the field is requiredpublic final <T> void setFieldValue(T bean, String value) throws CsvDataTypeMismatchException, CsvRequiredFieldEmptyException, CsvConstraintViolationException
BeanField
setFieldValue
in interface BeanField<T>
T
- Type of the bean.bean
- Object containing the field to be set.value
- String containing the value to set the field to.CsvDataTypeMismatchException
- When the result of data conversion returns
an object that cannot be assigned to the selected fieldCsvRequiredFieldEmptyException
- When a field is mandatory, but there is no
input datum in the CSV fileCsvConstraintViolationException
- When the internal structure of
data would be violated by the data in the CSV fileprotected abstract Object convert(String value) throws CsvDataTypeMismatchException, CsvRequiredFieldEmptyException, CsvConstraintViolationException
value
- The string from the selected field of the CSV fileObject
representing the input data converted
into the proper typeCsvDataTypeMismatchException
- If the input string cannot be converted into
the proper typeCsvRequiredFieldEmptyException
- If the field is mandatory but the input is
empty. Empty means empty or only whitespace.CsvConstraintViolationException
- When the internal structure of
data would be violated by the data in the CSV filepublic final String write(T bean) throws CsvDataTypeMismatchException, CsvRequiredFieldEmptyException
convertToWrite(java.lang.Object)
for the actual conversion, and itself performs validation and handles
exceptions thrown by convertToWrite(java.lang.Object)
. The
validation consists of verifying that both bean
and field
are not null before calling convertToWrite(java.lang.Object)
.write
in interface BeanField<T>
bean
- The bean holding the field to be writtenCsvDataTypeMismatchException
- If expected to convert an
unsupported data typeCsvRequiredFieldEmptyException
- If the field is marked as required,
but currently contains nullprotected String convertToWrite(Object value) throws CsvDataTypeMismatchException, CsvRequiredFieldEmptyException
write(java.lang.Object)
and should be overridden in
derived classes.
The default implementation simply calls toString()
on the
object in question. Derived classes will, in most cases, want to override
this method. Alternatively, for complex types, overriding the
toString()
method in the type of the field in question would also
work fine.
value
- The contents of the field currently being processed from the
bean to be written. Can be null.value
is nullCsvDataTypeMismatchException
- This implementation does not throw
this exceptionCsvRequiredFieldEmptyException
- If this field has been marked as
required, but is nullwrite(java.lang.Object)
Copyright © 2017. All rights reserved.