Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for UserInterface and Parser class #157

Merged
merged 5 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 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,23 @@
import budgetbuddy.transaction.type.Transaction;
import budgetbuddy.ui.UserInterface;

/**

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice explanation of the methods

* 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 containes 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 +43,16 @@ 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 +123,18 @@ 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 +168,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 +203,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 +221,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
Loading