Package com.opencsv.bean
Interface CsvToBeanFilter
-
@Deprecated public interface CsvToBeanFilter
Deprecated.Please useBeanVerifier
instead.Filters allow lines of input to be ignored before a bean is created.Using a filter means you are looking at the data from the input after it has been parsed, but before a bean has been created and populated.
Filters must be thread-safe.
Here's an example showing how to use
CsvToBean
with a column name mapping and line filtering. It assumes that there is a class namedFeature
defined with setterssetName(String)
andsetState(String)
. The FEATURE_NAME and STATE columns in the CSV file will be used. Any additional columns will be ignored. The filter will eliminate any lines where the STATE value is "production".private class StateFilter implements CsvToBeanFilter { private final MappingStrategy strategy; public StateFilter(MappingStrategy strategy) { this.strategy = strategy; } public boolean allowLine(String[] line) { String value = line[1]; boolean result = !"production".equals(value); return result; } } public List<Feature> parseCsv(InputStreamReader streamReader) { HeaderColumnNameTranslateMappingStrategy<Feature> strategy = new HeaderColumnNameTranslateMappingStrategy(); Map<String, String> columnMap = new HashMap(); columnMap.put("FEATURE_NAME", "name"); columnMap.put("STATE", "state"); strategy.setColumnMapping(columnMap); strategy.setType(Feature.class); CSVReader reader = new CSVReader(streamReader); CsvToBeanFilter filter = new StateFilter(strategy); return new CsvToBean().parse(strategy, reader, filter); }
- See Also:
BeanVerifier
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description boolean
allowLine(java.lang.String[] line)
Deprecated.Determines if a line from the CSV file will be included in the output ofCsvToBean
.
-
-
-
Method Detail
-
allowLine
boolean allowLine(java.lang.String[] line)
Deprecated.Determines if a line from the CSV file will be included in the output ofCsvToBean
.- Parameters:
line
- A line of data from the CSV file- Returns:
- True if the line is to be included in the output. Otherwise, false.
-
-