2.17.2: 2011-06-17

net.sf.basedb.util.parser
Class ColumnMapper

java.lang.Object
  extended by net.sf.basedb.util.parser.ColumnMapper
All Implemented Interfaces:
Mapper

public class ColumnMapper
extends Object
implements Mapper

Returns the string found in the column given by the index set in the constructor. If the index is larger than the number of columns, an empty string is returned.

Version:
2.0
Author:
nicklas
Last modified
$Date: 2008-09-11 22:08:14 +0200 (Thu, 11 Sep 2008) $

Field Summary
private  int index
           
private  String name
           
private  boolean nullIfException
           
private  NumberFormat parser
           
private  ParsePosition pos
           
 
Constructor Summary
ColumnMapper(int index, String name)
          Create a new column mapper.
ColumnMapper(int index, String name, NumberFormat parser)
          Deprecated. Use ColumnMapper(int, String, NumberFormat, boolean)
ColumnMapper(int index, String name, NumberFormat parser, boolean nullIfException)
          Create a new column mapper using a specific number format.
 
Method Summary
private  Double getDouble(String value)
           
 Float getFloat(FlatFileParser.Data data)
          Get the value for the line of data as a float.
 Integer getInt(FlatFileParser.Data data)
          Get the value for the line of data as an integer.
 String getValue(FlatFileParser.Data data)
          Get the value in the data objects column with the index specified in the constructor.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

index

private final int index

name

private final String name

parser

private final NumberFormat parser

pos

private final ParsePosition pos

nullIfException

private final boolean nullIfException
Constructor Detail

ColumnMapper

public ColumnMapper(int index,
                    String name)
Create a new column mapper.

Parameters:
index - The index of the data column to use, starting at 0
name - An optional name of the column, use in the toString method

ColumnMapper

public ColumnMapper(int index,
                    String name,
                    NumberFormat parser)
Deprecated. Use ColumnMapper(int, String, NumberFormat, boolean)

Create a new column mapper using a specific number format.


ColumnMapper

public ColumnMapper(int index,
                    String name,
                    NumberFormat parser,
                    boolean nullIfException)
Create a new column mapper using a specific number format.

Parameters:
index - The index of the data column to use, starting at 0
name - An optional name of the column, use in the toString method
nullIfException - If TRUE, the mapper returns null for unparsable numeric values, otherwise an excption is thrown
parser - The parser to use or null to use Double.valueOf()
Since:
2.4
Method Detail

getValue

public String getValue(FlatFileParser.Data data)
Get the value in the data objects column with the index specified in the constructor.

Specified by:
getValue in interface Mapper
Parameters:
data - The line of data
Returns:
The value or null if the index is out of bounds

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

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

toString

public String toString()
Overrides:
toString in class Object

getDouble

private Double getDouble(String value)

2.17.2: 2011-06-17