Class HashMapper

All Implemented Interfaces:
BoolCellProcessor, CellProcessor, 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
Author:
Dominique De Vito, James Bassett
  • Field Summary

    Fields inherited from class org.supercsv.cellprocessor.CellProcessorAdaptor

    next
  • Constructor Summary

    Constructors
    Constructor
    Description
    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(Map<Object,Object> mapping, 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(Map<Object,Object> mapping, 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.
    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

    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 org.supercsv.cellprocessor.CellProcessorAdaptor

    toString, validateInputNotNull

    Methods inherited from class java.lang.Object

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

    • HashMapper

      public HashMapper(Map<Object,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:
      NullPointerException - if mapping is null
      IllegalArgumentException - if mapping is empty
    • HashMapper

      public HashMapper(Map<Object,Object> mapping, 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 Map
      defaultValue - the value to return if no mapping is found
      Throws:
      NullPointerException - if mapping is null
      IllegalArgumentException - if mapping is empty
    • HashMapper

      public HashMapper(Map<Object,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 Map
      next - the next processor in the chain
      Throws:
      NullPointerException - if mapping or next is null
      IllegalArgumentException - if mapping is empty
    • HashMapper

      public HashMapper(Map<Object,Object> mapping, 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 Map
      defaultValue - the value to return if no mapping is found
      next - the next processor in the chain
      Throws:
      NullPointerException - if mapping or next is null
      IllegalArgumentException - if mapping is empty
  • 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