forked from nus-cs2103-AY2425S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into multiDelete
# Conflicts: # src/main/java/seedu/address/logic/parser/CliSyntax.java
- Loading branch information
Showing
14 changed files
with
309 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/seedu/address/storage/JsonAdaptedCourse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
Oops, something went wrong.