forked from nus-cs2103-AY1920S1/addressbook-level3
-
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.
Refactor parsers and add tests (#235)
* Update AboutUs.adoc for team members to commit * Add a newline in AboutUs.adoc * Add more use cases to Developer Guide * Fix missing endline * Update various docs to display TagLine * Add placeholder image * Fix minor typo in user guide * Update Tagline to TagLine * Update team name * Fix some typos in user guide and developer guide * Refactor parsers and add new tests - Also fixes prefix for groups
- Loading branch information
Showing
36 changed files
with
314 additions
and
256 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
54 changes: 54 additions & 0 deletions
54
src/main/java/tagline/logic/parser/contact/ClearContactParser.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,54 @@ | ||
//@@author tanlk99 | ||
package tagline.logic.parser.contact; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import tagline.logic.commands.contact.ClearContactCommand; | ||
import tagline.logic.parser.Parser; | ||
import tagline.logic.parser.ParserUtil; | ||
import tagline.logic.parser.Prompt; | ||
import tagline.logic.parser.exceptions.ParseException; | ||
import tagline.logic.parser.exceptions.PromptRequestException; | ||
|
||
/** | ||
* Parses input arguments and creates a new ClearContactCommand object. | ||
*/ | ||
public class ClearContactParser implements Parser<ClearContactCommand> { | ||
public static final String CONTACT_CLEAR_COMMAND_CONFIRM_STRING = "Are you sure you want to clear your contact " | ||
+ "list? Enter 'Y' to continue."; | ||
public static final String CONTACT_CLEAR_COMMAND_ABORTED_STRING = "The current command has been aborted."; | ||
public static final String CONTACT_CLEAR_CONFIRM_STRING = "Y"; | ||
|
||
/** | ||
* Validates and parses the given {@code String} of arguments and a list of prompts in the context of a | ||
* ClearContactCommand. | ||
* | ||
* @throws PromptRequestException if the prompt list is empty | ||
* @throws ParseException if the prompt response does not match the confirmation string | ||
*/ | ||
public ClearContactCommand parse(String args, List<Prompt> promptList) throws ParseException { | ||
if (promptList.isEmpty()) { | ||
throw new PromptRequestException(Arrays.asList( | ||
new Prompt("", CONTACT_CLEAR_COMMAND_CONFIRM_STRING))); | ||
} | ||
|
||
if (ParserUtil.getPromptResponseFromPrefix("", promptList) | ||
.equals(CONTACT_CLEAR_CONFIRM_STRING)) { | ||
return new ClearContactCommand(); | ||
} else { | ||
throw new ParseException(CONTACT_CLEAR_COMMAND_ABORTED_STRING); | ||
} | ||
} | ||
|
||
/** | ||
* @see ClearContactParser#parse(String, List). | ||
* | ||
* Calling this method will always throw a {@code PromptRequestException} containing a single prompt requesting | ||
* confirmation. | ||
*/ | ||
public ClearContactCommand parse(String args) throws ParseException { | ||
return parse(args, Collections.emptyList()); | ||
} | ||
} |
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
Oops, something went wrong.