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

Modify tag to create group parameter #50

Merged
merged 6 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@
4. THIRD_PARTY_PACKAGE: defined as com imports
-->
<module name="CustomImportOrder">
<property name="customImportOrderRules"
value="STATIC###STANDARD_JAVA_PACKAGE###SPECIAL_IMPORTS###THIRD_PARTY_PACKAGE"/>
<property name="specialImportsRegExp" value="^org\."/>
<property name="thirdPartyPackageRegExp" value="^com\."/>
<property name="sortImportsInGroupAlphabetically" value="true"/>
<property name="customImportOrderRules"
value="STATIC###STANDARD_JAVA_PACKAGE###SPECIAL_IMPORTS###THIRD_PARTY_PACKAGE"/>
<property name="specialImportsRegExp" value="^org\."/>
<property name="thirdPartyPackageRegExp" value="^com\."/>
<property name="sortImportsInGroupAlphabetically" value="true"/>
</module>

<!-- Checks for redundant import statements.
Expand Down Expand Up @@ -216,7 +216,7 @@
some other variants which we don't publicized to promote consistency).
-->
<property name="reliefPattern"
value="fall through|Fall through|fallthru|Fallthru|falls through|Falls through|fallthrough|Fallthrough|No break|NO break|no break|continue on"/>
value="fall through|Fall through|fallthru|Fallthru|falls through|Falls through|fallthrough|Fallthrough|No break|NO break|no break|continue on"/>
</module>

<module name="MissingSwitchDefault"/>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public static String format(Person person) {
.append(person.getAddress())
.append("; Grade: ")
.append(person.getGrade())
.append("; Tags: ");
person.getTags().forEach(builder::append);
.append("; Groups: ");
person.getGroups().forEach(builder::append);
return builder.toString();
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GROUP;
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_STUDENTID;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
Expand All @@ -30,16 +30,16 @@ public class AddCommand extends Command {
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_ADDRESS + "ADDRESS "
+ PREFIX_GRADE + "GRADE"
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "[" + PREFIX_GROUP + "GROUP]...\n"
+ "Example: " + COMMAND_WORD + " "
+ PREFIX_STUDENTID + "A0123456H "
+ PREFIX_NAME + "John Doe "
+ PREFIX_PHONE + "98765432 "
+ PREFIX_EMAIL + "[email protected] "
+ PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 "
+ PREFIX_GRADE + "A+"
+ PREFIX_TAG + "friends "
+ PREFIX_TAG + "owesMoney";
+ PREFIX_GROUP + "Group 1 "
+ PREFIX_GROUP + "Group 1B";

public static final String MESSAGE_SUCCESS = "New person added: %1$s";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book";
Expand Down
38 changes: 19 additions & 19 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GROUP;
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_STUDENTID;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS;

import java.util.Collections;
Expand All @@ -23,14 +23,14 @@
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.group.Group;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.StudentId;
import seedu.address.model.tag.Tag;

/**
* Edits the details of an existing person in the address book.
Expand All @@ -49,7 +49,7 @@ public class EditCommand extends Command {
+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_ADDRESS + "ADDRESS] "
+ "[" + PREFIX_GRADE + "GRADE] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "[" + PREFIX_GROUP + "GROUP]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_PHONE + "91234567 "
+ PREFIX_EMAIL + "[email protected]";
Expand Down Expand Up @@ -107,10 +107,10 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail());
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Grade updatedGrade = editPersonDescriptor.getGrade().orElse(personToEdit.getGrade());
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());
Set<Group> updatedGroups = editPersonDescriptor.getGroups().orElse(personToEdit.getGroups());

return new Person(updatedName, updatedStudentId, updatedPhone, updatedEmail, updatedAddress,
updatedGrade, updatedTags);
updatedGrade, updatedGroups);
}

@Override
Expand Down Expand Up @@ -147,30 +147,30 @@ public static class EditPersonDescriptor {
private Phone phone;
private Email email;
private Address address;
private Set<Group> groups;
private Grade grade;
private Set<Tag> tags;

public EditPersonDescriptor() {}

/**
* Copy constructor.
* A defensive copy of {@code tags} is used internally.
* A defensive copy of {@code groups} is used internally.
*/
public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setName(toCopy.name);
setStudentId(toCopy.studentId);
setPhone(toCopy.phone);
setEmail(toCopy.email);
setAddress(toCopy.address);
setGroups(toCopy.groups);
setGrade(toCopy.grade);
setTags(toCopy.tags);
}

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

public void setName(Name name) {
Expand Down Expand Up @@ -222,20 +222,20 @@ public Optional<Grade> getGrade() {
}

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

/**
* Returns an unmodifiable tag set, which throws {@code UnsupportedOperationException}
* Returns an unmodifiable group set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
* Returns {@code Optional#empty()} if {@code tags} is null.
* Returns {@code Optional#empty()} if {@code groups} is null.
*/
public Optional<Set<Tag>> getTags() {
return (tags != null) ? Optional.of(Collections.unmodifiableSet(tags)) : Optional.empty();
public Optional<Set<Group>> getGroups() {
return (groups != null) ? Optional.of(Collections.unmodifiableSet(groups)) : Optional.empty();
}

@Override
Expand All @@ -256,7 +256,7 @@ public boolean equals(Object other) {
&& Objects.equals(email, otherEditPersonDescriptor.email)
&& Objects.equals(address, otherEditPersonDescriptor.address)
&& Objects.equals(grade, otherEditPersonDescriptor.grade)
&& Objects.equals(tags, otherEditPersonDescriptor.tags);
&& Objects.equals(groups, otherEditPersonDescriptor.groups);
}

@Override
Expand All @@ -268,7 +268,7 @@ public String toString() {
.add("email", email)
.add("address", address)
.add("grade", grade)
.add("tags", tags)
.add("groups", groups)
.toString();
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/seedu/address/logic/parser/AddCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GROUP;
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_STUDENTID;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import java.util.Set;
import java.util.stream.Stream;

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.group.Group;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.StudentId;
import seedu.address.model.tag.Tag;

/**
* Parses input arguments and creates a new AddCommand object
Expand All @@ -36,7 +36,7 @@ public class AddCommandParser implements Parser<AddCommand> {
public AddCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_STUDENTID, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_GRADE, PREFIX_ADDRESS, PREFIX_TAG);
PREFIX_GRADE, PREFIX_ADDRESS, PREFIX_GROUP);

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_STUDENTID, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_GRADE)
Expand All @@ -52,9 +52,8 @@ public AddCommand parse(String args) throws ParseException {
Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get());
Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get());
Grade grade = ParserUtil.parseGrade(argMultimap.getValue(PREFIX_GRADE).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));

Person person = new Person(name, studentId, phone, email, address, grade, tagList);
Set<Group> groupList = ParserUtil.parseGroups(argMultimap.getAllValues(PREFIX_GROUP));
Person person = new Person(name, studentId, phone, email, address, grade, groupList);

return new AddCommand(person);
}
Expand Down
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 @@ -11,7 +11,7 @@ public class CliSyntax {
public static final Prefix PREFIX_PHONE = new Prefix("p/");
public static final Prefix PREFIX_EMAIL = new Prefix("e/");
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_GROUP = new Prefix("gp/");
public static final Prefix PREFIX_GRADE = new Prefix("g/"); //TODO: check usages
public static final Prefix PREFIX_TAG = new Prefix("t/");

}
24 changes: 12 additions & 12 deletions src/main/java/seedu/address/logic/parser/EditCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GROUP;
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_STUDENTID;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import java.util.Collection;
import java.util.Collections;
Expand All @@ -19,7 +19,7 @@
import seedu.address.logic.commands.EditCommand;
import seedu.address.logic.commands.EditCommand.EditPersonDescriptor;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.tag.Tag;
import seedu.address.model.group.Group;

/**
* Parses input arguments and creates a new EditCommand object
Expand All @@ -35,7 +35,7 @@ public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_STUDENTID, PREFIX_PHONE, PREFIX_EMAIL,
PREFIX_ADDRESS, PREFIX_GRADE, PREFIX_TAG);
PREFIX_ADDRESS, PREFIX_GRADE, PREFIX_GROUP);

Index index;

Expand Down Expand Up @@ -67,7 +67,7 @@ public EditCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_GRADE).isPresent()) {
editPersonDescriptor.setGrade(ParserUtil.parseGrade(argMultimap.getValue(PREFIX_GRADE).get()));
}
parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editPersonDescriptor::setTags);
parseGroupsForEdit(argMultimap.getAllValues(PREFIX_GROUP)).ifPresent(editPersonDescriptor::setGroups);

if (!editPersonDescriptor.isAnyFieldEdited()) {
throw new ParseException(EditCommand.MESSAGE_NOT_EDITED);
Expand All @@ -77,18 +77,18 @@ public EditCommand 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> groups} into a {@code Set<Group>} if {@code groups} is non-empty.
* If {@code groups} contain only one element which is an empty string, it will be parsed into a
* {@code Set<Group>} containing zero groups.
*/
private Optional<Set<Tag>> parseTagsForEdit(Collection<String> tags) throws ParseException {
assert tags != null;
private Optional<Set<Group>> parseGroupsForEdit(Collection<String> groups) throws ParseException {
assert groups != null;

if (tags.isEmpty()) {
if (groups.isEmpty()) {
return Optional.empty();
}
Collection<String> tagSet = tags.size() == 1 && tags.contains("") ? Collections.emptySet() : tags;
return Optional.of(ParserUtil.parseTags(tagSet));
Collection<String> groupSet = groups.size() == 1 && groups.contains("") ? Collections.emptySet() : groups;
return Optional.of(ParserUtil.parseGroups(groupSet));
}

}
33 changes: 17 additions & 16 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.group.Group;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Grade;
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
import seedu.address.model.person.StudentId;
import seedu.address.model.tag.Tag;

/**
* Contains utility methods used for parsing strings in the various *Parser classes.
Expand Down Expand Up @@ -128,30 +128,31 @@ public static Grade parseGrade(String grade) throws ParseException {
}

/**
* Parses a {@code String tag} into a {@code Tag}.
* Parses a {@code String group} into a {@code Group}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code tag} is invalid.
* @throws ParseException if the given {@code group} is invalid.
*/
public static Tag parseTag(String tag) throws ParseException {
requireNonNull(tag);
String trimmedTag = tag.trim();
if (!Tag.isValidTagName(trimmedTag)) {
throw new ParseException(Tag.MESSAGE_CONSTRAINTS);
public static Group parseGroup(String group) throws ParseException {
requireNonNull(group);
String trimmedGroup = group.trim();
if (!Group.isValidGroupName(trimmedGroup)) {
throw new ParseException(Group.MESSAGE_CONSTRAINTS);
}
return new Tag(trimmedTag);
return new Group(trimmedGroup);
}

/**
* Parses {@code Collection<String> tags} into a {@code Set<Tag>}.
* Parses {@code Collection<String> groups} into a {@code Set<Group>}.
*/
public static Set<Tag> parseTags(Collection<String> tags) throws ParseException {
requireNonNull(tags);
final Set<Tag> tagSet = new HashSet<>();
for (String tagName : tags) {
tagSet.add(parseTag(tagName));
public static Set<Group> parseGroups(Collection<String> groups) throws ParseException {
requireNonNull(groups);
final Set<Group> groupSet = new HashSet<>();
for (String groupName : groups) {
groupSet.add(parseGroup(groupName));
}
return tagSet;
return groupSet;

}


Expand Down
Loading
Loading