Skip to content

Commit

Permalink
Refactor almost all Tag to Category
Browse files Browse the repository at this point in the history
  • Loading branch information
joloong committed Oct 23, 2019
1 parent f9c5b59 commit 269c9d8
Show file tree
Hide file tree
Showing 35 changed files with 365 additions and 342 deletions.
27 changes: 16 additions & 11 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,32 @@ By: `AY1920S1-CS2103T-W12-3` Since: `SEPT 2019` Licence: `MIT`

== Introduction

PalPay is for those who *prefer to use a desktop app for managing personal finances*. More importantly, PalPay is *optimized for those who prefer to work with a Command Line Interface* (CLI) while still having the benefits of a Graphical User Interface (GUI). If you can type fast, PalPay can get your finance management tasks done faster than traditional GUI apps. Ready to start your journey to financial freedom? Jump to the <<Quick Start>> to get started. Enjoy!
PalPay is for those who *prefer to use a desktop app for managing personal finances*.
More importantly, PalPay is *optimized for those who prefer to work with a Command Line Interface* (CLI) while still having the benefits of a Graphical User Interface (GUI).
If you can type fast, PalPay can get your finance management tasks done faster than traditional GUI apps.
Ready to start your journey to financial freedom?
Jump to the <<Quick Start>> to get started.
Enjoy!

== Quick Start

. Ensure you have Java `11` or above installed in your Computer.
. Download the latest `palpay.jar` link:{repoURL}/releases[here].
. Copy the file to the folder you want to use as the home folder for your finance manager.
. Double-click the file to start the app. The GUI should appear within a few seconds.
. Ensure you have Java `11` or above installed in your Computer.
. Download the latest `palpay.jar` link:{repoURL}/releases[here].
. Copy the file to the folder you want to use as the home folder for your finance manager.
. Double-click the file to start the app.
The GUI should appear within a few seconds.
+
+
. Type your command in the command box and press kbd:[Enter] to execute it. +
. Type your command in the command box and press kbd:[Enter] to execute it. +
e.g. typing *`help`* and pressing kbd:[Enter] will open the help window.
. Some example commands you can try:
. Some example commands you can try:

* *`view`* : shows statistics of your current finances
* **`in`**`100 n/mother c/allowance` : adds an income to your personal finance of *100* dollars under the catergory *mother* and the item type *allowance*.
* **`out`**`3 n/pie c/food` : adds an expenditure to your personal finance of *3* dollars under the category *food* and the item type *pie*.
* *`exit`* : exits the app

. Refer to <<Features>> for details of each command.
. Refer to <<Features>> for details of each command.

[[Features]]
== Features
Expand Down Expand Up @@ -156,8 +162,7 @@ Updates the specified income or expenditure from the finance manager. +
Format: `update --TYPE $/AMOUNT1 $/AMOUNT2 n/ITEM [c/CATEGORY]`

****
* `TYPE` only accepts `in` or `out`. (e.g. `update --out ...` refers to deleting an *expenditure*)
*`AMOUNT1` is the new amount you want to update the current in/out with.
* `TYPE` only accepts `in` or `out`. (e.g. `update --out ...` refers to deleting an *expenditure*) *`AMOUNT1` is the new amount you want to update the current in/out with.
* Updates the item from the given category with it's given amount.
* If there is no given category, it will only search for given type with it's corresponding amount.
* If AMOUNT/ITEM/CATEGORY or a combination of any of the 3 does not match, no operation will be performed
Expand All @@ -170,7 +175,7 @@ Examples:
* `update --out $/100 300 n/transport`
* `update --in $/60 70 n/dad`

=== Filtering based on tags: `filter`
=== Filtering based on categories: `filter`

Shows all relevant transactions with given `CATEGORY` +
Format: `filter CATEGORY`
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/commands/FilterCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import seedu.address.commons.core.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.transaction.TransactionContainsTagsPredicate;
import seedu.address.model.transaction.TransactionContainsCategoriesPredicate;

/**
* Filters the transactions in the bank account.
Expand All @@ -21,9 +21,9 @@ public class FilterCommand extends Command {

public static final String MESSAGE_SUCCESS = "Bank Account has been filtered!";

private final TransactionContainsTagsPredicate pred;
private final TransactionContainsCategoriesPredicate pred;

public FilterCommand(TransactionContainsTagsPredicate pred) {
public FilterCommand(TransactionContainsCategoriesPredicate pred) {
requireNonNull(pred);
this.pred = pred;
}
Expand Down
44 changes: 23 additions & 21 deletions src/main/java/seedu/address/logic/commands/UpdateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ public class UpdateCommand extends Command {
public static final String COMMAND_WORD = "update";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Updates the details of the person identified "
+ "by the index number used in the displayed person list. "
+ "Existing values will be overwritten by the input values.\n"
+ "Parameters: INDEX (must be a positive integer) "
+ "[" + PREFIX_AMOUNT + "AMOUNT] "
+ "[" + PREFIX_DATE + "DATE] "
+ "[" + PREFIX_CATEGORY + "CATEGORY]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_AMOUNT + "123 "
+ PREFIX_DATE + "12022019";
+ "by the index number used in the displayed person list. "
+ "Existing values will be overwritten by the input values.\n"
+ "Parameters: INDEX (must be a positive integer) "
+ "[" + PREFIX_AMOUNT + "AMOUNT] "
+ "[" + PREFIX_DATE + "DATE] "
+ "[" + PREFIX_CATEGORY + "CATEGORY]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_AMOUNT + "123 "
+ PREFIX_DATE + "12022019";

public static final String MESSAGE_NOT_EDITED = "At least one field to update must be provided.";
public static final String MESSAGE_UPDATE_TRANSACTION_SUCCESS = "Updated Transaction: %1$s";
Expand Down Expand Up @@ -66,26 +66,27 @@ public CommandResult execute(Model model) throws CommandException {

BankAccountOperation transactionToReplace = lastShownList.get(targetIndex.getZeroBased());
BankAccountOperation updatedTransaction = createUpdatedTransaction(transactionToReplace,
updateTransactionDescriptor);
updateTransactionDescriptor);

model.setTransaction(transactionToReplace, updatedTransaction);
model.commitBankAccount();


return new CommandResult(String.format(MESSAGE_UPDATE_TRANSACTION_SUCCESS, updatedTransaction));
}

/**
* Creates and returns a {@code Person} with the details of {@code personToEdit}
* edited with {@code editPersonDescriptor}.
*/
private static BankAccountOperation createUpdatedTransaction(BankAccountOperation transactionToEdit,
UpdateTransactionDescriptor updateTransactionDescriptor) {
private static BankAccountOperation createUpdatedTransaction(
BankAccountOperation transactionToEdit, UpdateTransactionDescriptor updateTransactionDescriptor) {
assert transactionToEdit != null;

Amount updatedAmount = updateTransactionDescriptor.getAmount().orElse(transactionToEdit.getAmount());
Date updatedDate = updateTransactionDescriptor.getDate().orElse(transactionToEdit.getDate());
Set<Category> updatedCategories = updateTransactionDescriptor
.getCategories().orElse(transactionToEdit.getCategories());
.getCategories().orElse(transactionToEdit.getCategories());

if (transactionToEdit instanceof InTransaction) {
return new InTransaction(updatedAmount, updatedDate, updatedCategories);
Expand All @@ -104,11 +105,12 @@ public static class UpdateTransactionDescriptor {
private Date date;
private Set<Category> categories;

public UpdateTransactionDescriptor() {}
public UpdateTransactionDescriptor() {
}

/**
* Copy constructor.
* A defensive copy of {@code tags} is used internally.
* A defensive copy of {@code categories} is used internally.
*/
public UpdateTransactionDescriptor(UpdateCommand.UpdateTransactionDescriptor toCopy) {
setAmount(toCopy.amount);
Expand Down Expand Up @@ -140,17 +142,17 @@ public Optional<Date> getDate() {
}

/**
* Sets {@code tags} to this object's {@code tags}.
* A defensive copy of {@code tags} is used internally.
* Sets {@code categories} to this object's {@code categories}.
* A defensive copy of {@code categories} is used internally.
*/
public void setCategories(Set<Category> categories) {
this.categories = (categories != null) ? new HashSet<>(categories) : null;
}

/**
* Returns an unmodifiable tag set, which throws {@code UnsupportedOperationException}
* Returns an unmodifiable category set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
* Returns {@code Optional#empty()} if {@code tags} is null.
* Returns {@code Optional#empty()} if {@code categories} is null.
*/
public Optional<Set<Category>> getCategories() {
return (categories != null) ? Optional.of(Collections.unmodifiableSet(categories)) : Optional.empty();
Expand All @@ -172,8 +174,8 @@ public boolean equals(Object other) {
UpdateCommand.UpdateTransactionDescriptor e = (UpdateCommand.UpdateTransactionDescriptor) other;

return getAmount().equals(e.getAmount())
&& getDate().equals(e.getDate())
&& getCategories().equals(e.getCategories());
&& getDate().equals(e.getDate())
&& getCategories().equals(e.getCategories());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import seedu.address.commons.core.Messages;
import seedu.address.logic.commands.FilterCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.transaction.TransactionContainsTagsPredicate;
import seedu.address.model.transaction.TransactionContainsCategoriesPredicate;

/**
* Parses input arguments and creates a new FilterCommand object
Expand All @@ -27,7 +27,7 @@ public FilterCommand parse(String args) throws ParseException {

String[] tagKeywords = trimmedArgs.split("\\s+");

return new FilterCommand(new TransactionContainsTagsPredicate(Arrays.asList(tagKeywords)));
return new FilterCommand(new TransactionContainsCategoriesPredicate(Arrays.asList(tagKeywords)));
}

}
20 changes: 11 additions & 9 deletions src/main/java/seedu/address/logic/parser/UpdateCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ public class UpdateCommandParser implements Parser<UpdateCommand> {
/**
* Parses the given {@code String} of arguments in the context of the UpdateCommand
* and returns an UpdateCommand object for execution.
*
* @throws ParseException if the user input does not conform the expected format
*/
public UpdateCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_AMOUNT, PREFIX_DATE, PREFIX_CATEGORY);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_AMOUNT, PREFIX_DATE, PREFIX_CATEGORY);

Index index;

Expand All @@ -48,7 +49,7 @@ public UpdateCommand parse(String args) throws ParseException {
updateTransactionDescriptor.setDate(ParserUtil.parseDate(argMultimap.getValue(PREFIX_DATE).get()));
}
parseTagsForEdit(argMultimap.getAllValues(PREFIX_CATEGORY))
.ifPresent(updateTransactionDescriptor::setCategories);
.ifPresent(updateTransactionDescriptor::setCategories);

if (!updateTransactionDescriptor.isAnyFieldEdited()) {
throw new ParseException(UpdateCommand.MESSAGE_NOT_EDITED);
Expand All @@ -58,17 +59,18 @@ public UpdateCommand parse(String args) throws ParseException {
}

/**
* Parses {@code Collection<String> tags} into a {@code Set<Tag>} if {@code tags} is non-empty.
* If {@code tags} contain only one element which is an empty string, it will be parsed into a
* {@code Set<Tag>} containing zero tags.
* Parses {@code Collection<String> categories} into a {@code Set<Category>} if {@code categories} is non-empty.
* If {@code categories} contain only one element which is an empty string, it will be parsed into a
* {@code Set<Category>} containing zero categories.
*/
private Optional<Set<Category>> parseTagsForEdit(Collection<String> tags) throws ParseException {
assert tags != null;
private Optional<Set<Category>> parseTagsForEdit(Collection<String> categories) throws ParseException {
assert categories != null;

if (tags.isEmpty()) {
if (categories.isEmpty()) {
return Optional.empty();
}
Collection<String> tagSet = tags.size() == 1 && tags.contains("") ? Collections.emptySet() : tags;
Collection<String> tagSet = categories.size() == 1 && categories.contains("")
? Collections.emptySet() : categories;
return Optional.of(ParserUtil.parseCategories(tagSet));
}
}
32 changes: 16 additions & 16 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Amount getBalance() {
}

/**
* Returns an immutable tag set, which throws {@code UnsupportedOperationException}
* Returns an immutable category set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
*/
public Set<Category> getCategories() {
Expand All @@ -88,8 +88,8 @@ public boolean isSamePerson(Person otherPerson) {
}

return otherPerson != null
&& otherPerson.getName().equals(getName())
&& (otherPerson.getPhone().equals(getPhone()) || otherPerson.getEmail().equals(getEmail()));
&& otherPerson.getName().equals(getName())
&& (otherPerson.getPhone().equals(getPhone()) || otherPerson.getEmail().equals(getEmail()));
}

/**
Expand Down Expand Up @@ -120,10 +120,10 @@ public boolean equals(Object other) {

Person otherPerson = (Person) other;
return otherPerson.getName().equals(getName())
&& otherPerson.getPhone().equals(getPhone())
&& otherPerson.getEmail().equals(getEmail())
&& otherPerson.getAddress().equals(getAddress())
&& otherPerson.getCategories().equals(getCategories());
&& otherPerson.getPhone().equals(getPhone())
&& otherPerson.getEmail().equals(getEmail())
&& otherPerson.getAddress().equals(getAddress())
&& otherPerson.getCategories().equals(getCategories());
}

@Override
Expand All @@ -136,15 +136,15 @@ public int hashCode() {
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append(getName())
.append(" Balance: ")
.append(getBalance())
.append(" Phone: ")
.append(getPhone())
.append(" Email: ")
.append(getEmail())
.append(" Address: ")
.append(getAddress())
.append(" Tags: ");
.append(" Balance: ")
.append(getBalance())
.append(" Phone: ")
.append(getPhone())
.append(" Email: ")
.append(getEmail())
.append(" Address: ")
.append(getAddress())
.append(" Categories: ");
getCategories().forEach(builder::append);
return builder.toString();
}
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/seedu/address/model/transaction/Budget.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public Budget() {
}

/**
* Constructor for Budget with no tags given.
* By default, tag is "general"
* Constructor for Budget with no categories given.
* By default, category is "general"
*/
public Budget(Amount amount, Date date) {
this.amount = amount;
Expand Down Expand Up @@ -68,6 +68,7 @@ public boolean isValid() {

/**
* Updates the amount of this budget given a new amount.
*
* @param amount
* @return
*/
Expand All @@ -83,6 +84,7 @@ private void updateDeadline(Date date) {

/**
* Calculates the new Date given the amount of duration from Today.
*
* @return Date after {@code duration} days from today
*/
private Date calculateDeadline(int duration) {
Expand All @@ -93,6 +95,7 @@ private Date calculateDeadline(int duration) {

/**
* Checks if the given budget is the same Budget object as this budget.
*
* @param otherBudget
* @return
*/
Expand All @@ -102,8 +105,8 @@ public boolean isSameBudget(Budget otherBudget) {
}

return otherBudget != null
&& otherBudget.getBudget().equals(getBudget())
&& otherBudget.getDeadline().equals(getDeadline());
&& otherBudget.getBudget().equals(getBudget())
&& otherBudget.getDeadline().equals(getDeadline());
}

@Override
Expand All @@ -113,7 +116,7 @@ public boolean equals(Object obj) {
} else if (obj instanceof Budget) {
Budget inObj = (Budget) obj;
return amount.equals(inObj.amount)
&& deadline.equals(inObj.deadline);
&& deadline.equals(inObj.deadline);
} else {
return false;
}
Expand Down

0 comments on commit 269c9d8

Please sign in to comment.