From 6102913e5089b0b86f83eececb0d854f455caa72 Mon Sep 17 00:00:00 2001
From: Harry Linrui XU <xulr0820@hotmail.com>
Date: Sun, 23 Apr 2023 15:55:09 +0200
Subject: [PATCH] Moved method from archive class to selectedbudget class

---
 .../Budget/FileHandlingBudgetArchive.java     | 23 -----------
 .../Budget/FileHandlingSelectedBudget.java    | 39 ++++++++++++++++---
 2 files changed, 33 insertions(+), 29 deletions(-)

diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingBudgetArchive.java b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingBudgetArchive.java
index 3599d709..5bef228d 100644
--- a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingBudgetArchive.java
+++ b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingBudgetArchive.java
@@ -105,27 +105,4 @@ public class FileHandlingBudgetArchive {
     }
     return budgetRegister;
   }
-
-  /**
-   * Method for deleting a budget directory which holds all budget, income and expense
-   * data for a particular budget. This class holds this responsibility, as any budgets
-   * that should be removed should have their directory deleted.
-
-   * @param budgetId The name of the budget directory that holds all the data
-   *                 for a given budget.
-   * @return True, if the directory is successfully deleted. Else, returns false.
-   */
-  public static boolean deleteBudgetDirectory(String budgetId) {
-    File targetDirectory = new File(filePath + budgetId);
-    System.out.println("Deleting directory:" + targetDirectory.getPath());
-
-    String[]entries = targetDirectory.list();
-    assert entries != null;
-    for(String file : entries){
-      File currentFile = new File(targetDirectory.getPath(),file);
-      currentFile.delete();
-    }
-
-    return targetDirectory.delete();
-  }
 }
diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingSelectedBudget.java b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingSelectedBudget.java
index 9a0b065c..d3d8ff7d 100644
--- a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingSelectedBudget.java
+++ b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingSelectedBudget.java
@@ -105,17 +105,41 @@ public class FileHandlingSelectedBudget {
     return f.mkdir();
   }
 
+  /**
+   * Method for deleting a budget directory which holds all budget, income and expense
+   * data for a particular budget. This class holds this responsibility, as any budgets
+   * that should be removed should have their directory deleted.
+
+   * @param budgetId The name of the budget directory that holds all the data
+   *                 for a given budget.
+   * @return True, if the directory is successfully deleted. Else, returns false.
+   */
+  public static boolean deleteBudgetDirectory(String budgetId) {
+    File targetDirectory = new File(filePath + budgetId);
+    System.out.println("Deleting directory:" + targetDirectory.getPath());
+
+    String[]entries = targetDirectory.list();
+    assert entries != null;
+    for(String file : entries){
+      File currentFile = new File(targetDirectory.getPath(),file);
+      currentFile.delete();
+    }
+
+    return targetDirectory.delete();
+  }
+
   /**
    * Method for creating a file holding all income data.
 
    * @param budgetId The name of the directory that stores all the data for a
    * given budget.
    * @param incomeFileTitle The name of the income file.
+   * True, if the file was created, else returns false.
    * @throws IOException if an input or output exception occurred.
    */
-  public static void createNewIncomeFile(String budgetId, String incomeFileTitle) throws IOException {
+  public static boolean createNewIncomeFile(String budgetId, String incomeFileTitle) throws IOException {
     File incomeFile = new File(filePath +  budgetId + "/" + incomeFileTitle + registerFileType);
-    incomeFile.createNewFile();
+    return incomeFile.createNewFile();
   }
 
   /**
@@ -124,12 +148,14 @@ public class FileHandlingSelectedBudget {
    * @param budgetId The name of the directory that stores all the data for a
    * given budget.
    * @param expenseFileTitle The name of the expense file.
+   * @return True, if the file was created, else returns false.
    * @throws IOException if an input or output exception occurred.
    */
-  public static void createNewExpenseFile(String budgetId, String expenseFileTitle) throws IOException {
+
+  public static boolean createNewExpenseFile(String budgetId, String expenseFileTitle) throws IOException {
     System.out.println("Expense filePath: " + filePath + budgetId + "/" + expenseFileTitle + registerFileType);
     File expenseFile = new File(filePath + budgetId + "/" + expenseFileTitle + registerFileType);
-    expenseFile.createNewFile();
+    return expenseFile.createNewFile();
   }
 
   /**
@@ -138,11 +164,12 @@ public class FileHandlingSelectedBudget {
    * @param budgetId The name of the directory that stores all the data for a
    * given budget.
    * @param budgetFileTitle The name of the budget file.
+   * @return True, if the file was created, else returns false.
    * @throws IOException if an input or output exception occurred.
    */
-  public static void createNewBudgetFile(String budgetId, String budgetFileTitle) throws IOException {
+  public static boolean createNewBudgetFile(String budgetId, String budgetFileTitle) throws IOException {
     System.out.println("Budget filePath: " + filePath + budgetId + "/" + budgetFileTitle + budgetFileType);
     File budgetFile = new File(filePath + budgetId + "/" + budgetFileTitle + budgetFileType);
-    budgetFile.createNewFile();
+    return budgetFile.createNewFile();
   }
 }
-- 
GitLab