Class ParseEnum

All Implemented Interfaces:
CellProcessor, StringCellProcessor

public class ParseEnum extends CellProcessorAdaptor implements StringCellProcessor
Converts a String to an Enum. Patch originally supplied by Adrian Ber.
Since:
2.2.0
Author:
James Bassett
  • Field Summary

    Fields inherited from class CellProcessorAdaptor

    next
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     <T extends Enum<?>>
    ParseEnum(Class<T> enumClass)
    Constructs a new ParseEnum processor, which converts a String to a Enum.
     <T extends Enum<?>>
    ParseEnum(Class<T> enumClass, boolean ignoreCase)
    Constructs a new ParseEnum processor, which converts a String to a Enum, ignoring the case of the input (or not) depending on the supplied flag.
     <T extends Enum<?>>
    ParseEnum(Class<T> enumClass, boolean ignoreCase, CellProcessor next)
    Constructs a new ParseEnum processor, which converts a String to a Enum, ignoring the case of the input (or not) depending on the supplied flag, then calls the next processor in the chain.
     <T extends Enum<?>>
    ParseEnum(Class<T> enumClass, CellProcessor next)
    Constructs a new ParseEnum processor, which converts a String to a Enum 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

    • ParseEnum

      public <T extends Enum<?>> ParseEnum(Class<T> enumClass)
      Constructs a new ParseEnum processor, which converts a String to a Enum.
      Type Parameters:
      T - the Enum type
      Parameters:
      enumClass - the enum class to convert to
      Throws:
      NullPointerException - if enumClass is null
    • ParseEnum

      public <T extends Enum<?>> ParseEnum(Class<T> enumClass, boolean ignoreCase)
      Constructs a new ParseEnum processor, which converts a String to a Enum, ignoring the case of the input (or not) depending on the supplied flag.
      Type Parameters:
      T - the Enum type
      Parameters:
      enumClass - the enum class to convert to
      ignoreCase - whether to ignore the case of the input
      Throws:
      NullPointerException - if enumClass is null
    • ParseEnum

      public <T extends Enum<?>> ParseEnum(Class<T> enumClass, CellProcessor next)
      Constructs a new ParseEnum processor, which converts a String to a Enum then calls the next processor in the chain.
      Type Parameters:
      T - the Enum type
      Parameters:
      enumClass - the enum class to convert to
      next - the next processor in the chain
      Throws:
      NullPointerException - if enumClass or next is null
    • ParseEnum

      public <T extends Enum<?>> ParseEnum(Class<T> enumClass, boolean ignoreCase, CellProcessor next)
      Constructs a new ParseEnum processor, which converts a String to a Enum, ignoring the case of the input (or not) depending on the supplied flag, then calls the next processor in the chain.
      Type Parameters:
      T - the Enum type
      Parameters:
      enumClass - the enum class to convert to
      ignoreCase - whether to ignore the case of the input
      next - the next processor in the chain
      Throws:
      NullPointerException - if enumClass or next is null
  • 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 or can't be parsed as an Enum