Improved scanner datastructure
Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
@ -12,14 +12,19 @@ public class CSVScanner {
|
|||||||
* @return a list of csv entries
|
* @return a list of csv entries
|
||||||
* @throws FileNotFoundException if file doesn't exist
|
* @throws FileNotFoundException if file doesn't exist
|
||||||
*/
|
*/
|
||||||
public List<String> scan() throws FileNotFoundException {
|
public List<List<String>> scan() throws FileNotFoundException {
|
||||||
List<String> entries = new ArrayList<>();
|
List<List<String>> entries = new ArrayList<>();
|
||||||
|
|
||||||
Scanner scanner = new Scanner(new File("sales.csv"));
|
Scanner scanner = new Scanner(new File("sales.csv"));
|
||||||
scanner.useDelimiter(";");
|
while (scanner.hasNextLine()) {
|
||||||
while (scanner.hasNext()) {
|
List<String> line = new ArrayList<>();
|
||||||
String current = scanner.next();
|
String line_str = scanner.nextLine();
|
||||||
entries.add(current);
|
Scanner line_scanner = new Scanner(line_str);
|
||||||
|
line_scanner.useDelimiter(";");
|
||||||
|
while (line_scanner.hasNext()) {
|
||||||
|
line.add(line_scanner.next());
|
||||||
|
}
|
||||||
|
entries.add(line);
|
||||||
}
|
}
|
||||||
scanner.close();
|
scanner.close();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user