From ff38fdfdd01d76e32ab253fb5d33d25e3c9e15e9 Mon Sep 17 00:00:00 2001 From: Nikollai Date: Mon, 18 May 2026 15:09:54 +0200 Subject: [PATCH] Removed reduntant attributes for CSVParser and changed the parse method to reflect earlier changes --- .../controller/fileIO/CSVStockFileParser.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main/java/millions/controller/fileIO/CSVStockFileParser.java b/src/main/java/millions/controller/fileIO/CSVStockFileParser.java index fa74dde..530ed02 100644 --- a/src/main/java/millions/controller/fileIO/CSVStockFileParser.java +++ b/src/main/java/millions/controller/fileIO/CSVStockFileParser.java @@ -7,7 +7,6 @@ /** Parses CSV lines into Stock objects. */ public class CSVStockFileParser { - private List lines; public CSVStockFileParser() {} @@ -19,22 +18,21 @@ public boolean verifyCSV(List lines) { } public List parse(List lines) { + List stocks = new ArrayList<>(); if (verifyCSV(lines)) { - this.lines = lines; + lines.stream() + .filter(l -> !((l.startsWith("#") || l.isBlank()))) + .forEach( + l -> { + String[] split = l.split(","); + String symbol = split[0]; + String company = split[1]; + BigDecimal price = new BigDecimal(split[2]); + stocks.add(new Stock(symbol, company, price)); + }); } else { throw new InvalidFormatException("Incorrect format for CSV File"); } - List stocks = new ArrayList<>(); - lines.stream() - .filter(l -> !((l.startsWith("#") || l.isBlank()))) - .forEach( - l -> { - String[] split = l.split(","); - String symbol = split[0]; - String company = split[1]; - BigDecimal price = new BigDecimal(split[2]); - stocks.add(new Stock(symbol, company, price)); - }); return stocks; } }