-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from IDATT2003-gruppe06/javadocs
Javadocs
- Loading branch information
Showing
26 changed files
with
489 additions
and
21 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
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
27 changes: 13 additions & 14 deletions
27
src/main/java/millions/controller/fileIO/CSVStockFileParser.java
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 |
|---|---|---|
| @@ -1,42 +1,41 @@ | ||
| package millions.controller.fileIO; | ||
|
|
||
| import millions.model.Stock; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import millions.model.Stock; | ||
|
|
||
| /** Parses CSV lines into Stock objects. */ | ||
| public class CSVStockFileParser { | ||
| private List<String> lines; | ||
|
|
||
| public CSVStockFileParser(List<String> lines) { | ||
| if (verifyCSV(lines)) { | ||
| this.lines = lines; | ||
| } | ||
| else { | ||
| } else { | ||
| // throw file format error | ||
| } | ||
| } | ||
|
|
||
| // returns true if all entries have exactly 3 data points | ||
| public boolean verifyCSV(List<String> lines) { | ||
| return lines.stream() | ||
| .filter(l -> !(l.startsWith("#") || l.isBlank())) | ||
| .noneMatch(l -> l.split(",").length != 3); | ||
|
|
||
| .filter(l -> !(l.startsWith("#") || l.isBlank())) | ||
| .noneMatch(l -> l.split(",").length != 3); | ||
| } | ||
|
|
||
| public List<Stock> parse() { | ||
| 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)); | ||
| }); | ||
| .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; | ||
| } | ||
| } |
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
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
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
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.