Skip to content

Commit

Permalink
Merge bbef29e into 02947ce
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadaljunied committed Oct 16, 2019
2 parents 02947ce + bbef29e commit 1e2aa56
Show file tree
Hide file tree
Showing 27 changed files with 391 additions and 130 deletions.
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_CURRENCY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
Expand All @@ -21,11 +22,13 @@ public class AddCommand extends Command {
+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_AMOUNT + "AMOUNT "
+ "[" + PREFIX_CURRENCY + "CURRENCY] "
+ "[" + PREFIX_DATE + "DATE] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "Textbook "
+ PREFIX_AMOUNT + "$23.50 "
+ PREFIX_CURRENCY + "USD "
+ PREFIX_DATE + "1245 "
+ PREFIX_TAG + "education "
+ PREFIX_TAG + "school";
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_CURRENCY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
Expand All @@ -19,6 +20,7 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.expense.Amount;
import seedu.address.model.expense.Currency;
import seedu.address.model.expense.Date;
import seedu.address.model.expense.Expense;
import seedu.address.model.expense.Name;
Expand All @@ -37,6 +39,7 @@ public class EditCommand extends Command {
+ "Parameters: INDEX (must be a positive integer) "
+ "[" + PREFIX_NAME + "NAME] "
+ "[" + PREFIX_AMOUNT + "AMOUNT] "
+ "[" + PREFIX_CURRENCY + "CURRENCY] "
+ "[" + PREFIX_DATE + "DATE] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
Expand Down Expand Up @@ -92,10 +95,11 @@ private static Expense createEditedExpense(Expense expenseToEdit, EditExpenseDes

Name updatedName = editExpenseDescriptor.getName().orElse(expenseToEdit.getName());
Amount updatedAmount = editExpenseDescriptor.getAmount().orElse(expenseToEdit.getAmount());
Currency updatedCurrency = editExpenseDescriptor.getCurrency().orElse(expenseToEdit.getCurrency());
Date updatedDate = editExpenseDescriptor.getDate().orElse(expenseToEdit.getDate());
Set<Tag> updatedTags = editExpenseDescriptor.getTags().orElse(expenseToEdit.getTags());

return new Expense(updatedName, updatedAmount, updatedDate, updatedTags);
return new Expense(updatedName, updatedAmount, updatedCurrency, updatedDate, updatedTags);
}

@Override
Expand Down Expand Up @@ -124,6 +128,7 @@ public static class EditExpenseDescriptor {

private Name name;
private Amount amount;
private Currency currency;
private Date date;
private Set<Tag> tags;

Expand All @@ -137,6 +142,7 @@ public EditExpenseDescriptor() {
public EditExpenseDescriptor(EditExpenseDescriptor toCopy) {
setName(toCopy.name);
setAmount(toCopy.amount);
setCurrency(toCopy.currency);
setDate(toCopy.date);
setTags(toCopy.tags);
}
Expand Down Expand Up @@ -164,6 +170,14 @@ public Optional<Amount> getAmount() {
return Optional.ofNullable(amount);
}

public void setCurrency(Currency currency) {
this.currency = currency;
}

public Optional<Currency> getCurrency() {
return Optional.ofNullable(currency);
}

public void setDate(Date date) {
this.date = date;
}
Expand Down Expand Up @@ -206,6 +220,7 @@ public boolean equals(Object other) {

return getName().equals(e.getName())
&& getAmount().equals(e.getAmount())
&& getCurrency().equals(e.getCurrency())
&& getDate().equals(e.getDate())
&& getTags().equals(e.getTags());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_CURRENCY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
Expand All @@ -12,6 +13,7 @@
import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.expense.Amount;
import seedu.address.model.expense.Currency;
import seedu.address.model.expense.Date;
import seedu.address.model.expense.Expense;
import seedu.address.model.expense.Name;
Expand All @@ -30,7 +32,7 @@ public class AddCommandParser implements Parser<AddCommand> {
*/
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_AMOUNT, PREFIX_DATE, PREFIX_TAG);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_AMOUNT, PREFIX_CURRENCY, PREFIX_DATE, PREFIX_TAG);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_AMOUNT)
|| !argMultimap.getPreamble().isEmpty()) {
Expand All @@ -39,10 +41,11 @@ public AddCommand parse(String args) throws ParseException {

Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Amount amount = ParserUtil.parseAmount(argMultimap.getValue(PREFIX_AMOUNT).get());
Currency currency = ParserUtil.parseCurrency(argMultimap);
Date date = ParserUtil.parseDate(argMultimap);
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

Expense expense = new Expense(name, amount, date, tagList);
Expense expense = new Expense(name, amount, currency, date, tagList);

return new AddCommand(expense);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class CliSyntax {
/* Prefix definitions */
public static final Prefix PREFIX_NAME = new Prefix("n/");
public static final Prefix PREFIX_AMOUNT = new Prefix("a/");
public static final Prefix PREFIX_CURRENCY = new Prefix("c/");
public static final Prefix PREFIX_DATE = new Prefix("d/");
public static final Prefix PREFIX_TAG = new Prefix("t/");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_AMOUNT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_CURRENCY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
Expand Down Expand Up @@ -49,6 +50,9 @@ public EditCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_AMOUNT).isPresent()) {
editExpenseDescriptor.setAmount(ParserUtil.parseAmount(argMultimap.getValue(PREFIX_AMOUNT).get()));
}
if (argMultimap.getValue(PREFIX_CURRENCY).isPresent()) {
editExpenseDescriptor.setCurrency(ParserUtil.parseCurrency(argMultimap));
}
if (argMultimap.getValue(PREFIX_DATE).isPresent()) {
editExpenseDescriptor.setDate(ParserUtil.parseDate(argMultimap.getValue(PREFIX_DATE).get()));
}
Expand Down
36 changes: 35 additions & 1 deletion src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.logic.parser;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_CURRENCY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;

import java.time.LocalDateTime;
Expand All @@ -14,6 +15,7 @@
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.expense.Amount;
import seedu.address.model.expense.Currency;
import seedu.address.model.expense.Date;
import seedu.address.model.expense.Name;
import seedu.address.model.tag.Tag;
Expand Down Expand Up @@ -69,6 +71,38 @@ public static Amount parseAmount(String amount) throws ParseException {
return new Amount(trimmedAmount);
}

/**
* Parses a {@code String currency} into a {@code Currency}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code currency} is invalid.
*/
public static Currency parseCurrency(String currency) throws ParseException {
requireNonNull(currency);
String trimmedCurrency = currency.trim();
if (!Currency.isValidCurrency(trimmedCurrency)) {
throw new ParseException(Currency.MESSAGE_CONSTRAINTS);
}
return new Currency(trimmedCurrency);
}

/**
* Parses a {@code ArgumentMultiMap argMultiMap} into an {@code Currency}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code currency} is invalid.
*/
public static Currency parseCurrency(ArgumentMultimap argMultimap) throws ParseException {
Optional<String> currencyField = argMultimap.getValue(PREFIX_CURRENCY);
String currency;
if (!currencyField.isPresent()) {
currency = "SGD";
} else {
currency = currencyField.get();
}
return parseCurrency(currency);
}

/**
* Parses a {@code String date} into an {@code Date}.
* Leading and trailing whitespaces will be trimmed.
Expand All @@ -95,7 +129,7 @@ public static Date parseDate(ArgumentMultimap argMultimap) throws ParseException
String date;
if (!dateField.isPresent()) {
LocalDateTime currentDateTime = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd MMM yyyy, H:mma");
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy Hmm");
date = currentDateTime.format(formatter);
} else {
date = dateField.get();
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/seedu/address/model/expense/Currency.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package seedu.address.model.expense;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;

/**
* Represents the currency of an expense in the MYMorise.
* Guarantees: immutable; is valid as declared in {@link #isValidCurrency(String)}
*/
public class Currency {

public static final String MESSAGE_CONSTRAINTS = "Currency should exactly 3 Letters "
+ "and it should not be blank";
public static final String VALIDATION_REGEX = "([a-zA-Z]){3}";

public final String value;

/**
* Constructs an {@code Amount}.
*
* @param currency A valid amount.
*/
public Currency(String currency) {
requireNonNull(currency);
checkArgument(isValidCurrency(currency), MESSAGE_CONSTRAINTS);
value = currency.toUpperCase();
}

/**
* Returns if a given string is a valid currency.
*/
public static boolean isValidCurrency(String test) {
//TODO: Extend and verify against ISO-4217 Currency Representation List
return test.matches(VALIDATION_REGEX);
}

@Override
public String toString() {
return value;
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Currency // instanceof handles nulls
&& value.equals(((Currency) other).value)); // state check
}

@Override
public int hashCode() {
return value.hashCode();
}
}
17 changes: 13 additions & 4 deletions src/main/java/seedu/address/model/expense/Expense.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Expense {
// Identity fields
private final Name name;
private final Amount amount;
private final Currency currency;

// Data Fields
private final Date date;
Expand All @@ -26,10 +27,11 @@ public class Expense {
/**
* Every field must be present and not null.
*/
public Expense(Name name, Amount amount, Date date, Set<Tag> tags) {
requireAllNonNull(name, amount, date, tags);
public Expense(Name name, Amount amount, Currency currency, Date date, Set<Tag> tags) {
requireAllNonNull(name, amount, currency, date, tags);
this.name = name;
this.amount = amount;
this.currency = currency;
this.date = date;
this.tags.addAll(tags);
}
Expand All @@ -42,6 +44,10 @@ public Amount getAmount() {
return amount;
}

public Currency getCurrency() {
return currency;
}

public Date getDate() {
return date;
}
Expand All @@ -65,7 +71,8 @@ public boolean isSameExpense(Expense otherExpense) {

return otherExpense != null
&& otherExpense.getName().equals(getName())
&& (otherExpense.getAmount().equals(getAmount()) || otherExpense.getDate().equals(getDate()));
&& (otherExpense.getAmount().equals(getAmount())
|| (otherExpense.getCurrency().equals(getCurrency()) || otherExpense.getDate().equals(getDate())));
}

/**
Expand All @@ -85,14 +92,15 @@ public boolean equals(Object other) {
Expense otherExpense = (Expense) other;
return otherExpense.getName().equals(getName())
&& otherExpense.getAmount().equals(getAmount())
&& otherExpense.getCurrency().equals(getCurrency())
&& otherExpense.getDate().equals(getDate())
&& otherExpense.getTags().equals(getTags());
}

@Override
public int hashCode() {
// use this method for custom fields hashing instead of implementing your own
return Objects.hash(name, amount, date, tags);
return Objects.hash(name, amount, currency, date, tags);
}

@Override
Expand All @@ -102,6 +110,7 @@ public String toString() {
.append(getName())
.append(" ")
.append(getAmount())
.append(" " + getCurrency())
.append("\n")
.append(getDate())
.append("\n");
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import seedu.address.model.ExpenseList;
import seedu.address.model.ReadOnlyExpenseList;
import seedu.address.model.expense.Amount;
import seedu.address.model.expense.Currency;
import seedu.address.model.expense.Date;
import seedu.address.model.expense.Expense;
import seedu.address.model.expense.Name;
Expand All @@ -19,17 +20,22 @@ public class SampleDataUtil {

public static Expense[] getSampleExpenses() {
return new Expense[] {
new Expense(new Name("Coffee"), new Amount("$1.8"), new Date("1245", false),
new Expense(new Name("Coffee"), new Amount("$1.8"), new Currency("SGD"),
new Date("1245", false),
getTagSet("food")),
new Expense(new Name("Textbook"), new Amount("$23.50"), new Date("930", false),
new Expense(new Name("Textbook"), new Amount("$23.50"), new Currency("SGD"),
new Date("930", false),
getTagSet("education", "school")),
new Expense(new Name("Earphone"), new Amount("$45"), new Date("10/12/2019 1800", false),
getTagSet("utility")),
new Expense(new Name("Hang out"), new Amount("$50"), new Date("15/12/2019 2100", false),
new Expense(new Name("Earphone"), new Amount("$45"), new Currency("SGD"),
new Date("10/12/2019 1800", false), getTagSet("utility")),
new Expense(new Name("Hang out"), new Amount("$50"), new Currency("SGD"),
new Date("15/12/2019 2100", false),
getTagSet("entertainment")),
new Expense(new Name("Travel to Paris"), new Amount("€850"), new Date("25/12/2019 800", false),
new Expense(new Name("Travel to Paris"), new Amount("€850"), new Currency("SGD"),
new Date("25/12/2019 800", false),
getTagSet("travel")),
new Expense(new Name("Gift for duke"), new Amount("$30"), new Date("1/11/2019", false),
new Expense(new Name("Gift for duke"), new Amount("$30"), new Currency("SGD"),
new Date("1/11/2019", false),
getTagSet("relationship"))
};
}
Expand Down
Loading

0 comments on commit 1e2aa56

Please sign in to comment.