Package net.sf.basedb.util.parser
Class ColFunction
java.lang.Object
net.sf.basedb.util.parser.ColFunction
- All Implemented Interfaces:
JepFunction
,org.nfunk.jep.function.PostfixMathCommandI
Adds a
col()
function to Jep. The col function is used with the
FlatFileParser
to get the value of a data column. The argument to
the col function is either the column name or index (0-based). Use the
FlatFileParser.getMapper(String)
with an argument starting with an equal
sign to create a mapper that uses Jep.
FlatFileParser ffp = ... Mapper diameterMapper = ffp.getMapper("=col('Radius') * 2"); while (ffp.hasMoreData()) { Data data = ffp.nextData(); float diameter = diameterMapper.getFloat(data); }
- Version:
- 2.0
- Author:
- nicklas
- Last modified
- $Date: 2019-03-21 13:37:48 +0100 (tors, 21 mars 2019) $
-
Field Summary
Modifier and TypeFieldDescriptionprivate FlatFileParser.Data
private boolean
private Type
private final NumberFormat
private final ParsePosition
-
Constructor Summary
ConstructorDescriptionColFunction
(List<String> columnHeaders, NumberFormat numberFormat) ColFunction
(List<String> columnHeaders, NumberFormat numberFormat, Formatter<Date> dateFormat) ColFunction
(Map<String, Integer> columnHeaders, NumberFormat numberFormat) ColFunction
(Map<String, Integer> columnHeaders, NumberFormat numberFormat, Formatter<Date> dateFormat) -
Method Summary
Modifier and TypeMethodDescriptionboolean
checkNumberOfParameters
(int n) private Integer
findColumn
(String regex) Find column index by checking each column header against a regular expression.Get the name of this function.int
void
void
setCurNumberOfParameters
(int n) void
setData
(FlatFileParser.Data data, Type valueType) void
setIgnoreNonExistingColumns
(boolean ignoreNonExistingColumns) Set to TRUE to ignore non-existing columns.
-
Field Details
-
columnHeaders
-
numberFormat
-
dateFormat
-
pos
-
data
-
nextValueType
-
ignoreNonExistingColumns
private boolean ignoreNonExistingColumns
-
-
Constructor Details
-
Method Details
-
getFunctionName
Description copied from interface:JepFunction
Get the name of this function. It is used when registering the function with aJEP
parser.- Specified by:
getFunctionName
in interfaceJepFunction
- Returns:
- The string "col"
- See Also:
-
getNumberOfParameters
public int getNumberOfParameters()- Specified by:
getNumberOfParameters
in interfaceorg.nfunk.jep.function.PostfixMathCommandI
- Returns:
- Always 1
-
setCurNumberOfParameters
public void setCurNumberOfParameters(int n) - Specified by:
setCurNumberOfParameters
in interfaceorg.nfunk.jep.function.PostfixMathCommandI
-
checkNumberOfParameters
public boolean checkNumberOfParameters(int n) - Specified by:
checkNumberOfParameters
in interfaceorg.nfunk.jep.function.PostfixMathCommandI
-
run
- Specified by:
run
in interfaceorg.nfunk.jep.function.PostfixMathCommandI
- Throws:
ParseException
-
setIgnoreNonExistingColumns
public void setIgnoreNonExistingColumns(boolean ignoreNonExistingColumns) Set to TRUE to ignore non-existing columns. Set to FALSE to throw an exception (default).- Since:
- 2.6
-
setData
-
findColumn
Find column index by checking each column header against a regular expression. The first match found is returned. The map is updated with a new regex -> index entry.- Returns:
- The column index or null if no column is found or if the string is not a valid regular expression
-