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

The following examples show how to use org.apache.commons.csv.CSVRecord#isMapped() . 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: CsvDatabaseImporter.java    From budget-watch with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Extract a string from the items array. The index into the array
 * is determined by looking up the index in the fields map using the
 * "key" as the key. If no such key exists, defaultValue is returned
 * if it is not null. Otherwise, a FormatException is thrown.
 */
private String extractString(String key, CSVRecord record, String defaultValue)
        throws FormatException
{
    String toReturn = defaultValue;

    if(record.isMapped(key))
    {
        toReturn = record.get(key);
    }
    else
    {
        if(defaultValue == null)
        {
            throw new FormatException("Field not used but expected: " + key);
        }
    }

    return toReturn;
}
 
Example 2
Source File: CsvDatabaseImporter.java    From budget-watch with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Extract an integer from the items array. The index into the array
 * is determined by looking up the index in the fields map using the
 * "key" as the key. If no such key exists, or the data is not a valid
 * int, a FormatException is thrown.
 */
private int extractInt(String key, CSVRecord record)
        throws FormatException
{
    if(record.isMapped(key) == false)
    {
        throw new FormatException("Field not used but expected: " + key);
    }

    try
    {
        return Integer.parseInt(record.get(key));
    }
    catch(NumberFormatException e)
    {
        throw new FormatException("Failed to parse field: " + key, e);
    }
}
 
Example 3
Source File: CsvDatabaseImporter.java    From budget-watch with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Extract an double from the items array. The index into the array
 * is determined by looking up the index in the fields map using the
 * "key" as the key. If no such key exists, or the data is not a valid
 * double, a FormatException is thrown.
 */
private double extractDouble(String key, CSVRecord record)
        throws FormatException
{
    if(record.isMapped(key) == false)
    {
        throw new FormatException("Field not used but expected: " + key);
    }

    try
    {
        return Double.parseDouble(record.get(key));
    }
    catch(NumberFormatException e)
    {
        throw new FormatException("Failed to parse field: " + key, e);
    }
}
 
Example 4
Source File: CsvDatabaseImporter.java    From budget-watch with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Extract an long from the items array. The index into the array
 * is determined by looking up the index in the fields map using the
 * "key" as the key. If no such key exists, or the data is not a valid
 * long, a FormatException is thrown.
 */
private long extractLong(String key, CSVRecord record)
        throws FormatException
{
    if(record.isMapped(key) == false)
    {
        throw new FormatException("Field not used but expected: " + key);
    }

    try
    {
        return Long.parseLong(record.get(key));
    }
    catch(NumberFormatException e)
    {
        throw new FormatException("Failed to parse field: " + key, e);
    }
}
 
Example 5
Source File: TckResultsComparator.java    From openCypher with Apache License 2.0 5 votes vote down vote up
private static Scenarios getFeaturesFromCsv(File reportFile) throws IOException {
    Reader in = new FileReader(reportFile);
    Iterable<CSVRecord> records = CSVFormat.DEFAULT
        .withFirstRecordAsHeader()
        .parse(in);

    List<Scenario> scenarios = new ArrayList<>();
    for (CSVRecord r : records) {
        boolean failed = !r.isMapped("status") || !"passed".equalsIgnoreCase(r.get("status"));
        Scenario scenario = new Scenario(r.get("feature"), r.get("scenario"), failed);
        scenarios.add(scenario);
    }

    return Scenarios.create(scenarios);
}
 
Example 6
Source File: DtoFromRecordBuilder.java    From CineLog with GNU General Public License v3.0 4 votes vote down vote up
protected String getId(CSVRecord csvRecord) {
    return csvRecord.isMapped("id") ? csvRecord.get("id") : null;
}
 
Example 7
Source File: DtoFromRecordBuilder.java    From CineLog with GNU General Public License v3.0 4 votes vote down vote up
protected int getMaxRating(CSVRecord csvRecord) {
    return csvRecord.isMapped("max_rating") ?
            formatInteger(csvRecord.get("max_rating")) :
            formatInteger(preferencesWrapper.getStringPreference(context, "default_max_rate_value", "5"));
}