Skip to content
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

[T4A2][F11-B3]Lim Hong Wei #1652

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/seedu/addressbook/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends ReadOnlyPerson> relevantPersons;
Expand All @@ -26,6 +26,10 @@ public CommandResult(String feedbackToUser, List<? extends ReadOnlyPerson> relev
this.relevantPersons = relevantPersons;
}

public String getFeedbackToUser() {
return feedbackToUser;
}

/**
* Returns list of persons relevant to the command command result, if any.
*/
Expand Down
35 changes: 33 additions & 2 deletions src/seedu/addressbook/data/person/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions src/seedu/addressbook/data/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/**

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will work. However, it more meaningful to init to 1 since the variable is called next SequenceNumber and post increment.

* Assumption: Every field must be present and not null.
*/
Expand All @@ -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;

}

/**
Expand Down
16 changes: 7 additions & 9 deletions src/seedu/addressbook/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,13 @@ public static class ParseException extends Exception {
*/
public static final Pattern BASIC_COMMAND_FORMAT = Pattern.compile("(?<commandWord>\\S+)(?<arguments>.*)");

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));
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -150,7 +148,7 @@ private static Set<String> 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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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");
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/seedu/addressbook/ui/TextUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void showResultToUser(CommandResult result) {
if(resultPersons.isPresent()) {
showPersonListView(resultPersons.get());
}
showToUser(result.feedbackToUser, DIVIDER);
showToUser(result.getFeedbackToUser(), DIVIDER);
}

/**
Expand Down
9 changes: 0 additions & 9 deletions test/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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!
|| ===================================================
Expand Down
9 changes: 0 additions & 9 deletions test/input.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
##########################################################
Expand Down