Java Code Examples for org.apache.commons.csv.CSVRecord#isConsistent()

The following examples show how to use org.apache.commons.csv.CSVRecord#isConsistent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CsvParser.java    From RepoSense with MIT License 6 votes vote down vote up
/**
 * Returns true if {@code record} does not contain the same number of columns as the header or contains missing
 * values at the mandatory columns in CSV format.
 */
private boolean isLineMalformed(CSVRecord record) {
    if (!record.isConsistent()) {
        logger.warning(String.format(MESSAGE_MALFORMED_LINE_FORMAT, getLineNumber(record),
                csvFilePath.getFileName(), getRowContentAsRawString(record)));
        return true;
    }
    for (int position : mandatoryPositions()) {
        if (record.get(position).isEmpty()) {
            logger.warning(String.format(MESSAGE_MALFORMED_LINE_FORMAT, getLineNumber(record),
                    csvFilePath.getFileName(), getRowContentAsRawString(record)));
            return true;
        }
    }
    return false;
}
 
Example 2
Source File: DSV.java    From validatar with Apache License 2.0 5 votes vote down vote up
private static void addRow(CSVRecord record, Result result, Map<String, Type> header) {
    if (!record.isConsistent()) {
        log.warn("Record does not have the same number of fields as the header mapping. Skipping record: {}", record);
        return;
    }
    for (Map.Entry<String, Type> field : header.entrySet()) {
        String fieldName = field.getKey();
        TypedObject fieldValue = getTyped(field.getValue(), record.get(fieldName));
        result.addColumnRow(fieldName, fieldValue);
    }
}