Skip to content

Commit

Permalink
Merge pull request #157 from rgonslayer/plan-tag-4
Browse files Browse the repository at this point in the history
Add Plan Tag Feature
  • Loading branch information
senwei01 authored Oct 25, 2022
2 parents 5dae718 + 2b6cea3 commit 7f20abf
Show file tree
Hide file tree
Showing 32 changed files with 371 additions and 116 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ run {
}

dependencies {
String jUnitVersion = '5.4.0'
String jUnitVersion = '5.9.0'
String javaFxVersion = '11'

implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win'
Expand Down
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 @@ -7,6 +7,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_MONTHLY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PLANTAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_RISKTAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

Expand All @@ -30,6 +31,7 @@ public class AddCommand extends Command {
+ "[" + PREFIX_INCOME + "INCOME] "
+ "[" + PREFIX_MONTHLY + "MONTHLY] "
+ "[" + PREFIX_RISKTAG + "RISKTAG] "
+ "[" + PREFIX_PLANTAG + "PLANTAG] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_NAME + "John Doe "
Expand All @@ -39,6 +41,7 @@ public class AddCommand extends Command {
+ PREFIX_INCOME + "$1000 "
+ PREFIX_MONTHLY + "$200 "
+ PREFIX_RISKTAG + "HIGH "
+ PREFIX_PLANTAG + "Savings Plan"
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_MONTHLY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PLANTAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_RISKTAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.EditPersonDescriptor.createEditedPerson;
Expand Down Expand Up @@ -39,6 +40,7 @@ public class EditCommand extends Command {
+ "[" + PREFIX_INCOME + "INCOME] "
+ "[" + PREFIX_MONTHLY + "MONTHLY} "
+ "[" + PREFIX_RISKTAG + "RISKTAG] "
+ "[" + PREFIX_PLANTAG + "PLANTAG] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_MONTHLY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PLANTAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_RISKTAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

Expand All @@ -24,8 +25,9 @@
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.tag.NormalTag;
import seedu.address.model.tag.PlanTag;
import seedu.address.model.tag.RiskTag;
import seedu.address.model.tag.Tag;

/**
* Parses input arguments and creates a new AddCommand object
Expand All @@ -41,10 +43,10 @@ public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_ADDRESS, PREFIX_INCOME, PREFIX_MONTHLY, PREFIX_RISKTAG,
PREFIX_TAG, PREFIX_APPOINTMENT_DATE, PREFIX_APPOINTMENT_LOCATION);
PREFIX_PLANTAG, PREFIX_TAG, PREFIX_APPOINTMENT_DATE, PREFIX_APPOINTMENT_LOCATION);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE,
PREFIX_EMAIL, PREFIX_INCOME, PREFIX_MONTHLY, PREFIX_RISKTAG)
PREFIX_EMAIL, PREFIX_INCOME, PREFIX_MONTHLY, PREFIX_PLANTAG, PREFIX_RISKTAG)
|| !argMultimap.getPreamble().isEmpty()
|| arePrefixesPresent(argMultimap, PREFIX_APPOINTMENT_DATE, PREFIX_APPOINTMENT_LOCATION)) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
Expand All @@ -57,9 +59,9 @@ public AddCommand parse(String args) throws ParseException {
IncomeLevel incomeLevel = ParserUtil.parseIncomeLevel(argMultimap.getValue(PREFIX_INCOME).get());
Monthly monthly = ParserUtil.parseMonthly(argMultimap.getValue(PREFIX_MONTHLY).get());
RiskTag riskTag = ParserUtil.parseRiskTag(argMultimap.getValue(PREFIX_RISKTAG).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

Person person = new Person(name, phone, email, address, incomeLevel, monthly, riskTag, tagList);
PlanTag planTag = ParserUtil.parsePlanTag(argMultimap.getValue(PREFIX_PLANTAG).get());
Set<NormalTag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));
Person person = new Person(name, phone, email, address, incomeLevel, monthly, riskTag, planTag, tagList);

return new AddCommand(person);
}
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 @@ -11,6 +11,7 @@ public class CliSyntax {
public static final Prefix PREFIX_EMAIL = new Prefix("e/");
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_RISKTAG = new Prefix("r/");
public static final Prefix PREFIX_PLANTAG = new Prefix("ip/");
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_APPOINTMENT_DATE = new Prefix("d/");
public static final Prefix PREFIX_APPOINTMENT_LOCATION = new Prefix("l/");
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/seedu/address/logic/parser/EditCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_MONTHLY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PLANTAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_RISKTAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

Expand All @@ -19,7 +20,7 @@
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.EditCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.tag.Tag;
import seedu.address.model.tag.NormalTag;

/**
* Parses input arguments and creates a new EditCommand object
Expand All @@ -34,7 +35,8 @@ public class EditCommandParser implements Parser<EditCommand> {
public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE,
PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_INCOME, PREFIX_MONTHLY, PREFIX_RISKTAG, PREFIX_TAG);
PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_INCOME, PREFIX_MONTHLY,
PREFIX_RISKTAG, PREFIX_PLANTAG, PREFIX_TAG);

Index index;

Expand All @@ -60,6 +62,9 @@ public EditCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_RISKTAG).isPresent()) {
editPersonDescriptor.setRiskTag(ParserUtil.parseRiskTag(argMultimap.getValue(PREFIX_RISKTAG).get()));
}
if (argMultimap.getValue(PREFIX_PLANTAG).isPresent()) {
editPersonDescriptor.setPlanTag(ParserUtil.parsePlanTag(argMultimap.getValue(PREFIX_PLANTAG).get()));
}
if (argMultimap.getValue(PREFIX_INCOME).isPresent()) {
editPersonDescriptor.setIncome(ParserUtil.parseIncomeLevel(argMultimap.getValue(PREFIX_INCOME).get()));
}
Expand All @@ -81,7 +86,7 @@ public EditCommand parse(String args) throws ParseException {
* If {@code tags} contain only one element which is an empty string, it will be parsed into a
* {@code Set<Tag>} containing zero tags.
*/
private Optional<Set<Tag>> parseTagsForEdit(Collection<String> tags) throws ParseException {
private Optional<Set<NormalTag>> parseTagsForEdit(Collection<String> tags) throws ParseException {
assert tags != null;

if (tags.isEmpty()) {
Expand Down
28 changes: 21 additions & 7 deletions src/main/java/seedu/address/logic/parser/EditPersonDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.tag.NormalTag;
import seedu.address.model.tag.PlanTag;
import seedu.address.model.tag.RiskTag;
import seedu.address.model.tag.Tag;

/**
* Stores the details to edit the person with. Each non-empty field value will replace the
Expand All @@ -30,7 +31,8 @@ public class EditPersonDescriptor {
private IncomeLevel income;
private Monthly monthly;
private RiskTag riskTag;
private Set<Tag> tags;
private PlanTag planTag;
private Set<NormalTag> tags;
public EditPersonDescriptor() {}

/**
Expand All @@ -45,14 +47,15 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setIncome(toCopy.income);
setMonthly(toCopy.monthly);
setRiskTag(toCopy.riskTag);
setPlanTag(toCopy.planTag);
setTags(toCopy.tags);
}

/**
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, phone, email, address, income, monthly, riskTag, tags);
return CollectionUtil.isAnyNonNull(name, phone, email, address, income, monthly, riskTag, planTag, tags);
}

public void setName(Name name) {
Expand Down Expand Up @@ -95,6 +98,14 @@ public Optional<RiskTag> getRiskTag() {
return Optional.ofNullable(riskTag);
}

public void setPlanTag(PlanTag planTag) {
this.planTag = planTag;
}

public Optional<PlanTag> getPlanTag() {
return Optional.ofNullable(planTag);
}

public void setIncome(IncomeLevel income) {
this.income = income;
}
Expand All @@ -112,7 +123,7 @@ public Optional<Monthly> getMonthly() {
* Sets {@code tags} to this object's {@code tags}.
* A defensive copy of {@code tags} is used internally.
*/
public void setTags(Set<Tag> tags) {
public void setTags(Set<NormalTag> tags) {
this.tags = (tags != null) ? new HashSet<>(tags) : null;
}

Expand All @@ -121,7 +132,7 @@ public void setTags(Set<Tag> tags) {
* if modification is attempted.
* Returns {@code Optional#empty()} if {@code tags} is null.
*/
public Optional<Set<Tag>> getTags() {
public Optional<Set<NormalTag>> getTags() {
return (tags != null) ? Optional.of(Collections.unmodifiableSet(tags)) : Optional.empty();
}

Expand All @@ -139,11 +150,13 @@ public static Person createEditedPerson(Person personToEdit, EditPersonDescripto
IncomeLevel updatedIncomeLevel = editPersonDescriptor.getIncome().orElse(personToEdit.getIncome());
Monthly updateMonthly = editPersonDescriptor.getMonthly().orElse(personToEdit.getMonthly());
RiskTag updatedRiskTag = editPersonDescriptor.getRiskTag().orElse(personToEdit.getRiskTag());
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());
PlanTag updatedPlanTag = editPersonDescriptor.getPlanTag().orElse(personToEdit.getPlanTag());
Set<NormalTag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());
MaximumSortedList<Appointment> originalAppointments = personToEdit.getAppointments();

return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedIncomeLevel,
updateMonthly, updatedRiskTag, updatedTags, originalAppointments);
updateMonthly, updatedRiskTag, updatedPlanTag, updatedTags, originalAppointments);

}
@Override
public boolean equals(Object other) {
Expand All @@ -166,6 +179,7 @@ && getEmail().equals(e.getEmail())
&& getAddress().equals(e.getAddress())
&& getRiskTag().equals(e.getRiskTag())
&& getMonthly().equals(e.getMonthly())
&& getPlanTag().equals(e.getPlanTag())
&& getTags().equals(e.getTags());
}
}
29 changes: 21 additions & 8 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
import seedu.address.model.person.Monthly;
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
import seedu.address.model.tag.NormalTag;
import seedu.address.model.tag.PlanTag;
import seedu.address.model.tag.RiskTag;
import seedu.address.model.tag.Tag;

/**
* Contains utility methods used for parsing strings in the various *Parser classes.
Expand Down Expand Up @@ -217,7 +218,7 @@ public static Monthly parseMonthly(String monthly) throws ParseException {
}

/**
* Parses a {@code String dateAndTime} into an {@code DateTime}.
* Parses a {@code String riskTag} into an {@code RiskTag}.
* Leading and trailing whitespaces will be trimmed.
*/
public static RiskTag parseRiskTag(String riskTag) throws ParseException {
Expand All @@ -229,28 +230,40 @@ public static RiskTag parseRiskTag(String riskTag) throws ParseException {
return new RiskTag(trimmedRiskTag);
}

/**
* Parses a {@code String planTag} into an {@code PlanTag}.
* Leading and trailing whitespaces will be trimmed.
*/
public static PlanTag parsePlanTag(String planTag) throws ParseException {
requireNonNull(planTag);
String trimmedPlanTag = planTag.trim();
if (!PlanTag.isValidPlanTagName(trimmedPlanTag)) {
throw new ParseException(PlanTag.MESSAGE_CONSTRAINTS);
}
return new PlanTag(trimmedPlanTag);
}

/**
* 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 {
public static NormalTag parseTag(String tag) throws ParseException {
requireNonNull(tag);
String trimmedTag = tag.trim();
if (!Tag.isValidTagName(trimmedTag)) {
throw new ParseException(Tag.MESSAGE_CONSTRAINTS);
if (!NormalTag.isValidTagName(trimmedTag)) {
throw new ParseException(NormalTag.MESSAGE_CONSTRAINTS);
}
return new Tag(trimmedTag);
return new NormalTag(trimmedTag);
}

/**
* Parses {@code Collection<String> tags} into a {@code Set<Tag>}.
*/
public static Set<Tag> parseTags(Collection<String> tags) throws ParseException {
public static Set<NormalTag> parseTags(Collection<String> tags) throws ParseException {
requireNonNull(tags);
final Set<Tag> tagSet = new HashSet<>();
final Set<NormalTag> tagSet = new HashSet<>();
for (String tagName : tags) {
tagSet.add(parseTag(tagName));
}
Expand Down
23 changes: 16 additions & 7 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import seedu.address.logic.util.MaximumSortedList;
import seedu.address.model.calendar.CalendarEvent;
import seedu.address.model.tag.NormalTag;
import seedu.address.model.tag.PlanTag;
import seedu.address.model.tag.RiskTag;
import seedu.address.model.tag.Tag;

Expand All @@ -30,24 +32,26 @@ public class Person {
// Data fields
private final Address address;
private final RiskTag riskTag;
private final PlanTag planTag;
private final Set<Tag> specialTags = new HashSet<>();

private final Set<Tag> tags = new HashSet<>();
private final Set<NormalTag> tags = new HashSet<>();
private MaximumSortedList<Appointment> appointments = new MaximumSortedList<>(MAXIMUM_NUM_OF_APPOINTMENTS);

/**
* Every field must be present and not null.
*/
public Person(Name name, Phone phone, Email email, Address address, IncomeLevel incomeLevel,
Monthly monthly, RiskTag riskTag, Set<Tag> tags) {
requireAllNonNull(name, phone, email, address, incomeLevel, monthly, riskTag, tags);
Monthly monthly, RiskTag riskTag, PlanTag planTag, Set<NormalTag> tags) {
requireAllNonNull(name, phone, email, address, incomeLevel, monthly, riskTag, planTag, tags);

this.name = name;
this.phone = phone;
this.email = email;
this.address = address;
this.riskTag = riskTag;
this.planTag = planTag;
this.specialTags.add(riskTag);
this.specialTags.add(planTag);
this.incomeLevel = incomeLevel;
this.monthly = monthly;
this.tags.addAll(tags);
Expand All @@ -57,14 +61,16 @@ public Person(Name name, Phone phone, Email email, Address address, IncomeLevel
* Every field must be present and not null.
*/
public Person(Name name, Phone phone, Email email, Address address, IncomeLevel incomeLevel, Monthly monthly,
RiskTag riskTag, Set<Tag> tags, MaximumSortedList<Appointment> appointments) {
RiskTag riskTag, PlanTag planTag, Set<NormalTag> tags, MaximumSortedList<Appointment> appointments) {
requireAllNonNull(name, phone, email, address, tags);
this.name = name;
this.phone = phone;
this.email = email;
this.address = address;
this.riskTag = riskTag;
this.planTag = planTag;
this.specialTags.add(riskTag);
this.specialTags.add(planTag);
this.monthly = monthly;
this.tags.addAll(tags);
this.appointments = appointments;
Expand Down Expand Up @@ -106,13 +112,16 @@ public IncomeLevel getIncome() {
public RiskTag getRiskTag() {
return riskTag;
}
public PlanTag getPlanTag() {
return planTag;
}


/**
* Returns an immutable tag set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
*/
public Set<Tag> getTags() {
public Set<NormalTag> getTags() {
return Collections.unmodifiableSet(tags);
}
public Set<Tag> getSpecialTags() {
Expand Down Expand Up @@ -186,7 +195,7 @@ public String toString() {
);
}

Set<Tag> tags = getTags();
Set<NormalTag> tags = getTags();
if (!tags.isEmpty()) {
builder.append("; Tags: ");
tags.forEach(builder::append);
Expand Down
Loading

0 comments on commit 7f20abf

Please sign in to comment.