Package org.supercsv.cellprocessor
Class ParseEnum
- java.lang.Object
-
- org.supercsv.cellprocessor.CellProcessorAdaptor
-
- org.supercsv.cellprocessor.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 java.lang.Class<? extends java.lang.Enum<?>>
enumClass
private boolean
ignoreCase
-
Fields inherited from class org.supercsv.cellprocessor.CellProcessorAdaptor
next
-
-
Constructor Summary
Constructors Constructor Description ParseEnum(java.lang.Class<T> enumClass)
Constructs a new ParseEnum processor, which converts a String to a Enum.ParseEnum(java.lang.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(java.lang.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(java.lang.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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
checkPreconditions(java.lang.Class<?> enumClass)
Checks the preconditions for creating a new ParseEnum processor.java.lang.Object
execute(java.lang.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
-
-
-
-
Constructor Detail
-
ParseEnum
public ParseEnum(java.lang.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:
java.lang.NullPointerException
- if enumClass is null
-
ParseEnum
public ParseEnum(java.lang.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 toignoreCase
- whether to ignore the case of the input- Throws:
java.lang.NullPointerException
- if enumClass is null
-
ParseEnum
public ParseEnum(java.lang.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 tonext
- the next processor in the chain- Throws:
java.lang.NullPointerException
- if enumClass or next is null
-
ParseEnum
public ParseEnum(java.lang.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 toignoreCase
- whether to ignore the case of the inputnext
- the next processor in the chain- Throws:
java.lang.NullPointerException
- if enumClass or next is null
-
-
Method Detail
-
checkPreconditions
private static void checkPreconditions(java.lang.Class<?> enumClass)
Checks the preconditions for creating a new ParseEnum processor.- Parameters:
enumClass
- the enum class- Throws:
java.lang.NullPointerException
- if enumClass is null
-
execute
public java.lang.Object execute(java.lang.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 interfaceCellProcessor
- Parameters:
value
- the value to be processedcontext
- the CSV context- Returns:
- the result of cell processor execution
- Throws:
SuperCsvCellProcessorException
- if value is null or can't be parsed as an Enum
-
-