All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gr.uom.java.xmi.util.CsvUtils Maven / Gradle / Ivy

package gr.uom.java.xmi.util;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class CsvUtils {
    public static List extractParametersFromCsv(String s) {
        List parameters = new ArrayList<>();
        String[] tokens = s.split(",");
        for (String token : tokens) {
            String trimmed = token.trim();
            if (trimmed.startsWith("\"")) {
                trimmed = trimmed.substring(1, trimmed.length());
            }
            if (trimmed.endsWith("\"")) {
                trimmed = trimmed.substring(0, trimmed.length() - 1);
            }
            parameters.add(trimmed);
        }
        return parameters;
    }

    public static List> extractParametersFromCsvFile(List tests) {
        List> testParameters = new ArrayList<>();
        for (String test : tests) {
            List parameters = extractParametersFromCsv(test);
            testParameters.add(parameters);
        }
        return testParameters;
    }

    public static List readLinesOfCsvFile(String csvFile) throws IOException {
        List parameters = new ArrayList<>();
        BufferedReader br = new BufferedReader(new FileReader(csvFile));
        String line = br.readLine();
        while (line != null) {
            parameters.add(line);
            line = br.readLine();
        }
        br.close();
        return parameters;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy