Package org.supercsv.cellprocessor
Class HashMapper
- java.lang.Object
-
- org.supercsv.cellprocessor.CellProcessorAdaptor
-
- org.supercsv.cellprocessor.HashMapper
-
- All Implemented Interfaces:
BoolCellProcessor
,CellProcessor
,DateCellProcessor
,DoubleCellProcessor
,LongCellProcessor
,StringCellProcessor
public class HashMapper extends CellProcessorAdaptor implements BoolCellProcessor, DateCellProcessor, DoubleCellProcessor, LongCellProcessor, StringCellProcessor
Maps from one object to another, by looking up a Map with the input as the key, and returning its corresponding value.- Since:
- 1.50
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Object
defaultValue
private java.util.Map<java.lang.Object,java.lang.Object>
mapping
-
Fields inherited from class org.supercsv.cellprocessor.CellProcessorAdaptor
next
-
-
Constructor Summary
Constructors Constructor Description HashMapper(java.util.Map<java.lang.Object,java.lang.Object> mapping)
Constructs a new HashMapper processor, which maps from one object to another, by looking up a Map with the input as the key, and returning its corresponding value.HashMapper(java.util.Map<java.lang.Object,java.lang.Object> mapping, java.lang.Object defaultValue)
Constructs a new HashMapper processor, which maps from one object to another, by looking up a Map with the input as the key, and returning its corresponding value.HashMapper(java.util.Map<java.lang.Object,java.lang.Object> mapping, java.lang.Object defaultValue, CellProcessor next)
Constructs a new HashMapper processor, which maps from one object to another, by looking up a Map with the input as the key, and returning its corresponding value.HashMapper(java.util.Map<java.lang.Object,java.lang.Object> mapping, CellProcessor next)
Constructs a new HashMapper processor, which maps from one object to another, by looking up a Map with the input as the key, and returning its corresponding value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static void
checkPreconditions(java.util.Map<java.lang.Object,java.lang.Object> mapping)
Checks the preconditions for creating a new HashMapper 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
-
HashMapper
public HashMapper(java.util.Map<java.lang.Object,java.lang.Object> mapping)
Constructs a new HashMapper processor, which maps from one object to another, by looking up a Map with the input as the key, and returning its corresponding value. If no mapping is found, then null is returned.- Parameters:
mapping
- the Map- Throws:
java.lang.NullPointerException
- if mapping is nulljava.lang.IllegalArgumentException
- if mapping is empty
-
HashMapper
public HashMapper(java.util.Map<java.lang.Object,java.lang.Object> mapping, java.lang.Object defaultValue)
Constructs a new HashMapper processor, which maps from one object to another, by looking up a Map with the input as the key, and returning its corresponding value. If no mapping is found, then the supplied default value is returned.- Parameters:
mapping
- the MapdefaultValue
- the value to return if no mapping is found- Throws:
java.lang.NullPointerException
- if mapping is nulljava.lang.IllegalArgumentException
- if mapping is empty
-
HashMapper
public HashMapper(java.util.Map<java.lang.Object,java.lang.Object> mapping, CellProcessor next)
Constructs a new HashMapper processor, which maps from one object to another, by looking up a Map with the input as the key, and returning its corresponding value. If no mapping is found, then null is returned. Regardless of whether a mapping is found, the next processor in the chain will be called.- Parameters:
mapping
- the Mapnext
- the next processor in the chain- Throws:
java.lang.NullPointerException
- if mapping or next is nulljava.lang.IllegalArgumentException
- if mapping is empty
-
HashMapper
public HashMapper(java.util.Map<java.lang.Object,java.lang.Object> mapping, java.lang.Object defaultValue, CellProcessor next)
Constructs a new HashMapper processor, which maps from one object to another, by looking up a Map with the input as the key, and returning its corresponding value. If no mapping is found, then the supplied default value is returned. Regardless of whether a mapping is found, the next processor in the chain will be called.- Parameters:
mapping
- the MapdefaultValue
- the value to return if no mapping is foundnext
- the next processor in the chain- Throws:
java.lang.NullPointerException
- if mapping or next is nulljava.lang.IllegalArgumentException
- if mapping is empty
-
-
Method Detail
-
checkPreconditions
private static void checkPreconditions(java.util.Map<java.lang.Object,java.lang.Object> mapping)
Checks the preconditions for creating a new HashMapper processor.- Parameters:
mapping
- the Map- Throws:
java.lang.NullPointerException
- if mapping is nulljava.lang.IllegalArgumentException
- if mapping is empty
-
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
-
-