Search in sources :

Example 6 with CSVEntryMap

use of com.dexels.navajo.adapter.csvmap.CSVEntryMap in project navajo by Dexels.

the class CSVMap method parseLineWithEmpty.

private void parseLineWithEmpty(String line, List<CSVEntryMap> entryList) {
    String sep = separator;
    if (sep == null) {
        sep = " ";
    }
    if (sep.length() > 1) {
        throw new IllegalArgumentException("Can not include empty when separator is > 1 char.Sorry, feel free to implement.");
    }
    char sepChar = sep.charAt(0);
    int startindex = 0;
    List<String> currentLine = new ArrayList<>();
    for (int i = 0; i < line.length(); i++) {
        char c = line.charAt(i);
        if (c == sepChar) {
            if (startindex == -1) {
                currentLine.add(null);
                startindex = -1;
            } else {
                if (startindex == i) {
                    currentLine.add(null);
                } else {
                    String ss = line.substring(startindex, i);
                    currentLine.add(ss);
                }
                startindex = i + 1;
            }
        }
    }
    // add the last item on the line, not ended by the separator
    if (startindex == line.length()) {
        currentLine.add(null);
    } else {
        String ss = line.substring(startindex, line.length());
        currentLine.add(ss);
    }
    CSVEntryMap csvEntry = new CSVEntryMap();
    csvEntry.entries = new String[currentLine.size()];
    for (int i = 0; i < currentLine.size(); i++) {
        csvEntry.entries[i] = currentLine.get(i);
    }
    entryList.add(csvEntry);
}
Also used : CSVEntryMap(com.dexels.navajo.adapter.csvmap.CSVEntryMap) ArrayList(java.util.ArrayList)

Aggregations

CSVEntryMap (com.dexels.navajo.adapter.csvmap.CSVEntryMap)6 UserException (com.dexels.navajo.script.api.UserException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Binary (com.dexels.navajo.document.types.Binary)1 Mappable (com.dexels.navajo.script.api.Mappable)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StringTokenizer (java.util.StringTokenizer)1