Skip to content

Commit

Permalink
Removed reduntant attributes for CSVParser and changed the parse meth…
Browse files Browse the repository at this point in the history
…od to reflect earlier changes
  • Loading branch information
Nikollai committed May 18, 2026
1 parent 2f63d03 commit ff38fdf
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/main/java/millions/controller/fileIO/CSVStockFileParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

/** Parses CSV lines into Stock objects. */
public class CSVStockFileParser {
private List<String> lines;

public CSVStockFileParser() {}

Expand All @@ -19,22 +18,21 @@ public boolean verifyCSV(List<String> lines) {
}

public List<Stock> parse(List<String> lines) {
List<Stock> 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<Stock> 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;
}
}

0 comments on commit ff38fdf

Please sign in to comment.