Package no.ntnu.idatt1002.spendwise.data
Class Register
java.lang.Object
no.ntnu.idatt1002.spendwise.data.Register
The main class responsible for holding the data of all transactions and categories.
It consists of a hierarchy where Register holds multiple instances of Category.
Category consists of transactions (see Category).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds all categories passed to the register.voidAdds all categories passed to the register.voidaddCategory(Category category) Adds a category to the register.voidaddTransactionToCategory(Transaction transaction, String catString) Adds a transaction to the register with a specified category.Returns an ArrayList of all transactions in the register.Returns all categories present in the register, with all transactions.getCategoriesByTransactionType(boolean isExpense) Returns categories given a transaction type (expense/income).getCategoryByName(String text) Returns the category with the given name.getTransactionByTransactionType(boolean isExpense) Returns all transactions given a transaction type (expense/income).getTransactionsByCategoryType(boolean recurring) Returns all transactions given a certain category type (boolean).voidremoveCategoryByString(String categoryName) Removes a category by name from the register.voidremoveTransaction(Transaction transaction) Removes a transaction from the register.
-
Constructor Details
-
Register
public Register()
-
-
Method Details
-
addTransactionToCategory
public void addTransactionToCategory(Transaction transaction, String catString) throws ConformityException Adds a transaction to the register with a specified category. If the transaction type does not match the category type, a ConformityException will be thrown.- Parameters:
transaction- The transaction to be added.catString- The name of the category to add the transaction to.- Throws:
ConformityException- If the transaction type does not match the category type.
-
getCategoriesByTransactionType
Returns categories given a transaction type (expense/income).- Parameters:
isExpense- If the category is an expense category or not.- Returns:
- A list of categories.
-
getTransactionByTransactionType
Returns all transactions given a transaction type (expense/income).- Parameters:
isExpense- If the transaction is an expense or not.- Returns:
- A list of transactions.
-
getTransactionsByCategoryType
Returns all transactions given a certain category type (boolean).- Parameters:
recurring- The category type you want to search for.- Returns:
- All transactions found as an ArrayList, returns an empty arraylist if none were found.
-
addCategory
Adds a category to the register. If the category already exists a DuplicateNameException will be thrown, as categories must be unequivocally named- Parameters:
category- Category object to add to the register- Throws:
DuplicateNameExceptionConformityException
-
addAll
public void addAll(ArrayList<Category> categories) throws DuplicateNameException, ConformityException Adds all categories passed to the register. If any of the categories already exists a DuplicateNameException will be thrown. The categories are passed as an ArrayList- Parameters:
categories- ArrayList of categories- Throws:
DuplicateNameExceptionConformityException
-
addAll
Adds all categories passed to the register. If any of the categories already exists a DuplicateNameException will be thrown. The categories are passed as varargs.- Parameters:
categories- Categories to add.- Throws:
DuplicateNameExceptionConformityException
-
getCategories
Returns all categories present in the register, with all transactions. This is a deep copy, and can therefore not be used to modify the register.- Returns:
- A list of categories.
-
getAllTransactions
Returns an ArrayList of all transactions in the register.- Returns:
- All transactions as an ArrayList.
-
getCategoryByName
Returns the category with the given name. If no category is found, null is returned. This is a shallow copy, and can be used to modify the register.- Parameters:
text- Name of the category to search for- Returns:
- The category with the given name, or null if no category was found
-
removeCategoryByString
Removes a category by name from the register.- Parameters:
categoryName- Name of the category to remove.- Throws:
NameNotFoundException- If no category with the given name was found.
-
removeTransaction
Removes a transaction from the register.- Parameters:
transaction- Transaction to remove.- Throws:
ConformityException- If the transaction does not conform to the category.
-