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 3599d7092245be09c4aeaee1fb0a5ddfd5caba5f..5bef228d32a349d7ea8f7331a6906d005959054d 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 9a0b065c4de4c212887f53eed62566d2fea93e72..d3d8ff7dbb5678e6458288c0069d26c168b6365b 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(); } }