Class Category

java.lang.Object
no.ntnu.idatt1002.spendwise.data.Category

public class Category extends Object
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 Details

    • Category

      public Category(String name, boolean isExpenseCategory, boolean isRecurringCategory)
      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

      public String getName()
      Returns the name of the category.
      Returns:
      Name of the category as a String.
    • getTransactions

      public List<Transaction> 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

      public void addTransaction(Transaction t) throws ConformityException
      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

      public void removeTransaction(Transaction transaction)
      Removes a transaction from the category.
      Parameters:
      transaction - The transaction to be removed
    • addAll

      public void addAll(List<Transaction> transactionsToAdd) throws ConformityException
      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

      public double getTotalAmountWithinTimeFrame(LocalDate from, LocalDate to)
      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.