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
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Class<? extends Enum<?>>
     
    private final boolean
     

    Fields inherited from class org.supercsv.cellprocessor.CellProcessorAdaptor

    next
  • Constructor Summary

    Constructors
    Constructor
    Description
    ParseEnum(Class<T> enumClass)
    Constructs a new ParseEnum processor, which converts a String to a 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.
    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.
    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
    private static void
    checkPreconditions(Class<?> enumClass)
    Checks the preconditions for creating a new ParseEnum processor.
    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 org.supercsv.cellprocessor.CellProcessorAdaptor

    toString, validateInputNotNull

    Methods inherited from class java.lang.Object

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

    • enumClass

      private final Class<? extends Enum<?>> enumClass
    • ignoreCase

      private final boolean ignoreCase
  • Constructor Details

    • ParseEnum

      public 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 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 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 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

    • checkPreconditions

      private static void checkPreconditions(Class<?> enumClass)
      Checks the preconditions for creating a new ParseEnum processor.
      Parameters:
      enumClass - the enum class
      Throws:
      NullPointerException - if enumClass is null
    • 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