Skip to content

Commit

Permalink
Merge pull request #157 from Vavinan/branch-docs
Browse files Browse the repository at this point in the history
Add documentation for UserInterface and Parser class
  • Loading branch information
Vavinan committed Apr 14, 2024
2 parents f1285d5 + 739e3df commit a09e1bf
Show file tree
Hide file tree
Showing 2 changed files with 559 additions and 26 deletions.
50 changes: 49 additions & 1 deletion src/main/java/budgetbuddy/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,22 @@
import budgetbuddy.transaction.type.Transaction;
import budgetbuddy.ui.UserInterface;

/**
* Parses the user input into data that is easily understandable by other classes and methods.
*/
public class Parser {

public static final int ADD_COMMAND_INDEX = 3;
public static final int HELP_BEGIN_INDEX = 4;
private static final int ADD_ACC_COMMAND_INDEX = 7;

/**
* The function `parseAccountNumber` extracts and returns an account number from a given input
* string following a specific syntax.
*
* @param input The input string that contains the account number to be parsed.
* @return The method is returning an integer value, which is the account number parsed from the input string.
*/
public static int parseAccountNumber(String input) throws InvalidArgumentSyntaxException {
String data = input.substring(ADD_COMMAND_INDEX + 1);
String[] parseData = data.split("/");
Expand All @@ -32,6 +42,15 @@ public static int parseAccountNumber(String input) throws InvalidArgumentSyntaxE
throw new InvalidArgumentSyntaxException("Invalid add syntax.");
}

/**
* The function `parseUserInputToTransaction` takes user input, parses it to create a transaction
* object (either income or expense), and handles various exceptions related to invalid input.
*
* @param input takes a user input that contain transaction details in a specific format.
* @param account The `account` parameter in this method represents the account to which the transaction belongs.
* @return The method `parseUserInputToTransaction` is returning a `Transaction` object, which can
* be either an `Income` or an `Expense` object based on the type provided in the input.
*/
public Transaction parseUserInputToTransaction(String input, Account account)
throws InvalidTransactionTypeException, NumberFormatException,
EmptyArgumentException, InvalidCategoryException, InvalidAddTransactionSyntax {
Expand Down Expand Up @@ -102,6 +121,17 @@ public Transaction parseUserInputToTransaction(String input, Account account)
}

//@@author Vavinan
/**
* The `parseEditTransaction` function in Java parses a new transaction string and creates either
* an Income or Expense object based on the transaction type, validating the category number and
* throwing exceptions for invalid data.
*
* @param newTransaction The `newTransaction` string is expected to be in a specific format
* @param account The `account` parameter in the `parseEditTransaction` method represents the
* account to which the transaction belongs.
* @return The `parseEditTransaction` method is returning a `Transaction` object, which can be
* either an `Income` or `Expense` object based on the type provided in the `newTransaction` string.
*/
public Transaction parseEditTransaction(String newTransaction, Account account) throws InvalidEditTransactionData,
InvalidCategoryException {
String[] parts = newTransaction.split(" \\| ");
Expand Down Expand Up @@ -135,6 +165,13 @@ public String parseHelpCommand(String input) {
}
//@@author

/**
* The `parseAddAccount` function in Java parses the input and returns the account name and
* balance of the new account that is to added.
*
* @param input It contains details about account name and initial balance
* @return A string array that contains the account name and initial balance
*/
public static String[] parseAddAccount(String input) throws NumberFormatException, EmptyArgumentException {
String data = input.substring(ADD_ACC_COMMAND_INDEX + 1).trim();
String[] parseData = data.split("/");
Expand Down Expand Up @@ -163,6 +200,12 @@ public static String[] parseAddAccount(String input) throws NumberFormatExceptio
return new String[]{name, initialBalance};
}

/**
* The `parseRemoveAccount` function in Java parses the input and returns the account
* number that is to be deleted
* @param input It contains details about account number that is to be deleted
* @return A integer value representing the account number
*/
public static int parseRemoveAccount(String input)
throws NumberFormatException, EmptyArgumentException {
if (input.trim().length() < 11) {
Expand All @@ -175,7 +218,12 @@ public static int parseRemoveAccount(String input)
return Integer.parseInt(data);
}


/**
* The `parseEditAccount` function in Java parses the input and returns the account
* number that is to be edited
* @param input It contains details about account number that is to be edited
* @return A integer value representing the account number
*/
public static int parseEditAccount(String input) throws EmptyArgumentException {
if (input.trim().length() < 9) {
throw new EmptyArgumentException("edit-acc index ");
Expand Down
Loading

0 comments on commit a09e1bf

Please sign in to comment.