forked from AY2324S1-CS2103T-W08-1/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
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 AY2324S1-CS2103T-W08-1#109 from ivanleekk/filter-a…
…pplicants Add FilterCommand
- Loading branch information
Showing
19 changed files
with
727 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ src/test/data/sandbox/ | |
.DS_Store | ||
docs/_site/ | ||
docs/_markbind/logs/ | ||
/htmlReport/ |
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,42 @@ | ||
@startuml | ||
'https://plantuml.com/activity-diagram-beta | ||
|
||
start | ||
:User enters filter command syntax; | ||
:ApplicantBookParser and FilterCommandParser | ||
parse arguments; | ||
if (At least 1 argument is provided) then (true) | ||
:Parse provided fields; | ||
if (Provided fields are valid) then (true) | ||
:Create new CustomFilterPredicate | ||
from specified fields; | ||
:Create new FilterCommand | ||
from CustomFilterPredicate; | ||
:FilterCommand updates predicate used in | ||
ModelManager with CustomFilterPredicate; | ||
:Display success message and show updated list in GUI; | ||
stop | ||
else (false) | ||
:Throw ParseException with | ||
invalid command format | ||
message and proper Filter | ||
syntax; | ||
:Display error message; | ||
stop | ||
endif | ||
|
||
else (false) | ||
label 1 | ||
label 2 | ||
label 3 | ||
|
||
:Throw ParseException with | ||
invalid command format | ||
message and proper Filter | ||
syntax; | ||
:Display error message; | ||
stop | ||
endif | ||
|
||
@enduml | ||
|
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
80 changes: 80 additions & 0 deletions
80
src/main/java/seedu/staffsnap/logic/commands/FilterCommand.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,80 @@ | ||
package seedu.staffsnap.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_EMAIL; | ||
import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_GREATER_THAN_SCORE; | ||
import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_LESS_THAN_SCORE; | ||
import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_PHONE; | ||
import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_POSITION; | ||
import static seedu.staffsnap.logic.parser.CliSyntax.PREFIX_STATUS; | ||
|
||
import seedu.staffsnap.commons.util.ToStringBuilder; | ||
import seedu.staffsnap.logic.Messages; | ||
import seedu.staffsnap.model.Model; | ||
import seedu.staffsnap.model.applicant.CustomFilterPredicate; | ||
|
||
|
||
|
||
/** | ||
* Finds and lists all applicants in address book whose name contains any of the argument keywords. | ||
* Keyword matching is case-insensitive. | ||
*/ | ||
public class FilterCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "filter"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Filters all applicants who match the descriptor."; | ||
public static final String MESSAGE_FAILURE = "Please add at least one field to filter by. " | ||
+ "Possible fields include:" + "\n" | ||
+ PREFIX_NAME + " [NAME], " | ||
+ PREFIX_EMAIL + " [EMAIL], " | ||
+ PREFIX_POSITION + " [POSITION], " | ||
+ PREFIX_PHONE + " [PHONE], " | ||
+ PREFIX_STATUS + " [STATUS], " | ||
+ PREFIX_LESS_THAN_SCORE + " [SCORE], " | ||
+ PREFIX_GREATER_THAN_SCORE + " [SCORE]"; | ||
public static final String MESSAGE_SCORE_PARSE_FAILURE = "Score in lts/ or gts/ has to be a number with up to 1 " | ||
+ "decimal place"; | ||
|
||
private final CustomFilterPredicate predicate; | ||
|
||
public FilterCommand(CustomFilterPredicate predicate) { | ||
this.predicate = predicate; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
requireNonNull(model); | ||
model.updateFilteredApplicantList(predicate); | ||
return new CommandResult( | ||
String.format(Messages.MESSAGE_APPLICANTS_LISTED_OVERVIEW, model.getFilteredApplicantList().size())); | ||
} | ||
|
||
/** | ||
* Checks if the two FilterCommand objects are equivalent, by comparing the equivalence of their predicates. | ||
* @param other Other FilterCommand. | ||
* @return true if equals, false if not equals. | ||
*/ | ||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof FilterCommand)) { | ||
return false; | ||
} | ||
|
||
FilterCommand otherFilterCommand = (FilterCommand) other; | ||
return predicate.equals(otherFilterCommand.predicate); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("predicate", predicate) | ||
.toString(); | ||
} | ||
} |
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
Oops, something went wrong.