From 52fc3b33d84c8327963b5f6a4c2451486e6355b9 Mon Sep 17 00:00:00 2001
From: Harry Linrui XU <xulr0820@hotmail.com>
Date: Mon, 17 Apr 2023 14:13:43 +0200
Subject: [PATCH] Added new method for identifying new Budgets

---
 .../demo/data/Budget/FileHandlingBudget.java  | 23 ++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingBudget.java b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingBudget.java
index 9188cd93..ede36ec1 100644
--- a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingBudget.java
+++ b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingBudget.java
@@ -34,7 +34,7 @@ public class FileHandlingBudget {
     }
 
     /**
-     * Method for checking if a .register file is empty.
+     * Method for checking if a .budget file is empty.
      *
      * @param fileTitle the name of the file you want to check
      * @return true or false depending on if file is empty.
@@ -46,6 +46,27 @@ public class FileHandlingBudget {
         }
     }
 
+    /**
+     * Method for checking if a .budget file is new (no categories)
+     * or old (has budget categories)
+     * @param fileTitle The name of the file
+     * @return True, if the budget is new. Else, returns false
+     * @throws IOException
+     */
+    public boolean isNewBudget(String fileTitle) throws IOException {
+        try (BufferedReader br = new BufferedReader(
+            new FileReader(filePath + fileTitle + fileType))) {
+
+            for (int i = 0; i < 3; ++i)
+                br.readLine();
+
+            if (br.readLine() == null) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     /**
      * Method for reading (getting) a Budget from a file.
      *
-- 
GitLab