-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CSV parser added and StringUtil:trim method added
- Loading branch information
Jan Lolling
committed
May 12, 2021
1 parent
0b53f00
commit 6add1e7
Showing
7 changed files
with
139 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package routines; | ||
|
||
import java.io.StringReader; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.apache.commons.csv.CSVFormat; | ||
import org.apache.commons.csv.CSVParser; | ||
import org.apache.commons.csv.CSVRecord; | ||
|
||
public class CSVUtil { | ||
|
||
private static Map<String, CSVFormat> formats = new HashMap<>(); | ||
|
||
public static int getCountColumns(String row, char delimiter, char enclosure) throws Exception { | ||
int count = 0; | ||
if (row != null && row.trim().isEmpty() == false) { | ||
CSVFormat csvFormat = formats.get(delimiter + "/" + enclosure); | ||
if (csvFormat == null) { | ||
csvFormat = CSVFormat.newFormat(delimiter).withQuote(enclosure); | ||
formats.put(delimiter + "/" + enclosure, csvFormat); | ||
} | ||
CSVParser parser = csvFormat.parse(new StringReader(row)); | ||
CSVRecord firstRecord = parser.iterator().next(); | ||
return firstRecord.size(); | ||
} | ||
return count; | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.