Class FileHandlingSelectedBudget

java.lang.Object
no.ntnu.idatt1002.demo.data.budget.FileHandlingSelectedBudget

public class FileHandlingSelectedBudget extends Object
Class that holds the responsibility of any action relating to the SelectedBudget.current file which holds the budget name of the budget that currently is viewed.
Since:
19.04.2023
Author:
Harry Linrui Xu
  • Constructor Details

    • FileHandlingSelectedBudget

      public FileHandlingSelectedBudget()
  • Method Details

    • readSelectedBudget

      public static String readSelectedBudget(String fileDestination) throws IOException
      Reads the name of the currently selected budget.
      Parameters:
      fileDestination - The file destination in resources.
      Returns:
      A string of the budget name.
      Throws:
      IOException - if an input or output exception occurred.
    • updateSelectedBudget

      public static void updateSelectedBudget(String budgetName, String fileDestination) throws IOException
      Writes the currently used budget name to file, essentially updating the file.
      Parameters:
      budgetName - The name of the budget.
      fileDestination - File destination in resources.
      Throws:
      IOException - if an input or output exception occurred.
    • clearSelectedBudget

      public static void clearSelectedBudget(String fileDestination) throws IOException
      Clears the entire file that holds the current budget. In case a budget is deleted, this method prevents the file of containing a budget name that no longer exists.
      Parameters:
      fileDestination - The title of the file.
      Throws:
      IOException - if an input or output exception occurred.
    • isSelectedBudgetEmpty

      public static boolean isSelectedBudgetEmpty(String fileDestination) throws IOException
      Checks if the file that holds the selected budget contains any budget. In other words, the method checks if this file is empty.
      Parameters:
      fileDestination - The title of the file.
      Returns:
      True, if only "null" is read from the file. Else, returns false.
      Throws:
      IOException - if an input or output exception occurred.
    • createBudgetDirectory

      public static boolean createBudgetDirectory(String budgetId)
      Method for creating a new directory for a newly created budget.
      Parameters:
      budgetId - The name of the directory that stores all the data for a given budget.
      Returns:
      True, if a directory is successfully created. Else, returns false.
    • deleteBudgetDirectory

      public static boolean deleteBudgetDirectory(String budgetDestination)
      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.
      Parameters:
      budgetDestination - The destination of the budget directory that holds all the data for a given budget.
      Returns:
      True, if the directory is successfully deleted. Else, returns false.
    • createNewIncomeFile

      public static boolean createNewIncomeFile(String budgetDestination, String incomeFileTitle) throws IOException
      Method for creating a file holding all income data.
      Parameters:
      budgetDestination - The destination of the budget directory that holds all the data for a given budget.
      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.
    • createNewExpenseFile

      public static boolean createNewExpenseFile(String budgetDestination, String expenseFileTitle) throws IOException
      Method for creating a file holding all expense data.
      Parameters:
      budgetDestination - The destination of the budget directory that holds all the data for a given budget.
      expenseFileTitle - The name of the expense file.
      Returns:
      True, if the file was created, else returns false.
      Throws:
      IOException - if an input or output exception occurred.
    • createNewBudgetFile

      public static boolean createNewBudgetFile(String budgetDestination, String budgetFileTitle) throws IOException
      Method for creating a file holding all income data.
      Parameters:
      budgetDestination - The destination of the budget directory that holds all the data for a given budget.
      budgetFileTitle - The name of the budget file.
      Returns:
      True, if the file was created, else returns false.
      Throws:
      IOException - if an input or output exception occurred.