diff --git a/src/seedu/addressbook/commands/CommandResult.java b/src/seedu/addressbook/commands/CommandResult.java index cf4e72585..f234ff506 100644 --- a/src/seedu/addressbook/commands/CommandResult.java +++ b/src/seedu/addressbook/commands/CommandResult.java @@ -11,7 +11,7 @@ public class CommandResult { /** The feedback message to be shown to the user. Contains a description of the execution result */ - public final String feedbackToUser; + private final String feedbackToUser; /** The list of persons that was produced by the command */ private final List relevantPersons; @@ -26,6 +26,10 @@ public CommandResult(String feedbackToUser, List relev this.relevantPersons = relevantPersons; } + public String getFeedbackToUser() { + return feedbackToUser; + } + /** * Returns list of persons relevant to the command command result, if any. */ diff --git a/src/seedu/addressbook/data/person/Address.java b/src/seedu/addressbook/data/person/Address.java index 8ac726444..c749c1ccc 100644 --- a/src/seedu/addressbook/data/person/Address.java +++ b/src/seedu/addressbook/data/person/Address.java @@ -14,6 +14,11 @@ public class Address { public final String value; private boolean isPrivate; + private String theBlock; + private String theStreet; + private String theUnit; + private String thePostalCode; + /** * Validates given address. @@ -26,11 +31,37 @@ public Address(String address, boolean isPrivate) throws IllegalValueException { throw new IllegalValueException(MESSAGE_ADDRESS_CONSTRAINTS); } this.value = address; + splitAddress(); } - + /** - * Returns true if a given string is a valid person email. + * Splits address into different classes */ + public void splitAddress() { + String[] parts = new String[4]; + parts = value.split(", "); + theBlock = parts[0]; + theStreet = parts[1]; + theUnit = parts[2]; + thePostalCode = parts[3]; + } + + public String getTheBlock() { + return theBlock; + } + + public String getTheStreet() { + return theStreet; + } + + public String getTheUnit() { + return theUnit; + } + + public String getThePostalCode() { + return thePostalCode; + } + public static boolean isValidAddress(String test) { return test.matches(ADDRESS_VALIDATION_REGEX); } diff --git a/src/seedu/addressbook/data/person/Person.java b/src/seedu/addressbook/data/person/Person.java index cf6211841..a4b5e649c 100644 --- a/src/seedu/addressbook/data/person/Person.java +++ b/src/seedu/addressbook/data/person/Person.java @@ -14,8 +14,10 @@ public class Person implements ReadOnlyPerson { private Phone phone; private Email email; private Address address; + public int sequenceNumber; private final UniqueTagList tags; + public static int nextSequenceNumber = 0; /** * Assumption: Every field must be present and not null. */ @@ -25,6 +27,9 @@ public Person(Name name, Phone phone, Email email, Address address, UniqueTagLis this.email = email; this.address = address; this.tags = new UniqueTagList(tags); // protect internal tags from changes in the arg list + nextSequenceNumber++; + this.sequenceNumber = nextSequenceNumber; + } /** diff --git a/src/seedu/addressbook/parser/Parser.java b/src/seedu/addressbook/parser/Parser.java index 7d8b944d7..1390aded4 100644 --- a/src/seedu/addressbook/parser/Parser.java +++ b/src/seedu/addressbook/parser/Parser.java @@ -42,15 +42,13 @@ public static class ParseException extends Exception { */ public static final Pattern BASIC_COMMAND_FORMAT = Pattern.compile("(?\\S+)(?.*)"); - public Parser() {} - /** * Parses user input into command for execution. * * @param userInput full user input string * @return the command based on the user input */ - public Command parseCommand(String userInput) { + public static Command parseCommand(String userInput) { final Matcher matcher = BASIC_COMMAND_FORMAT.matcher(userInput.trim()); if (!matcher.matches()) { return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, HelpCommand.MESSAGE_USAGE)); @@ -96,7 +94,7 @@ public Command parseCommand(String userInput) { * @param args full command args string * @return the prepared command */ - private Command prepareAdd(String args){ + private static Command prepareAdd(String args){ final Matcher matcher = PERSON_DATA_ARGS_FORMAT.matcher(args.trim()); // Validate arg string format if (!matcher.matches()) { @@ -150,7 +148,7 @@ private static Set getTagsFromArgs(String tagArguments) throws IllegalVa * @param args full command args string * @return the prepared command */ - private Command prepareDelete(String args) { + private static Command prepareDelete(String args) { try { final int targetIndex = parseArgsAsDisplayedIndex(args); return new DeleteCommand(targetIndex); @@ -167,7 +165,7 @@ private Command prepareDelete(String args) { * @param args full command args string * @return the prepared command */ - private Command prepareView(String args) { + private static Command prepareView(String args) { try { final int targetIndex = parseArgsAsDisplayedIndex(args); @@ -186,7 +184,7 @@ private Command prepareView(String args) { * @param args full command args string * @return the prepared command */ - private Command prepareViewAll(String args) { + private static Command prepareViewAll(String args) { try { final int targetIndex = parseArgsAsDisplayedIndex(args); @@ -207,7 +205,7 @@ private Command prepareViewAll(String args) { * @throws ParseException if no region of the args string could be found for the index * @throws NumberFormatException the args string region is not a valid number */ - private int parseArgsAsDisplayedIndex(String args) throws ParseException, NumberFormatException { + private static int parseArgsAsDisplayedIndex(String args) throws ParseException, NumberFormatException { final Matcher matcher = PERSON_INDEX_ARGS_FORMAT.matcher(args.trim()); if (!matcher.matches()) { throw new ParseException("Could not find index number to parse"); @@ -222,7 +220,7 @@ private int parseArgsAsDisplayedIndex(String args) throws ParseException, Number * @param args full command args string * @return the prepared command */ - private Command prepareFind(String args) { + private static Command prepareFind(String args) { final Matcher matcher = KEYWORDS_ARGS_FORMAT.matcher(args.trim()); if (!matcher.matches()) { return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, diff --git a/src/seedu/addressbook/ui/TextUi.java b/src/seedu/addressbook/ui/TextUi.java index 39a2c6615..8442aa2fe 100644 --- a/src/seedu/addressbook/ui/TextUi.java +++ b/src/seedu/addressbook/ui/TextUi.java @@ -126,7 +126,7 @@ public void showResultToUser(CommandResult result) { if(resultPersons.isPresent()) { showPersonListView(resultPersons.get()); } - showToUser(result.feedbackToUser, DIVIDER); + showToUser(result.getFeedbackToUser(), DIVIDER); } /** diff --git a/test/expected.txt b/test/expected.txt index 7196c699f..37d60c78a 100644 --- a/test/expected.txt +++ b/test/expected.txt @@ -30,15 +30,6 @@ || exit: Exits the program. || Example: exit || =================================================== -|| Enter command: || [Command entered: delete 1] -|| The person index provided is invalid -|| =================================================== -|| Enter command: || [Command entered: view 1] -|| The person index provided is invalid -|| =================================================== -|| Enter command: || [Command entered: viewall 1] -|| The person index provided is invalid -|| =================================================== || Enter command: || [Command entered: clear] || Address book has been cleared! || =================================================== diff --git a/test/input.txt b/test/input.txt index 5ecae97f8..3d8d88237 100644 --- a/test/input.txt +++ b/test/input.txt @@ -5,15 +5,6 @@ # should recognise invalid command sfdfd -########################################################## -# commands using list index before any listing created -########################################################## - - # should show appropriate message when no listing has happened yet - delete 1 - view 1 - viewall 1 - ########################################################## # clean and check state ##########################################################