Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into multiDelete
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/seedu/address/logic/parser/CliSyntax.java
  • Loading branch information
Clarenceeey committed Oct 10, 2024
2 parents 1f78465 + 79b68a9 commit a19c32d
Show file tree
Hide file tree
Showing 14 changed files with 309 additions and 28 deletions.
29 changes: 26 additions & 3 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.course.Course;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
Expand Down Expand Up @@ -100,8 +101,9 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript
Email updatedEmail = editPersonDescriptor.getEmail().orElse(personToEdit.getEmail());
Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress());
Set<Tag> updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags());
Set<Course> updatedCourses = editPersonDescriptor.getCourses().orElse(personToEdit.getCourses());

return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags);
return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags, updatedCourses);
}

@Override
Expand Down Expand Up @@ -138,6 +140,7 @@ public static class EditPersonDescriptor {
private Email email;
private Address address;
private Set<Tag> tags;
private Set<Course> courses;

public EditPersonDescriptor() {}

Expand All @@ -151,13 +154,14 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) {
setEmail(toCopy.email);
setAddress(toCopy.address);
setTags(toCopy.tags);
setCourses(toCopy.courses);
}

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

public void setName(Name name) {
Expand Down Expand Up @@ -209,6 +213,23 @@ public Optional<Set<Tag>> getTags() {
return (tags != null) ? Optional.of(Collections.unmodifiableSet(tags)) : Optional.empty();
}

/**
* Sets {@code courses} to this object's {@code courses}.
* A defensive copy of {@code courses} is used internally.
*/
public void setCourses(Set<Course> courses) {
this.courses = (courses != null) ? new HashSet<>(courses) : null;
}

/**
* Returns an unmodifiable course set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
* Returns {@code Optional#empty()} if {@code courses} is null.
*/
public Optional<Set<Course>> getCourses() {
return (courses != null) ? Optional.of(Collections.unmodifiableSet(courses)) : Optional.empty();
}

@Override
public boolean equals(Object other) {
if (other == this) {
Expand All @@ -225,7 +246,8 @@ public boolean equals(Object other) {
&& Objects.equals(phone, otherEditPersonDescriptor.phone)
&& Objects.equals(email, otherEditPersonDescriptor.email)
&& Objects.equals(address, otherEditPersonDescriptor.address)
&& Objects.equals(tags, otherEditPersonDescriptor.tags);
&& Objects.equals(tags, otherEditPersonDescriptor.tags)
&& Objects.equals(courses, otherEditPersonDescriptor.courses);
}

@Override
Expand All @@ -236,6 +258,7 @@ public String toString() {
.add("email", email)
.add("address", address)
.add("tags", tags)
.add("courses", courses)
.toString();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
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_PHONE;
Expand All @@ -12,6 +13,7 @@

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.course.Course;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
Expand Down Expand Up @@ -44,8 +46,9 @@ 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());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));
Set<Course> courseList = ParserUtil.parseCourses(argMultimap.getAllValues(PREFIX_COURSE));

Person person = new Person(name, phone, email, address, tagList);
Person person = new Person(name, phone, email, address, tagList, courseList);

return new AddCommand(person);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public class CliSyntax {
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
public static final Prefix PREFIX_TAG = new Prefix("t/");
public static final Prefix PREFIX_DELETE_INDEX = new Prefix("i/");
public static final Prefix PREFIX_COURSE = new Prefix("c/");

}
28 changes: 28 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.course.Course;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
Expand Down Expand Up @@ -133,4 +134,31 @@ public static Set<Tag> parseTags(Collection<String> tags) throws ParseException
}
return tagSet;
}

/**
* Parses a {@code String course} into a {@code Course}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws ParseException if the given {@code tag} is invalid.
*/
public static Course parseCourse(String course) throws ParseException {
requireNonNull(course);
String trimmedCourse = course.trim();
if (!Course.isValidCourse(trimmedCourse)) {
throw new ParseException(Course.MESSAGE_CONSTRAINTS);
}
return new Course(trimmedCourse);
}

/**
* Parses {@code Collection<String> courses} into a {@code Set<Course>}.
*/
public static Set<Course> parseCourses(Collection<String> courses) throws ParseException {
requireNonNull(courses);
final Set<Course> courseSet = new HashSet<>();
for (String courseName : courses) {
courseSet.add(parseCourse(courseName));
}
return courseSet;
}
}
62 changes: 62 additions & 0 deletions src/main/java/seedu/address/model/course/Course.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package seedu.address.model.course;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;

/**
* Represents a Student's course in the system.
* Guarantees: immutable; is valid as declared in {@link #isValidCourse(String)}
*/
public class Course {
public static final String MESSAGE_CONSTRAINTS = "Courses should be in the format of two to four letters "
+ "followed by four digits, followed by 0-2 letters: e.g., MA1100, GEA1000N, GESS1000T etc.";
/*
* The course code must follow the format specified in MESSAGE_CONSTRAINTS as shown above.
*/
public static final String VALIDATION_REGEX = "[a-zA-Z]{2,4}\\d{4}[a-zA-Z]{0,2}";

public final String courseCode;

/**
* Constructs a {@code Course} and converts the given courseCode into uppercase.
*
* @param courseCode A valid course code, case-insensitive.
*/
public Course(String courseCode) {
requireNonNull(courseCode);
checkArgument(isValidCourse(courseCode), MESSAGE_CONSTRAINTS);
this.courseCode = courseCode.toUpperCase();
}

/**
* Returns true if a given string is a valid course code.
*/
public static boolean isValidCourse(String test) {
return test.matches(VALIDATION_REGEX);
}

@Override
public String toString() {
return courseCode;
}

@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}

// instanceof handles nulls
if (!(other instanceof Course)) {
return false;
}

Course otherCourse = (Course) other;
return courseCode.equals(otherCourse.courseCode);
}

@Override
public int hashCode() {
return courseCode.hashCode();
}
}
21 changes: 17 additions & 4 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Set;

import seedu.address.commons.util.ToStringBuilder;
import seedu.address.model.course.Course;
import seedu.address.model.tag.Tag;

/**
Expand All @@ -24,17 +25,19 @@ public class Person {
// Data fields
private final Address address;
private final Set<Tag> tags = new HashSet<>();
private final Set<Course> courses = new HashSet<>();

/**
* Every field must be present and not null.
*/
public Person(Name name, Phone phone, Email email, Address address, Set<Tag> tags) {
requireAllNonNull(name, phone, email, address, tags);
public Person(Name name, Phone phone, Email email, Address address, Set<Tag> tags, Set<Course> courses) {
requireAllNonNull(name, phone, email, address, tags, courses);
this.name = name;
this.phone = phone;
this.email = email;
this.address = address;
this.tags.addAll(tags);
this.courses.addAll(courses);
}

public Name getName() {
Expand All @@ -61,6 +64,14 @@ public Set<Tag> getTags() {
return Collections.unmodifiableSet(tags);
}

/**
* Returns an immutable course set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
*/
public Set<Course> getCourses() {
return Collections.unmodifiableSet(courses);
}

/**
* Returns true if both persons have the same name.
* This defines a weaker notion of equality between two persons.
Expand Down Expand Up @@ -94,13 +105,14 @@ public boolean equals(Object other) {
&& phone.equals(otherPerson.phone)
&& email.equals(otherPerson.email)
&& address.equals(otherPerson.address)
&& tags.equals(otherPerson.tags);
&& tags.equals(otherPerson.tags)
&& courses.equals(otherPerson.courses);
}

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

@Override
Expand All @@ -111,6 +123,7 @@ public String toString() {
.add("email", email)
.add("address", address)
.add("tags", tags)
.add("courses", courses)
.toString();
}

Expand Down
22 changes: 16 additions & 6 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import seedu.address.model.AddressBook;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.course.Course;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
Expand All @@ -21,22 +22,22 @@ public static Person[] getSamplePersons() {
return new Person[] {
new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"),
new Address("Blk 30 Geylang Street 29, #06-40"),
getTagSet("friends")),
getTagSet("friends"), getCourseSet("cs2103t")),
new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"),
new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"),
getTagSet("colleagues", "friends")),
getTagSet("colleagues", "friends"), getCourseSet("cs2103t, cs2109s")),
new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"),
new Address("Blk 11 Ang Mo Kio Street 74, #11-04"),
getTagSet("neighbours")),
getTagSet("neighbours"), getCourseSet("ma1100")),
new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"),
new Address("Blk 436 Serangoon Gardens Street 26, #16-43"),
getTagSet("family")),
getTagSet("family"), getCourseSet("ma1100, ma2104, ma2108")),
new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"),
new Address("Blk 47 Tampines Street 20, #17-35"),
getTagSet("classmates")),
getTagSet("classmates"), getCourseSet("CS3230, CS3263, CS3264")),
new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"),
new Address("Blk 45 Aljunied Street 85, #11-31"),
getTagSet("colleagues"))
getTagSet("colleagues"), getCourseSet())
};
}

Expand All @@ -57,4 +58,13 @@ public static Set<Tag> getTagSet(String... strings) {
.collect(Collectors.toSet());
}

/**
* Returns a course set containing the list of strings given.
*/
public static Set<Course> getCourseSet(String... strings) {
return Arrays.stream(strings)
.map(Course::new)
.collect(Collectors.toSet());
}

}
48 changes: 48 additions & 0 deletions src/main/java/seedu/address/storage/JsonAdaptedCourse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package seedu.address.storage;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.course.Course;

/**
* Jackson-friendly version of {@link Course}.
*/
class JsonAdaptedCourse {

private final String courseCode;

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

/**
* Converts a given {@code Course} into this class for Jackson use.
*/
public JsonAdaptedCourse(Course source) {
courseCode = source.courseCode;
}

@JsonValue
public String getCourseCode() {
return courseCode;
}

/**
* Converts this Jackson-friendly adapted tag object into the model's {@code Course} object.
*
* @throws IllegalValueException if there were any data constraints violated in the adapted tag.
*/
public Course toModelType() throws IllegalValueException {
if (!Course.isValidCourse(courseCode)) {
throw new IllegalValueException(Course.MESSAGE_CONSTRAINTS);
}
return new Course(courseCode);
}

}
Loading

0 comments on commit a19c32d

Please sign in to comment.