Skip to content

Commit

Permalink
Merge pull request #250 from ghos7ie/code-changes
Browse files Browse the repository at this point in the history
Enhance Find commands and update GroupName regex
  • Loading branch information
SooYap authored Nov 4, 2024
2 parents 83cece2 + 29f82bc commit 99b692f
Show file tree
Hide file tree
Showing 29 changed files with 128 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
public class AddExistingTaskToGroupCommand extends Command {

public static final String COMMAND_WORD = "add_et_grp";
public static final String COMMAND_WORD = "add_et_g";
public static final String COMMAND_WORD_ALIAS = "aetg";

public static final String MESSAGE_USAGE = COMMAND_WORD + "/" + COMMAND_WORD_ALIAS
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/seedu/address/model/group/GroupName.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
public class GroupName {

public static final String MESSAGE_CONSTRAINTS =
"Group Names should only contain alphanumeric characters, spaces and hyphens, and it should not be blank.";
"Group Names must have 3 sections:\n"
+ "1. Course type - CS2103 or CS2103T\n"
+ "2. Tutorial Group - Any letter followed by a number\n"
+ "3. Group Number - Any number\n"
+ "e.g. CS2103T-W1-12 or CS2103-I2-9";

/*
* The first character of the address must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
*/
public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} \\-]*";
public static final String VALIDATION_REGEX = "^(?i)CS2103T?-[A-Z]\\d+-\\d+$";

private final String fullName;

Expand All @@ -28,7 +32,7 @@ public class GroupName {
public GroupName(String name) {
requireNonNull(name);
checkArgument(isValidName(name), MESSAGE_CONSTRAINTS);
fullName = name;
fullName = name.toUpperCase();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public boolean test(Group group) {
.anyMatch(keyword -> {
GroupName groupName = group.getGroupName();
String groupNameString = groupName.getGroupName().toLowerCase();
return groupNameString.equalsIgnoreCase(keyword);
return groupNameString.contains(keyword.toLowerCase());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import java.util.function.Predicate;

import seedu.address.commons.util.StringUtil;
import seedu.address.commons.util.ToStringBuilder;

/**
Expand All @@ -18,12 +19,16 @@ public StudentMatchesQueryPredicate(List<String> keywords) {

@Override
public boolean test(Student student) {
String groupName = student.getGroupName().isPresent()
? student.getGroupName().get().getGroupName() : "!nogroup";
return
keywords.stream().anyMatch(keyword ->
student.getStudentNumber().getStudentNumber().equalsIgnoreCase(keyword)
|| student.getName().getFullName().equalsIgnoreCase(keyword)
|| student.getTags().stream().anyMatch(tag -> tag.getTagName().equalsIgnoreCase(keyword))
|| student.getEmail().getEmail().equalsIgnoreCase(keyword));
StringUtil.containsWordIgnoreCase(student.getStudentNumber().getStudentNumber(), keyword)
|| StringUtil.containsWordIgnoreCase(student.getName().getFullName(), keyword)
|| student.getTags().stream().anyMatch(tag -> StringUtil.containsWordIgnoreCase(tag.getTagName(),
keyword))
|| StringUtil.containsWordIgnoreCase(student.getEmail().getEmail(), keyword)
|| groupName.equals(keyword));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import java.util.function.Predicate;

import seedu.address.commons.util.StringUtil;
import seedu.address.commons.util.ToStringBuilder;

/**
Expand All @@ -21,7 +22,7 @@ public boolean test(Task task) {
return keywords.stream().anyMatch(keyword -> {
TaskName taskName = task.getTaskName();
String taskNameString = taskName.toString().toLowerCase();
return taskNameString.equalsIgnoreCase(keyword);
return StringUtil.containsWordIgnoreCase(taskNameString, keyword);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"email" : "[email protected]",
"tags" : [ ],
"studentNumber" : "A0123456B",
"groupName" : "Group 1"
"groupName" : "CS2103-F12-2"
}, {
"name" : "Student C",
"email" : "[email protected]",
Expand All @@ -16,7 +16,7 @@
"email" : "[email protected]",
"tags" : [ ],
"studentNumber" : "A0123456D",
"groupName" : "Group 1"
"groupName" : "CS2103-F12-2"
}, {
"name" : "Student A",
"email" : "[email protected]",
Expand All @@ -30,7 +30,7 @@
"email" : "[email protected]",
"tags" : [ ],
"studentNumber" : "A0123456D",
"groupName" : "Group 1"
"groupName" : "CS2103-F12-2"
}, {
"name" : "Student B",
"email" : "[email protected]",
Expand All @@ -39,11 +39,11 @@
"groupName" : "!"
} ],
"tasks" : [ ],
"groupName" : "Group 1"
"groupName" : "CS2103-F12-2"
},{
"students" : [ ],
"tasks" : [ ],
"groupName" : "Group 1"
"groupName" : "CS2103-F12-2"
} ],
"tasks" : [ ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"email": "[email protected]",
"tags": [ "friends" ],
"student number" : "A0111111J",
"group": "Team 1"
"group": "CS2103-F12-2"
}, {
"name": "Alice Pauline",
"email": "[email protected]",
"student number" : "A0111111J",
"group": "Team 1"
"group": "CS2103-F12-2"
} ],
"groups" : [ ],
"tasks" : [ ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Hans Muster",
"email": "invalid@email!3e",
"student number": "A0123456Z",
"group": "Team 1"
"group": "CS2103-F12-2"
} ],
"groups" : [ ],
"tasks" : [ ]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
{
"persons" : [ ],
"tasks" : [ ],
"groups" : [ {
"students" : [ ],
"tasks" : [ ],
"groupName" : "Team5"
"groupName" : "CS2103T-F12-5"
}, {
"students" : [ ],
"tasks" : [ ],
"groupName" : "Team4"
"groupName" : "CS2103T-F12-4"
}, {
"students" : [ ],
"tasks" : [ ],
"groupName" : "Team3"
"groupName" : "CS2103-F12-3"
}, {
"students" : [ ],
"tasks" : [ ],
"groupName" : "Team2"
"groupName" : "CS2103-F12-2"
}, {
"students" : [ ],
"tasks" : [ ],
"groupName" : "Group1"
"groupName" : "CS2103-F12-1"
}, {
"students" : [ ],
"tasks" : [ ],
"groupName" : "Team1"
"groupName" : "CS2103T-F12-6"
}, {
"students" : [ ],
"tasks" : [ ],
"groupName" : "Group10"
"groupName" : "CS2103T-F12-7"
} ],
"tasks" : [ ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,43 @@
"email" : "[email protected]",
"tags" : [ "friends" ],
"student number" : "A0111111J",
"group" : "Team 1"
"group" : "CS2103-F12-1"
}, {
"name" : "Benson Meier",
"email" : "[email protected]",
"tags" : [ "owesMoney", "friends" ],
"student number" : "A0222222H",
"group" : "Team 2"
"group" : "CS2103-F12-2"
}, {
"name" : "Carl Kurz",
"email" : "[email protected]",
"tags" : [ ],
"student number" : "A0333333M",
"group" : "Team 3"
"group" : "CS2103-F12-3"
}, {
"name" : "Daniel Meier",
"email" : "[email protected]",
"tags" : [ "friends" ],
"student number" : "A0444444N",
"group" : "Team 2"
"group" : "CS2103-F12-4"
}, {
"name" : "Elle Meyer",
"email" : "[email protected]",
"tags" : [ ],
"student number" : "A0555555H",
"group" : "Team 1"
"group" : "CS2103-F12-5"
}, {
"name" : "Fiona Kunz",
"email" : "[email protected]",
"tags" : [ ],
"student number" : "A0666666J",
"group" : "Team 2"
"group" : "CS2103-F12-6"
}, {
"name" : "George Best",
"email" : "[email protected]",
"tags" : [ ],
"student number" : "A0888888M",
"group" : "Team 1"
"group" : "CS2103-F12-7"
} ],
"groups" : [ ],
"tasks" : [ ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

public class AddGroupCommandTest {

private static final GroupName VALID_GROUPNAME = new GroupName("Team1");
private static final GroupName VALID_GROUPNAME = new GroupName("CS2103-F12-4");

@Test
public void constructor_nullGroup_throwsNullPointerException() {
Expand Down Expand Up @@ -72,8 +72,8 @@ public void execute_duplicatePerson_throwsCommandException() {

@Test
public void equals() {
Group teamOne = new Group(new GroupName("Team 1"), new HashSet<>(), new HashSet<>());
Group teamTwo = new Group(new GroupName("Team 2"), new HashSet<>(), new HashSet<>());
Group teamOne = new Group(new GroupName("CS2103T-F1-12"), new HashSet<>(), new HashSet<>());
Group teamTwo = new Group(new GroupName("CS2103-F12-2"), new HashSet<>(), new HashSet<>());
List<Group> testGroups = new ArrayList<Group>();
testGroups.add(teamOne);
List<Group> testGroupsSecond = new ArrayList<Group>();
Expand All @@ -100,7 +100,7 @@ public void equals() {

@Test
public void toStringMethod() {
Group teamOne = new Group(new GroupName("Team 1"), new HashSet<>(), new HashSet<>());
Group teamOne = new Group(new GroupName("CS2103-F12-2"), new HashSet<>(), new HashSet<>());
List<Group> testGroups = new ArrayList<Group>();
testGroups.add(teamOne);
AddGroupCommand addTeamOneCommand = new AddGroupCommand(testGroups);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void toStringMethod() {
}

/**
* A default model stub that have all of the methods failing.
* A default model stub that have all the methods failing.
*/
private class ModelStub implements Model {
@Override
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/seedu/address/logic/commands/CommandTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public class CommandTestUtil {
public static final String VALID_STUDENT_NUMBER_AMY = "A0234567J";
public static final String VALID_STUDENT_NUMBER_BOB = "A0224466H";

public static final String TEAM_ONE = "Team1";
public static final String TEAM_TWO = "Team2";
public static final String TEAM_THREE = "Team3";
public static final String TEAM_FOUR = "Team4";
public static final String TEAM_FIVE = "Team5";
public static final String GROUP_ONE = "Group1";
public static final String GROUP_TEN = "Group10";
public static final String TEAM_ONE = "CS2103-F12-1";
public static final String TEAM_TWO = "CS2103-F12-2";
public static final String TEAM_THREE = "CS2103-F12-3";
public static final String TEAM_FOUR = "CS2103T-F12-4";
public static final String TEAM_FIVE = "CS2103T-F12-5";
public static final String GROUP_ONE = "CS2103T-F12-6";
public static final String GROUP_TEN = "CS2103T-F12-7";

public static final String NAME_DESC_AMY = " " + PREFIX_STUDENT_NAME + VALID_NAME_AMY;
public static final String NAME_DESC_BOB = " " + PREFIX_STUDENT_NAME + VALID_NAME_BOB;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class DeleteStudentCommandTest {
@Test
public void execute_validStudentNumber_success() {
Student studentToDelete = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased());
System.out.println(studentToDelete);
StudentNumber studentNumber = studentToDelete.getStudentNumber();
DeleteStudentCommand deleteStudentCommand = new DeleteStudentCommand(studentNumber);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* {@code DeleteStudentFromGroupCommand}.
*/
public class DeleteStudentFromGroupCommandTest {
private static final Group validGroup = new Group(new GroupName("Team 1"));
private static final Group validGroup = new Group(new GroupName("CS2103-F12-2"));
private static final Student validStudent = new PersonBuilder().build();
private Model model;

Expand Down Expand Up @@ -70,15 +70,15 @@ public void execute_studentDoesNotExistInGroup_throwsCommandException() {

@Test
public void execute_groupDoesNotExist_throwsCommandException() {
DeleteStudentFromGroupCommand command = new DeleteStudentFromGroupCommand(new GroupName("Team 5"),
DeleteStudentFromGroupCommand command = new DeleteStudentFromGroupCommand(new GroupName("CS2103-F12-5"),
validStudent.getStudentNumber());
assertThrows(CommandException.class, Messages.MESSAGE_GROUP_NAME_NOT_FOUND, () -> command.execute(model));
}

@Test
public void equals() {
GroupName teamOneName = new GroupName("Team 1");
GroupName teamTwoName = new GroupName("Team 2");
GroupName teamOneName = new GroupName("CS2103-F12-4");
GroupName teamTwoName = new GroupName("CS2103T-F12-4");
StudentNumber studentNumberOne = new StudentNumber("A0123456Z");
StudentNumber studentNumberTwo = new StudentNumber("A0654321Z");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ public class EditGroupCommandTest {
@BeforeEach
public void setUp() {
model = new ModelManager();
originalGroup = new Group(new GroupName("Original Group"));
originalGroup = new Group(new GroupName("CS2103-A12-1"));
model.addGroup(originalGroup);
}

@Test
public void execute_duplicateGroup_throwsCommandException() {
Group anotherGroup = new Group(new GroupName("Another Group"));
Group anotherGroup = new Group(new GroupName("CS2103-F12-4"));
model.addGroup(anotherGroup);

EditGroupDescriptor descriptorDuplicate = new EditGroupDescriptor();
descriptorDuplicate.setGroupName(new GroupName("Original Group"));
descriptorDuplicate.setGroupName(new GroupName("CS2103T-S1-12"));

EditGroupCommand editGroupCommand = new EditGroupCommand(Index.fromZeroBased(2),
descriptorDuplicate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ public void execute_zeroKeywords_noStudentFound() {

@Test
public void execute_singleKeyword_multipleStudentsFound() {
String expectedMessage = String.format(MESSAGE_STUDENTS_LISTED_OVERVIEW, 2);
StudentMatchesQueryPredicate predicate = new StudentMatchesQueryPredicate(List.of("Alice Pauline", "A0888888M"
));
String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 2);
StudentMatchesQueryPredicate predicate = new StudentMatchesQueryPredicate(List.of("Alice", "A0888888M"));
FindStudentCommand command = new FindStudentCommand(predicate);
expectedModel.updateFilteredPersonList(predicate);
assertCommandSuccess(command, model, expectedMessage, expectedModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public void execute_zeroKeywords_noTaskFound() {
@Test
public void execute_multipleKeywords_multipleTasksFound() {
String expectedMessage = String.format(MESSAGE_TASKS_LISTED_OVERVIEW, 2);
TaskNameContainsKeywordsPredicate predicate = new TaskNameContainsKeywordsPredicate(Arrays.asList("Finish iP",
"finish tP v1.3"));
TaskNameContainsKeywordsPredicate predicate = new TaskNameContainsKeywordsPredicate(Arrays.asList("iP",
"v1.3"));
FindTaskCommand command = new FindTaskCommand(predicate);
expectedModel.updateFilteredTaskList(predicate);
assertCommandSuccess(command, model, expectedMessage, expectedModel);
Expand Down
Loading

0 comments on commit 99b692f

Please sign in to comment.