Skip to content

Commit

Permalink
Update files for Edit command
Browse files Browse the repository at this point in the history
  • Loading branch information
gongg21 committed Oct 16, 2023
1 parent f8c4a2e commit 677f489
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
20 changes: 17 additions & 3 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_COURSE;
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_STUDENTS;

Expand Down Expand Up @@ -41,6 +42,7 @@ public class EditCommand extends Command {
+ "[" + PREFIX_NAME + "NAME] "
+ "[" + PREFIX_COURSE + "COURSE] "
+ "[" + PREFIX_EMAIL + "EMAIL] "
+ "[" + PREFIX_REMARK + "REMARK] "
+ "[" + PREFIX_TAG + "TAG]...\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_COURSE + "CS2103T "
Expand Down Expand Up @@ -96,7 +98,7 @@ private static Student createEditedStudent(Student studentToEdit, EditStudentDes
Name updatedName = editStudentDescriptor.getName().orElse(studentToEdit.getName());
Course updatedCourse = editStudentDescriptor.getCourse().orElse(studentToEdit.getCourse());
Email updatedEmail = editStudentDescriptor.getEmail().orElse(studentToEdit.getEmail());
Remark updatedRemark = studentToEdit.getRemark(); // edit command does not allow editing remarks
Remark updatedRemark = editStudentDescriptor.getRemark().orElse(studentToEdit.getRemark());
Set<Tag> updatedTags = editStudentDescriptor.getTags().orElse(studentToEdit.getTags());

return new Student(updatedName, updatedCourse, updatedEmail, updatedRemark, updatedTags);
Expand Down Expand Up @@ -134,6 +136,7 @@ public static class EditStudentDescriptor {
private Name name;
private Course course;
private Email email;
private Remark remark;
private Set<Tag> tags;

public EditStudentDescriptor() {}
Expand All @@ -146,14 +149,15 @@ public EditStudentDescriptor(EditStudentDescriptor toCopy) {
setName(toCopy.name);
setCourse(toCopy.course);
setEmail(toCopy.email);
setRemark(toCopy.remark);
setTags(toCopy.tags);
}

/**
* Returns true if at least one field is edited.
*/
public boolean isAnyFieldEdited() {
return CollectionUtil.isAnyNonNull(name, course, email, tags);
return CollectionUtil.isAnyNonNull(name, course, email, remark, tags);
}

public void setName(Name name) {
Expand All @@ -180,6 +184,14 @@ public Optional<Email> getEmail() {
return Optional.ofNullable(email);
}

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

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

/**
* Sets {@code tags} to this object's {@code tags}.
* A defensive copy of {@code tags} is used internally.
Expand Down Expand Up @@ -212,6 +224,7 @@ public boolean equals(Object other) {
return Objects.equals(name, otherEditStudentDescriptor.name)
&& Objects.equals(course, otherEditStudentDescriptor.course)
&& Objects.equals(email, otherEditStudentDescriptor.email)
&& Objects.equals(remark, otherEditStudentDescriptor.remark)
&& Objects.equals(tags, otherEditStudentDescriptor.tags);
}

Expand All @@ -221,6 +234,7 @@ public String toString() {
.add("name", name)
.add("course", course)
.add("email", email)
.add("email", remark)
.add("tags", tags)
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ExitCommand extends Command {

public static final String COMMAND_WORD = "exit";

public static final String MESSAGE_EXIT_ACKNOWLEDGEMENT = "Exiting Address Book as requested ...";
public static final String MESSAGE_EXIT_ACKNOWLEDGEMENT = "Exiting CodeSphere ...";

@Override
public CommandResult execute(Model model) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_COURSE;
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 @@ -30,7 +31,7 @@ public class EditCommandParser implements Parser<EditCommand> {
public EditCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_COURSE, PREFIX_EMAIL, PREFIX_TAG);
ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_COURSE, PREFIX_EMAIL, PREFIX_REMARK, PREFIX_TAG);

Index index;

Expand All @@ -40,7 +41,7 @@ public EditCommand parse(String args) throws ParseException {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE), pe);
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_COURSE, PREFIX_EMAIL);
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_COURSE, PREFIX_REMARK, PREFIX_EMAIL);

EditCommand.EditStudentDescriptor editStudentDescriptor = new EditCommand.EditStudentDescriptor();

Expand All @@ -53,6 +54,9 @@ public EditCommand parse(String args) throws ParseException {
if (argMultimap.getValue(PREFIX_EMAIL).isPresent()) {
editStudentDescriptor.setEmail(ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()));
}
if (argMultimap.getValue(PREFIX_REMARK).isPresent()) {
editStudentDescriptor.setRemark(ParserUtil.parseRemark(argMultimap.getValue(PREFIX_REMARK).get()));
}

parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editStudentDescriptor::setTags);

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import seedu.address.model.person.Course;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Remark;
import seedu.address.model.tag.StudentRank;
import seedu.address.model.tag.Tag;

Expand Down Expand Up @@ -80,6 +81,16 @@ public static Email parseEmail(String email) throws ParseException {
return new Email(trimmedEmail);
}

/**
* Parses a {@code String remark} into an {@code Remark}.
* Leading and trailing whitespaces will be trimmed.
*/
public static Remark parseRemark(String remark) {
requireNonNull(remark);
String trimmedRemark = remark.trim();
return new Remark(trimmedRemark);
}

/**
* Parses a {@code StudentRank tag} into a {@code Tag}.
* Leading and trailing whitespaces will be trimmed.
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/address/model/person/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Student {
* Every field must be present and not null.
*/
public Student(Name name, Course course, Email email, Remark remark, Set<Tag> tags) {
requireAllNonNull(name, course, email, tags);
requireAllNonNull(name, course, email, remark, tags);
this.name = name;
this.course = course;
this.email = email;
Expand Down Expand Up @@ -95,13 +95,14 @@ public boolean equals(Object other) {
return otherStudent.getName().equals(getName())
&& otherStudent.getCourse().equals(getCourse())
&& otherStudent.getEmail().equals(getEmail())
&& otherStudent.getRemark().equals(getRemark())
&& otherStudent.getTags().equals(getTags());
}

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

@Override
Expand Down

0 comments on commit 677f489

Please sign in to comment.