Search in sources :

Example 1 with Strlen

use of org.supercsv.cellprocessor.constraint.Strlen in project apex-malhar by apache.

the class CellProcessorBuilder method getStringCellProcessor.

/**
 * Method to get cellprocessor for String with constraints. These constraints
 * are evaluated against the String field for which this cellprocessor is
 * defined.
 *
 * @param constraints
 *          map of constraints applicable to String
 * @return CellProcessor
 */
private static CellProcessor getStringCellProcessor(Map<String, Object> constraints) {
    Boolean required = constraints.get(DelimitedSchema.REQUIRED) == null ? null : Boolean.parseBoolean((String) constraints.get(DelimitedSchema.REQUIRED));
    Integer strLen = constraints.get(DelimitedSchema.LENGTH) == null ? null : Integer.parseInt((String) constraints.get(DelimitedSchema.LENGTH));
    Integer minLength = constraints.get(DelimitedSchema.MIN_LENGTH) == null ? null : Integer.parseInt((String) constraints.get(DelimitedSchema.MIN_LENGTH));
    Integer maxLength = constraints.get(DelimitedSchema.MAX_LENGTH) == null ? null : Integer.parseInt((String) constraints.get(DelimitedSchema.MAX_LENGTH));
    String equals = constraints.get(DelimitedSchema.EQUALS) == null ? null : (String) constraints.get(DelimitedSchema.EQUALS);
    String pattern = constraints.get(DelimitedSchema.REGEX_PATTERN) == null ? null : (String) constraints.get(DelimitedSchema.REGEX_PATTERN);
    CellProcessor cellProcessor = null;
    if (StringUtils.isNotBlank(equals)) {
        cellProcessor = new Equals(equals);
    } else if (StringUtils.isNotBlank(pattern)) {
        cellProcessor = new StrRegEx(pattern);
    } else if (strLen != null) {
        cellProcessor = new Strlen(strLen);
    } else if (maxLength != null || minLength != null) {
        Long min = minLength == null ? 0L : minLength;
        Long max = maxLength == null ? LMinMax.MAX_LONG : maxLength;
        cellProcessor = new StrMinMax(min, max);
    }
    if (required == null || !required) {
        cellProcessor = addOptional(cellProcessor);
    }
    return cellProcessor;
}
Also used : Equals(org.supercsv.cellprocessor.constraint.Equals) ParseLong(org.supercsv.cellprocessor.ParseLong) DoubleCellProcessor(org.supercsv.cellprocessor.ift.DoubleCellProcessor) CellProcessor(org.supercsv.cellprocessor.ift.CellProcessor) LongCellProcessor(org.supercsv.cellprocessor.ift.LongCellProcessor) StrRegEx(org.supercsv.cellprocessor.constraint.StrRegEx) StrMinMax(org.supercsv.cellprocessor.constraint.StrMinMax) Strlen(org.supercsv.cellprocessor.constraint.Strlen)

Aggregations

ParseLong (org.supercsv.cellprocessor.ParseLong)1 Equals (org.supercsv.cellprocessor.constraint.Equals)1 StrMinMax (org.supercsv.cellprocessor.constraint.StrMinMax)1 StrRegEx (org.supercsv.cellprocessor.constraint.StrRegEx)1 Strlen (org.supercsv.cellprocessor.constraint.Strlen)1 CellProcessor (org.supercsv.cellprocessor.ift.CellProcessor)1 DoubleCellProcessor (org.supercsv.cellprocessor.ift.DoubleCellProcessor)1 LongCellProcessor (org.supercsv.cellprocessor.ift.LongCellProcessor)1