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 branch 'master' into branch-summary-bar
# Conflicts: # src/main/java/seedu/address/model/Model.java # src/test/java/seedu/address/logic/commands/AddCommandTest.java
- Loading branch information
Showing
24 changed files
with
584 additions
and
92 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
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes
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
63 changes: 63 additions & 0 deletions
63
src/main/java/seedu/address/logic/parser/ListCommandParser.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,63 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.commands.ListCommand.COMMAND_ORDER_WORD_ASCENDING; | ||
import static seedu.address.logic.commands.ListCommand.COMMAND_ORDER_WORD_DESCENDING; | ||
|
||
import seedu.address.logic.commands.ListCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.logic.sort.ApplicationStatusComparator; | ||
import seedu.address.logic.sort.InterviewSlotComparator; | ||
import seedu.address.logic.sort.NameComparator; | ||
import seedu.address.logic.sort.PriorityComparator; | ||
|
||
/** | ||
* Parses input arguments and creates a new ListCommand object | ||
*/ | ||
public class ListCommandParser implements Parser<ListCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the ListCommand | ||
* and returns a ListCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public ListCommand parse(String args) throws ParseException { | ||
String trimmedArgs = args.trim(); | ||
|
||
if (trimmedArgs.isEmpty()) /* Handles default list */ { | ||
return new ListCommand(); | ||
} | ||
|
||
String[] sortingArgs = trimmedArgs.split("\\s+"); | ||
|
||
if (sortingArgs.length == 1) { | ||
String keyword = sortingArgs[0]; | ||
if (keyword.equals(COMMAND_ORDER_WORD_DESCENDING)) { | ||
return new ListCommand(null, COMMAND_ORDER_WORD_DESCENDING); | ||
} else if (keyword.equals(COMMAND_ORDER_WORD_ASCENDING)) { | ||
return new ListCommand(); | ||
} | ||
} else { | ||
String sortingField = sortingArgs[0].toLowerCase(); | ||
String orderBy = sortingArgs[1].toUpperCase(); | ||
|
||
if (validateOrderBy(orderBy)) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ListCommand.MESSAGE_USAGE)); | ||
} else if (sortingField.equals(NameComparator.COMMAND_WORD)) { | ||
return new ListCommand(new NameComparator(), orderBy); | ||
} else if (sortingField.equals(InterviewSlotComparator.COMMAND_WORD)) { | ||
return new ListCommand(new InterviewSlotComparator(), orderBy); | ||
} else if (sortingField.equals(PriorityComparator.COMMAND_WORD)) { | ||
return new ListCommand(new PriorityComparator(), orderBy); | ||
} else if (sortingField.equals(ApplicationStatusComparator.COMMAND_WORD)) { | ||
return new ListCommand(new ApplicationStatusComparator(), orderBy); | ||
} | ||
} | ||
|
||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ListCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
private boolean validateOrderBy(String s) { | ||
return !s.equals(COMMAND_ORDER_WORD_DESCENDING) && !s.equals(COMMAND_ORDER_WORD_ASCENDING); | ||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
src/main/java/seedu/address/logic/sort/ApplicationStatusComparator.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.address.logic.sort; | ||
|
||
import static seedu.address.model.tag.ApplicationStatusTagType.ACCEPTED; | ||
import static seedu.address.model.tag.ApplicationStatusTagType.APPLIED; | ||
import static seedu.address.model.tag.ApplicationStatusTagType.INTERVIEWED; | ||
import static seedu.address.model.tag.ApplicationStatusTagType.NOT_APPLIED; | ||
import static seedu.address.model.tag.ApplicationStatusTagType.REJECTED; | ||
|
||
import java.util.Comparator; | ||
import java.util.Optional; | ||
|
||
import seedu.address.model.application.Application; | ||
import seedu.address.model.tag.Tag; | ||
|
||
public class ApplicationStatusComparator implements Comparator<Application> { | ||
|
||
public static final String COMMAND_WORD = "status"; | ||
|
||
@Override | ||
public int compare(Application o1, Application o2) { | ||
return getStatusRanking(o1.getApplicationStatusTag()) - getStatusRanking(o2.getApplicationStatusTag()); | ||
} | ||
|
||
/** | ||
* Compares the two application's status tag field. Returns a negative integer, zero, or a positive integer as | ||
* the first argument is less than, equal to, or greater than the second base on alphanumeric order. | ||
* The default order from ascending to descend is as follows ACCEPTED, REJECTED, INTERVIEWED, APPLIE and | ||
* NOT_APPLIED. | ||
* An empty tag will be considered as the lowest ranking, ranked below NOT_APPLIED. | ||
* */ | ||
private int getStatusRanking(Optional<Tag> t) { | ||
if (t.isEmpty()) { | ||
return 6; | ||
} else if (t.get().toString().equals(NOT_APPLIED.toString())) { | ||
return 5; | ||
} else if (t.get().toString().equals(APPLIED.toString())) { | ||
return 4; | ||
} else if (t.get().toString().equals(INTERVIEWED.toString())) { | ||
return 3; | ||
} else if (t.get().toString().equals(REJECTED.toString())) { | ||
return 2; | ||
} else if (t.get().toString().equals(ACCEPTED.toString())) { | ||
return 1; | ||
} else { | ||
return 0; | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return COMMAND_WORD; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/seedu/address/logic/sort/InterviewSlotComparator.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.logic.sort; | ||
|
||
import java.util.Comparator; | ||
|
||
import seedu.address.model.application.Application; | ||
|
||
public class InterviewSlotComparator implements Comparator<Application> { | ||
|
||
public static final String COMMAND_WORD = "interview"; | ||
|
||
/** | ||
* Compares the two application's interview slot field. Returns a negative integer, zero, or a positive integer as | ||
* the first argument is less than, equal to, or greater than the second base on alphanumeric order. | ||
* */ | ||
@Override | ||
public int compare(Application o1, Application o2) { | ||
return o1.getInterviewSlot().getValue().compareTo(o2.getInterviewSlot().getValue()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return COMMAND_WORD; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/seedu/address/logic/sort/NameComparator.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.logic.sort; | ||
|
||
import java.util.Comparator; | ||
|
||
import seedu.address.model.application.Application; | ||
|
||
public class NameComparator implements Comparator<Application> { | ||
|
||
public static final String COMMAND_WORD = "name"; | ||
|
||
/** | ||
* Compares the two application's name field. Returns a negative integer, zero, or a positive integer as | ||
* the first argument is less than, equal to, or greater than the second base on alphanumeric order. | ||
* */ | ||
@Override | ||
public int compare(Application o1, Application o2) { | ||
return o1.getName().toString().compareTo(o2.getName().toString()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return COMMAND_WORD; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/seedu/address/logic/sort/PriorityComparator.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.address.logic.sort; | ||
|
||
import java.util.Comparator; | ||
import java.util.Optional; | ||
|
||
import seedu.address.model.application.Application; | ||
import seedu.address.model.tag.PriorityTagType; | ||
import seedu.address.model.tag.Tag; | ||
|
||
public class PriorityComparator implements Comparator<Application> { | ||
|
||
public static final String COMMAND_WORD = "priority"; | ||
|
||
private static final String PRIORITY_HIGH = "[" + PriorityTagType.HIGH + "]"; | ||
private static final String PRIORITY_LOW = "[" + PriorityTagType.LOW + "]"; | ||
|
||
/** | ||
* Compares the two application's priority field. Returns a negative integer, zero, or a positive integer as | ||
* the first argument is less than, equal to, or greater than the second base on alphanumeric order. | ||
* The default order from ascending to descend is as follows HIGH, MEDIUM, LOW. | ||
* An empty tag will be considered as the lowest ranking, ranked below LOW. | ||
* */ | ||
@Override | ||
public int compare(Application o1, Application o2) { | ||
Optional<Tag> p1 = o1.getPriorityTag(); | ||
Optional<Tag> p2 = o2.getPriorityTag(); | ||
|
||
if (p1.isPresent() && p2.isEmpty()) { | ||
return 1; | ||
} else if (p1.isEmpty() && p2.isPresent()) { | ||
return -1; | ||
} else if (p1.isEmpty()) { | ||
return o1.getName().toString().compareTo(o2.getName().toString()); | ||
} else { | ||
if (p1.get().toString().equals(p2.get().toString())) { | ||
return o1.getName().toString().compareTo(o2.getName().toString()); | ||
} else if (p1.get().toString().equals(PRIORITY_HIGH)) { | ||
return 1; | ||
} else if (p2.get().toString().equals(PRIORITY_HIGH)) { | ||
return -1; | ||
} else if (p2.get().toString().equals(PRIORITY_LOW)) { | ||
return 1; | ||
} else { | ||
return -1; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return COMMAND_WORD; | ||
} | ||
} |
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
Oops, something went wrong.