Class ParseBool

All Implemented Interfaces:
CellProcessor, StringCellProcessor

public class ParseBool extends CellProcessorAdaptor implements StringCellProcessor
Converts a String to a Boolean.

The default values for true are: "true", "1", "y", "t"

The default values for false are: "false", "0", "n", "f"

By default (unless the ignoreCase parameter is supplied on the constructor) this processor will ignore the case of the value, i.e. "true", "TRUE", and "True" will all be converted to true (likewise for false).

Prior to version 2.2.1, this processor always ignored case, so it was necessary to ensure that all supplied true/false values were lowercase, as the input was converted to lowercase before comparison against the true/false values (to handle all variations of case in the input). This is no longer required (just use the ignoreCase parameter).

Since:
1.0
Author:
Kasper B. Graversen, Dominique De Vito, James Bassett
  • Field Summary

    Fields inherited from class CellProcessorAdaptor

    next
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new ParseBool processor, which converts a String to a Boolean using the default values (ignoring case).
    ParseBool(boolean ignoreCase)
    Constructs a new ParseBool processor, which converts a String to a Boolean using the default values (ignoring case if desired).
    ParseBool(boolean ignoreCase, BoolCellProcessor next)
    Constructs a new ParseBool processor, which converts a String to a Boolean using the default values (ignoring case if desired), then calls the next processor in the chain.
    ParseBool(String[] trueValues, String[] falseValues)
    Constructs a new ParseBool processor, which converts a String to a Boolean using the supplied true/false values (ignoring case).
    ParseBool(String[] trueValues, String[] falseValues, boolean ignoreCase)
    Constructs a new ParseBool processor, which converts a String to a Boolean using the supplied true/false values (ignoring case if desired).
    ParseBool(String[] trueValues, String[] falseValues, boolean ignoreCase, BoolCellProcessor next)
    Constructs a new ParseBool processor, which converts a String to a Boolean using the supplied true/false values (ignoring case if desired), then calls the next processor in the chain.
    ParseBool(String[] trueValues, String[] falseValues, BoolCellProcessor next)
    Constructs a new ParseBool processor, which converts a String to a Boolean using the supplied true/false values (ignoring case), then calls the next processor in the chain.
    ParseBool(String trueValue, String falseValue)
    Constructs a new ParseBool processor, which converts a String to a Boolean using the supplied true/false values (ignoring case).
    ParseBool(String trueValue, String falseValue, boolean ignoreCase)
    Constructs a new ParseBool processor, which converts a String to a Boolean using the supplied true/false values (ignoring case if desired).
    ParseBool(String trueValue, String falseValue, boolean ignoreCase, BoolCellProcessor next)
    Constructs a new ParseBool processor, which converts a String to a Boolean using the supplied true/false values (ignoring case if desired), then calls the next processor in the chain.
    ParseBool(String trueValue, String falseValue, BoolCellProcessor next)
    Constructs a new ParseBool processor, which converts a String to a Boolean using the supplied true/false values (ignoring case), then calls the next processor in the chain.
    Constructs a new ParseBool processor, which converts a String to a Boolean using the default values (ignoring case), then calls the next processor in the chain.
  • Method Summary

    Modifier and Type
    Method
    Description
    execute(Object value, CsvContext context)
    This method is invoked by the framework when the processor needs to process data or check constraints.

    Methods inherited from class CellProcessorAdaptor

    toString, validateInputNotNull

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ParseBool

      public ParseBool()
      Constructs a new ParseBool processor, which converts a String to a Boolean using the default values (ignoring case).
    • ParseBool

      public ParseBool(boolean ignoreCase)
      Constructs a new ParseBool processor, which converts a String to a Boolean using the default values (ignoring case if desired).
      Parameters:
      ignoreCase - whether to ignore the case when comparing against the true/false values
      Since:
      2.2.1
    • ParseBool

      public ParseBool(BoolCellProcessor next)
      Constructs a new ParseBool processor, which converts a String to a Boolean using the default values (ignoring case), then calls the next processor in the chain.
      Parameters:
      next - the next processor in the chain
      Throws:
      NullPointerException - if next is null
    • ParseBool

      public ParseBool(boolean ignoreCase, BoolCellProcessor next)
      Constructs a new ParseBool processor, which converts a String to a Boolean using the default values (ignoring case if desired), then calls the next processor in the chain.
      Parameters:
      ignoreCase - whether to ignore the case when comparing against the true/false values
      next - the next processor in the chain
      Throws:
      NullPointerException - if next is null
      Since:
      2.2.1
    • ParseBool

      public ParseBool(String trueValue, String falseValue)
      Constructs a new ParseBool processor, which converts a String to a Boolean using the supplied true/false values (ignoring case).
      Parameters:
      trueValue - the String which represents true
      falseValue - the String which represents false
      Throws:
      NullPointerException - if trueValue or falseValue is null
    • ParseBool

      public ParseBool(String trueValue, String falseValue, boolean ignoreCase)
      Constructs a new ParseBool processor, which converts a String to a Boolean using the supplied true/false values (ignoring case if desired).
      Parameters:
      trueValue - the String which represents true
      falseValue - the String which represents false
      ignoreCase - whether to ignore the case when comparing against the true/false values
      Throws:
      NullPointerException - if trueValue or falseValue is null
      Since:
      2.2.1
    • ParseBool

      public ParseBool(String[] trueValues, String[] falseValues)
      Constructs a new ParseBool processor, which converts a String to a Boolean using the supplied true/false values (ignoring case).
      Parameters:
      trueValues - the array of Strings which represent true
      falseValues - the array of Strings which represent false
      Throws:
      IllegalArgumentException - if trueValues or falseValues is empty
      NullPointerException - if trueValues or falseValues is null
    • ParseBool

      public ParseBool(String[] trueValues, String[] falseValues, boolean ignoreCase)
      Constructs a new ParseBool processor, which converts a String to a Boolean using the supplied true/false values (ignoring case if desired).
      Parameters:
      trueValues - the array of Strings which represent true
      falseValues - the array of Strings which represent false
      ignoreCase - whether to ignore the case when comparing against the true/false values
      Throws:
      IllegalArgumentException - if trueValues or falseValues is empty
      NullPointerException - if trueValues or falseValues is null
      Since:
      2.2.1
    • ParseBool

      public ParseBool(String trueValue, String falseValue, BoolCellProcessor next)
      Constructs a new ParseBool processor, which converts a String to a Boolean using the supplied true/false values (ignoring case), then calls the next processor in the chain.
      Parameters:
      trueValue - the String which represents true
      falseValue - the String which represents false
      next - the next processor in the chain
      Throws:
      NullPointerException - if trueValue, falseValue or next is null
    • ParseBool

      public ParseBool(String trueValue, String falseValue, boolean ignoreCase, BoolCellProcessor next)
      Constructs a new ParseBool processor, which converts a String to a Boolean using the supplied true/false values (ignoring case if desired), then calls the next processor in the chain.
      Parameters:
      trueValue - the String which represents true
      falseValue - the String which represents false
      ignoreCase - whether to ignore the case when comparing against the true/false values
      next - the next processor in the chain
      Throws:
      NullPointerException - if trueValue, falseValue or next is null
      Since:
      2.2.1
    • ParseBool

      public ParseBool(String[] trueValues, String[] falseValues, BoolCellProcessor next)
      Constructs a new ParseBool processor, which converts a String to a Boolean using the supplied true/false values (ignoring case), then calls the next processor in the chain.
      Parameters:
      trueValues - the array of Strings which represent true
      falseValues - the array of Strings which represent false
      next - the next processor in the chain
      Throws:
      IllegalArgumentException - if trueValues or falseValues is empty
      NullPointerException - if trueValues, falseValues, or next is null
    • ParseBool

      public ParseBool(String[] trueValues, String[] falseValues, boolean ignoreCase, BoolCellProcessor next)
      Constructs a new ParseBool processor, which converts a String to a Boolean using the supplied true/false values (ignoring case if desired), then calls the next processor in the chain.
      Parameters:
      trueValues - the array of Strings which represent true
      falseValues - the array of Strings which represent false
      ignoreCase - whether to ignore the case when comparing against the true/false values
      next - the next processor in the chain
      Throws:
      IllegalArgumentException - if trueValues or falseValues is empty
      NullPointerException - if trueValues, falseValues, or next is null
      Since:
      2.2.1
  • Method Details

    • execute

      public Object execute(Object value, CsvContext context)
      This method is invoked by the framework when the processor needs to process data or check constraints.
      Specified by:
      execute in interface CellProcessor
      Parameters:
      value - the value to be processed
      context - the CSV context
      Returns:
      the result of cell processor execution
      Throws:
      SuperCsvCellProcessorException - if value is null, not a String, or can't be parsed to a Boolean