fatiador.parser.NumericParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fatiador Show documentation
Show all versions of fatiador Show documentation
Convert flat strings to Java objects and vice-versa.
The newest version!
package fatiador.parser;
import org.apache.commons.lang3.StringUtils;
import fatiador.FlatField;
import fatiador.ParserArgumentException;
/**
* Numeric Type parse values with spaces at the beginning and at the end
*/
public class NumericParser implements FieldParser {
private static final String ERROR_MESSAGE = "Field [%s] not parsable. Value [%s] not convertible to Numeric.";
@Override
public String parse(String rawValue, FlatField flatField) throws ParserArgumentException {
if (StringUtils.isBlank(rawValue)) {
return "0";
}
rawValue = rawValue.trim();
if (!rawValue.matches("^[0-9]+$")) {
String msg = String.format(ERROR_MESSAGE, flatField.getName(), rawValue);
throw new ParserArgumentException(msg);
}
return rawValue;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy