Search in sources :

Example 1 with ParseDate

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

the class CellProcessorBuilder method getDateCellProcessor.

/**
 * Method to get cellprocessor for Date with constraints. These constraints
 * are evaluated against the Date field for which this cellprocessor is
 * defined.
 *
 * @param constraints
 *          map of constraints applicable to Date
 * @return CellProcessor
 */
private static CellProcessor getDateCellProcessor(Map<String, Object> constraints) {
    Boolean required = constraints.get(DelimitedSchema.REQUIRED) == null ? null : Boolean.parseBoolean((String) constraints.get(DelimitedSchema.REQUIRED));
    String format = constraints.get(DelimitedSchema.DATE_FORMAT) == null ? null : (String) constraints.get(DelimitedSchema.DATE_FORMAT);
    CellProcessor cellProcessor = null;
    String fmt = StringUtils.isNotBlank(format) ? format : "dd/MM/yyyy";
    cellProcessor = new ParseDate(fmt, false);
    if (required == null || !required) {
        cellProcessor = addOptional(cellProcessor);
    }
    return cellProcessor;
}
Also used : DoubleCellProcessor(org.supercsv.cellprocessor.ift.DoubleCellProcessor) CellProcessor(org.supercsv.cellprocessor.ift.CellProcessor) LongCellProcessor(org.supercsv.cellprocessor.ift.LongCellProcessor) ParseDate(org.supercsv.cellprocessor.ParseDate)

Example 2 with ParseDate

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

the class AbstractCsvParser method initialise.

// Initialise the properties and processors.
public void initialise(String[] properties, CellProcessor[] processors) {
    for (int i = 0; i < getFields().size(); i++) {
        FIELD_TYPE type = getFields().get(i).type;
        properties[i] = getFields().get(i).name;
        if (type == FIELD_TYPE.DOUBLE) {
            processors[i] = new Optional(new ParseDouble());
        } else if (type == FIELD_TYPE.INTEGER) {
            processors[i] = new Optional(new ParseInt());
        } else if (type == FIELD_TYPE.FLOAT) {
            processors[i] = new Optional(new ParseDouble());
        } else if (type == FIELD_TYPE.LONG) {
            processors[i] = new Optional(new ParseLong());
        } else if (type == FIELD_TYPE.SHORT) {
            processors[i] = new Optional(new ParseInt());
        } else if (type == FIELD_TYPE.STRING) {
            processors[i] = new Optional();
        } else if (type == FIELD_TYPE.CHARACTER) {
            processors[i] = new Optional(new ParseChar());
        } else if (type == FIELD_TYPE.BOOLEAN) {
            processors[i] = new Optional(new ParseChar());
        } else if (type == FIELD_TYPE.DATE) {
            processors[i] = new Optional(new ParseDate("dd/MM/yyyy"));
        }
    }
}
Also used : Optional(org.supercsv.cellprocessor.Optional) ParseLong(org.supercsv.cellprocessor.ParseLong) ParseDate(org.supercsv.cellprocessor.ParseDate) ParseDouble(org.supercsv.cellprocessor.ParseDouble) ParseInt(org.supercsv.cellprocessor.ParseInt) ParseChar(org.supercsv.cellprocessor.ParseChar)

Aggregations

ParseDate (org.supercsv.cellprocessor.ParseDate)2 Optional (org.supercsv.cellprocessor.Optional)1 ParseChar (org.supercsv.cellprocessor.ParseChar)1 ParseDouble (org.supercsv.cellprocessor.ParseDouble)1 ParseInt (org.supercsv.cellprocessor.ParseInt)1 ParseLong (org.supercsv.cellprocessor.ParseLong)1 CellProcessor (org.supercsv.cellprocessor.ift.CellProcessor)1 DoubleCellProcessor (org.supercsv.cellprocessor.ift.DoubleCellProcessor)1 LongCellProcessor (org.supercsv.cellprocessor.ift.LongCellProcessor)1