Package no.ntnu.idatt1002.spendwise.data
Class Category
java.lang.Object
no.ntnu.idatt1002.spendwise.data.Category
An instance of Category holds Transaction objects. A category has a name, and can only consist of
one type of Transaction (Expense/Income),
and can only consist of either recurring transactions or not.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAll(List<Transaction> transactionsToAdd) Adds all transactions present in a List to the category.voidAdds a transaction to the category.getName()Returns the name of the category.intReturns the number of transactions in the category.doubleReturns the total amount summed by all transactions in the category.doublegetTotalAmountWithinTimeFrame(LocalDate from, LocalDate to) Returns the sum of transactions in the category that fit the given timeframe.Returns all transactions in a category.booleanIf the category is an Expense category or not.booleanIf the category is an Income category or not.booleanReturns whether the category is of a recurring type.voidremoveTransaction(Transaction transaction) Removes a transaction from the category.
-
Constructor Details
-
Category
Constructor a category.- Parameters:
name- The name of the category.isExpenseCategory- If the category holds Expense objects or not.isRecurringCategory- If the category is recurring or not
-
-
Method Details
-
getName
Returns the name of the category.- Returns:
- Name of the category as a String.
-
getTransactions
Returns all transactions in a category. Does not make deep-copy since Transaction objects are immutable.- Returns:
- A List of all transactions in the category.
-
addTransaction
Adds a transaction to the category.- Parameters:
t- The transaction to be added.- Throws:
ConformityException- If the type of transaction does not match the category.
-
removeTransaction
Removes a transaction from the category.- Parameters:
transaction- The transaction to be removed
-
addAll
Adds all transactions present in a List to the category.- Parameters:
transactionsToAdd- The List of transactions to add- Throws:
ConformityException- If any addTransaction call fails
-
getNumberOfTransactions
public int getNumberOfTransactions()Returns the number of transactions in the category.- Returns:
- Number of transactions present.
-
isRecurring
public boolean isRecurring()Returns whether the category is of a recurring type.- Returns:
- If the category is recurring.
-
getTotalAmount
public double getTotalAmount()Returns the total amount summed by all transactions in the category. This will always be positive, even if the category has expenses.- Returns:
- The sum of amounts as a double.
-
getTotalAmountWithinTimeFrame
Returns the sum of transactions in the category that fit the given timeframe.- Parameters:
from- The "from" date as a LocalDate object.to- The "to" date as a LocalDate object.- Returns:
- The sum of transactions in the given timeframe as a double.
-
isExpenseCategory
public boolean isExpenseCategory()If the category is an Expense category or not.- Returns:
- True if the category is an Expense category.
-
isIncomeCategory
public boolean isIncomeCategory()If the category is an Income category or not.- Returns:
- True if the category is an Income category.
-