Package com.opencsv.bean.customconverter
Class ConverterLanguageToBoolean<T,I>
- java.lang.Object
-
- com.opencsv.bean.AbstractBeanField<T,I>
-
- com.opencsv.bean.customconverter.ConverterLanguageToBoolean<T,I>
-
- Type Parameters:
T
- Type of the bean to be manipulatedI
- Type of the index into multivalued fields
- All Implemented Interfaces:
BeanField<T,I>
- Direct Known Subclasses:
ConvertFrenchToBoolean
,ConvertGermanToBoolean
public abstract class ConverterLanguageToBoolean<T,I> extends AbstractBeanField<T,I>
A base class for any converter to and from booleans when the string values have been or should be localized to a specific language.
-
-
Field Summary
-
Fields inherited from class com.opencsv.bean.AbstractBeanField
converter, errorLocale, field, fieldAccess, required, type
-
-
Constructor Summary
Constructors Constructor Description ConverterLanguageToBoolean()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.lang.Object
convert(java.lang.String value)
Converts localized text into aBoolean
.protected java.lang.String
convertToWrite(java.lang.Object value)
This method takes the current value of the field in question in the bean passed in and converts it to a string.protected abstract java.lang.String[]
getAllLocalizedFalseValues()
This represents a list of all values accepted as "false".protected abstract java.lang.String[]
getAllLocalizedTrueValues()
This represents a list of all values accepted as "true".protected abstract java.lang.String
getLocalizedFalse()
This is the string for "false" in the localized language.protected abstract java.lang.String
getLocalizedTrue()
This is the string for "true" in the localized language.-
Methods inherited from class com.opencsv.bean.AbstractBeanField
assignValueToField, getErrorLocale, getField, getFieldValue, getType, indexAndSplitMultivaluedField, isFieldEmptyForWrite, isRequired, setErrorLocale, setField, setFieldValue, setRequired, setType, write
-
-
-
-
Method Detail
-
getLocalizedTrue
protected abstract java.lang.String getLocalizedTrue()
This is the string for "true" in the localized language. This value will be used on converting from a boolean to a string.- Returns:
- The canonical name of
true
in this language
-
getLocalizedFalse
protected abstract java.lang.String getLocalizedFalse()
This is the string for "false" in the localized language. This value will be used on converting from a boolean to a string.- Returns:
- The canonical name of
false
in this language
-
getAllLocalizedTrueValues
protected abstract java.lang.String[] getAllLocalizedTrueValues()
This represents a list of all values accepted as "true". Any language will have more than one way to say "true", such as "yes", "y", or "1". This array should list all possibilities. Comparison is done in a case-insensitive fashion.- Returns:
- An array of all "true" strings
-
getAllLocalizedFalseValues
protected abstract java.lang.String[] getAllLocalizedFalseValues()
This represents a list of all values accepted as "false". Any language will have more than one way to say "false", such as "no", "n", or "0". This array should list all possibilities. Comparison is done in a case-insensitive fashion.- Returns:
- An array of all "false" strings
-
convert
protected java.lang.Object convert(java.lang.String value) throws CsvDataTypeMismatchException
Converts localized text into aBoolean
. The comparisons are case-insensitive.- Specified by:
convert
in classAbstractBeanField<T,I>
- Parameters:
value
- String that should represent a Boolean- Returns:
- Boolean
- Throws:
CsvDataTypeMismatchException
- If anything other than the explicitly translated pairs is found
-
convertToWrite
protected java.lang.String convertToWrite(java.lang.Object value) throws CsvDataTypeMismatchException
This method takes the current value of the field in question in the bean passed in and converts it to a string. This implementation returns true/false values in the localized language.- Overrides:
convertToWrite
in 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:
- Localized text value for "true" or "false"
- Throws:
CsvDataTypeMismatchException
- If the field is not aboolean
orBoolean
- See Also:
AbstractBeanField.write(java.lang.Object, java.lang.Object)
-
-