Class ConstantMapper

java.lang.Object
net.sf.basedb.util.parser.ConstantMapper
All Implemented Interfaces:
Mapper

public class ConstantMapper
extends Object
implements Mapper
A constant string mapper. The getValue() always return the same string which is set in the contructor.
Version:
2.0
Author:
nicklas
Last modified
$Date: 2019-03-21 12:50:52 +0100 (tors, 21 mars 2019) $
  • Field Details

    • constant

      private final String constant
    • parser

      private final NumberFormat parser
    • dateParser

      private final Formatter<Date> dateParser
    • nullIfException

      private final boolean nullIfException
    • needToParseNumeric

      private boolean needToParseNumeric
    • needToParseDate

      private boolean needToParseDate
    • asDouble

      private Double asDouble
    • asLong

      private Long asLong
    • asDate

      private Date asDate
    • parseException

      private RuntimeException parseException
  • Constructor Details

    • ConstantMapper

      public ConstantMapper​(String constant)
      Create a constant mapper.
      Parameters:
      constant - The constant expression.
    • ConstantMapper

      public ConstantMapper​(String constant, NumberFormat parser, boolean nullIfException)
      Create a constant mapper using a specific number formatter as it's parser.
      Parameters:
      constant - The constant expression
      parser - The number format to use or null to use Double.valueOf()
      nullIfException - If TRUE, the mapper returns null for unparsable numeric values, otherwise an excption is thrown
      Since:
      2.4
    • ConstantMapper

      public ConstantMapper​(String constant, NumberFormat parser, Formatter<Date> dateParser, boolean nullIfException)
      Create a constant mapper using a specific number formatter as it's parser.
      Parameters:
      constant - The constant expression
      parser - The number format to use or null to use Double.valueOf()
      nullIfException - If TRUE, the mapper returns null for unparsable numeric values, otherwise an excption is thrown
      Since:
      3.15
    • ConstantMapper

      public ConstantMapper​(Integer constant)
    • ConstantMapper

      public ConstantMapper​(Float constant)
    • ConstantMapper

      public ConstantMapper​(Date constant, Formatter<Date> dateParser)
  • Method Details

    • getValue

      @Deprecated public String getValue​(FlatFileParser.Data data)
      Deprecated.
      Description copied from interface: Mapper
      Get the value for the line of data.
      Specified by:
      getValue in interface Mapper
      Parameters:
      data - The line of data
      Returns:
      The string set in the constructor
    • getString

      public String getString​(FlatFileParser.Data data)
      Description copied from interface: Mapper
      Get the value for the line of data as a string.
      Specified by:
      getString in interface Mapper
      Parameters:
      data - The line of data
      Returns:
      A string value
    • getInt

      public Integer getInt​(FlatFileParser.Data data)
      Description copied from interface: Mapper
      Get the value for the line of data as an integer.
      Specified by:
      getInt in interface Mapper
      Parameters:
      data - The line of data
      Returns:
      The value as an integer
    • getLong

      public Long getLong​(FlatFileParser.Data data)
      Description copied from interface: Mapper
      Get the value for the line of data as a long.
      Specified by:
      getLong in interface Mapper
      Parameters:
      data - The line of data
      Returns:
      The value as an long
    • getFloat

      public Float getFloat​(FlatFileParser.Data data)
      Description copied from interface: Mapper
      Get the value for the line of data as a float.
      Specified by:
      getFloat in interface Mapper
      Parameters:
      data - The line of data
      Returns:
      The value as a float
    • getDouble

      public Double getDouble​(FlatFileParser.Data data)
      Description copied from interface: Mapper
      Get the value for the line of data as a double.
      Specified by:
      getDouble in interface Mapper
      Parameters:
      data - The line of data
      Returns:
      The value as a double
    • getDate

      public Date getDate​(FlatFileParser.Data data)
      Description copied from interface: Mapper
      Get the value for the line of data as a date.
      Specified by:
      getDate in interface Mapper
      Parameters:
      data - The line of data
      Returns:
      The value as a date
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • parseNumeric

      private void parseNumeric()
    • parseDate

      private void parseDate()