Skip to content

Commit

Permalink
Merge pull request #238 from xxiaoweii/name-field-bug
Browse files Browse the repository at this point in the history
Fix bugs related to Add Command
  • Loading branch information
kayabuttertoastt authored Nov 11, 2023
2 parents afd9ef8 + 9994a25 commit 4a34707
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 12 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 @@ -48,6 +48,9 @@ public class AddCommand extends Command {
public static final String MESSAGE_DUPLICATE_PERSON = "Note: A person with the same name already exists." + "\n"
+ "Please edit the existing person or change the name of this person to be added";

public static final String MESSAGE_NAME_MISSING = "Note: Compulsory name input is missing"
+ "\nUnable to add a person without name";

private final Person toAdd;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ public AddCommand parse(String args) throws ParseException {
PREFIX_ROLE, PREFIX_CONTACT,
PREFIX_COURSE);

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

if (!arePrefixesPresent(argMultimap, PREFIX_NAME)) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_NAME_MISSING));
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_ROLE, PREFIX_CONTACT, PREFIX_COURSE);
Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Set<Role> roleList = ParserUtil.parseRoles(argMultimap.getAllValues(PREFIX_ROLE));
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
public class CliSyntax {

/* Prefix definitions */
public static final Prefix PREFIX_NAME = new Prefix("--name");
public static final Prefix PREFIX_ROLE = new Prefix("--role");
public static final Prefix PREFIX_CONTACT = new Prefix("--contact");
public static final Prefix PREFIX_COURSE = new Prefix("--course");
public static final Prefix PREFIX_NAME = new Prefix("--name ");
public static final Prefix PREFIX_ROLE = new Prefix("--role ");
public static final Prefix PREFIX_CONTACT = new Prefix("--contact ");
public static final Prefix PREFIX_COURSE = new Prefix("--course ");
public static final Prefix PREFIX_TUTORIAL = new Prefix("--tutorial");
public static final Prefix PREFIX_ADD = new Prefix("--add");
public static final Prefix PREFIX_DELETE = new Prefix("--delete");
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public static Set<Role> parseRoles(Collection<String> roles) throws ParseExcepti
for (String roleName : roleNameSplit) {
if (!roleName.trim().isEmpty()) {
roleSet.add(parseRole(roleName));
} else {
throw new ParseException(Role.MESSAGE_CONSTRAINTS);
}
}
}
Expand Down Expand Up @@ -145,7 +147,8 @@ public static Set<Course> parseCourses(Collection<String> courses) throws ParseE
String[] splitCourse = courseNames.split(Course.PARSE_COURSE_DELIMITER);
for (String courseName : splitCourse) {
if (!courseName.trim().isEmpty()) {
courseSet.add(parseCourse(courseName));
String courseNameUpperCase = courseName.toUpperCase();
courseSet.add(parseCourse(courseNameUpperCase));
} else {
throw new ParseException(Course.MESSAGE_CONSTRAINTS);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/person/Course.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public boolean equals(Object other) {
}

Course otherCourse = (Course) other;
return courseName.equals(otherCourse.courseName);
return courseName.equalsIgnoreCase(otherCourse.courseName);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/person/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public boolean equals(Object other) {
}

Name otherName = (Name) other;
return fullName.equals(otherName.fullName);
return fullName.equalsIgnoreCase(otherName.fullName);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/person/Tutorial.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Tutorial {
"Given course's name (%s) does not match Tutorial's course name (%s).";

// Matches a single character, any number of characters, a slash, a single character, then any number of characters.
public static final String VALIDATION_REGEX = "^[A-Za-z]{2,3}\\d{4}[A-Za-z]?\\/[^\\s].*$";
public static final String VALIDATION_REGEX = "^[A-Za-z]{2,3}\\d{4}[A-Za-z]?\\/[A-Za-z0-9]*-?[A-Za-z0-9].*$";

// A tutorial String is in the format of courseName + COURSE_TUTORIAL_DELIMITER + tutorialName.
// This is a constant representing that delimiter.
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/seedu/address/model/person/PersonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public void isSamePerson() {
editedAlice = new PersonBuilder(ALICE).withName(VALID_NAME_BOB).build();
assertFalse(ALICE.isSamePerson(editedAlice));

// name differs in case, all other attributes same -> returns false
// name differs in case, all other attributes same -> returns true
Person editedBob = new PersonBuilder(BOB).withName(VALID_NAME_BOB.toLowerCase()).build();
assertFalse(BOB.isSamePerson(editedBob));
assertTrue(BOB.isSamePerson(editedBob));

// name has trailing spaces, all other attributes same -> returns false
String nameWithTrailingSpaces = VALID_NAME_BOB + " ";
Expand Down

0 comments on commit 4a34707

Please sign in to comment.