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);
}
Aggregations