Package org.supercsv.cellprocessor
Class ParseEnum
java.lang.Object
org.supercsv.cellprocessor.CellProcessorAdaptor
org.supercsv.cellprocessor.ParseEnum
- All Implemented Interfaces:
CellProcessor
,StringCellProcessor
Converts a String to an Enum. Patch originally supplied by Adrian Ber.
- Since:
- 2.2.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final boolean
Fields inherited from class org.supercsv.cellprocessor.CellProcessorAdaptor
next
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new ParseEnum processor, which converts a String to a Enum.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 TypeMethodDescriptionprivate 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
-
Field Details
-
enumClass
-
ignoreCase
private final boolean ignoreCase
-
-
Constructor Details
-
ParseEnum
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
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:
NullPointerException
- if enumClass is null
-
ParseEnum
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:
NullPointerException
- if enumClass or next is null
-
ParseEnum
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:
NullPointerException
- if enumClass or next is null
-
-
Method Details
-
checkPreconditions
Checks the preconditions for creating a new ParseEnum processor.- Parameters:
enumClass
- the enum class- Throws:
NullPointerException
- if enumClass is null
-
execute
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
-