-
Notifications
You must be signed in to change notification settings - Fork 127
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
Testing #50
Open
Roycius
wants to merge
1
commit into
nus-cs2113-AY2122S1:master
Choose a base branch
from
Roycius:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Testing #50
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -51,8 +51,8 @@ public class Contacts1 { | |
private static final String COMMAND_ADD_WORD = "add"; | ||
private static final String COMMAND_ADD_DESC = "Adds a person to contacts."; | ||
private static final String COMMAND_ADD_PARAMETERS = "NAME " | ||
+ PERSON_DATA_PREFIX_PHONE + "PHONE_NUMBER " | ||
+ PERSON_DATA_PREFIX_EMAIL + "EMAIL"; | ||
+ PERSON_DATA_PREFIX_PHONE + "PHONE_NUMBER " | ||
+ PERSON_DATA_PREFIX_EMAIL + "EMAIL"; | ||
private static final String COMMAND_ADD_EXAMPLE = COMMAND_ADD_WORD + " John Doe p/98765432 e/[email protected]"; | ||
|
||
private static final String COMMAND_LIST_WORD = "list"; | ||
|
@@ -87,7 +87,7 @@ public class Contacts1 { | |
* The number of data elements for a single person. | ||
*/ | ||
private static final int PERSON_DATA_COUNT = 3; | ||
|
||
/** | ||
* Maximum number of persons that can be held. | ||
*/ | ||
|
@@ -192,8 +192,8 @@ private static void exitProgram() { | |
/** | ||
* Executes the command as specified by the {@code userInputString} | ||
* | ||
* @param userInputString raw input from user | ||
* @return feedback about how the command was executed | ||
* @param userInputString raw input from user | ||
* @return feedback about how the command was executed | ||
*/ | ||
private static String executeCommand(String userInputString) { | ||
final String[] commandTypeAndParams = splitCommandWordAndArgs(userInputString); | ||
|
@@ -219,11 +219,11 @@ private static String executeCommand(String userInputString) { | |
/** | ||
* Splits raw user input into command word and command arguments string | ||
* | ||
* @return size 2 array; first element is the command type and second element is the arguments string | ||
* @return size 2 array; first element is the command type and second element is the arguments string | ||
*/ | ||
private static String[] splitCommandWordAndArgs(String rawUserInput) { | ||
final String[] split = rawUserInput.trim().split("\\s+", 2); | ||
return split.length == 2 ? split : new String[] { split[0] , "" }; // else case: no parameters | ||
return split.length == 2 ? split : new String[]{split[0], ""}; // else case: no parameters | ||
} | ||
|
||
/** | ||
|
@@ -349,7 +349,6 @@ private static void showToUser(String... message) { | |
/** | ||
* Shows the list of persons to the user. | ||
* The list will be indexed, starting from 1. | ||
* | ||
*/ | ||
private static void showToUser(String[][] persons) { | ||
String listAsString = getDisplayString(persons); | ||
|
@@ -365,8 +364,8 @@ private static String getDisplayString(String[][] persons) { | |
final String[] person = persons[i]; | ||
final int displayIndex = i + 1; | ||
messageAccumulator.append('\t') | ||
.append(getIndexedPersonListElementMessage(displayIndex, person)) | ||
.append(LS); | ||
.append(getIndexedPersonListElementMessage(displayIndex, person)) | ||
.append(LS); | ||
} | ||
return messageAccumulator.toString(); | ||
} | ||
|
@@ -375,7 +374,7 @@ private static String getDisplayString(String[][] persons) { | |
* Constructs a prettified listing element message to represent a person and their data. | ||
* | ||
* @param visibleIndex visible index for this listing | ||
* @param person to show | ||
* @param person to show | ||
* @return formatted listing message with index | ||
*/ | ||
private static String getIndexedPersonListElementMessage(int visibleIndex, String[] person) { | ||
|
@@ -456,7 +455,7 @@ private static String getEmailFromPerson(String[] person) { | |
/** | ||
* Creates a person from the given data. | ||
* | ||
* @param name of person | ||
* @param name of person | ||
* @param phone without data prefix | ||
* @param email without data prefix | ||
* @return constructed person | ||
|
@@ -474,7 +473,7 @@ private static String[] makePersonFromData(String name, String phone, String ema | |
* | ||
* @param encoded string to be decoded | ||
* @return if cannot decode: empty Optional | ||
* else: Optional containing decoded person | ||
* else: Optional containing decoded person | ||
*/ | ||
private static String[] decodePersonFromString(String encoded) { | ||
// check that we can extract the parts of a person from the encoded string | ||
|
@@ -535,7 +534,7 @@ private static String extractPhoneFromPersonString(String encoded) { | |
return removePrefixSign(encoded.substring(indexOfPhonePrefix, encoded.length()).trim(), | ||
PERSON_DATA_PREFIX_PHONE); | ||
|
||
// phone is middle arg, target is from own prefix to next prefix | ||
// phone is middle arg, target is from own prefix to next prefix | ||
} else { | ||
return removePrefixSign( | ||
encoded.substring(indexOfPhonePrefix, indexOfEmailPrefix).trim(), | ||
|
@@ -558,7 +557,7 @@ private static String extractEmailFromPersonString(String encoded) { | |
return removePrefixSign(encoded.substring(indexOfEmailPrefix, encoded.length()).trim(), | ||
PERSON_DATA_PREFIX_EMAIL); | ||
|
||
// email is middle arg, target is from own prefix to next prefix | ||
// email is middle arg, target is from own prefix to next prefix | ||
} else { | ||
return removePrefixSign( | ||
encoded.substring(indexOfEmailPrefix, indexOfPhonePrefix).trim(), | ||
|
@@ -615,7 +614,9 @@ private static boolean isValidEmail(String email) { | |
* =============================================== | ||
*/ | ||
|
||
/** Returns usage info for all commands */ | ||
/** | ||
* Returns usage info for all commands | ||
*/ | ||
private static String getUsageInfoForAllCommands() { | ||
return getUsageInfoForAddCommand() + LS | ||
+ getUsageInfoForViewCommand() + LS | ||
|
@@ -624,32 +625,42 @@ private static String getUsageInfoForAllCommands() { | |
+ getUsageInfoForHelpCommand(); | ||
} | ||
|
||
/** Returns the string for showing 'add' command usage instruction */ | ||
/** | ||
* Returns the string for showing 'add' command usage instruction | ||
*/ | ||
private static String getUsageInfoForAddCommand() { | ||
return String.format(MESSAGE_COMMAND_HELP, COMMAND_ADD_WORD, COMMAND_ADD_DESC) + LS | ||
+ String.format(MESSAGE_COMMAND_HELP_PARAMETERS, COMMAND_ADD_PARAMETERS) + LS | ||
+ String.format(MESSAGE_COMMAND_HELP_EXAMPLE, COMMAND_ADD_EXAMPLE) + LS; | ||
} | ||
|
||
/** Returns string for showing 'clear' command usage instruction */ | ||
/** | ||
* Returns string for showing 'clear' command usage instruction | ||
*/ | ||
private static String getUsageInfoForClearCommand() { | ||
return String.format(MESSAGE_COMMAND_HELP, COMMAND_CLEAR_WORD, COMMAND_CLEAR_DESC) + LS | ||
+ String.format(MESSAGE_COMMAND_HELP_EXAMPLE, COMMAND_CLEAR_EXAMPLE) + LS; | ||
} | ||
|
||
/** Returns the string for showing 'view' command usage instruction */ | ||
/** | ||
* Returns the string for showing 'view' command usage instruction | ||
*/ | ||
private static String getUsageInfoForViewCommand() { | ||
return String.format(MESSAGE_COMMAND_HELP, COMMAND_LIST_WORD, COMMAND_LIST_DESC) + LS | ||
+ String.format(MESSAGE_COMMAND_HELP_EXAMPLE, COMMAND_LIST_EXAMPLE) + LS; | ||
} | ||
|
||
/** Returns string for showing 'help' command usage instruction */ | ||
/** | ||
* Returns string for showing 'help' command usage instruction | ||
*/ | ||
private static String getUsageInfoForHelpCommand() { | ||
return String.format(MESSAGE_COMMAND_HELP, COMMAND_HELP_WORD, COMMAND_HELP_DESC) + LS | ||
+ String.format(MESSAGE_COMMAND_HELP_EXAMPLE, COMMAND_HELP_EXAMPLE); | ||
} | ||
|
||
/** Returns the string for showing 'exit' command usage instruction */ | ||
/** | ||
* Returns the string for showing 'exit' command usage instruction | ||
*/ | ||
private static String getUsageInfoForExitCommand() { | ||
return String.format(MESSAGE_COMMAND_HELP, COMMAND_EXIT_WORD, COMMAND_EXIT_DESC) + LS | ||
+ String.format(MESSAGE_COMMAND_HELP_EXAMPLE, COMMAND_EXIT_EXAMPLE) + LS; | ||
|
@@ -665,9 +676,9 @@ private static String getUsageInfoForExitCommand() { | |
/** | ||
* Removes sign(p/, d/, etc) from parameter string | ||
* | ||
* @param s Parameter as a string | ||
* @param sign Parameter sign to be removed | ||
* @return string without the sign | ||
* @param s Parameter as a string | ||
* @param sign Parameter sign to be removed | ||
* @return string without the sign | ||
*/ | ||
private static String removePrefixSign(String s, String sign) { | ||
return s.replace(sign, ""); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
test