This repository has been archived by the owner on Sep 9, 2022. It is now read-only.
forked from nus-cs2103-AY2122S2/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 pull request #140 from joszx/branch-summary-bar
Feature - Summary Bar
- Loading branch information
Showing
20 changed files
with
531 additions
and
48 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
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
62 changes: 62 additions & 0 deletions
62
src/main/java/seedu/address/model/summarybar/SummaryBox.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,62 @@ | ||
package seedu.address.model.summarybar; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Represents a SummaryBox in InternApply. | ||
*/ | ||
public abstract class SummaryBox { | ||
|
||
private String name; | ||
private int totalApplications; | ||
|
||
/** | ||
* Constructs a {@Code SummaryBox}. | ||
* | ||
* @param name Name of the SummaryBox. | ||
* @param totalApplications Total number of applications in InternApply. | ||
*/ | ||
public SummaryBox(String name, int totalApplications) { | ||
this.name = name; | ||
this.totalApplications = totalApplications; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public int getTotalApplications() { | ||
return totalApplications; | ||
} | ||
|
||
public void setTotalApplications(int totalApplications) { | ||
this.totalApplications = totalApplications; | ||
} | ||
|
||
/** | ||
* Gets the number of applications this SummaryBox is tracking. | ||
* Returns Optional.empty() for SummaryBoxes that are not tracking any applications. | ||
* | ||
* @return The number of applications this SummaryBox is tracking. | ||
*/ | ||
public abstract Optional<Integer> getCurrApplications(); | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
SummaryBox that = (SummaryBox) o; | ||
return totalApplications == that.totalApplications | ||
&& Objects.equals(name, that.name); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name, totalApplications); | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
src/main/java/seedu/address/model/summarybar/SummaryList.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,106 @@ | ||
package seedu.address.model.summarybar; | ||
|
||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
import seedu.address.model.application.Application; | ||
import seedu.address.model.tag.Tag; | ||
|
||
/** | ||
* A list of SummaryBoxes that keeps track of their respective indices and tags. | ||
* | ||
*/ | ||
public class SummaryList { | ||
|
||
public static final int TOTAL_APPLICATIONS_INDEX = 0; | ||
public static final int TOTAL_HIGH_PRIORITY_APPLICATIONS_INDEX = 1; | ||
public static final int TOTAL_MEDIUM_PRIORITY_APPLICATIONS_INDEX = 2; | ||
public static final int TOTAL_LOW_PRIORITY_APPLICATIONS_INDEX = 3; | ||
public static final int TOTAL_APPLIED_APPLICATIONS_INDEX = 4; | ||
public static final int TOTAL_NOT_APPLIED_APPLICATIONS_INDEX = 5; | ||
|
||
private static final int SUMMARY_INFO_SIZE = 6; | ||
|
||
private static final String HIGH_PRIORITY_TAG = "HIGH"; | ||
private static final String MEDIUM_PRIORITY_TAG = "MEDIUM"; | ||
private static final String LOW_PRIORITY_TAG = "LOW"; | ||
private static final String APPLIED_STATUS_TAG = "APPLIED"; | ||
private static final String NOT_APPLIED_STATUS_TAG = "NOT_APPLIED"; | ||
|
||
private ObservableList<SummaryBox> summaryList; | ||
private ObservableList<Application> applications; | ||
|
||
/** | ||
* Constructs a SummaryList from the given list of applications. | ||
* | ||
* @param applications The list of applications to get the relevant statistics for the SummaryBoxes to hold. | ||
*/ | ||
public SummaryList(ObservableList<Application> applications) { | ||
this.applications = applications; | ||
summaryList = FXCollections.observableArrayList(); | ||
int totalApplications = getTotalApplications(); | ||
|
||
summaryList.add(new TotalApplicationsBox("Total", totalApplications)); | ||
summaryList.add(new TagSummaryBox("High Priority", getTotalTagApplications(HIGH_PRIORITY_TAG), | ||
totalApplications)); | ||
summaryList.add(new TagSummaryBox("Medium Priority", getTotalTagApplications(MEDIUM_PRIORITY_TAG), | ||
totalApplications)); | ||
summaryList.add(new TagSummaryBox("Low Priority", getTotalTagApplications(LOW_PRIORITY_TAG), | ||
totalApplications)); | ||
summaryList.add(new TagSummaryBox("Applied", getTotalTagApplications(APPLIED_STATUS_TAG), | ||
totalApplications)); | ||
summaryList.add(new TagSummaryBox("Not Applied", getTotalTagApplications(NOT_APPLIED_STATUS_TAG), | ||
totalApplications)); | ||
} | ||
|
||
public ObservableList<SummaryBox> getObservableList() { | ||
return summaryList; | ||
} | ||
|
||
/** | ||
* Updates the SummaryList by replacing each SummaryBox with a new one holding the updated statistics passed from | ||
* the given list of applications. | ||
* | ||
* @param applications The given list of applications to get statistics from. | ||
*/ | ||
public void update(ObservableList<Application> applications) { | ||
this.applications = applications; | ||
int[] summaryInfo = new int[SUMMARY_INFO_SIZE]; | ||
summaryInfo[TOTAL_APPLICATIONS_INDEX] = getTotalApplications(); | ||
summaryInfo[TOTAL_HIGH_PRIORITY_APPLICATIONS_INDEX] = getTotalTagApplications(HIGH_PRIORITY_TAG); | ||
summaryInfo[TOTAL_MEDIUM_PRIORITY_APPLICATIONS_INDEX] = getTotalTagApplications(MEDIUM_PRIORITY_TAG); | ||
summaryInfo[TOTAL_LOW_PRIORITY_APPLICATIONS_INDEX] = getTotalTagApplications(LOW_PRIORITY_TAG); | ||
summaryInfo[TOTAL_APPLIED_APPLICATIONS_INDEX] = getTotalTagApplications(APPLIED_STATUS_TAG); | ||
summaryInfo[TOTAL_NOT_APPLIED_APPLICATIONS_INDEX] = getTotalTagApplications(NOT_APPLIED_STATUS_TAG); | ||
|
||
String totalApplicationsBoxName = summaryList.get(TOTAL_APPLICATIONS_INDEX).getName(); | ||
summaryList.set(0, new TotalApplicationsBox(totalApplicationsBoxName, getTotalApplications())); | ||
|
||
for (int i = 1; i < summaryList.size(); i++) { | ||
String currSummaryBoxName = summaryList.get(i).getName(); | ||
summaryList.set(i, new TagSummaryBox(currSummaryBoxName, summaryInfo[i], getTotalApplications())); | ||
} | ||
} | ||
|
||
private int getTotalApplications() { | ||
return applications.size(); | ||
} | ||
|
||
/** | ||
* Gets the number of applications with the given tagName. | ||
* | ||
* @param tagName The given tagName of the applications search for and count. | ||
* @return | ||
*/ | ||
private int getTotalTagApplications(String tagName) { | ||
int count = 0; | ||
Tag toFind = new Tag(tagName); | ||
for (Application application : applications) { | ||
if (application.getTags().contains(toFind)) { | ||
count++; | ||
} | ||
} | ||
return count; | ||
} | ||
|
||
|
||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/seedu/address/model/summarybar/TagSummaryBox.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,49 @@ | ||
package seedu.address.model.summarybar; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Represents a SummaryBox in InternApply that keeps track of the number of applications with a specified tagName. | ||
*/ | ||
public class TagSummaryBox extends SummaryBox { | ||
private int currApplications; | ||
|
||
/** | ||
* Constructs a TagSummaryBox. | ||
* | ||
* @param name Given name of the TagSummaryBox. | ||
* @param currApplications Number of applications this TagSummaryBox is tracking. | ||
* @param totalApplications Total number of applications in InternApply. | ||
*/ | ||
TagSummaryBox(String name, int currApplications, int totalApplications) { | ||
super(name, totalApplications); | ||
this.currApplications = currApplications; | ||
} | ||
|
||
@Override | ||
public Optional<Integer> getCurrApplications() { | ||
return Optional.of(currApplications); | ||
} | ||
|
||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
if (!super.equals(o)) { | ||
return false; | ||
} | ||
TagSummaryBox that = (TagSummaryBox) o; | ||
return currApplications == that.currApplications; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(super.hashCode(), currApplications); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/seedu/address/model/summarybar/TotalApplicationsBox.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,24 @@ | ||
package seedu.address.model.summarybar; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Represents a SummaryBox that tracks the total number of applications in InternApply. | ||
*/ | ||
public class TotalApplicationsBox extends SummaryBox { | ||
|
||
/** | ||
* Constructs a TotalApplicationsBox. | ||
* | ||
* @param name The name of this TotalApplicationsBox. | ||
* @param totalApplications Total number of applications in InternApply. | ||
*/ | ||
public TotalApplicationsBox(String name, int totalApplications) { | ||
super(name, totalApplications); | ||
} | ||
|
||
@Override | ||
public Optional<Integer> getCurrApplications() { | ||
return Optional.empty(); | ||
} | ||
} |
Oops, something went wrong.