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 manipulated
I - 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.
  • Constructor Details

    • ConverterLanguageToBoolean

      public ConverterLanguageToBoolean()
  • Method Details

    • getLocalizedTrue

      protected abstract 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 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 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 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 Object convert(String value) throws CsvDataTypeMismatchException
      Converts localized text into a Boolean. The comparisons are case-insensitive.
      Specified by:
      convert in class AbstractBeanField<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 String convertToWrite(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 class AbstractBeanField<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 a boolean or Boolean
      See Also: