Class Register

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

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

      public List<String> getCategoriesByTransactionType(boolean isExpense)
      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

      public List<Transaction> getTransactionByTransactionType(boolean isExpense)
      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

      public ArrayList<Transaction> getTransactionsByCategoryType(boolean recurring)
      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

      public void addCategory(Category category) throws DuplicateNameException, ConformityException
      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:
      DuplicateNameException
      ConformityException
    • 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:
      DuplicateNameException
      ConformityException
    • addAll

      public void addAll(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 varargs.
      Parameters:
      categories - Categories to add.
      Throws:
      DuplicateNameException
      ConformityException
    • getCategories

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

      public ArrayList<Transaction> getAllTransactions()
      Returns an ArrayList of all transactions in the register.
      Returns:
      All transactions as an ArrayList.
    • getCategoryByName

      public Category getCategoryByName(String text)
      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

      public void removeCategoryByString(String categoryName) throws NameNotFoundException
      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

      public void removeTransaction(Transaction transaction) throws ConformityException
      Removes a transaction from the register.
      Parameters:
      transaction - Transaction to remove.
      Throws:
      ConformityException - If the transaction does not conform to the category.