com.opencsv.bean.processor.ConvertEmptyOrBlankStringsToDefault Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opencsv Show documentation
Show all versions of opencsv Show documentation
A simple library for reading and writing CSV in Java
package com.opencsv.bean.processor;
/**
* StringProcessor that converts the empty or blank strings to a desired value string.
* This is useful when you want a default value.
*
* A sample of this can be found in the unit test ProcessorTestBean and is annotated as follows.
*
*
* @PreAssignmentProcessor(processor = ConvertEmptyOrBlankStringsToDefault.class, paramString = "-1")
* @CsvBindByName(column = "id")
* private int beanId;
*
*
* @author Scott Conway
* @since 5.4
*/
public class ConvertEmptyOrBlankStringsToDefault implements StringProcessor {
String defaultValue;
/**
* Default constructor
*/
public ConvertEmptyOrBlankStringsToDefault() {
}
@Override
public String processString(String value) {
if (value == null || value.trim().isEmpty()) {
return defaultValue;
}
return value;
}
@Override
public void setParameterString(String value) {
defaultValue = value;
}
}