forked from nus-cs2103-AY1920S1/addressbook-level3
-
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.
Add more fields to Module View (#72)
* Refactor tests to use builder classes * Add prerequisite field to ArchivedModule * Add semesterData to ArchivedModule * Fix regression * Add SemesterDetail to ArchivedModule * Add preclusion to ArchivedModule * Refactor ModuleViewPanel to make it scrollable * Cleanup Ui
- Loading branch information
Showing
21 changed files
with
562 additions
and
61 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
59 changes: 59 additions & 0 deletions
59
src/main/java/seedu/module/model/module/SemesterDetail.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,59 @@ | ||
package seedu.module.model.module; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Represents semester details pertaining to a module. | ||
*/ | ||
public class SemesterDetail { | ||
|
||
private final int semester; | ||
private final Optional<LocalDateTime> examDate; // ISO standard datetime format | ||
private final int examDuration; // duration in minutes | ||
private final boolean offered; // whether the module is offered in this semester | ||
|
||
/** | ||
* Use this constructor to indicate the semester is offered. | ||
* @apiNote examDate may be null to indicate no exams for this semester. | ||
*/ | ||
public SemesterDetail(int semester, LocalDateTime examDate, int examDuration) { | ||
this.semester = semester; | ||
this.examDate = Optional.ofNullable(examDate); | ||
this.examDuration = examDuration; | ||
this.offered = true; | ||
} | ||
|
||
public SemesterDetail(int semester) { | ||
this.semester = semester; | ||
this.examDate = Optional.empty(); | ||
this.examDuration = 0; | ||
this.offered = false; | ||
} | ||
|
||
public boolean isOffered() { | ||
return offered; | ||
} | ||
|
||
public int getExamDuration() { | ||
return examDuration; | ||
} | ||
|
||
public Optional<LocalDateTime> getExamDate() { | ||
return examDate; | ||
} | ||
|
||
public int getSemester() { | ||
return semester; | ||
} | ||
|
||
// Compares 2 objects based on the identify field {@code semester}. | ||
@Override | ||
public boolean equals(Object o) { | ||
if (o instanceof SemesterDetail) { | ||
return ((SemesterDetail) o).getSemester() == this.semester; | ||
} | ||
|
||
return false; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/seedu/module/model/module/SemesterDetailList.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,53 @@ | ||
package seedu.module.model.module; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
import seedu.module.commons.core.index.Index; | ||
|
||
/** | ||
* Represents a list of semester details pertaining to a module. | ||
* There are a total of 4 "semesters", 2 semesters and 2 special terms. | ||
* | ||
* See http://www.nus.edu.sg/registrar/calendar.html | ||
*/ | ||
public class SemesterDetailList { | ||
|
||
private List<SemesterDetail> semesterDetails; | ||
|
||
/** | ||
* Constructs a SemesterDetailList. Contains 4 elements. | ||
* Each SemesterDetail defaults to unoffered status. | ||
*/ | ||
public SemesterDetailList() { | ||
this.semesterDetails = new ArrayList<>(4); | ||
for (int i = 1; i <= 4; i++) { | ||
this.semesterDetails.add(new SemesterDetail(i)); | ||
} | ||
} | ||
|
||
/** | ||
* Constructs and sets the SemesterDetailList with new semester details. | ||
* @param semesterDetails list of semester details, may be an incomplete list. | ||
*/ | ||
public SemesterDetailList(List<SemesterDetail> semesterDetails) { | ||
this(); | ||
for (SemesterDetail s : semesterDetails) { | ||
// Sets the corresponding semester details | ||
if (this.semesterDetails.contains(s)) { | ||
this.semesterDetails.set(Index.fromOneBased(s.getSemester()).getZeroBased(), s); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Returns the SemesterDetailList as an Observable List. | ||
*/ | ||
public ObservableList<SemesterDetail> getAsObservableList() { | ||
ObservableList<SemesterDetail> observableList = FXCollections.observableArrayList(); | ||
observableList.setAll(semesterDetails); | ||
return observableList; | ||
} | ||
} |
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
44 changes: 41 additions & 3 deletions
44
src/main/java/seedu/module/storage/JsonAdaptedArchivedModule.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 |
---|---|---|
@@ -1,35 +1,73 @@ | ||
package seedu.module.storage; | ||
|
||
import java.time.format.DateTimeParseException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.logging.Logger; | ||
import java.util.stream.Collectors; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import seedu.module.commons.core.LogsCenter; | ||
import seedu.module.model.module.ArchivedModule; | ||
import seedu.module.model.module.SemesterDetailList; | ||
|
||
/** | ||
* Jackson-friendly version of {@link ArchivedModule}. This class serves only as a reader. | ||
*/ | ||
class JsonAdaptedArchivedModule { | ||
private static final Logger logger = LogsCenter.getLogger(JsonAdaptedArchivedModule.class); | ||
|
||
private final String moduleCode; | ||
private final String title; | ||
private final String description; | ||
private final String prerequisite; | ||
private final String preclusion; | ||
private final List<JsonAdaptedSemesterDetail> semesterDetails; | ||
|
||
/** | ||
* Constructs a {@code JsonAdaptedArchivedModule} with the given module details. | ||
*/ | ||
@JsonCreator | ||
public JsonAdaptedArchivedModule(@JsonProperty("moduleCode") String moduleCode, @JsonProperty("title") String title, | ||
@JsonProperty("description") String description) { | ||
@JsonProperty("description") String description, @JsonProperty("prerequisite") String prerequisite, | ||
@JsonProperty("preclusion") String preclusion, | ||
@JsonProperty("semesterData") List<JsonAdaptedSemesterDetail> semesterDetails) { | ||
this.moduleCode = moduleCode; | ||
this.title = title; | ||
this.description = description; | ||
this.prerequisite = prerequisite; | ||
this.preclusion = preclusion; | ||
this.semesterDetails = Optional.ofNullable(semesterDetails).orElse(new ArrayList<>()); | ||
} | ||
|
||
/** | ||
* Converts this Jackson-friendly adapted module object into the model's {@code ArchivedModel} object. | ||
* Converts this Jackson-friendly adapted module object into the model's {@code ArchivedModule} object. | ||
*/ | ||
public ArchivedModule toModelType() { | ||
return new ArchivedModule(moduleCode, title, description); | ||
return new ArchivedModule(moduleCode, title, description, prerequisite, preclusion, | ||
fromListToSemesterDetailList(semesterDetails)); | ||
} | ||
|
||
/** | ||
* Converts the list of {@code JsonAdaptedSemesterDetail} to {@code SemesterDetailList}. | ||
*/ | ||
private SemesterDetailList fromListToSemesterDetailList(List<JsonAdaptedSemesterDetail> semesterDetails) { | ||
return new SemesterDetailList(semesterDetails.stream() | ||
.map(semesterDetail -> { | ||
try { | ||
return semesterDetail.toModelType(); | ||
} catch (DateTimeParseException e) { | ||
logger.info( | ||
String.format("ArchivedModule %s has bad semester data.", moduleCode)); | ||
return null; | ||
} | ||
}) | ||
.filter(semesterDetail -> semesterDetail != null) | ||
.collect(Collectors.toList()) | ||
); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/seedu/module/storage/JsonAdaptedSemesterDetail.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,44 @@ | ||
package seedu.module.storage; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import seedu.module.model.module.SemesterDetail; | ||
|
||
/** | ||
* Jackson-friendly version of {@code SemesterDetail} | ||
*/ | ||
public class JsonAdaptedSemesterDetail { | ||
private static final DateTimeFormatter format = DateTimeFormatter.ofPattern( | ||
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); // format used by NUSmods | ||
|
||
private final int semester; | ||
private final String examDate; // ISO standard datetime format | ||
private final int examDuration; // duration in minutes | ||
|
||
/** | ||
* Constructs a {@code JsonAdaptedSemesterDetail} with the given parameters. | ||
*/ | ||
public JsonAdaptedSemesterDetail(@JsonProperty("semester") int semester, | ||
@JsonProperty("examDate") String examDate, | ||
@JsonProperty("examDuration") int examDuration) { | ||
this.semester = semester; | ||
this.examDate = examDate; | ||
this.examDuration = examDuration; | ||
} | ||
|
||
/** | ||
* Converts this Jackson-friendly semester detail object into the model's {@code SemesterDetail} object. | ||
*/ | ||
public SemesterDetail toModelType() throws DateTimeParseException { | ||
// null indicates that the semester has no exam | ||
if (examDate == null) { | ||
return new SemesterDetail(semester, null, examDuration); | ||
} | ||
|
||
return new SemesterDetail(semester, LocalDateTime.parse(examDate, format), examDuration); | ||
} | ||
} |
Oops, something went wrong.