-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add functionality to whitelist and blacklist commands #156
Changes from all commits
4f064d6
6fbf7f3
8aa931f
c9eccc7
8671ade
23ebabf
deb62b5
4a09380
7daa34b
a26e74c
c8eb4f8
281d50f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.parser.FindCommandParser; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.Model; | ||
|
||
/** | ||
* Lists out all blacklisted clients | ||
*/ | ||
public class BlacklistListCommand extends BlacklistCommand { | ||
|
||
/** | ||
* Instantiates a {@code BlacklistListCommand} object. | ||
*/ | ||
public BlacklistListCommand() { | ||
super(Index.fromZeroBased(0)); // this is irrelevant but necessary | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
requireNonNull(model); | ||
|
||
try { | ||
// make the find command do the hard work | ||
return (new FindCommandParser().parse("find cs/blacklisted")).execute(model); | ||
} catch (ParseException pe) { | ||
return null; // this will never happen | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.Messages; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.person.ArgumentPredicateToFail; | ||
import seedu.address.model.person.ClientStatus; | ||
|
||
/** | ||
* Lists out all whitelisted clients | ||
*/ | ||
public class WhitelistListCommand extends WhitelistCommand { | ||
|
||
/** | ||
* Instantiates a {@code WhitelistListCommand} object. | ||
* | ||
* @param argPredToFail an argument predicate that should fail | ||
*/ | ||
public WhitelistListCommand() { | ||
// this is irrelevant but necessary | ||
super(Index.fromZeroBased(0), new ClientStatus("old")); | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
requireNonNull(model); | ||
|
||
// here, the predicate dictates that the client status should be blacklisted; | ||
// hence if the predicate fails (ensured by the ArgumentPredicateToFail object), | ||
// the client is not blacklisted => they are whitelisted | ||
model.updateFilteredPersonList(ArgumentPredicateToFail.getNotBlacklistedPredicate()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for my understanding, how come there is a different execution for whitelistcommand and blacklistcommand? Couldn't it be easier if there was a predicate 'getBlacklistedPredicate' that kept things consistent and reduces Blacklist's dependence on other code? That being said, I think this still works 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I will be decoupling the |
||
|
||
return new CommandResult( | ||
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size())); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By any chance would it be good to have a good error message/log message anyways? In case find command changes or other code is modified? But for now, I agree, it won't happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This portion of the find command is reliant on the
ArgumentPredicate
being changed, which is highly unlikely. But in the future I will be decoupling theblacklist
command from thefind
command entirely; this was just a quick addition that I did not want to initially spend too much time on, so I could focus on the test cases and thewhitelist
command.