diff --git a/millions/src/main/java/no/ntnu/gruppe53/FileHandler.java b/millions/src/main/java/no/ntnu/gruppe53/FileHandler.java index dedff0a..8133e72 100644 --- a/millions/src/main/java/no/ntnu/gruppe53/FileHandler.java +++ b/millions/src/main/java/no/ntnu/gruppe53/FileHandler.java @@ -11,9 +11,19 @@ import java.util.ArrayList; import java.util.List; +/** + * Handles file operations for the application. + */ public class FileHandler { + /** + * Writes a list of {@link Stock}s to a text-file. Class is structed for {@code .csv} files. + * + * @param stockList the list of stocks to be converted to text + * @param path output path for the file + * @param filename name of the file (not including extension) + */ public static void writeStocksToFile(List stockList, String path, String filename) { String pathString = path + filename; Path filePath = Paths.get(pathString); @@ -40,6 +50,13 @@ public static void writeStocksToFile(List stockList, String path, String } } + /** + * Reads a .csv file and converts it to a list of {@code Stock} objects. + * + * @param path path to the file to be read + * @param filename name of the file to be read (including extension) + * @return a list of {@code Stock} objects converted from text + */ public static List readStocksFromFile(String path, String filename) { List stocks = new ArrayList<>(); String pathString = path + filename; @@ -101,13 +118,11 @@ public static List readStocksFromFile(String path, String filename) { } stocks.add(new Stock(symbol, name, price)); } - - } catch (IOException e) { + } + catch (IOException e) { System.out.println("ERROR: Something went wrong while reading the csv file."); System.out.println("Message: " + e.getMessage()); } - return stocks; } - }