Skip to content

Commit

Permalink
Refactor Email to Remark
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathantjendana committed Oct 17, 2019
1 parent e1aed5f commit fb0428c
Show file tree
Hide file tree
Showing 34 changed files with 277 additions and 377 deletions.
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_COST;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import seedu.address.logic.commands.exceptions.CommandException;
Expand All @@ -22,14 +22,14 @@ public class AddCommand extends Command {
+ "Parameters: "
+ PREFIX_NAME + "NAME "
+ PREFIX_DATE + "DATE "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_REMARK + "REMARK "
+ PREFIX_COST + "COST "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
+ PREFIX_DATE + "today "
+ PREFIX_EMAIL + "johnd@example.com "
+ PREFIX_COST + "1.50 "
+ PREFIX_REMARK + "Likes to play games"
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";

Expand Down
33 changes: 17 additions & 16 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_COST;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_SPENDINGS;

Expand All @@ -21,8 +21,8 @@
import seedu.address.model.Model;
import seedu.address.model.spending.Cost;
import seedu.address.model.spending.Date;
import seedu.address.model.spending.Email;
import seedu.address.model.spending.Name;
import seedu.address.model.spending.Remark;
import seedu.address.model.spending.Spending;
import seedu.address.model.tag.Tag;

Expand All @@ -39,12 +39,12 @@ public class EditCommand extends Command {
+ "Parameters: INDEX (must be a positive integer) "
+ "[" + PREFIX_NAME + "NAME] "
+ "[" + PREFIX_DATE + "DATE] "
+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_COST + "COST] "
+ "[" + PREFIX_REMARK + "REMARK] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_DATE + "today "
+ PREFIX_EMAIL + "johndoe@example.com";
+ PREFIX_REMARK + "Likes to play soccer";

public static final String MESSAGE_EDIT_SPENDING_SUCCESS = "Edited Spending: %1$s";
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
Expand Down Expand Up @@ -96,11 +96,11 @@ private static Spending createEditedSpending(Spending spendingToEdit,

Name updatedName = editSpendingDescriptor.getName().orElse(spendingToEdit.getName());
Date updatedDate = editSpendingDescriptor.getDate().orElse(spendingToEdit.getDate());
Email updatedEmail = editSpendingDescriptor.getEmail().orElse(spendingToEdit.getEmail());
Remark updatedRemark = editSpendingDescriptor.getRemark().orElse(spendingToEdit.getRemark());
Cost updatedCost = editSpendingDescriptor.getCost().orElse(spendingToEdit.getCost());
Set<Tag> updatedTags = editSpendingDescriptor.getTags().orElse(spendingToEdit.getTags());

return new Spending(updatedName, updatedDate, updatedEmail, updatedCost, updatedTags);
return new Spending(updatedName, updatedDate, updatedRemark, updatedCost, updatedTags);
}

@Override
Expand All @@ -122,13 +122,14 @@ public boolean equals(Object other) {
}

/**
* Stores the details to edit the Spending with. Each non-empty field value will replace the
* corresponding field value of the Spending.
* Stores the details to edit the Spending with.
* Each non-empty field value will replace the corresponding field value of the Spending.
*/
public static class EditSpendingDescriptor {

private Name name;
private Date date;
private Email email;
private Remark remark;
private Cost cost;
private Set<Tag> tags;

Expand All @@ -141,7 +142,7 @@ public EditSpendingDescriptor() {}
public EditSpendingDescriptor(EditSpendingDescriptor toCopy) {
setName(toCopy.name);
setDate(toCopy.date);
setEmail(toCopy.email);
setRemark(toCopy.remark);
setCost(toCopy.cost);
setTags(toCopy.tags);
}
Expand All @@ -150,7 +151,7 @@ public EditSpendingDescriptor(EditSpendingDescriptor toCopy) {
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, date, email, cost, tags);
return CollectionUtil.isAnyNonNull(name, date, remark, cost, tags);
}

public void setName(Name name) {
Expand All @@ -169,12 +170,12 @@ public Optional<Date> getDate() {
return Optional.ofNullable(date);
}

public void setEmail(Email email) {
this.email = email;
public void setRemark(Remark remark) {
this.remark = remark;
}

public Optional<Email> getEmail() {
return Optional.ofNullable(email);
public Optional<Remark> getRemark() {
return Optional.ofNullable(remark);
}

public void setCost(Cost cost) {
Expand Down Expand Up @@ -219,7 +220,7 @@ public boolean equals(Object other) {

return getName().equals(e.getName())
&& getDate().equals(e.getDate())
&& getEmail().equals(e.getEmail())
&& getRemark().equals(e.getRemark())
&& getCost().equals(e.getCost())
&& getTags().equals(e.getTags());
}
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_COST;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import java.util.Set;
Expand All @@ -14,8 +14,8 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.spending.Cost;
import seedu.address.model.spending.Date;
import seedu.address.model.spending.Email;
import seedu.address.model.spending.Name;
import seedu.address.model.spending.Remark;
import seedu.address.model.spending.Spending;
import seedu.address.model.tag.Tag;

Expand All @@ -24,37 +24,37 @@
*/
public class AddCommandParser implements Parser<AddCommand> {


/**
* Parses the given {@code String} of arguments in the context of the AddCommand
* and returns an AddCommand object for execution.
* Parses the given {@code String} of arguments in the context of the AddCommand and returns an AddCommand object
* for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_DATE, PREFIX_EMAIL, PREFIX_COST, PREFIX_TAG);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_DATE, PREFIX_REMARK, PREFIX_COST, PREFIX_TAG);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_DATE, PREFIX_COST, PREFIX_EMAIL)
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_DATE, PREFIX_COST, PREFIX_REMARK)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}

Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Date date = ParserUtil.parseDate(argMultimap.getValue(PREFIX_DATE).get());
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Remark remark = ParserUtil.parseRemark(argMultimap.getValue(PREFIX_REMARK).get());
Cost cost = ParserUtil.parseCost(argMultimap.getValue(PREFIX_COST).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

Spending spending = new Spending(name, date, email, cost, tagList);
Spending spending = new Spending(name, date, remark, cost, tagList);

return new AddCommand(spending);
}

/**
* Returns true if none of the prefixes contains empty {@code Optional} values in the given
* {@code ArgumentMultimap}.
* Returns true if none of the prefixes contains empty {@code Optional} values in the given {@code
* ArgumentMultimap}.
*/
private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) {
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent());
}

}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class CliSyntax {
/* Prefix definitions */
public static final Prefix PREFIX_NAME = new Prefix("n/");
public static final Prefix PREFIX_DATE = new Prefix("d/");
public static final Prefix PREFIX_EMAIL = new Prefix("e/");
public static final Prefix PREFIX_REMARK = new Prefix("r/");
public static final Prefix PREFIX_COST = new Prefix("c/");
public static final Prefix PREFIX_TAG = new Prefix("t/");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_COST;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import java.util.Collection;
Expand All @@ -32,7 +32,7 @@ public class EditCommandParser implements Parser<EditCommand> {
public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_DATE, PREFIX_EMAIL, PREFIX_COST, PREFIX_TAG);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_DATE, PREFIX_REMARK, PREFIX_COST, PREFIX_TAG);

Index index;

Expand All @@ -49,8 +49,8 @@ public EditCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_DATE).isPresent()) {
editSpendingDescriptor.setDate(ParserUtil.parseDate(argMultimap.getValue(PREFIX_DATE).get()));
}
if (argMultimap.getValue(PREFIX_EMAIL).isPresent()) {
editSpendingDescriptor.setEmail(ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()));
if (argMultimap.getValue(PREFIX_REMARK).isPresent()) {
editSpendingDescriptor.setRemark(ParserUtil.parseRemark(argMultimap.getValue(PREFIX_REMARK).get()));
}
if (argMultimap.getValue(PREFIX_COST).isPresent()) {
editSpendingDescriptor.setCost(ParserUtil.parseCost(argMultimap.getValue(PREFIX_COST).get()));
Expand Down
22 changes: 7 additions & 15 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.spending.Cost;
import seedu.address.model.spending.Date;
import seedu.address.model.spending.Email;
import seedu.address.model.spending.Name;
import seedu.address.model.spending.Remark;
import seedu.address.model.tag.Tag;

/**
Expand All @@ -38,7 +38,6 @@ public static Index parseIndex(String oneBasedIndex) throws ParseException {
/**
* Parses a {@code String name} into a {@code Name}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code name} is invalid.
*/
public static Name parseName(String name) throws ParseException {
Expand All @@ -53,7 +52,6 @@ public static Name parseName(String name) throws ParseException {
/**
* Parses a {@code String date} into a {@code Date}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code date} is invalid.
*/
public static Date parseDate(String date) throws ParseException {
Expand All @@ -68,7 +66,6 @@ public static Date parseDate(String date) throws ParseException {
/**
* Parses a {@code String cost} into an {@code cost}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code cost} is invalid.
*/
public static Cost parseCost (String cost) throws ParseException {
Expand All @@ -81,24 +78,19 @@ public static Cost parseCost (String cost) throws ParseException {
}

/**
* Parses a {@code String email} into an {@code Email}.
* Parses a {@code String remark} into an {@code remark}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code email} is invalid.
* @throws ParseException if the given {@code remark} is invalid.
*/
public static Email parseEmail(String email) throws ParseException {
requireNonNull(email);
String trimmedEmail = email.trim();
if (!Email.isValidEmail(trimmedEmail)) {
throw new ParseException(Email.MESSAGE_CONSTRAINTS);
}
return new Email(trimmedEmail);
public static Remark parseRemark(String remark) throws ParseException {
requireNonNull(remark);
String trimmedRemark = remark.trim();
return new Remark(trimmedRemark);
}

/**
* Parses a {@code String tag} into a {@code Tag}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code tag} is invalid.
*/
public static Tag parseTag(String tag) throws ParseException {
Expand Down
67 changes: 0 additions & 67 deletions src/main/java/seedu/address/model/spending/Email.java

This file was deleted.

Loading

0 comments on commit fb0428c

Please sign in to comment.