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

[T5A1][F11-B3]Lim Hong Wei #1695

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
26 changes: 26 additions & 0 deletions doc/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,32 @@
* JDK 8 or later
* Eclipse IDE

**UserStories**
Level of Importance(*, * *, * * *) | Name of function | Purpose of function
1. *** | Find Command | To find the person in the address book.
2. *** | List Command | To present all persons in the address book in a list.
3. *** | Add Command | To add new person into the address book.
3. *** | Edit Command | To edit details of the persons in the address book.
4. *** | Help Command | To help persons familiarize with the address book interface and commands.
5. * * | Delete Command | To remove the persons from the address book.
6. * * | Tag Command | To tag the persons with a tag (e.g. friends, family).
7. * | RemoveTag Command | Removing the tag from a person.
8. * | Edit Tag Command | Editing a person's tag.
9. * | Exit command | Exit the program.

**Use Case for Rename Tag**
1. User will use list command to request for the list of persons in address book.
2. AddressBook will list the persons.
3. User will find the specific person and request to change the tag of the person.
4. AddressBook will ask to confirm the change.
5. User will confirm the change and a notification will appear showing the change is successful.

**Non-Functional Requirements **
1. AddressBook should be able to store up to 1000 person.
2. AddressBook should be user friendly.
3. AddressBook should run fast (~1/2 seconds)
4. The size of the program should be small.

**Importing the project into Eclipse**

0. Fork this repo, and clone the fork to your computer
Expand Down
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
29 changes: 5 additions & 24 deletions src/seedu/addressbook/data/person/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,34 @@
* Represents a Person's address in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidAddress(String)}
*/
public class Address {
public class Address extends Contact{

public static final String EXAMPLE = "123, some street";
public static final String MESSAGE_ADDRESS_CONSTRAINTS = "Person addresses can be in any format";
public static final String ADDRESS_VALIDATION_REGEX = ".+";

public final String value;
private boolean isPrivate;

/**
* Validates given address.
*
* @throws IllegalValueException if given address string is invalid.
*/
public Address(String address, boolean isPrivate) throws IllegalValueException {
this.isPrivate = isPrivate;
super(address, isPrivate);
//this.isPrivate = isPrivate;
if (!isValidAddress(address)) {
throw new IllegalValueException(MESSAGE_ADDRESS_CONSTRAINTS);
}
this.value = address;
}

/**
* Returns true if a given string is a valid person email.
*/

public static boolean isValidAddress(String test) {
return test.matches(ADDRESS_VALIDATION_REGEX);
}

@Override
public String toString() {
return value;
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Address // instanceof handles nulls
&& this.value.equals(((Address) other).value)); // state check
}

@Override
public int hashCode() {
return value.hashCode();
}

public boolean isPrivate() {
return isPrivate;
}

}
21 changes: 21 additions & 0 deletions src/seedu/addressbook/data/person/Contact.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package seedu.addressbook.data.person;

public class Contact {
public final String value;
private boolean isPrivate;

public Contact(String newStr, boolean isPrivate) {
this.isPrivate = isPrivate;
value = newStr.trim();
}

public int hashCode() {
return value.hashCode();
}
public boolean isPrivate() {
return isPrivate;
}
public String toString() {
return value;
}
}
24 changes: 2 additions & 22 deletions src/seedu/addressbook/data/person/Email.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,23 @@
* Represents a Person's email in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidEmail(String)}
*/
public class Email {
public class Email extends Contact {

public static final String EXAMPLE = "[email protected]";
public static final String MESSAGE_EMAIL_CONSTRAINTS =
"Person emails should be 2 alphanumeric/period strings separated by '@'";
public static final String EMAIL_VALIDATION_REGEX = "[\\w\\.]+@[\\w\\.]+";

public final String value;
private boolean isPrivate;

/**
* Validates given email.
*
* @throws IllegalValueException if given email address string is invalid.
*/
public Email(String email, boolean isPrivate) throws IllegalValueException {
this.isPrivate = isPrivate;
email = email.trim();
super(email, isPrivate);
if (!isValidEmail(email)) {
throw new IllegalValueException(MESSAGE_EMAIL_CONSTRAINTS);
}
this.value = email;
}

/**
Expand All @@ -37,25 +32,10 @@ public static boolean isValidEmail(String test) {
return test.matches(EMAIL_VALIDATION_REGEX);
}

@Override
public String toString() {
return value;
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Email // instanceof handles nulls
&& this.value.equals(((Email) other).value)); // state check
}

@Override
public int hashCode() {
return value.hashCode();
}


public boolean isPrivate() {
return isPrivate;
}
}
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;
/**
* 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
22 changes: 2 additions & 20 deletions src/seedu/addressbook/data/person/Phone.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,23 @@
* Represents a Person's phone number in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidPhone(String)}
*/
public class Phone {
public class Phone extends Contact {

public static final String EXAMPLE = "123456789";
public static final String MESSAGE_PHONE_CONSTRAINTS = "Person phone numbers should only contain numbers";
public static final String PHONE_VALIDATION_REGEX = "\\d+";

public final String value;
private boolean isPrivate;

/**
* Validates given phone number.
*
* @throws IllegalValueException if given phone string is invalid.
*/
public Phone(String phone, boolean isPrivate) throws IllegalValueException {
this.isPrivate = isPrivate;
phone = phone.trim();
super(phone, isPrivate);
if (!isValidPhone(phone)) {
throw new IllegalValueException(MESSAGE_PHONE_CONSTRAINTS);
}
this.value = phone;
}

/**
Expand All @@ -36,24 +32,10 @@ public static boolean isValidPhone(String test) {
return test.matches(PHONE_VALIDATION_REGEX);
}

@Override
public String toString() {
return value;
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Phone // instanceof handles nulls
&& this.value.equals(((Phone) other).value)); // state check
}

@Override
public int hashCode() {
return value.hashCode();
}

public boolean isPrivate() {
return isPrivate;
}
}
14 changes: 7 additions & 7 deletions src/seedu/addressbook/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Parser() {}
* @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 +96,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 +150,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 +167,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 +186,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 +207,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 +222,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