forked from nus-cs2103-AY2223S1/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 #190 from AY2223S1-CS2103T-W16-4/feat-viewclient-b…
…y-product ListClient by product
- Loading branch information
Showing
6 changed files
with
61 additions
and
8 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
38 changes: 38 additions & 0 deletions
38
src/main/java/seedu/address/logic/parser/ListClientCommandParser.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,38 @@ | ||
package seedu.address.logic.parser; | ||
|
||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PRODUCT; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import seedu.address.logic.commands.ListClientCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.product.Product; | ||
|
||
/** | ||
* Parses input arguments and creates a new ListClientCommand object | ||
*/ | ||
public class ListClientCommandParser { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the ViewMeetingCommand | ||
* and returns a ViewMeetingCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public ListClientCommand parse(String args) throws ParseException { | ||
requireNonNull(args); | ||
ArgumentMultimap argumentMultimap = ArgumentTokenizer.tokenize(args, PREFIX_PRODUCT); | ||
|
||
if (!arePrefixesPresent(argumentMultimap, PREFIX_PRODUCT)) { | ||
return new ListClientCommand(); | ||
} else { | ||
Product product = ParserUtil.parseProduct(argumentMultimap.getValue(PREFIX_PRODUCT).get()); | ||
return new ListClientCommand(product); | ||
} | ||
} | ||
|
||
private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { | ||
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); | ||
} | ||
} |
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