From 07f133ab64e7dbbd9fe98f033120c9c5e68a9177 Mon Sep 17 00:00:00 2001 From: Roar Date: Fri, 27 Mar 2026 12:15:03 +0100 Subject: [PATCH] Updated FileHandler Added JavaDoc. --- .../java/no/ntnu/gruppe53/FileHandler.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) 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; } - }