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

[T5A2][F11-B3]Lim Hong Wei #1696

Open
wants to merge 14 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
3 changes: 3 additions & 0 deletions src/seedu/addressbook/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,7 @@ public CommandResult execute() {
}
}

public boolean isMutating() {
return true;
}
}
4 changes: 4 additions & 0 deletions src/seedu/addressbook/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ public CommandResult execute() {
addressBook.clear();
return new CommandResult(MESSAGE_SUCCESS);
}

public boolean isMutating() {
return true;
}
}
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
5 changes: 4 additions & 1 deletion src/seedu/addressbook/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@ public CommandResult execute() {
return new CommandResult(Messages.MESSAGE_PERSON_NOT_IN_ADDRESSBOOK);
}
}


public boolean isMutating() {
return true;
}
}
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/ExitCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ public CommandResult execute() {
public static boolean isExit(Command command) {
return command instanceof ExitCommand; // instanceof returns false if it is null
}
public boolean isMutating() {
return false;
}


}
4 changes: 4 additions & 0 deletions src/seedu/addressbook/commands/FindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,9 @@ private List<ReadOnlyPerson> getPersonsWithNameContainingAnyKeyword(Set<String>
}
return matchedPersons;
}

public boolean isMutating() {
return false;
}

}
3 changes: 3 additions & 0 deletions src/seedu/addressbook/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ public CommandResult execute() {
+ "\n" + ExitCommand.MESSAGE_USAGE
);
}
public boolean isMutating() {
return false;
}
}
4 changes: 4 additions & 0 deletions src/seedu/addressbook/commands/IncorrectCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ public CommandResult execute() {
return new CommandResult(feedbackToUser);
}

public boolean isMutating() {
return false;
}

}
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public CommandResult execute() {
List<ReadOnlyPerson> allPersons = addressBook.getAllPersons().immutableListView();
return new CommandResult(getMessageForPersonListShownSummary(allPersons), allPersons);
}

public boolean isMutating() {
return false;
}

}
5 changes: 5 additions & 0 deletions src/seedu/addressbook/commands/ViewAllCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ public CommandResult execute() {
return new CommandResult(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX);
}
}

public boolean isMutating() {
return false;
}

}
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;
}
}
Loading