Skip to content
Snippets Groups Projects
Commit 6102913e authored by Harry Linrui XU's avatar Harry Linrui XU
Browse files

Moved method from archive class to selectedbudget class

parent 95386bd6
No related branches found
No related tags found
1 merge request!52Added tests for new classes
......@@ -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();
}
}
......@@ -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();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment