diff --git a/src/seedu/addressbook/AddressBook.java b/src/seedu/addressbook/AddressBook.java index 5a158b67..9804d54b 100644 --- a/src/seedu/addressbook/AddressBook.java +++ b/src/seedu/addressbook/AddressBook.java @@ -8,6 +8,7 @@ */ import java.io.File; + import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.Files; @@ -18,11 +19,14 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.Optional; import java.util.Scanner; import java.util.Set; +import seedu.addressbook.AddressBook.PersonProperty; + /* * NOTE : ============================================================= * This class header comment below is brief because details of how to @@ -135,21 +139,6 @@ public class AddressBook { private static final String DIVIDER = "==================================================="; - - /* We use a String array to store details of a single person. - * The constants given below are the indexes for the different data elements of a person - * used by the internal String[] storage format. - * For example, a person's name is stored as the 0th element in the array. - */ - private static final int PERSON_DATA_INDEX_NAME = 0; - private static final int PERSON_DATA_INDEX_PHONE = 1; - private static final int PERSON_DATA_INDEX_EMAIL = 2; - - /** - * The number of data elements for a single person. - */ - private static final int PERSON_DATA_COUNT = 3; - /** * Offset required to convert between 1-indexing and 0-indexing.COMMAND_ */ @@ -181,14 +170,14 @@ public class AddressBook { /** * List of all persons in the address book. */ - private static final ArrayList ALL_PERSONS = new ArrayList<>(); + private static final ArrayList> ALL_PERSONS = new ArrayList>(); /** * Stores the most recent list of persons shown to the user as a result of a user command. * This is a subset of the full list. Deleting persons in the pull list does not delete * those persons from this list. */ - private static ArrayList latestPersonListingView = getAllPersonsInAddressBook(); // initial view is of all + private static ArrayList> latestPersonListingView = getAllPersonsInAddressBook(); // initial view is of all /** * The path to the file used for storing person data. @@ -210,6 +199,9 @@ public static void main(String[] args) { showWelcomeMessage(); processProgramArgs(args); loadDataFromStorage(); + for ( int i =0; i<20; i++ ) { + System.out.println(i); + } while (true) { String userCommand = getUserInput(); echoUserCommand(userCommand); @@ -227,10 +219,12 @@ public static void main(String[] args) { */ private static void showWelcomeMessage() { + showToUser(DIVIDER, DIVIDER, VERSION, MESSAGE_WELCOME, DIVIDER); } private static void showResultToUser(String result) { + showToUser(result, DIVIDER); } @@ -417,7 +411,7 @@ private static String getMessageForInvalidCommandInput(String userCommand, Strin */ private static String executeAddPerson(String commandArgs) { // try decoding a person from the raw args - final Optional decodeResult = decodePersonFromString(commandArgs); + final Optional> decodeResult = decodePersonFromString(commandArgs); // checks if args are valid (decode result will not be present if the person is invalid) if (!decodeResult.isPresent()) { @@ -425,7 +419,7 @@ private static String executeAddPerson(String commandArgs) { } // add the person as specified - final String[] personToAdd = decodeResult.get(); + final HashMap personToAdd = decodeResult.get(); addPersonToAddressBook(personToAdd); return getMessageForSuccessfulAddPerson(personToAdd); } @@ -434,12 +428,12 @@ private static String executeAddPerson(String commandArgs) { * Constructs a feedback message for a successful add person command execution. * * @see #executeAddPerson(String) - * @param addedPerson person who was successfully added + * @param personToAdd person who was successfully added * @return successful add person feedback message */ - private static String getMessageForSuccessfulAddPerson(String[] addedPerson) { + private static String getMessageForSuccessfulAddPerson(HashMap personToAdd) { return String.format(MESSAGE_ADDED, - getNameFromPerson(addedPerson), getPhoneFromPerson(addedPerson), getEmailFromPerson(addedPerson)); + getNameFromPerson(personToAdd), getPhoneFromPerson(personToAdd), getEmailFromPerson(personToAdd)); } /** @@ -451,7 +445,7 @@ private static String getMessageForSuccessfulAddPerson(String[] addedPerson) { */ private static String executeFindPersons(String commandArgs) { final Set keywords = extractKeywordsFromFindPersonArgs(commandArgs); - final ArrayList personsFound = getPersonsWithNameContainingAnyKeyword(keywords); + final ArrayList> personsFound = getPersonsWithNameContainingAnyKeyword(keywords); showToUser(personsFound); return getMessageForPersonsDisplayedSummary(personsFound); } @@ -459,11 +453,11 @@ private static String executeFindPersons(String commandArgs) { /** * Constructs a feedback message to summarise an operation that displayed a listing of persons. * - * @param personsDisplayed used to generate summary + * @param toBeDisplayed used to generate summary * @return summary message for persons displayed */ - private static String getMessageForPersonsDisplayedSummary(ArrayList personsDisplayed) { - return String.format(MESSAGE_PERSONS_FOUND_OVERVIEW, personsDisplayed.size()); + private static String getMessageForPersonsDisplayedSummary(ArrayList> toBeDisplayed) { + return String.format(MESSAGE_PERSONS_FOUND_OVERVIEW, toBeDisplayed.size()); } /** @@ -482,9 +476,9 @@ private static Set extractKeywordsFromFindPersonArgs(String findPersonCo * @param keywords for searching * @return list of persons in full model with name containing some of the keywords */ - private static ArrayList getPersonsWithNameContainingAnyKeyword(Collection keywords) { - final ArrayList matchedPersons = new ArrayList<>(); - for (String[] person : getAllPersonsInAddressBook()) { + private static ArrayList> getPersonsWithNameContainingAnyKeyword(Collection keywords) { + final ArrayList> matchedPersons = new ArrayList>(); + for (HashMap person : getAllPersonsInAddressBook()) { final Set wordsInName = new HashSet<>(splitByWhitespace(getNameFromPerson(person))); if (!Collections.disjoint(wordsInName, keywords)) { matchedPersons.add(person); @@ -507,7 +501,7 @@ private static String executeDeletePerson(String commandArgs) { if (!isDisplayIndexValidForLastPersonListingView(targetVisibleIndex)) { return MESSAGE_INVALID_PERSON_DISPLAYED_INDEX; } - final String[] targetInModel = getPersonByLastVisibleIndex(targetVisibleIndex); + final HashMap targetInModel = getPersonByLastVisibleIndex(targetVisibleIndex); return deletePersonFromAddressBook(targetInModel) ? getMessageForSuccessfulDelete(targetInModel) // success : MESSAGE_PERSON_NOT_IN_ADDRESSBOOK; // not found } @@ -551,11 +545,11 @@ private static boolean isDisplayIndexValidForLastPersonListingView(int index) { * Constructs a feedback message for a successful delete person command execution. * * @see #executeDeletePerson(String) - * @param deletedPerson successfully deleted + * @param targetInModel successfully deleted * @return successful delete person feedback message */ - private static String getMessageForSuccessfulDelete(String[] deletedPerson) { - return String.format(MESSAGE_DELETE_PERSON_SUCCESS, getMessageForFormattedPersonData(deletedPerson)); + private static String getMessageForSuccessfulDelete(HashMap targetInModel) { + return String.format(MESSAGE_DELETE_PERSON_SUCCESS, getMessageForFormattedPersonData(targetInModel)); } /** @@ -574,7 +568,7 @@ private static String executeClearAddressBook() { * @return feedback display message for the operation result */ private static String executeListAllPersonsInAddressBook() { - ArrayList toBeDisplayed = getAllPersonsInAddressBook(); + ArrayList> toBeDisplayed = getAllPersonsInAddressBook(); showToUser(toBeDisplayed); return getMessageForPersonsDisplayedSummary(toBeDisplayed); } @@ -623,13 +617,12 @@ private static void showToUser(String... message) { System.out.println(LINE_PREFIX + m); } } - /** * Shows the list of persons to the user. * The list will be indexed, starting from 1. * */ - private static void showToUser(ArrayList persons) { + private static void showToUser(ArrayList> persons) { String listAsString = getDisplayString(persons); showToUser(listAsString); updateLatestViewedPersonListing(persons); @@ -638,10 +631,10 @@ private static void showToUser(ArrayList persons) { /** * Returns the display string representation of the list of persons. */ - private static String getDisplayString(ArrayList persons) { + private static String getDisplayString(ArrayList> persons) { final StringBuilder messageAccumulator = new StringBuilder(); for (int i = 0; i < persons.size(); i++) { - final String[] person = persons.get(i); + final HashMap person = persons.get(i); final int displayIndex = i + DISPLAYED_INDEX_OFFSET; messageAccumulator.append('\t') .append(getIndexedPersonListElementMessage(displayIndex, person)) @@ -657,7 +650,7 @@ private static String getDisplayString(ArrayList persons) { * @param person to show * @return formatted listing message with index */ - private static String getIndexedPersonListElementMessage(int visibleIndex, String[] person) { + private static String getIndexedPersonListElementMessage(int visibleIndex, HashMap person) { return String.format(MESSAGE_DISPLAY_LIST_ELEMENT_INDEX, visibleIndex) + getMessageForFormattedPersonData(person); } @@ -667,7 +660,7 @@ private static String getIndexedPersonListElementMessage(int visibleIndex, Strin * @param person to show * @return formatted message showing internal state */ - private static String getMessageForFormattedPersonData(String[] person) { + private static String getMessageForFormattedPersonData(HashMap person) { return String.format(MESSAGE_DISPLAY_PERSON_DATA, getNameFromPerson(person), getPhoneFromPerson(person), getEmailFromPerson(person)); } @@ -677,7 +670,7 @@ private static String getMessageForFormattedPersonData(String[] person) { * * @param newListing the new listing of persons */ - private static void updateLatestViewedPersonListing(ArrayList newListing) { + private static void updateLatestViewedPersonListing(ArrayList> newListing) { // clone to insulate from future changes to arg list latestPersonListingView = new ArrayList<>(newListing); } @@ -688,7 +681,7 @@ private static void updateLatestViewedPersonListing(ArrayList newListi * @param lastVisibleIndex displayed index from last shown person listing * @return the actual person object in the last shown person listing */ - private static String[] getPersonByLastVisibleIndex(int lastVisibleIndex) { + private static HashMap getPersonByLastVisibleIndex(int lastVisibleIndex) { return latestPersonListingView.get(lastVisibleIndex - DISPLAYED_INDEX_OFFSET); } @@ -728,8 +721,8 @@ private static void createFileIfMissing(String filePath) { * @param filePath file to load from * @return the list of decoded persons */ - private static ArrayList loadPersonsFromFile(String filePath) { - final Optional> successfullyDecoded = decodePersonsFromStrings(getLinesInFile(filePath)); + private static ArrayList> loadPersonsFromFile(String filePath) { + final Optional>> successfullyDecoded = decodePersonsFromStrings(getLinesInFile(filePath)); if (!successfullyDecoded.isPresent()) { showToUser(MESSAGE_INVALID_STORAGE_FILE_CONTENT); exitProgram(); @@ -760,7 +753,7 @@ private static ArrayList getLinesInFile(String filePath) { * * @param filePath file for saving */ - private static void savePersonsToFile(ArrayList persons, String filePath) { + private static void savePersonsToFile(ArrayList> persons, String filePath) { final ArrayList linesToWrite = encodePersonsToStrings(persons); try { Files.write(Paths.get(storageFilePath), linesToWrite); @@ -780,21 +773,22 @@ private static void savePersonsToFile(ArrayList persons, String filePa /** * Adds a person to the address book. Saves changes to storage file. * - * @param person to add + * @param personToAdd to add */ - private static void addPersonToAddressBook(String[] person) { - ALL_PERSONS.add(person); + + private static void addPersonToAddressBook(HashMap personToAdd) { + ALL_PERSONS.add(personToAdd); savePersonsToFile(getAllPersonsInAddressBook(), storageFilePath); } /** * Deletes the specified person from the addressbook if it is inside. Saves any changes to storage file. * - * @param exactPerson the actual person inside the address book (exactPerson == the person to delete in the full list) + * @param targetInModel the actual person inside the address book (exactPerson == the person to delete in the full list) * @return true if the given person was found and deleted in the model */ - private static boolean deletePersonFromAddressBook(String[] exactPerson) { - final boolean changed = ALL_PERSONS.remove(exactPerson); + private static boolean deletePersonFromAddressBook(HashMap targetInModel) { + final boolean changed = ALL_PERSONS.remove(targetInModel); if (changed) { savePersonsToFile(getAllPersonsInAddressBook(), storageFilePath); } @@ -804,7 +798,7 @@ private static boolean deletePersonFromAddressBook(String[] exactPerson) { /** * Returns all persons in the address book */ - private static ArrayList getAllPersonsInAddressBook() { + private static ArrayList> getAllPersonsInAddressBook() { return ALL_PERSONS; } @@ -821,7 +815,7 @@ private static void clearAddressBook() { * * @param persons list of persons to initialise the model with */ - private static void initialiseAddressBookModel(ArrayList persons) { + private static void initialiseAddressBookModel(ArrayList> persons) { ALL_PERSONS.clear(); ALL_PERSONS.addAll(persons); } @@ -838,26 +832,31 @@ private static void initialiseAddressBookModel(ArrayList persons) { * * @param person whose name you want */ - private static String getNameFromPerson(String[] person) { - return person[PERSON_DATA_INDEX_NAME]; + private static String getNameFromPerson(HashMap person) { + String personName = person.get(PersonProperty.NAME); + return personName; } + //person.get(PERSON...) /** * Returns given person's phone number * * @param person whose phone number you want */ - private static String getPhoneFromPerson(String[] person) { - return person[PERSON_DATA_INDEX_PHONE]; + private static String getPhoneFromPerson(HashMap person) { + String personPhone = person.get(PersonProperty.PHONE); + return personPhone; } + //person.get(PERSON...NUMBER) /** * Returns given person's email * - * @param person whose email you want + * @param personToAdd whose email you want */ - private static String getEmailFromPerson(String[] person) { - return person[PERSON_DATA_INDEX_EMAIL]; + private static String getEmailFromPerson(HashMap person) { + String personEmail = person.get(PersonProperty.EMAIL); + return personEmail; } /** @@ -868,21 +867,27 @@ private static String getEmailFromPerson(String[] person) { * @param email without data prefix * @return constructed person */ - private static String[] makePersonFromData(String name, String phone, String email) { - final String[] person = new String[PERSON_DATA_COUNT]; - person[PERSON_DATA_INDEX_NAME] = name; - person[PERSON_DATA_INDEX_PHONE] = phone; - person[PERSON_DATA_INDEX_EMAIL] = email; + private static HashMap makePersonFromData(String name, String phone, String email) { + final HashMap person = new HashMap(); + registerPersonDetails(name, phone, email, person); return person; } + private static void registerPersonDetails(String name, String phone, String email, + final HashMap person) { + person.put(PersonProperty.NAME, name); + person.put(PersonProperty.EMAIL, email); + person.put(PersonProperty.PHONE, phone); + } + public enum PersonProperty {NAME, EMAIL, PHONE}; + /** * Encodes a person into a decodable and readable string representation. * * @param person to be encoded * @return encoded string */ - private static String encodePersonToString(String[] person) { + private static String encodePersonToString(HashMap person) { return String.format(PERSON_STRING_REPRESENTATION, getNameFromPerson(person), getPhoneFromPerson(person), getEmailFromPerson(person)); } @@ -893,9 +898,9 @@ private static String encodePersonToString(String[] person) { * @param persons to be encoded * @return encoded strings */ - private static ArrayList encodePersonsToStrings(ArrayList persons) { + private static ArrayList encodePersonsToStrings(ArrayList> persons) { final ArrayList encoded = new ArrayList<>(); - for (String[] person : persons) { + for (HashMap person : persons) { encoded.add(encodePersonToString(person)); } return encoded; @@ -915,12 +920,12 @@ private static ArrayList encodePersonsToStrings(ArrayList pers * @return if cannot decode: empty Optional * else: Optional containing decoded person */ - private static Optional decodePersonFromString(String encoded) { + private static Optional> decodePersonFromString(String encoded) { // check that we can extract the parts of a person from the encoded string if (!isPersonDataExtractableFrom(encoded)) { return Optional.empty(); } - final String[] decodedPerson = makePersonFromData( + final HashMap decodedPerson = makePersonFromData( extractNameFromPersonString(encoded), extractPhoneFromPersonString(encoded), extractEmailFromPersonString(encoded) @@ -936,10 +941,10 @@ private static Optional decodePersonFromString(String encoded) { * @return if cannot decode any: empty Optional * else: Optional containing decoded persons */ - private static Optional> decodePersonsFromStrings(ArrayList encodedPersons) { - final ArrayList decodedPersons = new ArrayList<>(); + private static Optional>> decodePersonsFromStrings(ArrayList encodedPersons) { + final ArrayList> decodedPersons = new ArrayList<>(); for (String encodedPerson : encodedPersons) { - final Optional decodedPerson = decodePersonFromString(encodedPerson); + final Optional> decodedPerson = decodePersonFromString(encodedPerson); if (!decodedPerson.isPresent()) { return Optional.empty(); } @@ -974,7 +979,8 @@ private static String extractNameFromPersonString(String encoded) { final int indexOfEmailPrefix = encoded.indexOf(PERSON_DATA_PREFIX_EMAIL); // name is leading substring up to first data prefix symbol int indexOfFirstPrefix = Math.min(indexOfEmailPrefix, indexOfPhonePrefix); - return encoded.substring(0, indexOfFirstPrefix).trim(); + String nameFromPersonString = encoded.substring(0, indexOfFirstPrefix).trim(); + return nameFromPersonString; } /** @@ -989,14 +995,16 @@ private static String extractPhoneFromPersonString(String encoded) { // phone is last arg, target is from prefix to end of string if (indexOfPhonePrefix > indexOfEmailPrefix) { - return removePrefixSign(encoded.substring(indexOfPhonePrefix, encoded.length()).trim(), + String phoneFromPersonString = removePrefixSign(encoded.substring(indexOfPhonePrefix, encoded.length()).trim(), PERSON_DATA_PREFIX_PHONE); + return phoneFromPersonString; // phone is middle arg, target is from own prefix to next prefix } else { - return removePrefixSign( + String phoneFromPersonString = removePrefixSign( encoded.substring(indexOfPhonePrefix, indexOfEmailPrefix).trim(), PERSON_DATA_PREFIX_PHONE); + return phoneFromPersonString; } } @@ -1012,26 +1020,28 @@ private static String extractEmailFromPersonString(String encoded) { // email is last arg, target is from prefix to end of string if (indexOfEmailPrefix > indexOfPhonePrefix) { - return removePrefixSign(encoded.substring(indexOfEmailPrefix, encoded.length()).trim(), + String emailFromPersonString = removePrefixSign(encoded.substring(indexOfEmailPrefix, encoded.length()).trim(), PERSON_DATA_PREFIX_EMAIL); + return emailFromPersonString; // email is middle arg, target is from own prefix to next prefix } else { - return removePrefixSign( + String emailFromPersonString = removePrefixSign( encoded.substring(indexOfEmailPrefix, indexOfPhonePrefix).trim(), PERSON_DATA_PREFIX_EMAIL); + return emailFromPersonString; } } /** * Returns true if the given person's data fields are valid * - * @param person String array representing the person (used in internal data) + * @param decodedPerson String array representing the person (used in internal data) */ - private static boolean isPersonDataValid(String[] person) { - return isPersonNameValid(person[PERSON_DATA_INDEX_NAME]) - && isPersonPhoneValid(person[PERSON_DATA_INDEX_PHONE]) - && isPersonEmailValid(person[PERSON_DATA_INDEX_EMAIL]); + private static boolean isPersonDataValid(HashMap decodedPerson) { + return isPersonNameValid(decodedPerson.get(PersonProperty.NAME)) + && isPersonPhoneValid(decodedPerson.get(PersonProperty.PHONE)) + && isPersonEmailValid(decodedPerson.get(PersonProperty.EMAIL)); } /* @@ -1082,58 +1092,66 @@ private static boolean isPersonEmailValid(String email) { /** Returns usage info for all commands */ private static String getUsageInfoForAllCommands() { - return getUsageInfoForAddCommand() + LS + String infoForAllCommands = getUsageInfoForAddCommand() + LS + getUsageInfoForFindCommand() + LS + getUsageInfoForViewCommand() + LS + getUsageInfoForDeleteCommand() + LS + getUsageInfoForClearCommand() + LS + getUsageInfoForExitCommand() + LS + getUsageInfoForHelpCommand(); + return infoForAllCommands; } /** 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 infoForAddCommnads = 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; + return infoForAddCommnads; } /** Returns the string for showing 'find' command usage instruction */ private static String getUsageInfoForFindCommand() { - return String.format(MESSAGE_COMMAND_HELP, COMMAND_FIND_WORD, COMMAND_FIND_DESC) + LS + String infoForFindCommand = String.format(MESSAGE_COMMAND_HELP, COMMAND_FIND_WORD, COMMAND_FIND_DESC) + LS + String.format(MESSAGE_COMMAND_HELP_PARAMETERS, COMMAND_FIND_PARAMETERS) + LS + String.format(MESSAGE_COMMAND_HELP_EXAMPLE, COMMAND_FIND_EXAMPLE) + LS; + return infoForFindCommand; } /** Returns the string for showing 'delete' command usage instruction */ private static String getUsageInfoForDeleteCommand() { - return String.format(MESSAGE_COMMAND_HELP, COMMAND_DELETE_WORD, COMMAND_DELETE_DESC) + LS + String infoForDeleteCommand = String.format(MESSAGE_COMMAND_HELP, COMMAND_DELETE_WORD, COMMAND_DELETE_DESC) + LS + String.format(MESSAGE_COMMAND_HELP_PARAMETERS, COMMAND_DELETE_PARAMETER) + LS + String.format(MESSAGE_COMMAND_HELP_EXAMPLE, COMMAND_DELETE_EXAMPLE) + LS; + return infoForDeleteCommand; } /** 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 infoForClearCommand = String.format(MESSAGE_COMMAND_HELP, COMMAND_CLEAR_WORD, COMMAND_CLEAR_DESC) + LS + String.format(MESSAGE_COMMAND_HELP_EXAMPLE, COMMAND_CLEAR_EXAMPLE) + LS; + return infoForClearCommand; } /** 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 infoForViewCommand = String.format(MESSAGE_COMMAND_HELP, COMMAND_LIST_WORD, COMMAND_LIST_DESC) + LS + String.format(MESSAGE_COMMAND_HELP_EXAMPLE, COMMAND_LIST_EXAMPLE) + LS; + return infoForViewCommand; } /** Returns string for showing 'help' command usage instruction */ private static String getUsageInfoForHelpCommand() { - return String.format(MESSAGE_COMMAND_HELP, COMMAND_HELP_WORD, COMMAND_HELP_DESC) + String infoForHelpCommand = String.format(MESSAGE_COMMAND_HELP, COMMAND_HELP_WORD, COMMAND_HELP_DESC) + String.format(MESSAGE_COMMAND_HELP_EXAMPLE, COMMAND_HELP_EXAMPLE); + return infoForHelpCommand; } /** 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) + String infoForExitCommand = String.format(MESSAGE_COMMAND_HELP, COMMAND_EXIT_WORD, COMMAND_EXIT_DESC) + String.format(MESSAGE_COMMAND_HELP_EXAMPLE, COMMAND_EXIT_EXAMPLE); + return infoForExitCommand; } @@ -1150,9 +1168,23 @@ private static String getUsageInfoForExitCommand() { * @param sign Parameter sign to be removed * @return string without the sign */ - private static String removePrefixSign(String s, String sign) { - return s.replace(sign, ""); - } + private static String removePrefixSign(String s, String prefix) { + if ( prefix.equals(PERSON_DATA_PREFIX_PHONE) || prefix.equals(PERSON_DATA_PREFIX_EMAIL)) { + return removePrefix(s, prefix); + } + else { + return ""; + } + } + + private static String removePrefix(String fullString, String prefix) { + if ( !fullString.startsWith(prefix) ) { + return fullString; + } + else { + return fullString.replace(prefix, ""); + } + } /** * Splits a source string into the list of substrings that were separated by whitespace.