Skip to content

Commit

Permalink
Merge pull request AY2324S1-CS2103T-W15-4#53 from tiongjjyi/branch_tag
Browse files Browse the repository at this point in the history
Implement tag feature and enum class StudentRank.java
  • Loading branch information
tiongjjyi authored Oct 16, 2023
2 parents a31a135 + ac1c74a commit f8c4a2e
Show file tree
Hide file tree
Showing 23 changed files with 154 additions and 115 deletions.
13 changes: 11 additions & 2 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.tag.StudentRank;
import seedu.address.model.tag.Tag;

/**
Expand Down Expand Up @@ -80,7 +81,7 @@ public static Email parseEmail(String email) throws ParseException {
}

/**
* Parses a {@code String tag} into a {@code Tag}.
* Parses a {@code StudentRank tag} into a {@code Tag}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code tag} is invalid.
Expand All @@ -91,7 +92,15 @@ public static Tag parseTag(String tag) throws ParseException {
if (!Tag.isValidTagName(trimmedTag)) {
throw new ParseException(Tag.MESSAGE_CONSTRAINTS);
}
return new Tag(trimmedTag);
if (trimmedTag.equals(StudentRank.GOOD.toString())) {
return new Tag(StudentRank.GOOD);
} else if (trimmedTag.equals(StudentRank.POOR.toString())) {
return new Tag(StudentRank.POOR);
} else if (trimmedTag.equals(StudentRank.AVERAGE.toString())) {
return new Tag(StudentRank.AVERAGE);
} else {
throw new ParseException(Tag.MESSAGE_CONSTRAINTS_ENUMS);
}
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/seedu/address/model/tag/StudentRank.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package seedu.address.model.tag;

/**
* Enumeration representing the ranking of a student's performance.
*/
public enum StudentRank {
GOOD,
AVERAGE,
POOR
}
19 changes: 10 additions & 9 deletions src/main/java/seedu/address/model/tag/Tag.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@
public class Tag {

public static final String MESSAGE_CONSTRAINTS = "Tags names should be alphanumeric";
public static final String MESSAGE_CONSTRAINTS_ENUMS = "Tags names should be GOOD/AVERAGE/POOR";
public static final String VALIDATION_REGEX = "\\p{Alnum}+";

public final String tagName;
public final StudentRank ranking;

/**
* Constructs a {@code Tag}.
*
* @param tagName A valid tag name.
* @param ranking A valid tag name.
*/
public Tag(String tagName) {
requireNonNull(tagName);
checkArgument(isValidTagName(tagName), MESSAGE_CONSTRAINTS);
this.tagName = tagName;
public Tag(StudentRank ranking) {
requireNonNull(ranking);
checkArgument(isValidTagName(ranking.toString()), MESSAGE_CONSTRAINTS);
this.ranking = ranking;
}

/**
Expand All @@ -44,19 +45,19 @@ public boolean equals(Object other) {
}

Tag otherTag = (Tag) other;
return tagName.equals(otherTag.tagName);
return ranking.toString().equals(otherTag.ranking.toString());
}

@Override
public int hashCode() {
return tagName.hashCode();
return ranking.hashCode();
}

/**
* Format state as text for viewing.
*/
public String toString() {
return '[' + tagName + ']';
return '[' + ranking.toString() + ']';
}

}
18 changes: 9 additions & 9 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import seedu.address.model.person.Name;
import seedu.address.model.person.Remark;
import seedu.address.model.person.Student;
import seedu.address.model.tag.StudentRank;
import seedu.address.model.tag.Tag;

/**
Expand All @@ -19,20 +20,19 @@
public class SampleDataUtil {
public static final Remark EMPTY_REMARK = new Remark("");
public static Student[] getSampleStudents() {

return new Student[] {
new Student(new Name("Alex Yeoh"), new Course("CS2103T"), new Email("[email protected]"), EMPTY_REMARK,
getTagSet("GOOD")),
getTagSet(StudentRank.GOOD)),
new Student(new Name("Bernice Yu"), new Course("CS2103T"), new Email("[email protected]"),
EMPTY_REMARK, getTagSet("GOOD")),
EMPTY_REMARK, getTagSet(StudentRank.POOR)),
new Student(new Name("Charlotte Oliveiro"), new Course("CS2103T"), new Email("[email protected]"),
EMPTY_REMARK, getTagSet("POOR")),
EMPTY_REMARK, getTagSet(StudentRank.POOR)),
new Student(new Name("David Li"), new Course("CS2103T"), new Email("[email protected]"), EMPTY_REMARK,
getTagSet("POOR")),
getTagSet(StudentRank.AVERAGE)),
new Student(new Name("Irfan Ibrahim"), new Course("CS2103T"), new Email("[email protected]"),
EMPTY_REMARK, getTagSet("AVERAGE")),
EMPTY_REMARK, getTagSet(StudentRank.GOOD)),
new Student(new Name("Roy Balakrishnan"), new Course("CS2103T"), new Email("[email protected]"),
EMPTY_REMARK, getTagSet("AVERAGE"))
EMPTY_REMARK, getTagSet(StudentRank.GOOD))
};
}

Expand All @@ -47,8 +47,8 @@ public static ReadOnlyStudentList getSampleStudentList() {
/**
* Returns a tag set containing the list of strings given.
*/
public static Set<Tag> getTagSet(String... strings) {
return Arrays.stream(strings)
public static Set<Tag> getTagSet(StudentRank... ranking) {
return Arrays.stream(ranking)
.map(Tag::new)
.collect(Collectors.toSet());
}
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/seedu/address/storage/JsonAdaptedTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,34 @@
import com.fasterxml.jackson.annotation.JsonValue;

import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.logic.parser.ParserUtil;
import seedu.address.model.tag.Tag;

/**
* Jackson-friendly version of {@link Tag}.
*/
class JsonAdaptedTag {

private final String tagName;
private final String ranking;

/**
* Constructs a {@code JsonAdaptedTag} with the given {@code tagName}.
*/
@JsonCreator
public JsonAdaptedTag(String tagName) {
this.tagName = tagName;
public JsonAdaptedTag(String ranking) {
this.ranking = ranking;
}

/**
* Converts a given {@code Tag} into this class for Jackson use.
*/
public JsonAdaptedTag(Tag source) {
tagName = source.tagName;
ranking = source.ranking.toString();
}

@JsonValue
public String getTagName() {
return tagName;
return ranking;
}

/**
Expand All @@ -39,10 +40,10 @@ public String getTagName() {
* @throws IllegalValueException if there were any data constraints violated in the adapted tag.
*/
public Tag toModelType() throws IllegalValueException {
if (!Tag.isValidTagName(tagName)) {
if (!Tag.isValidTagName(ranking)) {
throw new IllegalValueException(Tag.MESSAGE_CONSTRAINTS);
}
return new Tag(tagName);
return ParserUtil.parseTag(ranking);
}

}
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/ui/StudentCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public StudentCard(Student student, int displayedIndex) {
email.setText(student.getEmail().value);
remark.setText(student.getRemark().value);
student.getTags().stream()
.sorted(Comparator.comparing(tag -> tag.tagName))
.forEach(tag -> tags.getChildren().add(new Label(tag.tagName)));
.sorted(Comparator.comparing(tag -> tag.ranking))
.forEach(tag -> tags.getChildren().add(new Label(tag.ranking.toString())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"phone": "94351253",
"email": "[email protected]",
"address": "123, Jurong West Ave 6, #08-111",
"remark" : "",
"tagged": [ "friends" ]
"remark" : ""
}, {
"name": "Alice Pauline",
"phone": "94351253",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"course": "CS2103T",
"email": "[email protected]",
"remark" : "",
"tags": [ "friends" ]
"tags": [ "GOOD" ]
}, {
"name": "Alice Pauline",
"course": "CS2103T",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"name" : "Alice Pauline",
"course" : "CS2103T",
"email" : "[email protected]",
"remark" : "",
"tags" : [ "friends" ]
"remark" : "She likes aardvarks.",
"tags" : [ "AVERAGE" ]

}, {
"name" : "Benson Meier",
"course" : "CS2103T",
"email" : "[email protected]",
"remark" : "",
"tags" : [ "owesMoney", "friends" ]
"remark" : "He can't take beer!",
"tags" : [ "GOOD" ]

}, {
"name" : "Carl Kurz",
Expand All @@ -26,7 +26,7 @@
"course" : "CS2103T",
"email" : "[email protected]",
"remark" : "",
"tags" : [ "friends" ]
"tags" : [ "GOOD" ]

}, {
"name" : "Elle Meyer",
Expand Down
27 changes: 20 additions & 7 deletions src/test/java/seedu/address/logic/commands/CommandTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import seedu.address.model.StudentList;
import seedu.address.model.person.NameContainsKeywordsPredicate;
import seedu.address.model.person.Student;
import seedu.address.model.tag.StudentRank;
import seedu.address.testutil.EditStudentDescriptorBuilder;

/**
Expand All @@ -27,23 +28,32 @@ public class CommandTestUtil {

public static final String VALID_NAME_AMY = "Amy Bee";
public static final String VALID_NAME_BOB = "Bob Choo";
public static final String VALID_NAME_CLARA = "Clara Ng";

public static final String VALID_COURSE_AMY = "11111111";
public static final String VALID_COURSE_BOB = "22222222";
public static final String VALID_COURSE_CLARA = "33333333";
public static final String VALID_EMAIL_AMY = "[email protected]";
public static final String VALID_EMAIL_BOB = "[email protected]";
public static final String VALID_EMAIL_CLARA = "[email protected]";
public static final String VALID_REMARK_AMY = "Like skiing.";
public static final String VALID_REMARK_BOB = "Favourite pastime: Eating";
public static final String VALID_TAG_HUSBAND = "husband";
public static final String VALID_TAG_FRIEND = "friend";
public static final StudentRank VALID_TAG_AVERAGE = StudentRank.AVERAGE;
public static final StudentRank VALID_TAG_GOOD = StudentRank.GOOD;
public static final StudentRank VALID_TAG_POOR = StudentRank.POOR;

public static final String NAME_DESC_AMY = " " + PREFIX_NAME + VALID_NAME_AMY;
public static final String NAME_DESC_BOB = " " + PREFIX_NAME + VALID_NAME_BOB;
public static final String NAME_DESC_CLARA = " " + PREFIX_NAME + VALID_NAME_CLARA;
public static final String COURSE_DESC_AMY = " " + PREFIX_COURSE + VALID_COURSE_AMY;
public static final String COURSE_DESC_BOB = " " + PREFIX_COURSE + VALID_COURSE_BOB;
public static final String COURSE_DESC_CLARA = " " + PREFIX_COURSE + VALID_COURSE_CLARA;
public static final String EMAIL_DESC_AMY = " " + PREFIX_EMAIL + VALID_EMAIL_AMY;
public static final String EMAIL_DESC_BOB = " " + PREFIX_EMAIL + VALID_EMAIL_BOB;
public static final String TAG_DESC_FRIEND = " " + PREFIX_TAG + VALID_TAG_FRIEND;
public static final String TAG_DESC_HUSBAND = " " + PREFIX_TAG + VALID_TAG_HUSBAND;
public static final String EMAIL_DESC_CLARA = " " + PREFIX_EMAIL + VALID_EMAIL_CLARA;
public static final String TAG_DESC_AVERAGE = " " + PREFIX_TAG + VALID_TAG_AVERAGE;
public static final String TAG_DESC_GOOD = " " + PREFIX_TAG + VALID_TAG_GOOD;
public static final String TAG_DESC_POOR = " " + PREFIX_TAG + VALID_TAG_POOR;

public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + "James&"; // '&' not allowed in names
public static final String INVALID_COURSE_DESC = " " + PREFIX_COURSE + "911CS"; // 'a' not allowed in COURSEs
Expand All @@ -52,17 +62,20 @@ public class CommandTestUtil {

public static final String PREAMBLE_WHITESPACE = "\t \r \n";
public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble";

public static final EditCommand.EditStudentDescriptor DESC_AMY;
public static final EditCommand.EditStudentDescriptor DESC_BOB;
public static final EditCommand.EditStudentDescriptor DESC_CLARA;

static {
DESC_AMY = new EditStudentDescriptorBuilder().withName(VALID_NAME_AMY)
.withCourse(VALID_COURSE_AMY).withEmail(VALID_EMAIL_AMY)
.withTags(VALID_TAG_FRIEND).build();
.withTags(VALID_TAG_AVERAGE).build();
DESC_BOB = new EditStudentDescriptorBuilder().withName(VALID_NAME_BOB)
.withCourse(VALID_COURSE_BOB).withEmail(VALID_EMAIL_BOB)
.withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND).build();
.withTags(VALID_TAG_POOR).build();
DESC_CLARA = new EditStudentDescriptorBuilder().withName(VALID_NAME_CLARA)
.withCourse(VALID_COURSE_CLARA).withEmail(VALID_EMAIL_CLARA)
.withTags(VALID_TAG_GOOD).build();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import static seedu.address.logic.commands.CommandTestUtil.DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_AVERAGE;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.CommandTestUtil.showStudentAtIndex;
Expand Down Expand Up @@ -54,13 +54,12 @@ public void execute_allFieldsSpecifiedUnfilteredList_success() {
public void execute_someFieldsSpecifiedUnfilteredList_success() {
Index indexLastStudent = Index.fromOneBased(model.getFilteredStudentList().size());
Student lastStudent = model.getFilteredStudentList().get(indexLastStudent.getZeroBased());

StudentBuilder studentInList = new StudentBuilder(lastStudent);
Student editedStudent = studentInList.withName(VALID_NAME_BOB).withCourse(VALID_COURSE_BOB)
.withTags(VALID_TAG_HUSBAND).build();
.withTags(VALID_TAG_AVERAGE).build();

EditStudentDescriptor descriptor = new EditStudentDescriptorBuilder().withName(VALID_NAME_BOB)
.withCourse(VALID_COURSE_BOB).withTags(VALID_TAG_HUSBAND).build();
.withCourse(VALID_COURSE_BOB).withTags(VALID_TAG_AVERAGE).build();
EditCommand editCommand = new EditCommand(indexLastStudent, descriptor);

String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_STUDENT_SUCCESS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_GOOD;

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -48,7 +48,7 @@ public void equals() {
assertFalse(DESC_AMY.equals(editedAmy));

// different tags -> returns false
editedAmy = new EditStudentDescriptorBuilder(DESC_AMY).withTags(VALID_TAG_HUSBAND).build();
editedAmy = new EditStudentDescriptorBuilder(DESC_AMY).withTags(VALID_TAG_GOOD).build();
assertFalse(DESC_AMY.equals(editedAmy));
}

Expand Down
Loading

0 comments on commit f8c4a2e

Please sign in to comment.